drv_otm8009a.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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-05-23 WillianChan first version
  9. */
  10. #include <board.h>
  11. #ifdef BSP_USING_LCD_OTM8009A
  12. extern DSI_HandleTypeDef hdsi;
  13. extern DSI_VidCfgTypeDef hdsi_video;
  14. const rt_uint8_t RDL01[] = {0x80, 0x09, 0x01, 0xFF};
  15. const rt_uint8_t RDL02[] = {0x80, 0x09, 0xFF};
  16. const rt_uint8_t RDL03[] = {0x00, 0x09, 0x0F, 0x0E, 0x07, 0x10, 0x0B, 0x0A, 0x04, 0x07, 0x0B, 0x08, 0x0F, 0x10, 0x0A, 0x01, 0xE1};
  17. const rt_uint8_t RDL04[] = {0x00, 0x09, 0x0F, 0x0E, 0x07, 0x10, 0x0B, 0x0A, 0x04, 0x07, 0x0B, 0x08, 0x0F, 0x10, 0x0A, 0x01, 0xE2};
  18. const rt_uint8_t RDL05[] = {0x79, 0x79, 0xD8};
  19. const rt_uint8_t RDL06[] = {0x00, 0x01, 0xB3};
  20. const rt_uint8_t RDL07[] = {0x85, 0x01, 0x00, 0x84, 0x01, 0x00, 0xCE};
  21. const rt_uint8_t RDL08[] = {0x18, 0x04, 0x03, 0x39, 0x00, 0x00, 0x00, 0x18, 0x03, 0x03, 0x3A, 0x00, 0x00, 0x00, 0xCE};
  22. const rt_uint8_t RDL09[] = {0x18, 0x02, 0x03, 0x3B, 0x00, 0x00, 0x00, 0x18, 0x01, 0x03, 0x3C, 0x00, 0x00, 0x00, 0xCE};
  23. const rt_uint8_t RDL10[] = {0x01, 0x01, 0x20, 0x20, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0xCF};
  24. const rt_uint8_t RDL11[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB};
  25. const rt_uint8_t RDL12[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB};
  26. const rt_uint8_t RDL13[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB};
  27. const rt_uint8_t RDL14[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB};
  28. const rt_uint8_t RDL15[] = {0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB};
  29. const rt_uint8_t RDL16[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0xCB};
  30. const rt_uint8_t RDL17[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB};
  31. const rt_uint8_t RDL18[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xCB};
  32. const rt_uint8_t RDL19[] = {0x00, 0x26, 0x09, 0x0B, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00, 0xCC};
  33. const rt_uint8_t RDL20[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x0A, 0x0C, 0x02, 0xCC};
  34. const rt_uint8_t RDL21[] = {0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCC};
  35. const rt_uint8_t RDL22[] = {0x00, 0x25, 0x0C, 0x0A, 0x02, 0x26, 0x00, 0x00, 0x00, 0x00, 0xCC};
  36. const rt_uint8_t RDL23[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x0B, 0x09, 0x01, 0xCC};
  37. const rt_uint8_t RDL24[] = {0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCC};
  38. const rt_uint8_t RDL25[] = {0xFF, 0xFF, 0xFF, 0xFF};
  39. const rt_uint8_t RDL27[] = {0x00, 0x00, 0x03, 0x1F, 0x2A};
  40. const rt_uint8_t RDL28[] = {0x00, 0x00, 0x01, 0xDF, 0x2B};
  41. const rt_uint8_t RDS01[] = {0x00, 0x00};
  42. const rt_uint8_t RDS02[] = {0x00, 0x80};
  43. const rt_uint8_t RDS03[] = {0xC4, 0x30};
  44. const rt_uint8_t RDS04[] = {0x00, 0x8A};
  45. const rt_uint8_t RDS05[] = {0xC4, 0x40};
  46. const rt_uint8_t RDS06[] = {0x00, 0xB1};
  47. const rt_uint8_t RDS07[] = {0xC5, 0xA9};
  48. const rt_uint8_t RDS08[] = {0x00, 0x91};
  49. const rt_uint8_t RDS09[] = {0xC5, 0x34};
  50. const rt_uint8_t RDS10[] = {0x00, 0xB4};
  51. const rt_uint8_t RDS11[] = {0xC0, 0x50};
  52. const rt_uint8_t RDS12[] = {0xD9, 0x4E};
  53. const rt_uint8_t RDS13[] = {0x00, 0x81};
  54. const rt_uint8_t RDS14[] = {0xC1, 0x66};
  55. const rt_uint8_t RDS15[] = {0x00, 0xA1};
  56. const rt_uint8_t RDS16[] = {0xC1, 0x08};
  57. const rt_uint8_t RDS17[] = {0x00, 0x92};
  58. const rt_uint8_t RDS18[] = {0xC5, 0x01};
  59. const rt_uint8_t RDS19[] = {0x00, 0x95};
  60. const rt_uint8_t RDS20[] = {0x00, 0x94};
  61. const rt_uint8_t RDS21[] = {0xC5, 0x33};
  62. const rt_uint8_t RDS22[] = {0x00, 0xA3};
  63. const rt_uint8_t RDS23[] = {0xC0, 0x1B};
  64. const rt_uint8_t RDS24[] = {0x00, 0x82};
  65. const rt_uint8_t RDS25[] = {0xC5, 0x83};
  66. const rt_uint8_t RDS26[] = {0xC4, 0x83};
  67. const rt_uint8_t RDS27[] = {0xC1, 0x0E};
  68. const rt_uint8_t RDS28[] = {0x00, 0xA6};
  69. const rt_uint8_t RDS29[] = {0x00, 0xA0};
  70. const rt_uint8_t RDS30[] = {0x00, 0xB0};
  71. const rt_uint8_t RDS31[] = {0x00, 0xC0};
  72. const rt_uint8_t RDS32[] = {0x00, 0xD0};
  73. const rt_uint8_t RDS33[] = {0x00, 0x90};
  74. const rt_uint8_t RDS34[] = {0x00, 0xE0};
  75. const rt_uint8_t RDS35[] = {0x00, 0xF0};
  76. const rt_uint8_t RDS36[] = {0x11, 0x00};
  77. const rt_uint8_t RDS37[] = {0x3A, 0x55};
  78. const rt_uint8_t RDS38[] = {0x3A, 0x77};
  79. const rt_uint8_t RDS39[] = {0x36, 0x60};
  80. const rt_uint8_t RDS40[] = {0x51, 0x7F};
  81. const rt_uint8_t RDS41[] = {0x53, 0x2C};
  82. const rt_uint8_t RDS42[] = {0x55, 0x02};
  83. const rt_uint8_t RDS43[] = {0x5E, 0xFF};
  84. const rt_uint8_t RDS44[] = {0x29, 0x00};
  85. const rt_uint8_t RDS45[] = {0x2C, 0x00};
  86. const rt_uint8_t RDS46[] = {0xCF, 0x00};
  87. const rt_uint8_t RDS47[] = {0xC5, 0x66};
  88. const rt_uint8_t RDS48[] = {0x00, 0xB6};
  89. const rt_uint8_t RDS49[] = {0xF5, 0x06};
  90. const rt_uint8_t RDS50[] = {0x00, 0xB1};
  91. const rt_uint8_t RDS51[] = {0xC6, 0x06};
  92. void otm8009a_reset(void)
  93. {
  94. rt_pin_mode (GET_PIN(H, 7), PIN_MODE_OUTPUT);
  95. rt_pin_write(GET_PIN(H, 7), PIN_LOW);
  96. rt_thread_delay(rt_tick_from_millisecond(20));
  97. rt_pin_write(GET_PIN(H, 7), PIN_HIGH);
  98. rt_thread_delay(rt_tick_from_millisecond(20));
  99. }
  100. static void otm8009a_write_cmd(uint8_t *p, uint32_t num)
  101. {
  102. if (num <= 1)
  103. {
  104. HAL_DSI_ShortWrite(&hdsi, hdsi_video.VirtualChannelID, DSI_DCS_SHORT_PKT_WRITE_P1, p[0], p[1]);
  105. }
  106. else
  107. {
  108. HAL_DSI_LongWrite(&hdsi, hdsi_video.VirtualChannelID, DSI_DCS_LONG_PKT_WRITE, num, p[num], p);
  109. }
  110. }
  111. static void otm8009a_delay(uint32_t d)
  112. {
  113. rt_thread_delay(rt_tick_from_millisecond(d));
  114. }
  115. static void otm8009a_config(rt_uint32_t pixel_format)
  116. {
  117. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  118. otm8009a_write_cmd((rt_uint8_t *)RDL01, 3);
  119. otm8009a_write_cmd((rt_uint8_t *)RDS02, 0);
  120. otm8009a_write_cmd((rt_uint8_t *)RDL02, 2);
  121. otm8009a_write_cmd((rt_uint8_t *)RDS02, 0);
  122. otm8009a_write_cmd((rt_uint8_t *)RDS03, 0);
  123. otm8009a_delay(10);
  124. otm8009a_write_cmd((rt_uint8_t *)RDS04, 0);
  125. otm8009a_write_cmd((rt_uint8_t *)RDS05, 0);
  126. otm8009a_delay(10);
  127. otm8009a_write_cmd((rt_uint8_t *)RDS06, 0);
  128. otm8009a_write_cmd((rt_uint8_t *)RDS07, 0);
  129. otm8009a_write_cmd((rt_uint8_t *)RDS08, 0);
  130. otm8009a_write_cmd((rt_uint8_t *)RDS09, 0);
  131. otm8009a_write_cmd((rt_uint8_t *)RDS10, 0);
  132. otm8009a_write_cmd((rt_uint8_t *)RDS11, 0);
  133. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  134. otm8009a_write_cmd((rt_uint8_t *)RDS12, 0);
  135. otm8009a_write_cmd((rt_uint8_t *)RDS13, 0);
  136. otm8009a_write_cmd((rt_uint8_t *)RDS14, 0);
  137. otm8009a_write_cmd((rt_uint8_t *)RDS15, 0);
  138. otm8009a_write_cmd((rt_uint8_t *)RDS16, 0);
  139. otm8009a_write_cmd((rt_uint8_t *)RDS17, 0);
  140. otm8009a_write_cmd((rt_uint8_t *)RDS18, 0);
  141. otm8009a_write_cmd((rt_uint8_t *)RDS19, 0);
  142. otm8009a_write_cmd((rt_uint8_t *)RDS09, 0);
  143. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  144. otm8009a_write_cmd((rt_uint8_t *)RDL05, 2);
  145. otm8009a_write_cmd((rt_uint8_t *)RDS20, 0);
  146. otm8009a_write_cmd((rt_uint8_t *)RDS21, 0);
  147. otm8009a_write_cmd((rt_uint8_t *)RDS22, 0);
  148. otm8009a_write_cmd((rt_uint8_t *)RDS23, 0);
  149. otm8009a_write_cmd((rt_uint8_t *)RDS24, 0);
  150. otm8009a_write_cmd((rt_uint8_t *)RDS25, 0);
  151. otm8009a_write_cmd((rt_uint8_t *)RDS13, 0);
  152. otm8009a_write_cmd((rt_uint8_t *)RDS26, 0);
  153. otm8009a_write_cmd((rt_uint8_t *)RDS15, 0);
  154. otm8009a_write_cmd((rt_uint8_t *)RDS27, 0);
  155. otm8009a_write_cmd((rt_uint8_t *)RDS28, 0);
  156. otm8009a_write_cmd((rt_uint8_t *)RDL06, 2);
  157. otm8009a_write_cmd((rt_uint8_t *)RDS02, 0);
  158. otm8009a_write_cmd((rt_uint8_t *)RDL07, 6);
  159. otm8009a_write_cmd((rt_uint8_t *)RDS29, 0);
  160. otm8009a_write_cmd((rt_uint8_t *)RDL08, 14);
  161. otm8009a_write_cmd((rt_uint8_t *)RDS30, 0);
  162. otm8009a_write_cmd((rt_uint8_t *)RDL09, 14);
  163. otm8009a_write_cmd((rt_uint8_t *)RDS31, 0);
  164. otm8009a_write_cmd((rt_uint8_t *)RDL10, 10);
  165. otm8009a_write_cmd((rt_uint8_t *)RDS32, 0);
  166. otm8009a_write_cmd((rt_uint8_t *)RDS46, 0);
  167. otm8009a_write_cmd((rt_uint8_t *)RDS02, 0);
  168. otm8009a_write_cmd((rt_uint8_t *)RDL11, 10);
  169. otm8009a_write_cmd((rt_uint8_t *)RDS33, 0);
  170. otm8009a_write_cmd((rt_uint8_t *)RDL12, 15);
  171. otm8009a_write_cmd((rt_uint8_t *)RDS29, 0);
  172. otm8009a_write_cmd((rt_uint8_t *)RDL13, 15);
  173. otm8009a_write_cmd((rt_uint8_t *)RDS30, 0);
  174. otm8009a_write_cmd((rt_uint8_t *)RDL14, 10);
  175. otm8009a_write_cmd((rt_uint8_t *)RDS31, 0);
  176. otm8009a_write_cmd((rt_uint8_t *)RDL15, 15);
  177. otm8009a_write_cmd((rt_uint8_t *)RDS32, 0);
  178. otm8009a_write_cmd((rt_uint8_t *)RDL16, 15);
  179. otm8009a_write_cmd((rt_uint8_t *)RDS34, 0);
  180. otm8009a_write_cmd((rt_uint8_t *)RDL17, 10);
  181. otm8009a_write_cmd((rt_uint8_t *)RDS35, 0);
  182. otm8009a_write_cmd((rt_uint8_t *)RDL18, 10);
  183. otm8009a_write_cmd((rt_uint8_t *)RDS02, 0);
  184. otm8009a_write_cmd((rt_uint8_t *)RDL19, 10);
  185. otm8009a_write_cmd((rt_uint8_t *)RDS33, 0);
  186. otm8009a_write_cmd((rt_uint8_t *)RDL20, 15);
  187. otm8009a_write_cmd((rt_uint8_t *)RDS29, 0);
  188. otm8009a_write_cmd((rt_uint8_t *)RDL21, 15);
  189. otm8009a_write_cmd((rt_uint8_t *)RDS30, 0);
  190. otm8009a_write_cmd((rt_uint8_t *)RDL22, 10);
  191. otm8009a_write_cmd((rt_uint8_t *)RDS31, 0);
  192. otm8009a_write_cmd((rt_uint8_t *)RDL23, 15);
  193. otm8009a_write_cmd((rt_uint8_t *)RDS32, 0);
  194. otm8009a_write_cmd((rt_uint8_t *)RDL24, 15);
  195. otm8009a_write_cmd((rt_uint8_t *)RDS13, 0);
  196. otm8009a_write_cmd((rt_uint8_t *)RDS47, 0);
  197. otm8009a_write_cmd((rt_uint8_t *)RDS48, 0);
  198. otm8009a_write_cmd((rt_uint8_t *)RDS49, 0);
  199. otm8009a_write_cmd((rt_uint8_t *)RDS50, 0);
  200. otm8009a_write_cmd((rt_uint8_t *)RDS51, 0);
  201. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  202. otm8009a_write_cmd((rt_uint8_t *)RDL25, 3);
  203. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  204. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  205. otm8009a_write_cmd((rt_uint8_t *)RDL03, 16);
  206. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  207. otm8009a_write_cmd((rt_uint8_t *)RDL04, 16);
  208. otm8009a_write_cmd((rt_uint8_t *)RDS36, 0);
  209. otm8009a_delay(120);
  210. switch (pixel_format)
  211. {
  212. case RTGRAPHIC_PIXEL_FORMAT_RGB565:
  213. otm8009a_write_cmd((rt_uint8_t *)RDS37, 0);
  214. break;
  215. case RTGRAPHIC_PIXEL_FORMAT_RGB888:
  216. case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
  217. otm8009a_write_cmd((rt_uint8_t *)RDS38, 0);
  218. break;
  219. }
  220. otm8009a_write_cmd((rt_uint8_t *)RDS39, 0);
  221. otm8009a_write_cmd((rt_uint8_t *)RDL27, 4);
  222. otm8009a_write_cmd((rt_uint8_t *)RDL28, 4);
  223. otm8009a_write_cmd((rt_uint8_t *)RDS40, 0);
  224. otm8009a_write_cmd((rt_uint8_t *)RDS41, 0);
  225. otm8009a_write_cmd((rt_uint8_t *)RDS42, 0);
  226. otm8009a_write_cmd((rt_uint8_t *)RDS43, 0);
  227. otm8009a_write_cmd((rt_uint8_t *)RDS44, 0);
  228. otm8009a_write_cmd((rt_uint8_t *)RDS01, 0);
  229. otm8009a_write_cmd((rt_uint8_t *)RDS45, 0);
  230. }
  231. void stm32_mipi_lcd_init(void)
  232. {
  233. otm8009a_reset();
  234. }
  235. void stm32_mipi_lcd_config(rt_uint32_t pixel_format)
  236. {
  237. otm8009a_config(pixel_format);
  238. }
  239. void stm32_mipi_display_on(void)
  240. {
  241. HAL_DSI_ShortWrite(&hdsi, hdsi_video.VirtualChannelID, DSI_DCS_SHORT_PKT_WRITE_P1, 0x29, 0x00);
  242. }
  243. void stm32_mipi_display_off(void)
  244. {
  245. HAL_DSI_ShortWrite(&hdsi, hdsi_video.VirtualChannelID, DSI_DCS_SHORT_PKT_WRITE_P1, 0x28, 0x00);
  246. }
  247. #endif