test_i80_lcd_panel.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "unity.h"
  4. #include "test_utils.h"
  5. #include "esp_lcd_panel_io.h"
  6. #include "esp_lcd_panel_vendor.h"
  7. #include "esp_lcd_panel_ops.h"
  8. #include "soc/soc_caps.h"
  9. #include "driver/gpio.h"
  10. #include "test_i80_board.h"
  11. #if SOC_LCDCAM_SUPPORTED
  12. TEST_CASE("lcd i80 device swap color bytes", "[lcd]")
  13. {
  14. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  15. esp_lcd_i80_bus_config_t bus_config = {
  16. .dc_gpio_num = TEST_LCD_DC_GPIO,
  17. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  18. .data_gpio_nums = {
  19. TEST_LCD_DATA0_GPIO,
  20. TEST_LCD_DATA1_GPIO,
  21. TEST_LCD_DATA2_GPIO,
  22. TEST_LCD_DATA3_GPIO,
  23. TEST_LCD_DATA4_GPIO,
  24. TEST_LCD_DATA5_GPIO,
  25. TEST_LCD_DATA6_GPIO,
  26. TEST_LCD_DATA7_GPIO,
  27. },
  28. .bus_width = 8,
  29. .max_transfer_bytes = 20,
  30. };
  31. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  32. esp_lcd_panel_io_handle_t io_handles[4] = {};
  33. esp_lcd_panel_io_i80_config_t io_config = {
  34. .cs_gpio_num = TEST_LCD_CS_GPIO,
  35. .pclk_hz = 5000000,
  36. .trans_queue_depth = 10,
  37. .dc_levels = {
  38. .dc_idle_level = 0,
  39. .dc_cmd_level = 0,
  40. .dc_dummy_level = 0,
  41. .dc_data_level = 1,
  42. },
  43. .lcd_cmd_bits = 8,
  44. .lcd_param_bits = 8,
  45. };
  46. io_config.flags.reverse_color_bits = 0;
  47. io_config.flags.swap_color_bytes = 0;
  48. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[0]));
  49. io_config.flags.reverse_color_bits = 0;
  50. io_config.flags.swap_color_bytes = 1;
  51. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[1]));
  52. io_config.flags.reverse_color_bits = 1;
  53. io_config.flags.swap_color_bytes = 0;
  54. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[2]));
  55. io_config.flags.reverse_color_bits = 1;
  56. io_config.flags.swap_color_bytes = 1;
  57. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[3]));
  58. for (int i = 0; i < 4; i++) {
  59. esp_lcd_panel_io_tx_param(io_handles[i], 0xA5, (uint8_t[]) {
  60. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
  61. }, 6);
  62. esp_lcd_panel_io_tx_color(io_handles[i], 0x5A, (uint8_t[]) {
  63. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
  64. }, 6);
  65. TEST_ESP_OK(esp_lcd_panel_io_del(io_handles[i]));
  66. }
  67. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  68. }
  69. TEST_CASE("lcd i80 device clock mode", "[lcd]")
  70. {
  71. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  72. esp_lcd_i80_bus_config_t bus_config = {
  73. .dc_gpio_num = TEST_LCD_DC_GPIO,
  74. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  75. .data_gpio_nums = {
  76. TEST_LCD_DATA0_GPIO,
  77. TEST_LCD_DATA1_GPIO,
  78. TEST_LCD_DATA2_GPIO,
  79. TEST_LCD_DATA3_GPIO,
  80. TEST_LCD_DATA4_GPIO,
  81. TEST_LCD_DATA5_GPIO,
  82. TEST_LCD_DATA6_GPIO,
  83. TEST_LCD_DATA7_GPIO,
  84. },
  85. .bus_width = 8,
  86. .max_transfer_bytes = 20,
  87. };
  88. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  89. esp_lcd_panel_io_handle_t io_handles[4] = {};
  90. esp_lcd_panel_io_i80_config_t io_config = {
  91. .cs_gpio_num = TEST_LCD_CS_GPIO,
  92. .pclk_hz = 5000000,
  93. .trans_queue_depth = 10,
  94. .dc_levels = {
  95. .dc_idle_level = 0,
  96. .dc_cmd_level = 0,
  97. .dc_dummy_level = 0,
  98. .dc_data_level = 1,
  99. },
  100. .lcd_cmd_bits = 8,
  101. .lcd_param_bits = 8,
  102. };
  103. io_config.flags.pclk_idle_low = 0;
  104. io_config.flags.pclk_active_neg = 0;
  105. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[0]));
  106. io_config.flags.pclk_idle_low = 0;
  107. io_config.flags.pclk_active_neg = 1;
  108. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[1]));
  109. io_config.flags.pclk_idle_low = 1;
  110. io_config.flags.pclk_active_neg = 0;
  111. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[2]));
  112. io_config.flags.pclk_idle_low = 1;
  113. io_config.flags.pclk_active_neg = 1;
  114. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handles[3]));
  115. for (int i = 0; i < 4; i++) {
  116. esp_lcd_panel_io_tx_param(io_handles[i], 0xA5, (uint8_t[]) {
  117. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06
  118. }, 6);
  119. TEST_ESP_OK(esp_lcd_panel_io_del(io_handles[i]));
  120. }
  121. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  122. }
  123. #endif // SOC_LCDCAM_SUPPORTED
  124. #if SOC_LCD_I80_SUPPORTED
  125. TEST_CASE("lcd i80 bus and device allocation", "[lcd]")
  126. {
  127. esp_lcd_i80_bus_handle_t i80_buses[SOC_LCD_I80_BUSES] = {};
  128. esp_lcd_i80_bus_config_t bus_config = {
  129. .dc_gpio_num = TEST_LCD_DC_GPIO,
  130. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  131. .data_gpio_nums = {
  132. TEST_LCD_DATA0_GPIO,
  133. TEST_LCD_DATA1_GPIO,
  134. TEST_LCD_DATA2_GPIO,
  135. TEST_LCD_DATA3_GPIO,
  136. TEST_LCD_DATA4_GPIO,
  137. TEST_LCD_DATA5_GPIO,
  138. TEST_LCD_DATA6_GPIO,
  139. TEST_LCD_DATA7_GPIO,
  140. },
  141. .bus_width = 8,
  142. .max_transfer_bytes = TEST_LCD_H_RES * 40 * sizeof(uint16_t)
  143. };
  144. for (int i = 0; i < SOC_LCD_I80_BUSES; i++) {
  145. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_buses[i]));
  146. }
  147. TEST_ASSERT_EQUAL(ESP_ERR_NOT_FOUND, esp_lcd_new_i80_bus(&bus_config, &i80_buses[0]));
  148. esp_lcd_panel_io_handle_t io_handles[10] = {};
  149. esp_lcd_panel_io_i80_config_t io_config = {
  150. .cs_gpio_num = TEST_LCD_CS_GPIO,
  151. .pclk_hz = 5000000,
  152. .trans_queue_depth = 4,
  153. .lcd_cmd_bits = 8,
  154. .lcd_param_bits = 8,
  155. };
  156. for (int i = 0; i < 10; i++) {
  157. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_buses[0], &io_config, &io_handles[i]));
  158. }
  159. // can't delete bus handle before we delete all devices
  160. TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, esp_lcd_del_i80_bus(i80_buses[0]));
  161. for (int i = 0; i < 10; i++) {
  162. TEST_ESP_OK(esp_lcd_panel_io_del(io_handles[i]));
  163. }
  164. for (int i = 0; i < SOC_LCD_I80_BUSES; i++) {
  165. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_buses[i]));
  166. }
  167. }
  168. TEST_CASE("lcd i80 bus exclusively owned by one device", "[lcd]")
  169. {
  170. esp_lcd_i80_bus_handle_t i80_bus_handle = NULL;
  171. esp_lcd_i80_bus_config_t bus_config = {
  172. .dc_gpio_num = TEST_LCD_DC_GPIO,
  173. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  174. .data_gpio_nums = {
  175. TEST_LCD_DATA0_GPIO,
  176. TEST_LCD_DATA1_GPIO,
  177. TEST_LCD_DATA2_GPIO,
  178. TEST_LCD_DATA3_GPIO,
  179. TEST_LCD_DATA4_GPIO,
  180. TEST_LCD_DATA5_GPIO,
  181. TEST_LCD_DATA6_GPIO,
  182. TEST_LCD_DATA7_GPIO,
  183. },
  184. .bus_width = 8,
  185. .max_transfer_bytes = TEST_LCD_H_RES * 40 * sizeof(uint16_t)
  186. };
  187. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus_handle));
  188. esp_lcd_panel_io_handle_t io_handle = NULL;
  189. esp_lcd_panel_io_i80_config_t io_config = {
  190. .cs_gpio_num = -1, // own the bus exclusively
  191. .pclk_hz = 5000000,
  192. .trans_queue_depth = 4,
  193. .lcd_cmd_bits = 8,
  194. .lcd_param_bits = 8,
  195. };
  196. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus_handle, &io_config, &io_handle));
  197. io_config.cs_gpio_num = 0;
  198. TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, esp_lcd_new_panel_io_i80(i80_bus_handle, &io_config, &io_handle));
  199. TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
  200. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus_handle));
  201. }
  202. TEST_CASE("lcd panel i80 io test", "[lcd]")
  203. {
  204. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  205. esp_lcd_i80_bus_config_t bus_config = {
  206. .dc_gpio_num = TEST_LCD_DC_GPIO,
  207. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  208. .data_gpio_nums = {
  209. TEST_LCD_DATA0_GPIO,
  210. TEST_LCD_DATA1_GPIO,
  211. TEST_LCD_DATA2_GPIO,
  212. TEST_LCD_DATA3_GPIO,
  213. TEST_LCD_DATA4_GPIO,
  214. TEST_LCD_DATA5_GPIO,
  215. TEST_LCD_DATA6_GPIO,
  216. TEST_LCD_DATA7_GPIO,
  217. TEST_LCD_DATA8_GPIO,
  218. TEST_LCD_DATA9_GPIO,
  219. TEST_LCD_DATA10_GPIO,
  220. TEST_LCD_DATA11_GPIO,
  221. TEST_LCD_DATA12_GPIO,
  222. TEST_LCD_DATA13_GPIO,
  223. TEST_LCD_DATA14_GPIO,
  224. TEST_LCD_DATA15_GPIO,
  225. },
  226. .bus_width = 16,
  227. .max_transfer_bytes = 100,
  228. };
  229. esp_lcd_panel_io_handle_t io_handle = NULL;
  230. esp_lcd_panel_io_i80_config_t io_config = {
  231. .cs_gpio_num = TEST_LCD_CS_GPIO,
  232. .pclk_hz = 8000000, // 8MHz
  233. .trans_queue_depth = 10,
  234. .dc_levels = {
  235. .dc_idle_level = 0,
  236. .dc_cmd_level = 0,
  237. .dc_dummy_level = 0,
  238. .dc_data_level = 1,
  239. },
  240. };
  241. esp_lcd_panel_handle_t panel_handle = NULL;
  242. esp_lcd_panel_dev_config_t panel_config = {
  243. .reset_gpio_num = TEST_LCD_RST_GPIO,
  244. .color_space = ESP_LCD_COLOR_SPACE_RGB,
  245. .bits_per_pixel = 16,
  246. };
  247. // On esp32, GPIO16 and GPIO17 are connected to PSRAM, and we don't have other spare GPIOs can be used in the test
  248. // so we skip the 16bit test on esp32 when PSRAM is enabled
  249. #if !CONFIG_ESP32_SPIRAM_SUPPORT
  250. printf("testing bus-width=16bit, cmd/param bit-width=8bit\r\n");
  251. bus_config.bus_width = 16;
  252. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  253. io_config.lcd_cmd_bits = 8;
  254. io_config.lcd_param_bits = 8;
  255. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  256. TEST_ESP_OK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
  257. esp_lcd_panel_io_tx_param(io_handle, 0x1A, NULL, 0);
  258. esp_lcd_panel_io_tx_param(io_handle, 0x1B, (uint8_t[]) {
  259. 0x11, 0x22, 0x33
  260. }, 3);
  261. esp_lcd_panel_io_tx_param(io_handle, 0x1C, NULL, 0);
  262. TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
  263. TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
  264. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  265. printf("testing bus-width=16bit, cmd/param bit-width=16bit\r\n");
  266. bus_config.bus_width = 16;
  267. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  268. io_config.lcd_cmd_bits = 16;
  269. io_config.lcd_param_bits = 16;
  270. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  271. TEST_ESP_OK(esp_lcd_new_panel_nt35510(io_handle, &panel_config, &panel_handle));
  272. esp_lcd_panel_io_tx_param(io_handle, 0x1A01, NULL, 0);
  273. esp_lcd_panel_io_tx_param(io_handle, 0x1B02, (uint16_t[]) {
  274. 0x11, 0x22, 0x33
  275. }, 6);
  276. esp_lcd_panel_io_tx_param(io_handle, 0x1C03, NULL, 0);
  277. TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
  278. TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
  279. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  280. #endif
  281. printf("testing bus-width=8bit, cmd/param bit-width=8bit\r\n");
  282. bus_config.bus_width = 8;
  283. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  284. io_config.lcd_cmd_bits = 8;
  285. io_config.lcd_param_bits = 8;
  286. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  287. TEST_ESP_OK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
  288. esp_lcd_panel_io_tx_param(io_handle, 0x1A, NULL, 0);
  289. esp_lcd_panel_io_tx_param(io_handle, 0x1B, (uint8_t[]) {
  290. 0x11, 0x22, 0x33
  291. }, 3);
  292. esp_lcd_panel_io_tx_param(io_handle, 0x1C, NULL, 0);
  293. TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
  294. TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
  295. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  296. printf("testing bus-width=8bit, cmd/param bit-width=16bit\r\n");
  297. bus_config.bus_width = 8;
  298. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  299. io_config.lcd_cmd_bits = 16;
  300. io_config.lcd_param_bits = 16;
  301. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  302. TEST_ESP_OK(esp_lcd_new_panel_nt35510(io_handle, &panel_config, &panel_handle));
  303. esp_lcd_panel_io_tx_param(io_handle, 0x1A01, NULL, 0);
  304. esp_lcd_panel_io_tx_param(io_handle, 0x1B02, (uint16_t[]) {
  305. 0x11, 0x22, 0x33
  306. }, 6);
  307. esp_lcd_panel_io_tx_param(io_handle, 0x1C03, NULL, 0);
  308. TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
  309. TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
  310. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  311. }
  312. TEST_CASE("lcd panel with i80 interface (st7789, 8bits)", "[lcd]")
  313. {
  314. #define TEST_IMG_SIZE (100 * 100 * sizeof(uint16_t))
  315. uint8_t *img = heap_caps_malloc(TEST_IMG_SIZE, MALLOC_CAP_DMA);
  316. TEST_ASSERT_NOT_NULL(img);
  317. gpio_config_t bk_gpio_config = {
  318. .mode = GPIO_MODE_OUTPUT,
  319. .pin_bit_mask = 1ULL << TEST_LCD_BK_LIGHT_GPIO
  320. };
  321. TEST_ESP_OK(gpio_config(&bk_gpio_config));
  322. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  323. esp_lcd_i80_bus_config_t bus_config = {
  324. .dc_gpio_num = TEST_LCD_DC_GPIO,
  325. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  326. .data_gpio_nums = {
  327. TEST_LCD_DATA0_GPIO,
  328. TEST_LCD_DATA1_GPIO,
  329. TEST_LCD_DATA2_GPIO,
  330. TEST_LCD_DATA3_GPIO,
  331. TEST_LCD_DATA4_GPIO,
  332. TEST_LCD_DATA5_GPIO,
  333. TEST_LCD_DATA6_GPIO,
  334. TEST_LCD_DATA7_GPIO,
  335. },
  336. .bus_width = 8,
  337. .max_transfer_bytes = TEST_IMG_SIZE + 10,
  338. };
  339. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  340. esp_lcd_panel_io_handle_t io_handle = NULL;
  341. esp_lcd_panel_io_i80_config_t io_config = {
  342. .cs_gpio_num = TEST_LCD_CS_GPIO,
  343. .pclk_hz = 8000000, // 8MHz
  344. .trans_queue_depth = 10,
  345. .dc_levels = {
  346. .dc_idle_level = 0,
  347. .dc_cmd_level = 0,
  348. .dc_dummy_level = 0,
  349. .dc_data_level = 1,
  350. },
  351. .lcd_cmd_bits = 8,
  352. .lcd_param_bits = 8,
  353. };
  354. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  355. esp_lcd_panel_handle_t panel_handle = NULL;
  356. esp_lcd_panel_dev_config_t panel_config = {
  357. .reset_gpio_num = TEST_LCD_RST_GPIO,
  358. .color_space = ESP_LCD_COLOR_SPACE_RGB,
  359. .bits_per_pixel = 16,
  360. };
  361. TEST_ESP_OK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
  362. // turn off backlight
  363. gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 0);
  364. esp_lcd_panel_reset(panel_handle);
  365. esp_lcd_panel_init(panel_handle);
  366. esp_lcd_panel_invert_color(panel_handle, true);
  367. // the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
  368. esp_lcd_panel_set_gap(panel_handle, 0, 20);
  369. // turn on backlight
  370. gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 1);
  371. for (int i = 0; i < 200; i++) {
  372. uint8_t color_byte = esp_random() & 0xFF;
  373. int x_start = esp_random() % (TEST_LCD_H_RES - 100);
  374. int y_start = esp_random() % (TEST_LCD_V_RES - 100);
  375. memset(img, color_byte, TEST_IMG_SIZE);
  376. esp_lcd_panel_draw_bitmap(panel_handle, x_start, y_start, x_start + 100, y_start + 100, img);
  377. }
  378. esp_lcd_panel_disp_off(panel_handle, true); // turn off screen
  379. TEST_ESP_OK(esp_lcd_panel_del(panel_handle));
  380. TEST_ESP_OK(esp_lcd_panel_io_del(io_handle));
  381. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  382. TEST_ESP_OK(gpio_reset_pin(TEST_LCD_BK_LIGHT_GPIO));
  383. free(img);
  384. #undef TEST_IMG_SIZE
  385. }
  386. // The following test shows a porting example of LVGL GUI library
  387. // To run the LVGL tests, you need to clone the LVGL library into components directory firstly
  388. #if CONFIG_LV_USE_USER_DATA
  389. #include "test_lvgl_port.h"
  390. static bool notify_lvgl_ready_to_flush(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
  391. {
  392. lv_disp_t *disp = *(lv_disp_t **)user_ctx;
  393. lv_disp_flush_ready(&disp->driver);
  394. return false;
  395. }
  396. TEST_CASE("lvgl gui with i80 interface (st7789, 8bits)", "[lcd][lvgl][ignore]")
  397. {
  398. // initialize LVGL graphics library
  399. lv_disp_t *disp = NULL;
  400. lv_init();
  401. gpio_config_t bk_gpio_config = {
  402. .mode = GPIO_MODE_OUTPUT,
  403. .pin_bit_mask = 1ULL << TEST_LCD_BK_LIGHT_GPIO
  404. };
  405. TEST_ESP_OK(gpio_config(&bk_gpio_config));
  406. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  407. esp_lcd_i80_bus_config_t bus_config = {
  408. .dc_gpio_num = TEST_LCD_DC_GPIO,
  409. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  410. .data_gpio_nums = {
  411. TEST_LCD_DATA0_GPIO,
  412. TEST_LCD_DATA1_GPIO,
  413. TEST_LCD_DATA2_GPIO,
  414. TEST_LCD_DATA3_GPIO,
  415. TEST_LCD_DATA4_GPIO,
  416. TEST_LCD_DATA5_GPIO,
  417. TEST_LCD_DATA6_GPIO,
  418. TEST_LCD_DATA7_GPIO,
  419. },
  420. .bus_width = 8,
  421. .max_transfer_bytes = TEST_LCD_H_RES * 40 * sizeof(uint16_t)
  422. };
  423. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  424. esp_lcd_panel_io_handle_t io_handle = NULL;
  425. esp_lcd_panel_io_i80_config_t io_config = {
  426. .cs_gpio_num = TEST_LCD_CS_GPIO,
  427. .pclk_hz = 10000000, // 10MHz
  428. .trans_queue_depth = 10,
  429. .dc_levels = {
  430. .dc_idle_level = 0,
  431. .dc_cmd_level = 0,
  432. .dc_dummy_level = 0,
  433. .dc_data_level = 1,
  434. },
  435. .flags = {
  436. .swap_color_bytes = 1,
  437. },
  438. .on_color_trans_done = notify_lvgl_ready_to_flush,
  439. .user_ctx = &disp,
  440. .lcd_cmd_bits = 8,
  441. .lcd_param_bits = 8,
  442. };
  443. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  444. esp_lcd_panel_handle_t panel_handle = NULL;
  445. esp_lcd_panel_dev_config_t panel_config = {
  446. .reset_gpio_num = TEST_LCD_RST_GPIO,
  447. .color_space = ESP_LCD_COLOR_SPACE_RGB,
  448. .bits_per_pixel = 16,
  449. };
  450. TEST_ESP_OK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
  451. // turn off backlight
  452. gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 0);
  453. esp_lcd_panel_reset(panel_handle);
  454. esp_lcd_panel_init(panel_handle);
  455. esp_lcd_panel_invert_color(panel_handle, true);
  456. // the gap is LCD panel specific, even panels with the same driver IC, can have different gap value
  457. esp_lcd_panel_set_gap(panel_handle, 0, 20);
  458. // turn on backlight
  459. gpio_set_level(TEST_LCD_BK_LIGHT_GPIO, 1);
  460. test_lvgl_task_loop(panel_handle, TEST_LCD_H_RES, TEST_LCD_V_RES, &disp);
  461. }
  462. #define TEST_NT35510_DATA_WIDTH (8) // change this to 16 when NT35510 is configured to 16bit in length
  463. TEST_CASE("lvgl gui with i80 interface (nt35510, 8/16bits)", "[lcd][lvgl][ignore]")
  464. {
  465. // initialize LVGL graphics library
  466. lv_disp_t *disp = NULL;
  467. lv_init();
  468. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  469. esp_lcd_i80_bus_config_t bus_config = {
  470. .dc_gpio_num = TEST_LCD_DC_GPIO,
  471. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  472. .data_gpio_nums = {
  473. TEST_LCD_DATA0_GPIO,
  474. TEST_LCD_DATA1_GPIO,
  475. TEST_LCD_DATA2_GPIO,
  476. TEST_LCD_DATA3_GPIO,
  477. TEST_LCD_DATA4_GPIO,
  478. TEST_LCD_DATA5_GPIO,
  479. TEST_LCD_DATA6_GPIO,
  480. TEST_LCD_DATA7_GPIO,
  481. TEST_LCD_DATA8_GPIO,
  482. TEST_LCD_DATA9_GPIO,
  483. TEST_LCD_DATA10_GPIO,
  484. TEST_LCD_DATA11_GPIO,
  485. TEST_LCD_DATA12_GPIO,
  486. TEST_LCD_DATA13_GPIO,
  487. TEST_LCD_DATA14_GPIO,
  488. TEST_LCD_DATA15_GPIO,
  489. },
  490. .bus_width = TEST_NT35510_DATA_WIDTH,
  491. .max_transfer_bytes = TEST_LCD_H_RES * 40 * sizeof(uint16_t)
  492. };
  493. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  494. esp_lcd_panel_io_handle_t io_handle = NULL;
  495. esp_lcd_panel_io_i80_config_t io_config = {
  496. .cs_gpio_num = TEST_LCD_CS_GPIO,
  497. .pclk_hz = 10000000, // 10MHz
  498. .trans_queue_depth = 4,
  499. .dc_levels = {
  500. .dc_idle_level = 0,
  501. .dc_cmd_level = 0,
  502. .dc_dummy_level = 0,
  503. .dc_data_level = 1,
  504. },
  505. .on_color_trans_done = notify_lvgl_ready_to_flush,
  506. .user_ctx = &disp,
  507. .lcd_cmd_bits = 16,
  508. .lcd_param_bits = 16,
  509. };
  510. TEST_ESP_OK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, &io_handle));
  511. esp_lcd_panel_handle_t panel_handle = NULL;
  512. esp_lcd_panel_dev_config_t panel_config = {
  513. .reset_gpio_num = -1,
  514. .color_space = ESP_LCD_COLOR_SPACE_RGB,
  515. .bits_per_pixel = 16,
  516. };
  517. TEST_ESP_OK(esp_lcd_new_panel_nt35510(io_handle, &panel_config, &panel_handle));
  518. esp_lcd_panel_reset(panel_handle);
  519. esp_lcd_panel_init(panel_handle);
  520. esp_lcd_panel_swap_xy(panel_handle, true);
  521. esp_lcd_panel_mirror(panel_handle, true, false);
  522. test_lvgl_task_loop(panel_handle, TEST_LCD_H_RES, TEST_LCD_V_RES, &disp);
  523. }
  524. #endif // CONFIG_LV_USE_USER_DATA
  525. #endif // SOC_LCD_I80_SUPPORTED
  526. #if SOC_I2S_LCD_I80_VARIANT
  527. #include "driver/i2s.h"
  528. TEST_CASE("i80 and i2s driver coexistance", "[lcd][i2s]")
  529. {
  530. esp_lcd_i80_bus_handle_t i80_bus = NULL;
  531. esp_lcd_i80_bus_config_t bus_config = {
  532. .dc_gpio_num = TEST_LCD_DC_GPIO,
  533. .wr_gpio_num = TEST_LCD_PCLK_GPIO,
  534. .data_gpio_nums = {
  535. TEST_LCD_DATA0_GPIO,
  536. TEST_LCD_DATA1_GPIO,
  537. TEST_LCD_DATA2_GPIO,
  538. TEST_LCD_DATA3_GPIO,
  539. TEST_LCD_DATA4_GPIO,
  540. TEST_LCD_DATA5_GPIO,
  541. TEST_LCD_DATA6_GPIO,
  542. TEST_LCD_DATA7_GPIO,
  543. },
  544. .bus_width = 8,
  545. .max_transfer_bytes = 20,
  546. };
  547. TEST_ESP_OK(esp_lcd_new_i80_bus(&bus_config, &i80_bus));
  548. i2s_config_t i2s_config = {
  549. .mode = I2S_MODE_MASTER | I2S_MODE_TX,
  550. .sample_rate = 36000,
  551. .bits_per_sample = 16,
  552. .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
  553. .communication_format = I2S_COMM_FORMAT_STAND_I2S,
  554. .dma_buf_count = 6,
  555. .dma_buf_len = 60,
  556. };
  557. // I2S driver won't be installed as the same I2S port has been used by LCD
  558. TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, i2s_driver_install(0, &i2s_config, 0, NULL));
  559. TEST_ESP_OK(esp_lcd_del_i80_bus(i80_bus));
  560. }
  561. #endif // SOC_I2S_LCD_I80_VARIANT