stm3210c_eval_lcd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. #include <rtthread.h>
  2. #include "stm3210c_eval_lcd.h"
  3. #include "stm32f10x.h"
  4. #include "stm32f10x_spi.h"
  5. #include <rtgui/rtgui.h>
  6. #include <rtgui/driver.h>
  7. #include <rtgui/rtgui_system.h>
  8. #include <rtgui/rtgui_server.h>
  9. #define START_BYTE 0x70
  10. #define SET_INDEX 0x00
  11. #define READ_STATUS 0x01
  12. #define LCD_WRITE_REG 0x02
  13. #define LCD_READ_REG 0x03
  14. void rt_hw_lcd_update(rtgui_rect_t *rect);
  15. rt_uint8_t * rt_hw_lcd_get_framebuffer(void);
  16. void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y);
  17. void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y);
  18. void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y);
  19. void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2);
  20. void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y);
  21. struct rtgui_graphic_driver _rtgui_lcd_driver =
  22. {
  23. "lcd",
  24. 2,
  25. 320,
  26. 240,
  27. rt_hw_lcd_update,
  28. rt_hw_lcd_get_framebuffer,
  29. rt_hw_lcd_set_pixel,
  30. rt_hw_lcd_get_pixel,
  31. rt_hw_lcd_draw_hline,
  32. rt_hw_lcd_draw_vline,
  33. rt_hw_lcd_draw_raw_hline
  34. };
  35. static void _delay_(__IO uint32_t nCount)
  36. {
  37. __IO uint32_t index = 0;
  38. for(index = (100000 * nCount); index != 0; index--)
  39. {}
  40. }
  41. /**
  42. * @brief Sets or reset LCD control lines.
  43. * @param GPIOx: where x can be B or D to select the GPIO peripheral.
  44. * @param CtrlPins: the Control line. This parameter can be:
  45. * @arg LCD_NCS_PIN: Chip Select pin
  46. * @param BitVal: specifies the value to be written to the selected bit.
  47. * This parameter can be:
  48. * @arg Bit_RESET: to clear the port pin
  49. * @arg Bit_SET: to set the port pin
  50. * @retval None
  51. */
  52. void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal)
  53. {
  54. /* Set or Reset the control line */
  55. GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
  56. }
  57. /**
  58. * @brief Reset LCD control line(/CS) and Send Start-Byte
  59. * @param Start_Byte: the Start-Byte to be sent
  60. * @retval None
  61. */
  62. void LCD_nCS_StartByte(uint8_t Start_Byte)
  63. {
  64. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
  65. SPI_I2S_SendData(LCD_SPI, Start_Byte);
  66. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  67. {}
  68. }
  69. /**
  70. * @brief Configures LCD control lines in Output Push-Pull mode.
  71. * @param None
  72. * @retval None
  73. */
  74. void LCD_CtrlLinesConfig(void)
  75. {
  76. GPIO_InitTypeDef GPIO_InitStructure;
  77. /* Enable GPIO clock */
  78. RCC_APB2PeriphClockCmd(LCD_NCS_GPIO_CLK, ENABLE);
  79. /* Configure NCS in Output Push-Pull mode */
  80. GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
  81. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  82. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  83. GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
  84. }
  85. /**
  86. * @brief Writes index to select the LCD register.
  87. * @param LCD_Reg: address of the selected register.
  88. * @retval None
  89. */
  90. void LCD_WriteRegIndex(uint8_t LCD_Reg)
  91. {
  92. /* Reset LCD control line(/CS) and Send Start-Byte */
  93. LCD_nCS_StartByte(START_BYTE | SET_INDEX);
  94. /* Write 16-bit Reg Index (High Byte is 0) */
  95. SPI_I2S_SendData(LCD_SPI, 0x00);
  96. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  97. {}
  98. SPI_I2S_SendData(LCD_SPI, LCD_Reg);
  99. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  100. {}
  101. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  102. }
  103. /**
  104. * @brief Reads the selected LCD Register.
  105. * @param None
  106. * @retval LCD Register Value.
  107. */
  108. uint16_t LCD_ReadReg(uint8_t LCD_Reg)
  109. {
  110. uint16_t tmp = 0;
  111. uint8_t i = 0;
  112. /* LCD_SPI prescaler: 4 */
  113. LCD_SPI->CR1 &= 0xFFC7;
  114. LCD_SPI->CR1 |= 0x0008;
  115. /* Write 16-bit Index (then Read Reg) */
  116. LCD_WriteRegIndex(LCD_Reg);
  117. /* Read 16-bit Reg */
  118. /* Reset LCD control line(/CS) and Send Start-Byte */
  119. LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
  120. for(i = 0; i < 5; i++)
  121. {
  122. SPI_I2S_SendData(LCD_SPI, 0xFF);
  123. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  124. {}
  125. /* One byte of invalid dummy data read after the start byte */
  126. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
  127. {}
  128. SPI_I2S_ReceiveData(LCD_SPI);
  129. }
  130. SPI_I2S_SendData(LCD_SPI, 0xFF);
  131. /* Read upper byte */
  132. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  133. {}
  134. /* Read lower byte */
  135. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
  136. {}
  137. tmp = SPI_I2S_ReceiveData(LCD_SPI);
  138. SPI_I2S_SendData(LCD_SPI, 0xFF);
  139. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  140. {}
  141. /* Read lower byte */
  142. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
  143. {}
  144. tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(LCD_SPI);
  145. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  146. /* LCD_SPI prescaler: 2 */
  147. LCD_SPI->CR1 &= 0xFFC7;
  148. return tmp;
  149. }
  150. /**
  151. * @brief Writes to the selected LCD register.
  152. * @param LCD_Reg: address of the selected register.
  153. * @param LCD_RegValue: value to write to the selected register.
  154. * @retval None
  155. */
  156. void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
  157. {
  158. /* Write 16-bit Index (then Write Reg) */
  159. LCD_WriteRegIndex(LCD_Reg);
  160. /* Write 16-bit Reg */
  161. /* Reset LCD control line(/CS) and Send Start-Byte */
  162. LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
  163. SPI_I2S_SendData(LCD_SPI, LCD_RegValue>>8);
  164. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  165. {}
  166. SPI_I2S_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
  167. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  168. {}
  169. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  170. }
  171. /**
  172. * @brief Writes to the LCD RAM.
  173. * @param RGB_Code: the pixel color in RGB mode (5-6-5).
  174. * @retval None
  175. */
  176. void LCD_WriteRAM(uint16_t RGB_Code)
  177. {
  178. SPI_I2S_SendData(LCD_SPI, RGB_Code >> 8);
  179. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  180. {}
  181. SPI_I2S_SendData(LCD_SPI, RGB_Code & 0xFF);
  182. while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  183. {}
  184. }
  185. /**
  186. * @brief Prepare to write to the LCD RAM.
  187. * @param None
  188. * @retval None
  189. */
  190. void LCD_WriteRAM_Prepare(void)
  191. {
  192. LCD_WriteRegIndex(R34); /* Select GRAM Reg */
  193. /* Reset LCD control line(/CS) and Send Start-Byte */
  194. LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
  195. }
  196. /**
  197. * @brief Writes 1 word to the LCD RAM.
  198. * @param RGB_Code: the pixel color in RGB mode (5-6-5).
  199. * @retval None
  200. */
  201. void LCD_WriteRAMWord(uint16_t RGB_Code)
  202. {
  203. LCD_WriteRAM_Prepare();
  204. LCD_WriteRAM(RGB_Code);
  205. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  206. }
  207. /**
  208. * @brief Power on the LCD.
  209. * @param None
  210. * @retval None
  211. */
  212. void LCD_PowerOn(void)
  213. {
  214. /* Power On sequence ---------------------------------------------------------*/
  215. LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  216. LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  217. LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  218. LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  219. _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
  220. LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  221. LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  222. _delay_(5); /* Delay 50 ms */
  223. LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  224. _delay_(5); /* delay 50 ms */
  225. LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  226. LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  227. _delay_(5); /* delay 50 ms */
  228. LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
  229. }
  230. /**
  231. * @brief Enables the Display.
  232. * @param None
  233. * @retval None
  234. */
  235. void LCD_DisplayOn(void)
  236. {
  237. /* Display On */
  238. LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
  239. }
  240. /**
  241. * @brief Disables the Display.
  242. * @param None
  243. * @retval None
  244. */
  245. void LCD_DisplayOff(void)
  246. {
  247. /* Display Off */
  248. LCD_WriteReg(R7, 0x0);
  249. }
  250. /**
  251. * @brief Configures the LCD_SPI interface.
  252. * @param None
  253. * @retval None
  254. */
  255. void LCD_SPIConfig(void)
  256. {
  257. SPI_InitTypeDef SPI_InitStructure;
  258. GPIO_InitTypeDef GPIO_InitStructure;
  259. /* Enable GPIO clock */
  260. RCC_APB2PeriphClockCmd(LCD_SPI_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
  261. GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
  262. /* Enable SPI clock */
  263. RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
  264. /* Configure SPI pins: SCK, MISO and MOSI */
  265. GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN | LCD_SPI_MISO_PIN | LCD_SPI_MOSI_PIN;
  266. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  267. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  268. GPIO_Init(LCD_SPI_GPIO_PORT, &GPIO_InitStructure);
  269. SPI_I2S_DeInit(LCD_SPI);
  270. /* SPI Config */
  271. SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  272. SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  273. SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  274. SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  275. SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  276. SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  277. SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
  278. SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  279. SPI_Init(LCD_SPI, &SPI_InitStructure);
  280. /* SPI enable */
  281. SPI_Cmd(LCD_SPI, ENABLE);
  282. }
  283. /**
  284. * @brief Setups the LCD.
  285. * @param None
  286. * @retval None
  287. */
  288. void LCD_Setup(void)
  289. {
  290. /* Configure the LCD Control pins --------------------------------------------*/
  291. LCD_CtrlLinesConfig();
  292. /* Configure the LCD_SPI interface ----------------------------------------------*/
  293. LCD_SPIConfig();
  294. _delay_(5); /* Delay 50 ms */
  295. /* Start Initial Sequence ------------------------------------------------*/
  296. LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */
  297. LCD_WriteReg(R0, 0x0001); /* Start internal OSC. */
  298. LCD_WriteReg(R1, 0x0100); /* set SS and SM bit */
  299. LCD_WriteReg(R2, 0x0700); /* set 1 line inversion */
  300. LCD_WriteReg(R3, 0x1030); /* set GRAM write direction and BGR=1. */
  301. LCD_WriteReg(R4, 0x0000); /* Resize register */
  302. LCD_WriteReg(R8, 0x0202); /* set the back porch and front porch */
  303. LCD_WriteReg(R9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
  304. LCD_WriteReg(R10, 0x0000); /* FMARK function */
  305. LCD_WriteReg(R12, 0x0000); /* RGB interface setting */
  306. LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
  307. LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */
  308. /* Power On sequence -----------------------------------------------------*/
  309. LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  310. LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  311. LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  312. LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  313. _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
  314. LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  315. LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  316. _delay_(5); /* Delay 50 ms */
  317. LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  318. _delay_(5); /* Delay 50 ms */
  319. LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  320. LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  321. _delay_(5); /* Delay 50 ms */
  322. LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
  323. LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */
  324. /* Adjust the Gamma Curve ------------------------------------------------*/
  325. LCD_WriteReg(R48, 0x0006);
  326. LCD_WriteReg(R49, 0x0101);
  327. LCD_WriteReg(R50, 0x0003);
  328. LCD_WriteReg(R53, 0x0106);
  329. LCD_WriteReg(R54, 0x0b02);
  330. LCD_WriteReg(R55, 0x0302);
  331. LCD_WriteReg(R56, 0x0707);
  332. LCD_WriteReg(R57, 0x0007);
  333. LCD_WriteReg(R60, 0x0600);
  334. LCD_WriteReg(R61, 0x020b);
  335. /* Set GRAM area ---------------------------------------------------------*/
  336. LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
  337. LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
  338. LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
  339. LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */
  340. LCD_WriteReg(R96, 0xa700); /* Gate Scan Line */
  341. LCD_WriteReg(R97, 0x0001); /* NDL,VLE, REV */
  342. LCD_WriteReg(R106, 0x0000); /* set scrolling line */
  343. /* Partial Display Control -----------------------------------------------*/
  344. LCD_WriteReg(R128, 0x0000);
  345. LCD_WriteReg(R129, 0x0000);
  346. LCD_WriteReg(R130, 0x0000);
  347. LCD_WriteReg(R131, 0x0000);
  348. LCD_WriteReg(R132, 0x0000);
  349. LCD_WriteReg(R133, 0x0000);
  350. /* Panel Control ---------------------------------------------------------*/
  351. LCD_WriteReg(R144, 0x0010);
  352. LCD_WriteReg(R146, 0x0000);
  353. LCD_WriteReg(R147, 0x0003);
  354. LCD_WriteReg(R149, 0x0110);
  355. LCD_WriteReg(R151, 0x0000);
  356. LCD_WriteReg(R152, 0x0000);
  357. /* Set GRAM write direction and BGR = 1 */
  358. /* I/D=01 (Horizontal : increment, Vertical : decrement) */
  359. /* AM=1 (address is updated in vertical writing direction) */
  360. LCD_WriteReg(R3, 0x1018);
  361. LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
  362. }
  363. /**
  364. * @brief Sets the cursor position.
  365. * @param Xpos: specifies the X position.
  366. * @param Ypos: specifies the Y position.
  367. * @retval None
  368. */
  369. void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
  370. {
  371. LCD_WriteReg(R32, Xpos);
  372. LCD_WriteReg(R33, Ypos);
  373. }
  374. void rt_hw_lcd_update(rtgui_rect_t *rect)
  375. {
  376. /* nothing for none-DMA mode driver */
  377. }
  378. rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
  379. {
  380. return RT_NULL; /* no framebuffer driver */
  381. }
  382. void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
  383. {
  384. unsigned short p;
  385. /* get color pixel */
  386. p = rtgui_color_to_565p(*c);
  387. /* set x and y */
  388. LCD_SetCursor(y, 319 - x);
  389. LCD_WriteRAMWord(p);
  390. }
  391. void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
  392. {
  393. // unsigned short p;
  394. /* set x and y */
  395. LCD_SetCursor(y, 319 - x);
  396. *c = rtgui_color_from_565p(0xffff);
  397. }
  398. void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
  399. {
  400. unsigned short p;
  401. /* get color pixel */
  402. p = rtgui_color_to_565p(*c);
  403. LCD_SetCursor(y, 319 - x1);
  404. LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
  405. while (x1 < x2)
  406. {
  407. LCD_WriteRAM(p);
  408. x1 ++;
  409. }
  410. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  411. }
  412. void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
  413. {
  414. unsigned short p;
  415. /* get color pixel */
  416. p = rtgui_color_to_565p(*c);
  417. LCD_SetCursor(y1, 319 - x);
  418. while (y1 < y2)
  419. {
  420. LCD_WriteRAMWord(p);
  421. y1++;
  422. LCD_SetCursor(y1, 319 - x);
  423. }
  424. }
  425. void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
  426. {
  427. rt_uint16_t *ptr;
  428. /* get pixel */
  429. ptr = (rt_uint16_t*) pixels;
  430. LCD_SetCursor(y, 319 - x1);
  431. LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
  432. while (x1 < x2)
  433. {
  434. LCD_WriteRAM(*ptr);
  435. x1 ++; ptr ++;
  436. }
  437. LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  438. }
  439. rt_err_t rt_hw_lcd_init(void)
  440. {
  441. LCD_Setup();
  442. /* add lcd driver into graphic driver */
  443. rtgui_graphic_driver_add(&_rtgui_lcd_driver);
  444. return RT_EOK;
  445. }
  446. void stm3210c_rtgui_init()
  447. {
  448. rtgui_rect_t rect;
  449. rtgui_system_server_init();
  450. /* register dock panel */
  451. rect.x1 = 0;
  452. rect.y1 = 0;
  453. rect.x2 = 320;
  454. rect.y2 = 25;
  455. rtgui_panel_register("info", &rect);
  456. /* register main panel */
  457. rect.x1 = 0;
  458. rect.y1 = 25;
  459. rect.x2 = 320;
  460. rect.y2 = 240;
  461. rtgui_panel_register("main", &rect);
  462. rtgui_panel_set_default_focused("main");
  463. rt_hw_lcd_init();
  464. info_init();
  465. today_init();
  466. }
  467. #include <finsh.h>
  468. void hline(rt_base_t x1, rt_base_t x2, rt_base_t y, rt_uint32_t pixel)
  469. {
  470. rt_hw_lcd_draw_hline(&pixel, x1, x2, y);
  471. }
  472. FINSH_FUNCTION_EXPORT(hline, draw a hline);
  473. void vline(int x, int y1, int y2, rt_uint32_t pixel)
  474. {
  475. rt_hw_lcd_draw_vline(&pixel, x, y1, y2);
  476. }
  477. FINSH_FUNCTION_EXPORT(vline, draw a vline);
  478. void cls(rt_uint32_t c)
  479. {
  480. rt_size_t index;
  481. for(index = 0; index < 240; index ++)
  482. rt_hw_lcd_draw_hline(&c, 0, 320, index);
  483. }
  484. FINSH_FUNCTION_EXPORT(cls, clear screen);