hpm_panel.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include "hpm_panel.h"
  8. #include "hpm_clock_drv.h"
  9. extern hpm_panel_t panel_tm070rdh13;
  10. extern hpm_panel_t panel_cc10128007;
  11. extern hpm_panel_t panel_mc10128007_31b;
  12. extern hpm_panel_t panel_tm103xdgp01;
  13. static hpm_panel_t *panel_list[] = {
  14. #if defined(CONFIG_PANEL_RGB_TM070RDH13) && CONFIG_PANEL_RGB_TM070RDH13
  15. &panel_tm070rdh13,
  16. #endif
  17. #if defined(CONFIG_PANEL_LVDS_CC10128007) && CONFIG_PANEL_LVDS_CC10128007
  18. &panel_cc10128007,
  19. #endif
  20. #if defined(CONFIG_PANEL_MIPI_MC10128007_31B) && CONFIG_PANEL_MIPI_MC10128007_31B
  21. &panel_mc10128007_31b,
  22. #endif
  23. #if defined(CONFIG_PANEL_LVDS_TM103XDGP01) && CONFIG_PANEL_LVDS_TM103XDGP01
  24. &panel_tm103xdgp01,
  25. #endif
  26. };
  27. hpm_panel_t *hpm_panel_find_device_default(void)
  28. {
  29. if (sizeof(panel_list) > 0)
  30. return panel_list[0];
  31. return NULL;
  32. }
  33. hpm_panel_t *hpm_panel_find_device(const char *name)
  34. {
  35. int n = sizeof(panel_list) / sizeof(panel_list[0]);
  36. for (int i = 0; i < n; i++)
  37. if (!strcmp(panel_list[i]->name, name))
  38. return panel_list[i];
  39. return NULL;
  40. }
  41. const char *hpm_panel_get_name(hpm_panel_t *panel)
  42. {
  43. return panel->name;
  44. }
  45. const hpm_panel_timing_t *hpm_panel_get_timing(hpm_panel_t *panel)
  46. {
  47. return &panel->timing;
  48. }
  49. hpm_panel_if_type_t hpm_panel_get_if_type(hpm_panel_t *panel)
  50. {
  51. return panel->if_type;
  52. }
  53. void hpm_panel_register_interface(hpm_panel_t *panel, hpm_panel_hw_interface_t *hw_if)
  54. {
  55. if (hw_if)
  56. memcpy(&panel->hw_if, hw_if, sizeof(*hw_if));
  57. }
  58. void hpm_panel_reset(hpm_panel_t *panel)
  59. {
  60. if (panel->funcs.reset)
  61. panel->funcs.reset(panel);
  62. }
  63. void hpm_panel_init(hpm_panel_t *panel)
  64. {
  65. if (panel->funcs.init)
  66. panel->funcs.init(panel);
  67. }
  68. void hpm_panel_power_on(hpm_panel_t *panel)
  69. {
  70. if (panel->funcs.power_on)
  71. panel->funcs.power_on(panel);
  72. }
  73. void hpm_panel_power_off(hpm_panel_t *panel)
  74. {
  75. if (panel->funcs.power_off)
  76. panel->funcs.power_off(panel);
  77. }
  78. void hpm_panel_set_backlight(hpm_panel_t *panel, uint16_t percent)
  79. {
  80. if (percent > 100)
  81. percent = 100;
  82. if (panel->hw_if.set_backlight &&
  83. panel->state.backlight_percent != percent) {
  84. panel->hw_if.set_backlight(percent);
  85. panel->state.backlight_percent = percent;
  86. }
  87. }
  88. uint8_t hpm_panel_get_backlight(hpm_panel_t *panel)
  89. {
  90. return panel->state.backlight_percent;
  91. }
  92. void hpm_panel_delay_ms(uint32_t ms)
  93. {
  94. clock_cpu_delay_ms(ms);
  95. }
  96. void hpm_panel_delay_us(uint32_t us)
  97. {
  98. clock_cpu_delay_us(us);
  99. }