diff --git a/components/esp_lcd/dsi/esp_lcd_mipi_dsi_bus.c b/components/esp_lcd/dsi/esp_lcd_mipi_dsi_bus.c index 26b75ad507..49933e0160 100644 --- a/components/esp_lcd/dsi/esp_lcd_mipi_dsi_bus.c +++ b/components/esp_lcd/dsi/esp_lcd_mipi_dsi_bus.c @@ -40,8 +40,6 @@ esp_err_t esp_lcd_new_dsi_bus(const esp_lcd_dsi_bus_config_t *bus_config, esp_lc // Enable the APB clock for accessing the DSI host and bridge registers DSI_RCC_ATOMIC() { mipi_dsi_ll_enable_bus_clock(bus_id, true); - mipi_dsi_ll_enable_host_clock(bus_id, true); - mipi_dsi_ll_enable_host_config_clock(bus_id, true); mipi_dsi_ll_reset_register(bus_id); } @@ -144,8 +142,6 @@ esp_err_t esp_lcd_del_dsi_bus(esp_lcd_dsi_bus_handle_t bus) // disable the APB clock for accessing the DSI peripheral registers DSI_RCC_ATOMIC() { mipi_dsi_ll_enable_bus_clock(bus_id, false); - mipi_dsi_ll_enable_host_clock(bus_id, false); - mipi_dsi_ll_enable_host_config_clock(bus_id, false); } if (bus->pm_lock) { esp_pm_lock_release(bus->pm_lock); diff --git a/components/esp_lcd/dsi/esp_lcd_panel_dpi.c b/components/esp_lcd/dsi/esp_lcd_panel_dpi.c index 4bec7273eb..c41a8d7d6f 100644 --- a/components/esp_lcd/dsi/esp_lcd_panel_dpi.c +++ b/components/esp_lcd/dsi/esp_lcd_panel_dpi.c @@ -448,7 +448,7 @@ static esp_err_t dpi_panel_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int } if (!do_copy) { // no copy, just do cache memory write back - ESP_LOGD(TAG, "draw buffer is in frame buffer memory range, do cache write back only"); + ESP_LOGV(TAG, "draw buffer is in frame buffer memory range, do cache write back only"); // only write back the LCD lines that updated by the draw buffer uint8_t *cache_sync_start = dpi_panel->fbs[draw_buf_fb_index] + (y_start * dpi_panel->h_pixels) * bits_per_pixel / 8; size_t cache_sync_size = (y_end - y_start) * dpi_panel->h_pixels * bits_per_pixel / 8; @@ -461,7 +461,7 @@ static esp_err_t dpi_panel_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int dpi_panel->on_color_trans_done(&dpi_panel->base, NULL, dpi_panel->user_ctx); } } else if (!dpi_panel->fbcpy_handle) { // copy by CPU - ESP_LOGD(TAG, "copy draw buffer by CPU"); + ESP_LOGV(TAG, "copy draw buffer by CPU"); const uint8_t *from = draw_buffer; uint8_t *to = frame_buffer + (y_start * dpi_panel->h_pixels + x_start) * bits_per_pixel / 8; uint32_t copy_bytes_per_line = (x_end - x_start) * bits_per_pixel / 8; @@ -482,7 +482,7 @@ static esp_err_t dpi_panel_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int dpi_panel->on_color_trans_done(&dpi_panel->base, NULL, dpi_panel->user_ctx); } } else { // copy by DMA2D - ESP_LOGD(TAG, "copy draw buffer by DMA2D"); + ESP_LOGV(TAG, "copy draw buffer by DMA2D"); // ensure the previous draw operation is finished ESP_RETURN_ON_FALSE(xSemaphoreTake(dpi_panel->draw_sem, 0) == pdTRUE, ESP_ERR_INVALID_STATE, TAG, "previous draw operation is not finished"); diff --git a/components/hal/esp32p4/include/hal/mipi_dsi_brg_ll.h b/components/hal/esp32p4/include/hal/mipi_dsi_brg_ll.h index adfdacad70..f9cfe4e685 100644 --- a/components/hal/esp32p4/include/hal/mipi_dsi_brg_ll.h +++ b/components/hal/esp32p4/include/hal/mipi_dsi_brg_ll.h @@ -25,6 +25,17 @@ typedef enum { MIPI_DSI_LL_FLOW_CONTROLLER_BRIDGE, ///< DSI bridge is the flow controller } mipi_dsi_ll_flow_controller_t; +/** + * @brief Force enable the register clock for the DSI bridge + * + * @param dev Pointer to the DSI bridge controller register base address + * @param en true to enable, false to disable + */ +static inline void mipi_dsi_brg_ll_force_enable_reg_clock(dsi_brg_dev_t *dev, bool en) +{ + dev->clk_en.clk_en = en; +} + /** * @brief Enable the DSI bridge * diff --git a/components/hal/esp32p4/include/hal/mipi_dsi_ll.h b/components/hal/esp32p4/include/hal/mipi_dsi_ll.h index e310ef7c8e..3ea1767a7c 100644 --- a/components/hal/esp32p4/include/hal/mipi_dsi_ll.h +++ b/components/hal/esp32p4/include/hal/mipi_dsi_ll.h @@ -37,30 +37,6 @@ static inline void _mipi_dsi_ll_enable_bus_clock(int group_id, bool enable) /// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance #define mipi_dsi_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; _mipi_dsi_ll_enable_bus_clock(__VA_ARGS__) -/** - * @brief Enable the clock for MIPI DSI host - * - * @param group_id Group ID - * @param en true to enable, false to disable - */ -static inline void mipi_dsi_ll_enable_host_clock(int group_id, bool en) -{ - (void)group_id; - MIPI_DSI_BRIDGE.clk_en.clk_en = en; -} - -/** - * @brief Enable the config clock for MIPI DSI host - * - * @param group_id Group ID - * @param en true to enable, false to disable - */ -static inline void mipi_dsi_ll_enable_host_config_clock(int group_id, bool en) -{ - (void)group_id; - MIPI_DSI_BRIDGE.host_ctrl.dsi_cfg_ref_clk_en = en; -} - /** * @brief Reset the MIPI DSI module * diff --git a/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c b/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c index 87a2ea04de..f66f8fea92 100644 --- a/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c +++ b/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c @@ -5,6 +5,8 @@ */ #include +#include +#include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -73,14 +75,13 @@ static const char *TAG = "example"; //////////////////// Please update the following configuration according to your Application /////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#define EXAMPLE_LVGL_DRAW_BUF_LINES 200 // number of display lines in each draw buffer +#define EXAMPLE_LVGL_DRAW_BUF_LINES (EXAMPLE_MIPI_DSI_LCD_V_RES / 10) // number of display lines in each draw buffer #define EXAMPLE_LVGL_TICK_PERIOD_MS 2 -#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 -#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1 #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 -static SemaphoreHandle_t lvgl_api_mux = NULL; +// LVGL library is not thread-safe, this example will call LVGL APIs from different tasks, so use a mutex to protect it +static _lock_t lvgl_api_lock; extern void example_lvgl_demo_ui(lv_display_t *disp); @@ -101,36 +102,15 @@ static void example_increase_lvgl_tick(void *arg) lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS); } -static bool example_lvgl_lock(int timeout_ms) -{ - // Convert timeout in milliseconds to FreeRTOS ticks - // If `timeout_ms` is set to -1, the program will block until the condition is met - const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); - return xSemaphoreTakeRecursive(lvgl_api_mux, timeout_ticks) == pdTRUE; -} - -static void example_lvgl_unlock(void) -{ - xSemaphoreGiveRecursive(lvgl_api_mux); -} - static void example_lvgl_port_task(void *arg) { ESP_LOGI(TAG, "Starting LVGL task"); - uint32_t task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; + uint32_t time_till_next_ms = 0; while (1) { - // Lock the mutex due to the LVGL APIs are not thread-safe - if (example_lvgl_lock(-1)) { - task_delay_ms = lv_timer_handler(); - // Release the mutex - example_lvgl_unlock(); - } - if (task_delay_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) { - task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; - } else if (task_delay_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) { - task_delay_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS; - } - vTaskDelay(pdMS_TO_TICKS(task_delay_ms)); + _lock_acquire(&lvgl_api_lock); + time_till_next_ms = lv_timer_handler(); + _lock_release(&lvgl_api_lock); + usleep(1000 * time_till_next_ms); } } @@ -243,7 +223,7 @@ void app_main(void) .vsync_front_porch = EXAMPLE_MIPI_DSI_LCD_VFP, }, #if CONFIG_EXAMPLE_USE_DMA2D_COPY_FRAME - .flags.use_dma2d = true, + .flags.use_dma2d = true, // use DMA2D to copy draw buffer into frame buffer #endif }; @@ -289,6 +269,8 @@ void app_main(void) lv_display_t *display = lv_display_create(EXAMPLE_MIPI_DSI_LCD_H_RES, EXAMPLE_MIPI_DSI_LCD_V_RES); // associate the mipi panel handle to the display lv_display_set_user_data(display, mipi_dpi_panel); + // set color depth + lv_display_set_color_format(display, LV_COLOR_FORMAT_RGB888); // create draw buffer void *buf1 = NULL; void *buf2 = NULL; @@ -303,8 +285,6 @@ void app_main(void) assert(buf2); // initialize LVGL draw buffers lv_display_set_buffers(display, buf1, buf2, draw_buffer_sz, LV_DISPLAY_RENDER_MODE_PARTIAL); - // set color depth - lv_display_set_color_format(display, LV_COLOR_FORMAT_RGB888); // set the callback which can copy the rendered image to an area of the display lv_display_set_flush_cb(display, example_lvgl_flush_cb); @@ -326,18 +306,11 @@ void app_main(void) ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer)); ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000)); - // LVGL APIs are meant to be called across the threads without protection, so we use a mutex here - lvgl_api_mux = xSemaphoreCreateRecursiveMutex(); - assert(lvgl_api_mux); - ESP_LOGI(TAG, "Create LVGL task"); xTaskCreate(example_lvgl_port_task, "LVGL", EXAMPLE_LVGL_TASK_STACK_SIZE, NULL, EXAMPLE_LVGL_TASK_PRIORITY, NULL); ESP_LOGI(TAG, "Display LVGL Meter Widget"); - // Lock the mutex due to the LVGL APIs are not thread-safe - if (example_lvgl_lock(-1)) { - example_lvgl_demo_ui(display); - // Release the mutex - example_lvgl_unlock(); - } + _lock_acquire(&lvgl_api_lock); + example_lvgl_demo_ui(display); + _lock_release(&lvgl_api_lock); } diff --git a/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c b/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c index 8b423763a9..624c4aea4d 100644 --- a/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c +++ b/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c @@ -60,10 +60,6 @@ static const char *TAG = "example"; #define EXAMPLE_PIN_NUM_DATA15 40 // R4 #define EXAMPLE_PIN_NUM_DISP_EN -1 -// The pixel number in horizontal and vertical -#define EXAMPLE_LCD_H_RES 800 -#define EXAMPLE_LCD_V_RES 480 - #if CONFIG_EXAMPLE_DOUBLE_FB #define EXAMPLE_LCD_NUM_FB 2 #else