tftspi.c
Go to the documentation of this file.00001
00018 #include "em_device.h"
00019 #include "em_usart.h"
00020 #include "em_gpio.h"
00021 #include "em_cmu.h"
00022 #include "tftspi.h"
00023
00025 static const USART_InitSync_TypeDef inittft =
00026 { usartEnable,
00027 48000000,
00028 1000000,
00029 usartDatabits9,
00030 true,
00031 true,
00032 usartClockMode3,
00033 false,
00034 usartPrsRxCh0,
00035 false };
00036
00037
00038
00045 void SPI_TFT_Init(void)
00046 {
00047
00048 CMU_ClockEnable(cmuClock_HFPER, true);
00049 CMU_ClockEnable(cmuClock_USART1, true);
00050 CMU_ClockEnable(cmuClock_GPIO, true);
00051
00052
00053 GPIO_PinModeSet(gpioPortD, 0, gpioModePushPull, 0);
00054 GPIO_PinModeSet(gpioPortD, 1, gpioModeInput, 0);
00055 GPIO_PinModeSet(gpioPortD, 2, gpioModePushPull, 0);
00056 GPIO_PinModeSet(gpioPortD, 3, gpioModePushPull, 1);
00057
00058
00059 USART_Reset(USART1);
00060
00061
00062 USART_InitSync(USART1, &inittft);
00063
00064 USART1->ROUTE =
00065 USART_ROUTE_TXPEN |
00066 USART_ROUTE_RXPEN |
00067 USART_ROUTE_CLKPEN |
00068 USART_ROUTE_LOCATION_LOC1;
00069 }
00070
00071
00072
00082 void SPI_TFT_WriteRegister(uint8_t reg, uint16_t data)
00083 {
00084
00085 GPIO_PinOutClear(gpioPortD, 3);
00086
00087
00088 USART1->CTRL = USART1->CTRL & ~USART_CTRL_BIT8DV;
00089
00090 USART_Tx(USART1, reg & 0xFF);
00091 USART_Rx(USART1);
00092
00093
00094 USART1->CTRL = USART1->CTRL | USART_CTRL_BIT8DV;
00095 USART_Tx(USART1, (data & 0xff00) >> 8);
00096 USART_Rx(USART1);
00097 USART_Tx(USART1, (data & 0x00ff));
00098 USART_Rx(USART1);
00099
00100
00101 GPIO_PinOutSet(gpioPortD, 3);
00102 }