panel_sh8601z0.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_sh8601z0.h"
  8. #include "panel_device.h"
  9. /*********************
  10. * DEFINES
  11. *********************/
  12. /**
  13. * For 466x466 round panel, CONFIG_PANEL_FULL_SCREEN_OPT_AREA can be defined as follows:
  14. * 1) 7 areas
  15. * #define CONFIG_PANEL_FULL_SCREEN_OPT_AREA \
  16. * { \
  17. * { 124, 0, 341, 27 }, \
  18. * { 68, 28, 397, 67 }, \
  19. * { 28, 68, 437, 123 }, \
  20. * { 0, 124, 465, 341 }, \
  21. * { 28, 342, 437, 397 }, \
  22. * { 68, 398, 397, 437 }, \
  23. * { 124, 438, 341, 465 }, \
  24. * }
  25. *
  26. * 2) 3 areas
  27. * #define CONFIG_PANEL_FULL_SCREEN_OPT_AREA \
  28. * { \
  29. * { 68, 0, 397, 67 }, \
  30. * { 0, 68, 465, 397 }, \
  31. * { 68, 398, 397, 465 }, \
  32. * }
  33. */
  34. /* time to wait between pixel transfer and next command */
  35. #ifdef CONFIG_PANEL_FULL_SCREEN_OPT_AREA
  36. # define CONFIG_PANEL_PIXEL_WR_DELAY_US (17)
  37. #else
  38. # define CONFIG_PANEL_PIXEL_WR_DELAY_US (0)
  39. #endif
  40. /**********************
  41. * TYPEDEFS
  42. **********************/
  43. /**********************
  44. * STATIC PROTOTYPES
  45. **********************/
  46. /**********************
  47. * STATIC VARIABLES
  48. **********************/
  49. /**********************
  50. * MACROS
  51. **********************/
  52. /**********************
  53. * FUNCTIONS
  54. **********************/
  55. static void _panel_transmit(const struct device *dev, uint32_t cmd,
  56. const uint8_t *tx_data, size_t tx_count)
  57. {
  58. struct lcd_panel_data *data = dev->data;
  59. assert(data->transfering == 0);
  60. display_controller_write_config(data->lcdc_dev, DDIC_QSPI_CMD_WR(cmd), tx_data, tx_count);
  61. }
  62. static inline void _panel_transmit_cmd(const struct device *dev, uint32_t cmd)
  63. {
  64. _panel_transmit(dev, cmd, NULL, 0);
  65. }
  66. static inline void _panel_transmit_p1(const struct device *dev, uint32_t cmd, uint8_t tx_data)
  67. {
  68. _panel_transmit(dev, cmd, &tx_data, 1);
  69. }
  70. static void _panel_transmit_p2(const struct device *dev, uint32_t cmd, uint8_t tx_data0, uint8_t tx_data1)
  71. {
  72. uint8_t tx_data[] = { tx_data0, tx_data1 };
  73. _panel_transmit(dev, cmd, tx_data, sizeof(tx_data));
  74. }
  75. static void _panel_exit_sleep(const struct device *dev)
  76. {
  77. struct lcd_panel_data *data = dev->data;
  78. _panel_transmit_cmd(dev, DDIC_CMD_SLPOUT);
  79. k_msleep(150);
  80. data->in_sleep = 0;
  81. }
  82. static int _panel_init(const struct device *dev)
  83. {
  84. /* Sleep Out */
  85. _panel_exit_sleep(dev);
  86. /* te */
  87. const uint8_t data_44[] = { CONFIG_PANEL_TE_SCANLINE >> 8, CONFIG_PANEL_TE_SCANLINE & 0xFF };
  88. _panel_transmit(dev, DDIC_CMD_TESCAN, data_44, sizeof(data_44));
  89. _panel_transmit_p1(dev, DDIC_CMD_TEON, 0x00);
  90. /* pixel format RGB-565 */
  91. _panel_transmit_p1(dev, DDIC_CMD_COLMOD, 0x55);
  92. /* brightness */
  93. _panel_transmit_p2(dev, DDIC_CMD_WRDISBV, CONFIG_PANEL_BRIGHTNESS, 0);
  94. /* HBM brightness */
  95. _panel_transmit_p2(dev, DDIC_CMD_HBM_WRDISBV, CONFIG_PANEL_BRIGHTNESS, 0);
  96. /* AOD brightness */
  97. _panel_transmit_p2(dev, DDIC_CMD_AOD_WRDISBV, CONFIG_PANEL_AOD_BRIGHTNESS, 0);
  98. _panel_transmit_p1(dev, 0x53, 0x20);
  99. _panel_transmit_p1(dev, 0xC4, 0x00);
  100. /* Display on */
  101. //_panel_transmit(dev, DDIC_CMD_DISPON, NULL, 0);
  102. return 0;
  103. }
  104. static int _panel_set_brightness(const struct device *dev, uint8_t brightness)
  105. {
  106. _panel_transmit_p2(dev, DDIC_CMD_WRDISBV, brightness, 0);
  107. return 0;
  108. }
  109. static int _panel_set_mem_area(const struct device *dev, uint16_t x, uint16_t y, uint16_t w,
  110. uint16_t h)
  111. {
  112. uint16_t cmd_data[2];
  113. x += CONFIG_PANEL_MEM_OFFSET_X;
  114. y += CONFIG_PANEL_MEM_OFFSET_Y;
  115. cmd_data[0] = sys_cpu_to_be16(x);
  116. cmd_data[1] = sys_cpu_to_be16(x + w - 1);
  117. _panel_transmit(dev, DDIC_CMD_CASET, (uint8_t *)&cmd_data[0], 4);
  118. cmd_data[0] = sys_cpu_to_be16(y);
  119. cmd_data[1] = sys_cpu_to_be16(y + h - 1);
  120. _panel_transmit(dev, DDIC_CMD_PASET, (uint8_t *)&cmd_data[0], 4);
  121. return 0;
  122. }
  123. static int _panel_blanking_on(const struct device *dev)
  124. {
  125. _panel_transmit_cmd(dev, DDIC_CMD_DISPOFF);
  126. _panel_transmit_cmd(dev, DDIC_CMD_SLPIN);
  127. return 0;
  128. }
  129. static int _panel_blanking_off(const struct device *dev)
  130. {
  131. struct lcd_panel_data *data = dev->data;
  132. if (data->in_sleep)
  133. _panel_exit_sleep(dev);
  134. _panel_transmit_cmd(dev, DDIC_CMD_DISPON);
  135. k_msleep(80);
  136. return 0;
  137. }
  138. static int _panel_lowpower_enter(const struct device *dev)
  139. {
  140. _panel_transmit_cmd(dev, DDIC_CMD_AODON);
  141. return 0;
  142. }
  143. static int _panel_lowpower_exit(const struct device *dev)
  144. {
  145. _panel_transmit_cmd(dev, DDIC_CMD_AODOFF);
  146. return 0;
  147. }
  148. static const struct lcd_panel_ops lcd_panel_ops = {
  149. .init = _panel_init,
  150. .blanking_on = _panel_blanking_on,
  151. .blanking_off = _panel_blanking_off,
  152. .lowpower_enter = _panel_lowpower_enter,
  153. .lowpower_exit = _panel_lowpower_exit,
  154. .set_brightness = _panel_set_brightness,
  155. .write_prepare = _panel_set_mem_area,
  156. };
  157. const struct lcd_panel_config lcd_panel_sh8601z0_config = {
  158. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  159. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  160. .ops = &lcd_panel_ops,
  161. .cmd_ramwr = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWR),
  162. .cmd_ramwc = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWRC),
  163. .tw_reset = 10,
  164. .ts_reset = 150,
  165. };