panel_icna3311.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_icna3311.h"
  8. #include "panel_device.h"
  9. #include <logging/log.h>
  10. LOG_MODULE_DECLARE(lcd_panel, CONFIG_DISPLAY_LOG_LEVEL);
  11. /*********************
  12. * DEFINES
  13. *********************/
  14. /**********************
  15. * TYPEDEFS
  16. **********************/
  17. /**********************
  18. * STATIC PROTOTYPES
  19. **********************/
  20. /**********************
  21. * STATIC VARIABLES
  22. **********************/
  23. /**********************
  24. * MACROS
  25. **********************/
  26. /**********************
  27. * FUNCTIONS
  28. **********************/
  29. static void _panel_read(const struct device *dev, uint32_t cmd,
  30. uint8_t *rx_data, size_t rx_count)
  31. {
  32. struct lcd_panel_data *data = dev->data;
  33. assert(data->transfering == 0);
  34. display_controller_read_config(data->lcdc_dev, DDIC_QSPI_CMD_RD(cmd), rx_data, rx_count);
  35. }
  36. static void _panel_transmit(const struct device *dev, uint32_t cmd,
  37. const uint8_t *tx_data, size_t tx_count)
  38. {
  39. struct lcd_panel_data *data = dev->data;
  40. assert(data->transfering == 0);
  41. display_controller_write_config(data->lcdc_dev, DDIC_QSPI_CMD_WR(cmd), tx_data, tx_count);
  42. }
  43. static inline void _panel_transmit_cmd(const struct device *dev, uint32_t cmd)
  44. {
  45. _panel_transmit(dev, cmd, NULL, 0);
  46. }
  47. static inline void _panel_transmit_p1(const struct device *dev, uint32_t cmd, uint8_t tx_data)
  48. {
  49. _panel_transmit(dev, cmd, &tx_data, 1);
  50. }
  51. static void _panel_exit_sleep(const struct device *dev)
  52. {
  53. struct lcd_panel_data *data = dev->data;
  54. _panel_transmit_cmd(dev, DDIC_CMD_SLPOUT);
  55. k_msleep(120);
  56. data->in_sleep = 0;
  57. }
  58. static int _panel_init(const struct device *dev)
  59. {
  60. const struct lcd_panel_config *config = dev->config;
  61. _panel_transmit_p1(dev, 0xFE, 0x00);
  62. _panel_transmit_p1(dev, 0xC4, 0x80);
  63. //_panel_transmit_p1(dev, 0x35, 0x00);
  64. _panel_transmit_p1(dev, 0x53, 0x20);
  65. _panel_transmit_p1(dev, 0x51, 0xFF);
  66. _panel_transmit_p1(dev, 0x63, 0xFF);
  67. /* te scanline */
  68. const uint8_t data_44[] = { CONFIG_PANEL_TE_SCANLINE >> 8, CONFIG_PANEL_TE_SCANLINE & 0xFF };
  69. _panel_transmit(dev, DDIC_CMD_STESL, data_44, sizeof(data_44));
  70. _panel_transmit_p1(dev, DDIC_CMD_TEON, 0x00);
  71. if (config->videomode.pixel_format == PIXEL_FORMAT_RGB_888) {
  72. _panel_transmit_p1(dev, DDIC_CMD_COLMOD, 0x77); /* RGB-888 */
  73. } else {
  74. _panel_transmit_p1(dev, DDIC_CMD_COLMOD, 0x55); /* RGB-565 */
  75. }
  76. //const uint8_t data_2A[] = { 0x00, 0x08, 0x01, 0x07 };
  77. //_panel_transmit(dev, 0x2A, data_2A, sizeof(data_2A));
  78. //const uint8_t data_2B[] = { 0x00, 0x00, 0x01, 0x91 };
  79. //_panel_transmit(dev, 0x2B, data_2B, sizeof(data_2B));
  80. /* Sleep Out */
  81. _panel_exit_sleep(dev);
  82. /* Display on */
  83. //_panel_transmit_cmd(dev, DDIC_CMD_DISPON);
  84. return 0;
  85. }
  86. static int _panel_set_brightness(const struct device *dev, uint8_t brightness)
  87. {
  88. _panel_transmit_p1(dev, DDIC_CMD_WRDISBV, brightness);
  89. return 0;
  90. }
  91. static int _panel_set_mem_area(const struct device *dev, uint16_t x,
  92. uint16_t y, uint16_t w, uint16_t h)
  93. {
  94. uint16_t cmd_data[2];
  95. x += CONFIG_PANEL_MEM_OFFSET_X;
  96. y += CONFIG_PANEL_MEM_OFFSET_Y;
  97. cmd_data[0] = sys_cpu_to_be16(x);
  98. cmd_data[1] = sys_cpu_to_be16(x + w - 1);
  99. _panel_transmit(dev, DDIC_CMD_CASET, (uint8_t *)&cmd_data[0], 4);
  100. cmd_data[0] = sys_cpu_to_be16(y);
  101. cmd_data[1] = sys_cpu_to_be16(y + h - 1);
  102. _panel_transmit(dev, DDIC_CMD_RASET, (uint8_t *)&cmd_data[0], 4);
  103. return 0;
  104. }
  105. static int _panel_blanking_on(const struct device *dev)
  106. {
  107. _panel_transmit_cmd(dev, DDIC_CMD_DISPOFF);
  108. _panel_transmit_cmd(dev, DDIC_CMD_SLPIN);
  109. return 0;
  110. }
  111. static int _panel_blanking_off(const struct device *dev)
  112. {
  113. struct lcd_panel_data *data = dev->data;
  114. if (data->in_sleep)
  115. _panel_exit_sleep(dev);
  116. _panel_transmit_cmd(dev, DDIC_CMD_DISPON);
  117. return 0;
  118. }
  119. static int _panel_lowpower_enter(const struct device *dev)
  120. {
  121. _panel_transmit_p1(dev, 0xFE, 0x00);
  122. _panel_transmit_cmd(dev, DDIC_CMD_IDMON);
  123. return 0;
  124. }
  125. static int _panel_lowpower_exit(const struct device *dev)
  126. {
  127. _panel_transmit_p1(dev, 0xFE, 0x00);
  128. _panel_transmit_cmd(dev, DDIC_CMD_IDMOFF);
  129. return 0;
  130. }
  131. static int _panel_esc_check(const struct device *dev)
  132. {
  133. uint8_t regv = 0;
  134. _panel_read(dev, 0x0a, &regv, 1);
  135. if (regv != 0x9c) {
  136. LOG_ERR("0x0A: %02x", regv);
  137. return -EIO;
  138. }
  139. return 0;
  140. }
  141. static const struct lcd_panel_ops lcd_panel_ops = {
  142. .init = _panel_init,
  143. .blanking_on = _panel_blanking_on,
  144. .blanking_off = _panel_blanking_off,
  145. .lowpower_enter = _panel_lowpower_enter,
  146. .lowpower_exit = _panel_lowpower_exit,
  147. .check_esd = _panel_esc_check,
  148. .set_brightness = _panel_set_brightness,
  149. .write_prepare = _panel_set_mem_area,
  150. };
  151. const struct lcd_panel_config lcd_panel_icna3311_config = {
  152. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  153. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  154. .ops = &lcd_panel_ops,
  155. .cmd_ramwr = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWR),
  156. .cmd_ramwc = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWRC),
  157. .tw_reset = 10,
  158. .ts_reset = 120,
  159. };