tftspi.c
Go to the documentation of this file.00001
00036 #include "em_device.h"
00037 #include "em_usart.h"
00038 #include "em_gpio.h"
00039 #include "em_cmu.h"
00040 #include "tftspi.h"
00041
00043 static const USART_InitSync_TypeDef inittft =
00044 { usartEnable,
00045 48000000,
00046 1000000,
00047 usartDatabits9,
00048 true,
00049 true,
00050 usartClockMode3,
00051 false,
00052 usartPrsRxCh0,
00053 false };
00054
00055
00056
00063 void SPI_TFT_Init(void)
00064 {
00065
00066 CMU_ClockEnable(cmuClock_HFPER, true);
00067 CMU_ClockEnable(cmuClock_USART1, true);
00068 CMU_ClockEnable(cmuClock_GPIO, true);
00069
00070
00071 GPIO_PinModeSet(gpioPortD, 0, gpioModePushPull, 0);
00072 GPIO_PinModeSet(gpioPortD, 1, gpioModeInput, 0);
00073 GPIO_PinModeSet(gpioPortD, 2, gpioModePushPull, 0);
00074 GPIO_PinModeSet(gpioPortD, 3, gpioModePushPull, 1);
00075
00076
00077 USART_Reset(USART1);
00078
00079
00080 USART_InitSync(USART1, &inittft);
00081
00082 USART1->ROUTE =
00083 USART_ROUTE_TXPEN |
00084 USART_ROUTE_RXPEN |
00085 USART_ROUTE_CLKPEN |
00086 USART_ROUTE_LOCATION_LOC1;
00087 }
00088
00089
00090
00100 void SPI_TFT_WriteRegister(uint8_t reg, uint16_t data)
00101 {
00102
00103 GPIO_PinOutClear(gpioPortD, 3);
00104
00105
00106 USART1->CTRL = USART1->CTRL & ~USART_CTRL_BIT8DV;
00107
00108 USART_Tx(USART1, reg & 0xFF);
00109 USART_Rx(USART1);
00110
00111
00112 USART1->CTRL = USART1->CTRL | USART_CTRL_BIT8DV;
00113 USART_Tx(USART1, (data & 0xff00) >> 8);
00114 USART_Rx(USART1);
00115 USART_Tx(USART1, (data & 0x00ff));
00116 USART_Rx(USART1);
00117
00118
00119 GPIO_PinOutSet(gpioPortD, 3);
00120 }