panel_er76288a.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_er76288a.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. assert(data->transfering == 0);
  32. display_controller_write_config(data->lcdc_dev, DDIC_QSPI_CMD_WR(cmd), tx_data, tx_count);
  33. }
  34. static inline void _panel_transmit_cmd(const struct device *dev, uint32_t cmd)
  35. {
  36. _panel_transmit(dev, cmd, NULL, 0);
  37. }
  38. static inline void _panel_transmit_p1(const struct device *dev, uint32_t cmd, uint8_t tx_data)
  39. {
  40. _panel_transmit(dev, cmd, &tx_data, 1);
  41. }
  42. __unused
  43. static void _panel_transmit_p2(const struct device *dev, uint32_t cmd, uint8_t tx_data0, uint8_t tx_data1)
  44. {
  45. uint8_t tx_data[] = { tx_data0, tx_data1 };
  46. _panel_transmit(dev, cmd, tx_data, sizeof(tx_data));
  47. }
  48. static void _panel_exit_sleep(const struct device *dev)
  49. {
  50. struct lcd_panel_data *data = dev->data;
  51. _panel_transmit_cmd(dev, DDIC_CMD_SLPOUT);
  52. k_msleep(120);
  53. data->in_sleep = 0;
  54. }
  55. static int _panel_init(const struct device *dev)
  56. {
  57. //const struct lcd_panel_config *config = dev->config;
  58. _panel_transmit_p1(dev, 0xff, 0x00);
  59. _panel_transmit_p1(dev, 0x51, 0xff);
  60. _panel_transmit_p1(dev, 0x53, 0x28);
  61. _panel_transmit_p1(dev, 0x35, 0x00); /* TE on */
  62. _panel_transmit_p2(dev, 0x44, 0x01, 0x00);
  63. _panel_transmit_p1(dev, 0xc4, 0x90);
  64. _panel_transmit_p1(dev, 0xff, 0x00);
  65. _panel_exit_sleep(dev);
  66. return 0;
  67. }
  68. static int _panel_set_brightness(const struct device *dev, uint8_t brightness)
  69. {
  70. _panel_transmit_p1(dev, DDIC_CMD_WRDISBV, brightness);
  71. return 0;
  72. }
  73. static int _panel_set_mem_area(const struct device *dev, uint16_t x,
  74. uint16_t y, uint16_t w, uint16_t h)
  75. {
  76. uint16_t cmd_data[2];
  77. x += CONFIG_PANEL_MEM_OFFSET_X;
  78. y += CONFIG_PANEL_MEM_OFFSET_Y;
  79. cmd_data[0] = sys_cpu_to_be16(x);
  80. cmd_data[1] = sys_cpu_to_be16(x + w - 1);
  81. _panel_transmit(dev, DDIC_CMD_CASET, (uint8_t *)&cmd_data[0], 4);
  82. cmd_data[0] = sys_cpu_to_be16(y);
  83. cmd_data[1] = sys_cpu_to_be16(y + h - 1);
  84. _panel_transmit(dev, DDIC_CMD_RASET, (uint8_t *)&cmd_data[0], 4);
  85. return 0;
  86. }
  87. static int _panel_blanking_on(const struct device *dev)
  88. {
  89. _panel_transmit_cmd(dev, DDIC_CMD_DISPOFF);
  90. _panel_transmit_cmd(dev, DDIC_CMD_SLPIN);
  91. return 0;
  92. }
  93. static int _panel_blanking_off(const struct device *dev)
  94. {
  95. struct lcd_panel_data *data = dev->data;
  96. if (data->in_sleep)
  97. _panel_exit_sleep(dev);
  98. _panel_transmit_cmd(dev, DDIC_CMD_DISPON);
  99. return 0;
  100. }
  101. static int _panel_lowpower_enter(const struct device *dev)
  102. {
  103. _panel_transmit(dev, DDIC_CMD_IDMON, NULL, 0);
  104. return 0;
  105. }
  106. static int _panel_lowpower_exit(const struct device *dev)
  107. {
  108. _panel_transmit(dev, DDIC_CMD_IDMOFF, NULL, 0);
  109. return 0;
  110. }
  111. static const struct lcd_panel_ops lcd_panel_ops = {
  112. .init = _panel_init,
  113. .blanking_on = _panel_blanking_on,
  114. .blanking_off = _panel_blanking_off,
  115. .lowpower_enter = _panel_lowpower_enter,
  116. .lowpower_exit = _panel_lowpower_exit,
  117. .set_brightness = _panel_set_brightness,
  118. .write_prepare = _panel_set_mem_area,
  119. };
  120. const struct lcd_panel_config lcd_panel_er76288a_config = {
  121. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  122. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  123. .ops = &lcd_panel_ops,
  124. .cmd_ramwr = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWR),
  125. .cmd_ramwc = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWRC),
  126. .tw_reset = 10,
  127. .ts_reset = 120,
  128. .td_slpin = 83,
  129. };