panel_ft2308.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_ft2308.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 << 8);
  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 = lcd_panel_get_config(dev);
  58. /* Sleep Out */
  59. _panel_exit_sleep(dev);
  60. const uint8_t data_ff00[] = { 0x23, 0x08, 0x01 };
  61. _panel_transmit(dev, 0xFF00, data_ff00, sizeof(data_ff00));
  62. _panel_transmit_p2(dev, 0xFF80, 0x23, 0x08);
  63. _panel_transmit_p1(dev, 0xb283, 0x12);
  64. _panel_transmit_p2(dev, 0x5100, 0xff, 0x00);
  65. /* TE */
  66. _panel_transmit_p1(dev, DDIC_CMD_TEON << 8, 0x00);
  67. if (config->videomode.pixel_format == PIXEL_FORMAT_BGR_565) {
  68. _panel_transmit_p1(dev, 0x3A00, 0x55); /* rgb565 */
  69. } else {
  70. _panel_transmit_p1(dev, 0x3A00, 0x77); /* rgb888 */
  71. }
  72. k_msleep(120);
  73. /* Display on */
  74. //_panel_transmit_cmd(dev, DDIC_CMD_DISPON << 8);
  75. return 0;
  76. }
  77. static int _panel_set_brightness(const struct device *dev, uint8_t brightness)
  78. {
  79. _panel_transmit_p2(dev, 0x5100, brightness, 0x00);
  80. return 0;
  81. }
  82. static int _panel_set_mem_area(const struct device *dev, uint16_t x,
  83. uint16_t y, uint16_t w, uint16_t h)
  84. {
  85. uint16_t cmd_data[2];
  86. x += CONFIG_PANEL_MEM_OFFSET_X;
  87. y += CONFIG_PANEL_MEM_OFFSET_Y;
  88. cmd_data[0] = sys_cpu_to_be16(x);
  89. cmd_data[1] = sys_cpu_to_be16(x + w - 1);
  90. _panel_transmit(dev, DDIC_CMD_CASET << 8, (uint8_t *)&cmd_data[0], 4);
  91. cmd_data[0] = sys_cpu_to_be16(y);
  92. cmd_data[1] = sys_cpu_to_be16(y + h - 1);
  93. _panel_transmit(dev, DDIC_CMD_PASET << 8, (uint8_t *)&cmd_data[0], 4);
  94. return 0;
  95. }
  96. static int _panel_blanking_on(const struct device *dev)
  97. {
  98. _panel_transmit_cmd(dev, DDIC_CMD_DISPOFF << 8);
  99. _panel_transmit_cmd(dev, DDIC_CMD_SLPIN << 8);
  100. return 0;
  101. }
  102. static int _panel_blanking_off(const struct device *dev)
  103. {
  104. struct lcd_panel_data *data = dev->data;
  105. if (data->in_sleep)
  106. _panel_exit_sleep(dev);
  107. _panel_transmit_cmd(dev, DDIC_CMD_DISPON << 8);
  108. k_msleep(120);
  109. return 0;
  110. }
  111. static int _panel_lowpower_enter(const struct device *dev)
  112. {
  113. _panel_transmit(dev, DDIC_CMD_IDMON, NULL, 0);
  114. return 0;
  115. }
  116. static int _panel_lowpower_exit(const struct device *dev)
  117. {
  118. _panel_transmit(dev, DDIC_CMD_IDMOFF, NULL, 0);
  119. return 0;
  120. }
  121. static const struct lcd_panel_ops lcd_panel_ops = {
  122. .init = _panel_init,
  123. .blanking_on = _panel_blanking_on,
  124. .blanking_off = _panel_blanking_off,
  125. .lowpower_enter = _panel_lowpower_enter,
  126. .lowpower_exit = _panel_lowpower_exit,
  127. .set_brightness = _panel_set_brightness,
  128. .write_prepare = _panel_set_mem_area,
  129. };
  130. const struct lcd_panel_config lcd_panel_ft2308_config = {
  131. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  132. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  133. .ops = &lcd_panel_ops,
  134. .cmd_ramwr = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWR),
  135. .cmd_ramwc = DDIC_QSPI_CMD_RAMWR(DDIC_CMD_RAMWRCNT),
  136. .tw_reset = 120,
  137. .ts_reset = 120,
  138. };