panel_rm690b0.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_rm690b0.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, (0x02 << 24) | (cmd << 8), 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. static void _panel_transmit_p2(const struct device *dev, uint32_t cmd, uint8_t data1, uint8_t data2)
  43. {
  44. uint8_t data_array[2] = { data1, data2, };
  45. _panel_transmit(dev, cmd, data_array, 2);
  46. }
  47. static void _panel_exit_sleep(const struct device *dev)
  48. {
  49. struct lcd_panel_data *data = dev->data;
  50. _panel_transmit_cmd(dev, DDIC_CMD_SLPOUT);
  51. k_msleep(150);
  52. data->in_sleep = 0;
  53. }
  54. static int _panel_init(const struct device *dev)
  55. {
  56. const struct lcd_panel_config *config = dev->config;
  57. _panel_transmit_p1(dev, 0xFE, 0x00);
  58. if (config->videomode.pixel_format == PIXEL_FORMAT_BGR_565) {
  59. _panel_transmit_p1(dev, 0x3A, 0x55); /* rgb565 */
  60. } else {
  61. _panel_transmit_p1(dev, 0x3A, 0x77); /* rgb888 */
  62. }
  63. /* TE */
  64. _panel_transmit_p2(dev, DDIC_CMD_STESL,
  65. CONFIG_PANEL_TE_SCANLINE >> 8, CONFIG_PANEL_TE_SCANLINE & 0xff);
  66. _panel_transmit_p1(dev, DDIC_CMD_TEON, 0x00);
  67. _panel_transmit_p1(dev, 0x53, 0x20);
  68. _panel_transmit_p1(dev, 0x51, 0xFF);
  69. _panel_transmit_p1(dev, 0x63, 0xFF);
  70. _panel_transmit_p1(dev, 0xC4, 0x60);
  71. /* Sleep Out */
  72. _panel_exit_sleep(dev);
  73. return 0;
  74. }
  75. static int _panel_set_brightness(const struct device *dev, uint8_t brightness)
  76. {
  77. _panel_transmit_p1(dev, DDIC_CMD_WRDISBV, brightness);
  78. return 0;
  79. }
  80. static int _panel_set_mem_area(const struct device *dev, uint16_t x,
  81. uint16_t y, uint16_t w, uint16_t h)
  82. {
  83. uint16_t cmd_data[2];
  84. x += CONFIG_PANEL_MEM_OFFSET_X;
  85. y += CONFIG_PANEL_MEM_OFFSET_Y;
  86. cmd_data[0] = sys_cpu_to_be16(x);
  87. cmd_data[1] = sys_cpu_to_be16(x + w - 1);
  88. _panel_transmit(dev, DDIC_CMD_CASET, (uint8_t *)&cmd_data[0], 4);
  89. cmd_data[0] = sys_cpu_to_be16(y);
  90. cmd_data[1] = sys_cpu_to_be16(y + h - 1);
  91. _panel_transmit(dev, DDIC_CMD_RASET, (uint8_t *)&cmd_data[0], 4);
  92. return 0;
  93. }
  94. static int _panel_blanking_on(const struct device *dev)
  95. {
  96. _panel_transmit_cmd(dev, DDIC_CMD_DISPOFF);
  97. _panel_transmit_cmd(dev, DDIC_CMD_SLPIN);
  98. return 0;
  99. }
  100. static int _panel_blanking_off(const struct device *dev)
  101. {
  102. struct lcd_panel_data *data = dev->data;
  103. if (data->in_sleep)
  104. _panel_exit_sleep(dev);
  105. _panel_transmit_cmd(dev, DDIC_CMD_DISPON);
  106. return 0;
  107. }
  108. static const struct lcd_panel_ops lcd_panel_ops = {
  109. .init = _panel_init,
  110. .blanking_on = _panel_blanking_on,
  111. .blanking_off = _panel_blanking_off,
  112. .set_brightness = _panel_set_brightness,
  113. .write_prepare = _panel_set_mem_area,
  114. };
  115. const struct lcd_panel_config lcd_panel_rm690b0_config = {
  116. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  117. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  118. .ops = &lcd_panel_ops,
  119. .cmd_ramwr = (0x32 << 24 | DDIC_CMD_RAMWR << 8),
  120. .cmd_ramwc = (0x32 << 24 | DDIC_CMD_RAMWRC << 8),
  121. .tw_reset = 30,
  122. .ts_reset = 120,
  123. };