stm3210c_eval_lcd.c 16 KB

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