drv_lcd_dsi.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-01-10 zylx first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <board.h>
  13. #ifdef BSP_USING_DSI
  14. #include <lcd_port_dsi.h>
  15. #include <string.h>
  16. #include "drv_gpio.h"
  17. #include "gfxmmu_lut_390x390_24bpp.h"
  18. #define DRV_DEBUG
  19. #define LOG_TAG "drv.lcd"
  20. #include <drv_log.h>
  21. static DSI_HandleTypeDef DsiHandle;
  22. struct drv_lcd_dsi_device
  23. {
  24. struct rt_device parent;
  25. struct rt_device_graphic_info lcd_info;
  26. struct rt_semaphore lcd_lock;
  27. rt_uint8_t *front_buf;
  28. };
  29. struct drv_lcd_dsi_device _lcd;
  30. static DMA2D_HandleTypeDef Dma2dHandle;
  31. static void CopyInVirtualBuffer(uint32_t *pSrc, uint32_t *pDst, uint16_t x, uint16_t y, uint16_t xsize, uint16_t ysize)
  32. {
  33. uint32_t destination = (uint32_t)pDst + (y * 390 + x) * 4;
  34. uint32_t source = (uint32_t)pSrc;
  35. Dma2dHandle.Instance = DMA2D;
  36. /*##-1- Configure the DMA2D Mode, Color Mode and output offset #############*/
  37. Dma2dHandle.Init.Mode = DMA2D_M2M_PFC;
  38. Dma2dHandle.Init.ColorMode = DMA2D_OUTPUT_RGB888;
  39. Dma2dHandle.Init.OutputOffset = 1024 - 390;
  40. /* No Output Alpha Inversion */
  41. Dma2dHandle.Init.AlphaInverted = DMA2D_REGULAR_ALPHA;
  42. /* No Output Red & Blue swap */
  43. Dma2dHandle.Init.RedBlueSwap = DMA2D_RB_REGULAR;
  44. /* Regular output byte order */
  45. Dma2dHandle.Init.BytesSwap = DMA2D_BYTES_REGULAR;
  46. /* Pixel mode */
  47. Dma2dHandle.Init.LineOffsetMode = DMA2D_LOM_PIXELS;
  48. /*##-2- Foreground Configuration ###########################################*/
  49. Dma2dHandle.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
  50. Dma2dHandle.LayerCfg[1].InputOffset = 0;
  51. Dma2dHandle.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
  52. /* Not used */
  53. Dma2dHandle.LayerCfg[1].InputAlpha = 0xFF;
  54. /* No ForeGround Red/Blue swap */
  55. Dma2dHandle.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR;
  56. /* No ForeGround Alpha inversion */
  57. Dma2dHandle.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA;
  58. /* DMA2D Initialization */
  59. if (HAL_DMA2D_Init(&Dma2dHandle) == HAL_OK)
  60. {
  61. if (HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) == HAL_OK)
  62. {
  63. if (HAL_DMA2D_Start(&Dma2dHandle, source, destination, xsize, ysize) == HAL_OK)
  64. {
  65. /* Polling For DMA transfer */
  66. HAL_DMA2D_PollForTransfer(&Dma2dHandle, 100);
  67. }
  68. }
  69. }
  70. }
  71. static rt_err_t drv_lcd_init(struct rt_device *device)
  72. {
  73. struct drv_lcd_dsi_device *lcd = (struct drv_lcd_dsi_device *)device;
  74. /* nothing, right now */
  75. lcd = lcd;
  76. return RT_EOK;
  77. }
  78. static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
  79. {
  80. struct drv_lcd_dsi_device *lcd = (struct drv_lcd_dsi_device *)device;
  81. rt_uint8_t color = 0;
  82. switch (cmd)
  83. {
  84. case RTGRAPHIC_CTRL_RECT_UPDATE:
  85. {
  86. /* update */
  87. rt_sem_take(&_lcd.lcd_lock, RT_TICK_PER_SECOND / 20);
  88. CopyInVirtualBuffer((uint32_t *)_lcd.lcd_info.framebuffer, (uint32_t *)LAYER_ADDRESS, 0, 0, 390, 390);
  89. HAL_DSI_Refresh(&DsiHandle);
  90. }
  91. break;
  92. case RTGRAPHIC_CTRL_GET_INFO:
  93. {
  94. struct rt_device_graphic_info *info = (struct rt_device_graphic_info *)args;
  95. RT_ASSERT(info != RT_NULL);
  96. info->pixel_format = lcd->lcd_info.pixel_format;
  97. info->bits_per_pixel = 32;
  98. info->width = lcd->lcd_info.width;
  99. info->height = lcd->lcd_info.height;
  100. info->framebuffer = lcd->lcd_info.framebuffer;
  101. }
  102. break;
  103. }
  104. return RT_EOK;
  105. }
  106. LTDC_HandleTypeDef LtdcHandle;
  107. rt_err_t stm32_lcd_init(struct drv_lcd_dsi_device *lcd)
  108. {
  109. DSI_PLLInitTypeDef dsiPllInit = {0};
  110. DSI_PHY_TimerTypeDef PhyTimings = {0};
  111. DSI_HOST_TimeoutTypeDef HostTimeouts = {0};
  112. DSI_LPCmdTypeDef LPCmd = {0};
  113. DSI_CmdCfgTypeDef CmdCfg = {0};
  114. GFXMMU_HandleTypeDef GfxmmuHandle = {0};
  115. LTDC_LayerCfgTypeDef LayerCfg = {0};
  116. /* GFXMMU CONFIGURATION */
  117. __HAL_GFXMMU_RESET_HANDLE_STATE(&GfxmmuHandle);
  118. GfxmmuHandle.Instance = GFXMMU;
  119. GfxmmuHandle.Init.BlocksPerLine = GFXMMU_192BLOCKS;
  120. GfxmmuHandle.Init.DefaultValue = 0xFFFFFFFF;
  121. GfxmmuHandle.Init.Buffers.Buf0Address = (uint32_t)lcd->front_buf;
  122. GfxmmuHandle.Init.Buffers.Buf1Address = 0;
  123. GfxmmuHandle.Init.Buffers.Buf2Address = 0;
  124. GfxmmuHandle.Init.Buffers.Buf3Address = 0;
  125. GfxmmuHandle.Init.Interrupts.Activation = DISABLE;
  126. GfxmmuHandle.Init.Interrupts.UsedInterrupts = GFXMMU_AHB_MASTER_ERROR_IT;
  127. if (HAL_OK != HAL_GFXMMU_Init(&GfxmmuHandle))
  128. {
  129. return -RT_ERROR;
  130. }
  131. /* Initialize LUT */
  132. if (HAL_OK != HAL_GFXMMU_ConfigLut(&GfxmmuHandle, 0, 390, (uint32_t) gfxmmu_lut_config_rgb888))
  133. {
  134. return -RT_ERROR;
  135. }
  136. /* Disable non visible lines : from line 390 to 1023 (634 lines) */
  137. if (HAL_OK != HAL_GFXMMU_DisableLutLines(&GfxmmuHandle, 390, 634))
  138. {
  139. return -RT_ERROR;
  140. }
  141. /**********************/
  142. /* LTDC CONFIGURATION */
  143. /**********************/
  144. /* LTDC initialization */
  145. __HAL_LTDC_RESET_HANDLE_STATE(&LtdcHandle);
  146. LtdcHandle.Instance = LTDC;
  147. LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
  148. LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL;
  149. LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
  150. LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
  151. /* HSYNC width - 1 */
  152. LtdcHandle.Init.HorizontalSync = 0;
  153. /* VSYNC width - 1 */
  154. LtdcHandle.Init.VerticalSync = 0;
  155. /* HSYNC width + HBP - 1 */
  156. LtdcHandle.Init.AccumulatedHBP = 1;
  157. /* VSYNC width + VBP - 1 */
  158. LtdcHandle.Init.AccumulatedVBP = 1;
  159. /* HSYNC width + HBP + Active width - 1 */
  160. LtdcHandle.Init.AccumulatedActiveW = 391;
  161. /* VSYNC width + VBP + Active height - 1 */
  162. LtdcHandle.Init.AccumulatedActiveH = 391;
  163. /* HSYNC width + HBP + Active width + HFP - 1 */
  164. LtdcHandle.Init.TotalWidth = 392;
  165. /* VSYNC width + VBP + Active height + VFP - 1 */
  166. LtdcHandle.Init.TotalHeigh = 392;
  167. LtdcHandle.Init.Backcolor.Red = 0;
  168. LtdcHandle.Init.Backcolor.Green = 0;
  169. LtdcHandle.Init.Backcolor.Blue = 0;
  170. LtdcHandle.Init.Backcolor.Reserved = 0xFF;
  171. if (HAL_LTDC_Init(&LtdcHandle) != HAL_OK)
  172. {
  173. return -RT_ERROR;
  174. }
  175. /* LTDC layer 1 configuration */
  176. LayerCfg.WindowX0 = 0;
  177. LayerCfg.WindowX1 = 390;
  178. LayerCfg.WindowY0 = 0;
  179. LayerCfg.WindowY1 = 390;
  180. LayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888;
  181. LayerCfg.Alpha = 0xFF;
  182. LayerCfg.Alpha0 = 0;
  183. LayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  184. LayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
  185. LayerCfg.FBStartAdress = LAYER_ADDRESS;
  186. /* virtual frame buffer contains 768 pixels per line for 24bpp */
  187. /* (192 blocs * 16) / (24bpp/3) = 1024 pixels per ligne */
  188. LayerCfg.ImageWidth = 1024;
  189. LayerCfg.ImageHeight = 390;
  190. LayerCfg.Backcolor.Red = 0;
  191. LayerCfg.Backcolor.Green = 0;
  192. LayerCfg.Backcolor.Blue = 0;
  193. LayerCfg.Backcolor.Reserved = 0xFF;
  194. if (HAL_LTDC_ConfigLayer(&LtdcHandle, &LayerCfg, LTDC_LAYER_1) != HAL_OK)
  195. {
  196. return -RT_ERROR;
  197. }
  198. /*********************/
  199. /* DSI CONFIGURATION */
  200. /*********************/
  201. /* DSI initialization */
  202. __HAL_DSI_RESET_HANDLE_STATE(&DsiHandle);
  203. DsiHandle.Instance = DSI;
  204. DsiHandle.Init.AutomaticClockLaneControl = DSI_AUTO_CLK_LANE_CTRL_DISABLE;
  205. /* We have 1 data lane at 500Mbps => lane byte clock at 500/8 = 62,5 MHZ */
  206. /* We want TX escape clock at arround 20MHz and under 20MHz so clock division is set to 4 */
  207. DsiHandle.Init.TXEscapeCkdiv = 4;
  208. DsiHandle.Init.NumberOfLanes = DSI_ONE_DATA_LANE;
  209. /* We have HSE value at 16 Mhz and we want data lane at 500Mbps */
  210. dsiPllInit.PLLNDIV = 20;
  211. dsiPllInit.PLLIDF = DSI_PLL_IN_DIV1;
  212. dsiPllInit.PLLODF = DSI_PLL_OUT_DIV2;
  213. if (HAL_DSI_Init(&DsiHandle, &dsiPllInit) != HAL_OK)
  214. {
  215. return -RT_ERROR;
  216. }
  217. /* Tclk-post + Tclk-trail + Ths-exit = [(60ns + 52xUI) + (60ns) + (300ns)]/16ns */
  218. PhyTimings.ClockLaneHS2LPTime = 33;
  219. /* Tlpx + (Tclk-prepare + Tclk-zero) + Tclk-pre = [150ns + 300ns + 8xUI]/16ns */
  220. PhyTimings.ClockLaneLP2HSTime = 30;
  221. /* Ths-trail + Ths-exit = [(60ns + 4xUI) + 100ns]/16ns */
  222. PhyTimings.DataLaneHS2LPTime = 11;
  223. /* Tlpx + (Ths-prepare + Ths-zero) + Ths-sync = [150ns + (145ns + 10xUI) + 8xUI]/16ns */
  224. PhyTimings.DataLaneLP2HSTime = 21;
  225. PhyTimings.DataLaneMaxReadTime = 0;
  226. PhyTimings.StopWaitTime = 7;
  227. if (HAL_DSI_ConfigPhyTimer(&DsiHandle, &PhyTimings) != HAL_OK)
  228. {
  229. return -RT_ERROR;
  230. }
  231. HostTimeouts.TimeoutCkdiv = 1;
  232. HostTimeouts.HighSpeedTransmissionTimeout = 0;
  233. HostTimeouts.LowPowerReceptionTimeout = 0;
  234. HostTimeouts.HighSpeedReadTimeout = 0;
  235. HostTimeouts.LowPowerReadTimeout = 0;
  236. HostTimeouts.HighSpeedWriteTimeout = 0;
  237. HostTimeouts.HighSpeedWritePrespMode = 0;
  238. HostTimeouts.LowPowerWriteTimeout = 0;
  239. HostTimeouts.BTATimeout = 0;
  240. if (HAL_DSI_ConfigHostTimeouts(&DsiHandle, &HostTimeouts) != HAL_OK)
  241. {
  242. return -RT_ERROR;
  243. }
  244. LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_ENABLE;
  245. LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_ENABLE;
  246. LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_ENABLE;
  247. LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_ENABLE;
  248. LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_ENABLE;
  249. LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_ENABLE;
  250. LPCmd.LPGenLongWrite = DSI_LP_GLW_DISABLE;
  251. LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_ENABLE;
  252. LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_ENABLE;
  253. LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_ENABLE;
  254. LPCmd.LPDcsLongWrite = DSI_LP_DLW_DISABLE;
  255. LPCmd.LPMaxReadPacket = DSI_LP_MRDP_DISABLE;
  256. LPCmd.AcknowledgeRequest = DSI_ACKNOWLEDGE_DISABLE;
  257. if (HAL_DSI_ConfigCommand(&DsiHandle, &LPCmd) != HAL_OK)
  258. {
  259. return -RT_ERROR;
  260. }
  261. CmdCfg.VirtualChannelID = 0;
  262. #if LCD_BITS_PER_PIXEL == 16
  263. CmdCfg.ColorCoding = DSI_RGB565;
  264. #else
  265. CmdCfg.ColorCoding = DSI_RGB888;
  266. #endif
  267. CmdCfg.CommandSize = 390;
  268. CmdCfg.TearingEffectSource = DSI_TE_DSILINK;
  269. CmdCfg.TearingEffectPolarity = DSI_TE_FALLING_EDGE;
  270. CmdCfg.HSPolarity = DSI_HSYNC_ACTIVE_LOW;
  271. CmdCfg.VSPolarity = DSI_VSYNC_ACTIVE_LOW;
  272. CmdCfg.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
  273. CmdCfg.VSyncPol = DSI_VSYNC_FALLING;
  274. CmdCfg.AutomaticRefresh = DSI_AR_ENABLE;
  275. CmdCfg.TEAcknowledgeRequest = DSI_TE_ACKNOWLEDGE_ENABLE;
  276. if (HAL_DSI_ConfigAdaptedCommandMode(&DsiHandle, &CmdCfg) != HAL_OK)
  277. {
  278. return -RT_ERROR;
  279. }
  280. /* Disable the Tearing Effect interrupt activated by default on previous function */
  281. __HAL_DSI_DISABLE_IT(&DsiHandle, DSI_IT_TE);
  282. if (HAL_DSI_ConfigFlowControl(&DsiHandle, DSI_FLOW_CONTROL_BTA) != HAL_OK)
  283. {
  284. return -RT_ERROR;
  285. }
  286. /* Enable DSI */
  287. __HAL_DSI_ENABLE(&DsiHandle);
  288. /*************************/
  289. /* LCD POWER ON SEQUENCE */
  290. /*************************/
  291. /* Step 1 */
  292. /* Go to command 2 */
  293. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x01);
  294. /* IC Frame rate control, set power, sw mapping, mux swithc timing command */
  295. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x06, 0x62);
  296. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0E, 0x80);
  297. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0F, 0x80);
  298. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x10, 0x71);
  299. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x13, 0x81);
  300. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x14, 0x81);
  301. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x15, 0x82);
  302. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x16, 0x82);
  303. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x18, 0x88);
  304. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x19, 0x55);
  305. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1A, 0x10);
  306. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1C, 0x99);
  307. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1D, 0x03);
  308. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1E, 0x03);
  309. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1F, 0x03);
  310. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x20, 0x03);
  311. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x25, 0x03);
  312. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x26, 0x8D);
  313. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2A, 0x03);
  314. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2B, 0x8D);
  315. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x36, 0x00);
  316. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x37, 0x10);
  317. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3A, 0x00);
  318. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3B, 0x00);
  319. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3D, 0x20);
  320. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3F, 0x3A);
  321. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x40, 0x30);
  322. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x41, 0x1A);
  323. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x42, 0x33);
  324. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x43, 0x22);
  325. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x44, 0x11);
  326. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x45, 0x66);
  327. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x46, 0x55);
  328. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x47, 0x44);
  329. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4C, 0x33);
  330. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4D, 0x22);
  331. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4E, 0x11);
  332. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x4F, 0x66);
  333. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x50, 0x55);
  334. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x51, 0x44);
  335. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x57, 0x33);
  336. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x6B, 0x1B);
  337. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x70, 0x55);
  338. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x74, 0x0C);
  339. /* Go to command 3 */
  340. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x02);
  341. /* Set the VGMP/VGSP coltage control */
  342. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9B, 0x40);
  343. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9C, 0x00);
  344. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9D, 0x20);
  345. /* Go to command 4 */
  346. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x03);
  347. /* Set the VGMP/VGSP coltage control */
  348. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9B, 0x40);
  349. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9C, 0x00);
  350. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x9D, 0x20);
  351. /* Go to command 5 */
  352. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x04);
  353. /* VSR command */
  354. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x5D, 0x10);
  355. /* VSR1 timing set */
  356. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x00, 0x8D);
  357. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x01, 0x00);
  358. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x02, 0x01);
  359. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x03, 0x01);
  360. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x04, 0x10);
  361. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x05, 0x01);
  362. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x06, 0xA7);
  363. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x07, 0x20);
  364. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x08, 0x00);
  365. /* VSR2 timing set */
  366. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x09, 0xC2);
  367. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0A, 0x00);
  368. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0B, 0x02);
  369. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0C, 0x01);
  370. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0D, 0x40);
  371. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0E, 0x06);
  372. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x0F, 0x01);
  373. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x10, 0xA7);
  374. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x11, 0x00);
  375. /* VSR3 timing set */
  376. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x12, 0xC2);
  377. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x13, 0x00);
  378. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x14, 0x02);
  379. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x15, 0x01);
  380. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x16, 0x40);
  381. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x17, 0x07);
  382. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x18, 0x01);
  383. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x19, 0xA7);
  384. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1A, 0x00);
  385. /* VSR4 timing set */
  386. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1B, 0x82);
  387. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1C, 0x00);
  388. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1D, 0xFF);
  389. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1E, 0x05);
  390. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x1F, 0x60);
  391. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x20, 0x02);
  392. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x21, 0x01);
  393. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x22, 0x7C);
  394. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x23, 0x00);
  395. /* VSR5 timing set */
  396. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x24, 0xC2);
  397. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x25, 0x00);
  398. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x26, 0x04);
  399. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x27, 0x02);
  400. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x28, 0x70);
  401. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x29, 0x05);
  402. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2A, 0x74);
  403. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2B, 0x8D);
  404. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2D, 0x00);
  405. /* VSR6 timing set */
  406. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2F, 0xC2);
  407. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x30, 0x00);
  408. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x31, 0x04);
  409. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x32, 0x02);
  410. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x33, 0x70);
  411. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x34, 0x07);
  412. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x35, 0x74);
  413. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x36, 0x8D);
  414. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x37, 0x00);
  415. /* VSR marping command */
  416. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x5E, 0x20);
  417. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x5F, 0x31);
  418. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x60, 0x54);
  419. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x61, 0x76);
  420. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x62, 0x98);
  421. /* Go to command 6 */
  422. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x05);
  423. /* Set the ELVSS voltage */
  424. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x05, 0x17);
  425. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x2A, 0x04);
  426. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x91, 0x00);
  427. /* Go back in standard commands */
  428. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xFE, 0x00);
  429. /* Set the Pixel format */
  430. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x3A, 0x07);
  431. /* Set tear off */
  432. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, DSI_SET_TEAR_OFF, 0x0);
  433. /* Set DSI mode to internal timing added vs ORIGINAL for Command mode */
  434. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0xC2, 0x0);
  435. /* Set memory address MODIFIED vs ORIGINAL */
  436. {
  437. uint8_t InitParam1[4] = {0x00, 0x04, 0x01, 0x89};
  438. uint8_t InitParam2[4] = {0x00, 0x00, 0x01, 0x85};
  439. HAL_DSI_LongWrite(&DsiHandle, 0, DSI_DCS_LONG_PKT_WRITE, 4, DSI_SET_COLUMN_ADDRESS, InitParam1);
  440. HAL_DSI_LongWrite(&DsiHandle, 0, DSI_DCS_LONG_PKT_WRITE, 4, DSI_SET_PAGE_ADDRESS, InitParam2);
  441. }
  442. /* Sleep out */
  443. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P0, DSI_EXIT_SLEEP_MODE, 0x0);
  444. HAL_Delay(120);
  445. /* Set default Brightness */
  446. HAL_DSI_ShortWrite(&DsiHandle, 0, DSI_DCS_SHORT_PKT_WRITE_P1, 0x51, BRIGHTNESS_NORMAL);
  447. /* Set display on */
  448. if (HAL_DSI_ShortWrite(&DsiHandle,
  449. 0,
  450. DSI_DCS_SHORT_PKT_WRITE_P0,
  451. DSI_SET_DISPLAY_ON,
  452. 0x0) != HAL_OK)
  453. {
  454. LOG_E("set display on failed");
  455. return -RT_ERROR;
  456. }
  457. /* Enable DSI Wrapper */
  458. __HAL_DSI_WRAPPER_ENABLE(&DsiHandle);
  459. /* NVIC configuration for DSI interrupt that is now enabled */
  460. HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
  461. HAL_NVIC_EnableIRQ(DSI_IRQn);
  462. HAL_DSI_Refresh(&DsiHandle);
  463. LOG_D("LCD init success");
  464. return RT_EOK;
  465. }
  466. #if defined(LCD_BACKLIGHT_USING_PWM)
  467. void turn_on_lcd_backlight(void)
  468. {
  469. struct rt_device_pwm *pwm_dev;
  470. /* turn on the LCD backlight */
  471. pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
  472. /* pwm frequency:100K = 10000ns */
  473. rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, 10000, 10000);
  474. rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
  475. }
  476. #elif defined(LCD_BACKLIGHT_USING_GPIO)
  477. void turn_on_lcd_backlight(void)
  478. {
  479. rt_pin_mode(LCD_BL_GPIO_NUM, PIN_MODE_OUTPUT);
  480. rt_pin_write(LCD_BL_GPIO_NUM, PIN_HIGH);
  481. }
  482. #endif
  483. void DSI_IRQHandler(void)
  484. {
  485. HAL_DSI_IRQHandler(&DsiHandle);
  486. }
  487. void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi)
  488. {
  489. rt_sem_release(&_lcd.lcd_lock);
  490. }
  491. #ifdef RT_USING_DEVICE_OPS
  492. const static struct rt_device_ops lcd_ops =
  493. {
  494. drv_lcd_init,
  495. RT_NULL,
  496. RT_NULL,
  497. RT_NULL,
  498. RT_NULL,
  499. drv_lcd_control
  500. };
  501. #endif
  502. int drv_lcd_hw_init(void)
  503. {
  504. rt_err_t result = RT_EOK;
  505. struct rt_device *device = &_lcd.parent;
  506. /* memset _lcd to zero */
  507. memset(&_lcd, 0x00, sizeof(_lcd));
  508. /* init lcd_lock semaphore */
  509. result = rt_sem_init(&_lcd.lcd_lock, "lcd_lock", 0, RT_IPC_FLAG_FIFO);
  510. if (result != RT_EOK)
  511. {
  512. LOG_E("init semaphore failed!\n");
  513. result = -RT_ENOMEM;
  514. goto __exit;
  515. }
  516. /* config LCD dev info */
  517. _lcd.lcd_info.height = LCD_HEIGHT;
  518. _lcd.lcd_info.width = LCD_WIDTH;
  519. _lcd.lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL;
  520. _lcd.lcd_info.pixel_format = LCD_PIXEL_FORMAT;
  521. /* malloc memory */
  522. _lcd.lcd_info.framebuffer = rt_malloc_align(LCD_DSI_BUF_SIZE, 16);
  523. _lcd.front_buf = rt_malloc_align(LCD_DSI_BUF_SIZE_ROUND, 16);
  524. if (_lcd.lcd_info.framebuffer == RT_NULL || _lcd.front_buf == RT_NULL)
  525. {
  526. LOG_E("init frame buffer failed!\n");
  527. result = -RT_ENOMEM;
  528. goto __exit;
  529. }
  530. /* memset buff to 0xFF */
  531. memset(_lcd.lcd_info.framebuffer, 0xFF, LCD_DSI_BUF_SIZE);
  532. memset(_lcd.front_buf, 0xFF, LCD_DSI_BUF_SIZE_ROUND);
  533. device->type = RT_Device_Class_Graphic;
  534. #ifdef RT_USING_DEVICE_OPS
  535. device->ops = &lcd_ops;
  536. #else
  537. device->init = drv_lcd_init;
  538. device->control = drv_lcd_control;
  539. #endif
  540. /* register lcd device */
  541. rt_device_register(device, "lcd_dsi", RT_DEVICE_FLAG_RDWR);
  542. /* init stm32 LTDC */
  543. if (stm32_lcd_init(&_lcd) != RT_EOK)
  544. {
  545. result = -RT_ERROR;
  546. goto __exit;
  547. }
  548. else
  549. {
  550. turn_on_lcd_backlight();
  551. }
  552. __exit:
  553. if (result != RT_EOK)
  554. {
  555. rt_sem_delete(&_lcd.lcd_lock);
  556. if (_lcd.lcd_info.framebuffer)
  557. {
  558. rt_free(_lcd.lcd_info.framebuffer);
  559. }
  560. if (_lcd.front_buf)
  561. {
  562. rt_free(_lcd.front_buf);
  563. }
  564. }
  565. return result;
  566. }
  567. INIT_DEVICE_EXPORT(drv_lcd_hw_init);
  568. #if defined(PKG_USING_GUIENGINE)
  569. #include <rtgui/driver.h>
  570. int graphic_device_init(void)
  571. {
  572. struct rt_device *device;
  573. device = rt_device_find("lcd_dsi");
  574. if (device)
  575. {
  576. rtgui_graphic_set_device(device);
  577. }
  578. return 0;
  579. }
  580. INIT_ENV_EXPORT(graphic_device_init);
  581. #endif
  582. #ifdef DRV_DEBUG
  583. #ifdef FINSH_USING_MSH
  584. int lcd_dsi_test()
  585. {
  586. struct drv_lcd_dsi_device *lcd;
  587. lcd = (struct drv_lcd_dsi_device *)rt_device_find("lcd_dsi");
  588. rt_uint8_t *ptr = lcd->lcd_info.framebuffer;
  589. while (1)
  590. {
  591. /* red */
  592. for (unsigned long long i = 0; i < LCD_DSI_BUF_SIZE/4; i++)
  593. {
  594. ptr[4 * i] = 0x00;
  595. ptr[4 * i + 1] = 0x00;
  596. ptr[4 * i + 2] = 0xFF;
  597. ptr[4 * i + 3] = 0xFF;
  598. }
  599. rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
  600. rt_thread_mdelay(1000);
  601. /* green */
  602. for (int i = 0; i < LCD_DSI_BUF_SIZE/4; i++)
  603. {
  604. ptr[4 * i] = 0x00;
  605. ptr[4 * i + 1] = 0xFF;
  606. ptr[4 * i + 2] = 0x00;
  607. ptr[4 * i + 3] = 0xFF;
  608. }
  609. rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
  610. rt_thread_mdelay(1000);
  611. /* blue */
  612. for (int i = 0; i < LCD_DSI_BUF_SIZE/4; i++)
  613. {
  614. ptr[4 * i] = 0xFF;
  615. ptr[4 * i + 1] = 0x00;
  616. ptr[4 * i + 2] = 0x00;
  617. ptr[4 * i + 3] = 0xFF;
  618. }
  619. rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
  620. rt_thread_mdelay(1000);
  621. }
  622. }
  623. MSH_CMD_EXPORT(lcd_dsi_test, lcd_dsi_test);
  624. //draw a line in screen
  625. void line()
  626. {
  627. struct drv_lcd_dsi_device *lcd;
  628. lcd = (struct drv_lcd_dsi_device *)rt_device_find("lcd_dsi");
  629. rt_uint8_t *ptr = lcd->lcd_info.framebuffer;
  630. /* red */
  631. for (unsigned long long i = LCD_DSI_BUF_SIZE/4/2; i <LCD_DSI_BUF_SIZE/4/2+390; i++)
  632. {
  633. ptr[4 * i] = 0x00;
  634. ptr[4 * i + 1] = 0x00;
  635. ptr[4 * i + 2] = 0xFF;
  636. ptr[4 * i + 3] = 0xFF;
  637. }
  638. rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
  639. }
  640. MSH_CMD_EXPORT(line, line);
  641. #endif /* FINSH_USING_MSH */
  642. #endif /* DRV_DEBUG */
  643. #endif /* BSP_USING_LCD */