|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | +#include <stdio.h> |
| 7 | +#include <string.h> |
| 8 | +#include <inttypes.h> |
| 9 | +#include "freertos/FreeRTOS.h" |
| 10 | +#include "freertos/task.h" |
| 11 | +#include "unity.h" |
| 12 | +#include "unity_test_utils.h" |
| 13 | +#include "esp_lcd_mipi_dsi.h" |
| 14 | +#include "esp_lcd_panel_ops.h" |
| 15 | +#include "esp_lcd_panel_io.h" |
| 16 | +#include "esp_random.h" |
| 17 | +#include "esp_attr.h" |
| 18 | +#include "test_mipi_dsi_board.h" |
| 19 | +#include "esp_lcd_ili9881c.h" |
| 20 | + |
| 21 | +IRAM_ATTR static bool test_rgb_panel_count_in_callback(esp_lcd_panel_handle_t panel, esp_lcd_dpi_panel_event_data_t *edata, void *user_ctx) |
| 22 | +{ |
| 23 | + uint32_t *count = (uint32_t *)user_ctx; |
| 24 | + *count = *count + 1; |
| 25 | + return false; |
| 26 | +} |
| 27 | + |
| 28 | +static void IRAM_ATTR test_delay_post_cache_disable(void *args) |
| 29 | +{ |
| 30 | + esp_rom_delay_us(200000); |
| 31 | +} |
| 32 | + |
| 33 | +#define TEST_IMG_SIZE (100 * 100 * sizeof(uint16_t)) |
| 34 | + |
| 35 | +TEST_CASE("MIPI DSI draw bitmap (ILI9881C) IRAM Safe", "[mipi_dsi]") |
| 36 | +{ |
| 37 | + esp_lcd_dsi_bus_handle_t mipi_dsi_bus; |
| 38 | + esp_lcd_panel_io_handle_t mipi_dbi_io; |
| 39 | + esp_lcd_panel_handle_t mipi_dpi_panel; |
| 40 | + esp_lcd_panel_handle_t ili9881c_ctrl_panel; |
| 41 | + |
| 42 | + test_bsp_enable_dsi_phy_power(); |
| 43 | + |
| 44 | + uint8_t *img = malloc(TEST_IMG_SIZE); |
| 45 | + TEST_ASSERT_NOT_NULL(img); |
| 46 | + |
| 47 | + esp_lcd_dsi_bus_config_t bus_config = { |
| 48 | + .bus_id = 0, |
| 49 | + .num_data_lanes = 2, |
| 50 | + .phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT, |
| 51 | + .lane_bit_rate_mbps = 1000, // 1000 Mbps |
| 52 | + }; |
| 53 | + TEST_ESP_OK(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus)); |
| 54 | + |
| 55 | + esp_lcd_dbi_io_config_t dbi_config = { |
| 56 | + .virtual_channel = 0, |
| 57 | + .lcd_cmd_bits = 8, |
| 58 | + .lcd_param_bits = 8, |
| 59 | + }; |
| 60 | + TEST_ESP_OK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &mipi_dbi_io)); |
| 61 | + |
| 62 | + esp_lcd_panel_dev_config_t lcd_dev_config = { |
| 63 | + .bits_per_pixel = 16, |
| 64 | + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, |
| 65 | + .reset_gpio_num = -1, |
| 66 | + }; |
| 67 | + TEST_ESP_OK(esp_lcd_new_panel_ili9881c(mipi_dbi_io, &lcd_dev_config, &ili9881c_ctrl_panel)); |
| 68 | + TEST_ESP_OK(esp_lcd_panel_reset(ili9881c_ctrl_panel)); |
| 69 | + TEST_ESP_OK(esp_lcd_panel_init(ili9881c_ctrl_panel)); |
| 70 | + // turn on display |
| 71 | + TEST_ESP_OK(esp_lcd_panel_disp_on_off(ili9881c_ctrl_panel, true)); |
| 72 | + |
| 73 | + esp_lcd_dpi_panel_config_t dpi_config = { |
| 74 | + .dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT, |
| 75 | + .dpi_clock_freq_mhz = MIPI_DSI_DPI_CLK_MHZ, |
| 76 | + .virtual_channel = 0, |
| 77 | + .pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565, |
| 78 | + .video_timing = { |
| 79 | + .h_size = MIPI_DSI_LCD_H_RES, |
| 80 | + .v_size = MIPI_DSI_LCD_V_RES, |
| 81 | + .hsync_back_porch = MIPI_DSI_LCD_HBP, |
| 82 | + .hsync_pulse_width = MIPI_DSI_LCD_HSYNC, |
| 83 | + .hsync_front_porch = MIPI_DSI_LCD_HFP, |
| 84 | + .vsync_back_porch = MIPI_DSI_LCD_VBP, |
| 85 | + .vsync_pulse_width = MIPI_DSI_LCD_VSYNC, |
| 86 | + .vsync_front_porch = MIPI_DSI_LCD_VFP, |
| 87 | + }, |
| 88 | + }; |
| 89 | + TEST_ESP_OK(esp_lcd_new_panel_dpi(mipi_dsi_bus, &dpi_config, &mipi_dpi_panel)); |
| 90 | + TEST_ESP_OK(esp_lcd_panel_init(mipi_dpi_panel)); |
| 91 | + uint32_t callback_calls = 0; |
| 92 | + esp_lcd_dpi_panel_event_callbacks_t cbs = { |
| 93 | + .on_refresh_done = test_rgb_panel_count_in_callback, |
| 94 | + }; |
| 95 | + TEST_ESP_OK(esp_lcd_dpi_panel_register_event_callbacks(mipi_dpi_panel, &cbs, &callback_calls)); |
| 96 | + |
| 97 | + uint8_t color_byte = rand() & 0xFF; |
| 98 | + int x_start = rand() % (MIPI_DSI_LCD_H_RES - 100); |
| 99 | + int y_start = rand() % (MIPI_DSI_LCD_V_RES - 100); |
| 100 | + memset(img, color_byte, TEST_IMG_SIZE); |
| 101 | + esp_lcd_panel_draw_bitmap(mipi_dpi_panel, x_start, y_start, x_start + 100, y_start + 100, img); |
| 102 | + vTaskDelay(pdMS_TO_TICKS(100)); |
| 103 | + |
| 104 | + printf("The LCD driver should keep flushing the color block in the background\r\n"); |
| 105 | + |
| 106 | + // disable the cache for a while, the LCD driver should stay working |
| 107 | + printf("disable the cache for a while\r\n"); |
| 108 | + unity_utils_run_cache_disable_stub(test_delay_post_cache_disable, NULL); |
| 109 | + printf("callback calls: %"PRIu32"\r\n", callback_calls); |
| 110 | + TEST_ASSERT(callback_calls > 2); |
| 111 | + |
| 112 | + TEST_ESP_OK(esp_lcd_panel_del(mipi_dpi_panel)); |
| 113 | + TEST_ESP_OK(esp_lcd_panel_del(ili9881c_ctrl_panel)); |
| 114 | + TEST_ESP_OK(esp_lcd_panel_io_del(mipi_dbi_io)); |
| 115 | + TEST_ESP_OK(esp_lcd_del_dsi_bus(mipi_dsi_bus)); |
| 116 | + free(img); |
| 117 | + |
| 118 | + test_bsp_disable_dsi_phy_power(); |
| 119 | +} |
0 commit comments