test_rgb_panel.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "unity.h"
  4. #include "test_utils.h"
  5. #include "esp_lcd_panel_rgb.h"
  6. #include "esp_lcd_panel_ops.h"
  7. #include "soc/soc_caps.h"
  8. #define TEST_LCD_H_RES (480)
  9. #define TEST_LCD_V_RES (272)
  10. #define TEST_LCD_VSYNC_GPIO (48)
  11. #define TEST_LCD_HSYNC_GPIO (47)
  12. #define TEST_LCD_DE_GPIO (45)
  13. #define TEST_LCD_PCLK_GPIO (21)
  14. #define TEST_LCD_DATA0_GPIO (3) // B0
  15. #define TEST_LCD_DATA1_GPIO (4) // B1
  16. #define TEST_LCD_DATA2_GPIO (5) // B2
  17. #define TEST_LCD_DATA3_GPIO (6) // B3
  18. #define TEST_LCD_DATA4_GPIO (7) // B4
  19. #define TEST_LCD_DATA5_GPIO (8) // G0
  20. #define TEST_LCD_DATA6_GPIO (9) // G1
  21. #define TEST_LCD_DATA7_GPIO (10) // G2
  22. #define TEST_LCD_DATA8_GPIO (11) // G3
  23. #define TEST_LCD_DATA9_GPIO (12) // G4
  24. #define TEST_LCD_DATA10_GPIO (13) // G5
  25. #define TEST_LCD_DATA11_GPIO (14) // R0
  26. #define TEST_LCD_DATA12_GPIO (15) // R1
  27. #define TEST_LCD_DATA13_GPIO (16) // R2
  28. #define TEST_LCD_DATA14_GPIO (17) // R3
  29. #define TEST_LCD_DATA15_GPIO (18) // R4
  30. #define TEST_LCD_DISP_EN_GPIO (39)
  31. #if SOC_LCD_RGB_SUPPORTED
  32. // RGB driver consumes a huge memory to save frame buffer, only test it with PSRAM enabled
  33. #if CONFIG_SPIRAM_USE_MALLOC
  34. TEST_CASE("lcd rgb lcd panel", "[lcd]")
  35. {
  36. #define TEST_IMG_SIZE (100 * 100 * sizeof(uint16_t))
  37. uint8_t *img = malloc(TEST_IMG_SIZE);
  38. TEST_ASSERT_NOT_NULL(img);
  39. esp_lcd_panel_handle_t panel_handle = NULL;
  40. esp_lcd_rgb_panel_config_t panel_config = {
  41. .data_width = 16,
  42. .disp_gpio_num = TEST_LCD_DISP_EN_GPIO,
  43. .pclk_gpio_num = TEST_LCD_PCLK_GPIO,
  44. .vsync_gpio_num = TEST_LCD_VSYNC_GPIO,
  45. .hsync_gpio_num = TEST_LCD_HSYNC_GPIO,
  46. .de_gpio_num = TEST_LCD_DE_GPIO,
  47. .data_gpio_nums = {
  48. TEST_LCD_DATA0_GPIO,
  49. TEST_LCD_DATA1_GPIO,
  50. TEST_LCD_DATA2_GPIO,
  51. TEST_LCD_DATA3_GPIO,
  52. TEST_LCD_DATA4_GPIO,
  53. TEST_LCD_DATA5_GPIO,
  54. TEST_LCD_DATA6_GPIO,
  55. TEST_LCD_DATA7_GPIO,
  56. TEST_LCD_DATA8_GPIO,
  57. TEST_LCD_DATA9_GPIO,
  58. TEST_LCD_DATA10_GPIO,
  59. TEST_LCD_DATA11_GPIO,
  60. TEST_LCD_DATA12_GPIO,
  61. TEST_LCD_DATA13_GPIO,
  62. TEST_LCD_DATA14_GPIO,
  63. TEST_LCD_DATA15_GPIO,
  64. },
  65. .timings = {
  66. .pclk_hz = 12000000,
  67. .h_res = TEST_LCD_H_RES,
  68. .v_res = TEST_LCD_V_RES,
  69. .hsync_back_porch = 43,
  70. .hsync_front_porch = 2,
  71. .hsync_pulse_width = 1,
  72. .vsync_back_porch = 12,
  73. .vsync_front_porch = 1,
  74. .vsync_pulse_width = 1,
  75. },
  76. .flags.fb_in_psram = 1,
  77. };
  78. // Test stream mode and one-off mode
  79. for (int i = 0; i < 2; i++) {
  80. panel_config.flags.relax_on_idle = i;
  81. TEST_ESP_OK(esp_lcd_new_rgb_panel(&panel_config, &panel_handle));
  82. TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
  83. TEST_ESP_OK(esp_lcd_panel_init(panel_handle));
  84. for (int i = 0; i < 200; i++) {
  85. uint8_t color_byte = esp_random() & 0xFF;
  86. int x_start = esp_random() % (TEST_LCD_H_RES - 100);
  87. int y_start = esp_random() % (TEST_LCD_V_RES - 100);
  88. memset(img, color_byte, TEST_IMG_SIZE);
  89. esp_lcd_panel_draw_bitmap(panel_handle, x_start, y_start, x_start + 100, y_start + 100, img);
  90. }
  91. TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
  92. }
  93. free(img);
  94. #undef TEST_IMG_SIZE
  95. }
  96. // The following test shows a porting example of LVGL GUI library
  97. // To run the LVGL tests, you need to clone the LVGL library into components directory firstly
  98. #if CONFIG_LV_USE_USER_DATA
  99. #include "test_lvgl_port.h"
  100. static bool notify_lvgl_ready_to_flush(esp_lcd_panel_handle_t panel, esp_lcd_rgb_panel_event_data_t *edata, void *user_ctx)
  101. {
  102. lv_disp_t *disp = *(lv_disp_t **)user_ctx;
  103. lv_disp_flush_ready(&disp->driver);
  104. return false;
  105. }
  106. TEST_CASE("lvgl gui with rgb interface", "[lcd][lvgl][ignore]")
  107. {
  108. // initialize LVGL graphics library
  109. lv_disp_t *disp = NULL;
  110. lv_init();
  111. esp_lcd_panel_handle_t panel_handle = NULL;
  112. esp_lcd_rgb_panel_config_t panel_config = {
  113. .data_width = 16,
  114. .disp_gpio_num = -1,
  115. .pclk_gpio_num = TEST_LCD_PCLK_GPIO,
  116. .vsync_gpio_num = TEST_LCD_VSYNC_GPIO,
  117. .hsync_gpio_num = TEST_LCD_HSYNC_GPIO,
  118. .de_gpio_num = TEST_LCD_DE_GPIO,
  119. .data_gpio_nums = {
  120. TEST_LCD_DATA0_GPIO,
  121. TEST_LCD_DATA1_GPIO,
  122. TEST_LCD_DATA2_GPIO,
  123. TEST_LCD_DATA3_GPIO,
  124. TEST_LCD_DATA4_GPIO,
  125. TEST_LCD_DATA5_GPIO,
  126. TEST_LCD_DATA6_GPIO,
  127. TEST_LCD_DATA7_GPIO,
  128. TEST_LCD_DATA8_GPIO,
  129. TEST_LCD_DATA9_GPIO,
  130. TEST_LCD_DATA10_GPIO,
  131. TEST_LCD_DATA11_GPIO,
  132. TEST_LCD_DATA12_GPIO,
  133. TEST_LCD_DATA13_GPIO,
  134. TEST_LCD_DATA14_GPIO,
  135. TEST_LCD_DATA15_GPIO,
  136. },
  137. .timings = {
  138. .pclk_hz = 6000000,
  139. .h_res = TEST_LCD_H_RES,
  140. .v_res = TEST_LCD_V_RES,
  141. .hsync_back_porch = 43,
  142. .hsync_front_porch = 2,
  143. .hsync_pulse_width = 1,
  144. .vsync_back_porch = 12,
  145. .vsync_front_porch = 1,
  146. .vsync_pulse_width = 1,
  147. },
  148. .flags.fb_in_psram = 1,
  149. .on_frame_trans_done = notify_lvgl_ready_to_flush,
  150. .user_ctx = &disp,
  151. };
  152. TEST_ESP_OK(esp_lcd_new_rgb_panel(&panel_config, &panel_handle));
  153. TEST_ESP_OK(esp_lcd_panel_reset(panel_handle));
  154. TEST_ESP_OK(esp_lcd_panel_init(panel_handle));
  155. test_lvgl_task_loop(panel_handle, TEST_LCD_H_RES, TEST_LCD_V_RES, &disp);
  156. }
  157. #endif // CONFIG_LV_USE_USER_DATA
  158. #endif // CONFIG_SPIRAM_USE_MALLOC
  159. #endif // SOC_LCD_RGB_SUPPORTED