panel_st77903.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <sys/byteorder.h>
  7. #include "panel_st77903.h"
  8. #include "panel_device.h"
  9. /*********************
  10. * DEFINES
  11. *********************/
  12. /**********************
  13. * TYPEDEFS
  14. **********************/
  15. /**********************
  16. * STATIC PROTOTYPES
  17. **********************/
  18. /**********************
  19. * STATIC VARIABLES
  20. **********************/
  21. /**********************
  22. * MACROS
  23. **********************/
  24. /**********************
  25. * FUNCTIONS
  26. **********************/
  27. static void _panel_transmit(const struct device *dev, uint32_t cmd,
  28. const uint8_t *tx_data, size_t tx_count)
  29. {
  30. struct lcd_panel_data *data = dev->data;
  31. display_controller_write_config(data->lcdc_dev, ST77903_WR_CMD(cmd), tx_data, tx_count);
  32. }
  33. static inline void _panel_transmit_cmd(const struct device *dev, uint32_t cmd)
  34. {
  35. _panel_transmit(dev, cmd, NULL, 0);
  36. }
  37. static inline void _panel_transmit_p1(const struct device *dev, uint32_t cmd, uint8_t tx_data)
  38. {
  39. _panel_transmit(dev, cmd, &tx_data, 1);
  40. }
  41. static int _panel_init(const struct device *dev)
  42. {
  43. const struct lcd_panel_config *config = dev->config;
  44. _panel_transmit_p1(dev, 0xf0, 0xc3);
  45. _panel_transmit_p1(dev, 0xf0, 0x96);
  46. _panel_transmit_p1(dev, 0xf0, 0xa5);
  47. _panel_transmit_p1(dev, 0xe9, 0x20);
  48. const uint8_t data_0xe7[] = { 0x80, 0x77, 0x1f, 0xcc, };
  49. _panel_transmit(dev, 0xe7, data_0xe7, sizeof(data_0xe7));
  50. const uint8_t data_0xc1[] = { 0x77, 0x07, 0xc2, 0x07, };
  51. _panel_transmit(dev, 0xc1, data_0xc1, sizeof(data_0xc1));
  52. const uint8_t data_0xc2[] = { 0x77, 0x07, 0xc2, 0x07, };
  53. _panel_transmit(dev, 0xc2, data_0xc2, sizeof(data_0xc2));
  54. const uint8_t data_0xc3[] = { 0x22, 0x02, 0x22, 0x04, };
  55. _panel_transmit(dev, 0xc3, data_0xc3, sizeof(data_0xc3));
  56. const uint8_t data_0xc4[] = { 0x22, 0x02, 0x22, 0x04, };
  57. _panel_transmit(dev, 0xc4, data_0xc4, sizeof(data_0xc4));
  58. _panel_transmit_p1(dev, 0xc5, 0x71);
  59. const uint8_t data_0xe0[] = {
  60. 0x87, 0x09, 0x0c, 0x06, 0x05, 0x03, 0x29, 0x32,
  61. 0x49, 0x0f, 0x1b, 0x17, 0x2a, 0x2f,
  62. };
  63. _panel_transmit(dev, 0xe0, data_0xe0, sizeof(data_0xe0));
  64. const uint8_t data_0xe1[] = {
  65. 0x87, 0x09, 0x0c, 0x06, 0x05, 0x03, 0x29, 0x32,
  66. 0x49, 0x0f, 0x1b, 0x17, 0x2a, 0x2f,
  67. };
  68. _panel_transmit(dev, 0xe1, data_0xe1, sizeof(data_0xe1));
  69. const uint8_t data_0xe5[] = {
  70. 0xb2, 0xf5, 0xbd, 0x24, 0x22, 0x25, 0x10, 0x22,
  71. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  72. };
  73. _panel_transmit(dev, 0xe5, data_0xe5, sizeof(data_0xe5));
  74. const uint8_t data_0xe6[] = {
  75. 0xb2, 0xf5, 0xbd, 0x24, 0x22, 0x25, 0x10, 0x22,
  76. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  77. };
  78. _panel_transmit(dev, 0xe6, data_0xe6, sizeof(data_0xe6));
  79. const uint8_t data_0xec[] = { 0x40, 0x03, };
  80. _panel_transmit(dev, 0xec, data_0xec, sizeof(data_0xec));
  81. _panel_transmit_p1(dev, 0x36, 0x0c);
  82. if (config->videomode.pixel_format == PIXEL_FORMAT_BGR_565) {
  83. _panel_transmit_p1(dev, 0x3a, 0x05);
  84. } else { /* RGB_888 */
  85. _panel_transmit_p1(dev, 0x3a, 0x07);
  86. }
  87. _panel_transmit_p1(dev, 0xb2, 0x00);
  88. _panel_transmit_p1(dev, 0xb3, 0x00); // ???
  89. _panel_transmit_p1(dev, 0xb4, 0x00);
  90. /* Set VFP(8) and VBP(8) in idle mode */
  91. const uint8_t data_0xb5[] = { 0x00, 0x08, 0x00, 0x8 };
  92. _panel_transmit(dev, 0xb5, data_0xb5, sizeof(data_0xb5));
  93. /* Resolution 400x400 */
  94. const uint8_t data_0xb6[] = { 0xc7, 0x31, };
  95. _panel_transmit(dev, 0xb6, data_0xb6, sizeof(data_0xb6));
  96. const uint8_t data_0xa5[] = {
  97. 0x00, 0x00, 0x00, 0x00, 0x20, 0x15, 0x2a, 0x8a,
  98. 0x02
  99. };
  100. _panel_transmit(dev, 0xa5, data_0xa5, sizeof(data_0xa5));
  101. const uint8_t data_0xa6[] = {
  102. 0x00, 0x00, 0x00, 0x00, 0x20, 0x15, 0x2a, 0x8a,
  103. 0x02
  104. };
  105. _panel_transmit(dev, 0xa6, data_0xa6, sizeof(data_0xa6));
  106. const uint8_t data_0xba[] = {
  107. 0x0a, 0x5a, 0x23, 0x10, 0x25, 0x02, 0x00
  108. };
  109. _panel_transmit(dev, 0xba, data_0xba, sizeof(data_0xba));
  110. const uint8_t data_0xbb[] = {
  111. 0x00, 0x30, 0x00, 0x29, 0x88, 0x87, 0x18, 0x00,
  112. };
  113. _panel_transmit(dev, 0xbb, data_0xbb, sizeof(data_0xbb));
  114. const uint8_t data_0xbc[] = {
  115. 0x00, 0x30, 0x00, 0x29, 0x88, 0x87, 0x18, 0x00,
  116. };
  117. _panel_transmit(dev, 0xbc, data_0xbc, sizeof(data_0xbc));
  118. const uint8_t data_0xbd[] = {
  119. 0xa1, 0xb2, 0x2b, 0x1a, 0x56, 0x43, 0x34, 0x65,
  120. 0xff, 0xff, 0x0f,
  121. };
  122. _panel_transmit(dev, 0xbd, data_0xbd, sizeof(data_0xbd));
  123. /* TE on */
  124. _panel_transmit_p1(dev, 0x35, 0x00);
  125. _panel_transmit_cmd(dev, 0x21);
  126. //_panel_transmit_cmd(dev, 0x38); /* idle mode off */
  127. _panel_transmit_cmd(dev, 0x11); /* Sleep Out */
  128. k_msleep(120);
  129. _panel_transmit_cmd(dev, 0x29); /* Display On */
  130. k_msleep(120);
  131. return 0;
  132. }
  133. static const struct lcd_panel_ops lcd_panel_ops = {
  134. .init = _panel_init,
  135. };
  136. /* RGB-565 */
  137. static uint8_t lcd_framebuffer_mem[CONFIG_PANEL_HOR_RES * CONFIG_PANEL_VER_RES * 2] __aligned(4);
  138. const struct lcd_panel_config lcd_panel_st77903_config = {
  139. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  140. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  141. .ops = &lcd_panel_ops,
  142. .fb_mem = lcd_framebuffer_mem,
  143. .cmd_ramwr = ST77903_WR_CMD(DDIC_CMD_VS),
  144. .cmd_hsync = ST77903_WR_CMD(DDIC_CMD_HS),
  145. .tw_reset = 10,
  146. .ts_reset = 120,
  147. };