Skip to content

Commit 29e30e9

Browse files
committed
feat(esp32_p4_function_ev_board): Allow to change HDMI resolution in runtime
1 parent ca23afe commit 29e30e9

File tree

6 files changed

+165
-122
lines changed

6 files changed

+165
-122
lines changed

bsp/esp32_p4_function_ev_board/esp32_p4_function_ev_board.c

Lines changed: 112 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#include <string.h>
78
#include "sdkconfig.h"
89
#include "driver/gpio.h"
910
#include "driver/ledc.h"
@@ -415,12 +416,16 @@ esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, bsp_l
415416
esp_lcd_dsi_bus_config_t bus_config = {
416417
.bus_id = 0,
417418
.num_data_lanes = BSP_LCD_MIPI_DSI_LANE_NUM,
418-
.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
419-
.lane_bit_rate_mbps = BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS,
419+
.phy_clk_src = config->dsi_bus.phy_clk_src,
420+
.lane_bit_rate_mbps = config->dsi_bus.lane_bit_rate_mbps,
420421
};
421422
ESP_RETURN_ON_ERROR(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus), TAG, "New DSI bus init failed");
422423

423424
#if !CONFIG_BSP_LCD_TYPE_HDMI
425+
if (config->hdmi_resolution != BSP_HDMI_RES_NONE) {
426+
ESP_LOGW(TAG, "Please select HDMI in menuconfig, if you want to use it.");
427+
}
428+
424429
ESP_LOGI(TAG, "Install MIPI DSI LCD control panel");
425430
// we use DBI interface to send LCD commands and parameters
426431
esp_lcd_dbi_io_config_t dbi_config = {
@@ -507,53 +512,59 @@ esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, bsp_l
507512
esp_lcd_panel_io_i2c_config_t io_config_avi = LT8912B_IO_CFG(CONFIG_BSP_I2C_CLK_SPEED_HZ, LT8912B_IO_I2C_AVI_ADDRESS);
508513
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_handle, &io_config_avi, &io_avi));
509514

510-
/* DPI config */
511-
#if CONFIG_BSP_LCD_HDMI_800x600_60HZ
512-
ESP_LOGI(TAG, "HDMI configuration for 800x600@60HZ");
513-
esp_lcd_dpi_panel_config_t dpi_config = LT8912B_800x600_PANEL_60HZ_DPI_CONFIG();
514-
#elif CONFIG_BSP_LCD_HDMI_1024x768_60HZ
515-
ESP_LOGI(TAG, "HDMI configuration for 1024x768@60HZ");
516-
esp_lcd_dpi_panel_config_t dpi_config = LT8912B_1024x768_PANEL_60HZ_DPI_CONFIG();
517-
#elif CONFIG_BSP_LCD_HDMI_1280x720_60HZ
518-
ESP_LOGI(TAG, "HDMI configuration for 1280x720@60HZ");
519-
esp_lcd_dpi_panel_config_t dpi_config = LT8912B_1280x720_PANEL_60HZ_DPI_CONFIG();
520-
#elif CONFIG_BSP_LCD_HDMI_1280x800_60HZ
521-
ESP_LOGI(TAG, "HDMI configuration for 1280x800@60HZ");
522-
esp_lcd_dpi_panel_config_t dpi_config = LT8912B_1280x800_PANEL_60HZ_DPI_CONFIG();
523-
#elif CONFIG_BSP_LCD_HDMI_1920x1080_30HZ
524-
ESP_LOGI(TAG, "HDMI configuration for 1920x1080@30HZ");
525-
esp_lcd_dpi_panel_config_t dpi_config = LT8912B_1920x1080_PANEL_30HZ_DPI_CONFIG();
526-
#elif CONFIG_BSP_LCD_HDMI_1920x1080_60HZ
527-
ESP_LOGI(TAG, "HDMI configuration for 1920x1080@60HZ");
528-
/* This setting is not working yet, it is only for developing and testing */
529-
esp_lcd_dpi_panel_config_t dpi_config = LT8912B_1920x1080_PANEL_60HZ_DPI_CONFIG();
530-
#else
531-
#error Unsupported display type
532-
#endif
533-
dpi_config.num_fbs = CONFIG_BSP_LCD_DPI_BUFFER_NUMS;
515+
const esp_lcd_dpi_panel_config_t dpi_configs[] = {
516+
LT8912B_800x600_PANEL_60HZ_DPI_CONFIG_WITH_FBS(CONFIG_BSP_LCD_DPI_BUFFER_NUMS),
517+
LT8912B_1024x768_PANEL_60HZ_DPI_CONFIG_WITH_FBS(CONFIG_BSP_LCD_DPI_BUFFER_NUMS),
518+
LT8912B_1280x720_PANEL_60HZ_DPI_CONFIG_WITH_FBS(CONFIG_BSP_LCD_DPI_BUFFER_NUMS),
519+
LT8912B_1280x800_PANEL_60HZ_DPI_CONFIG_WITH_FBS(CONFIG_BSP_LCD_DPI_BUFFER_NUMS),
520+
LT8912B_1920x1080_PANEL_30HZ_DPI_CONFIG_WITH_FBS(CONFIG_BSP_LCD_DPI_BUFFER_NUMS)
521+
};
522+
523+
const esp_lcd_panel_lt8912b_video_timing_t video_timings[] = {
524+
ESP_LCD_LT8912B_VIDEO_TIMING_800x600_60Hz(),
525+
ESP_LCD_LT8912B_VIDEO_TIMING_1024x768_60Hz(),
526+
ESP_LCD_LT8912B_VIDEO_TIMING_1280x720_60Hz(),
527+
ESP_LCD_LT8912B_VIDEO_TIMING_1280x800_60Hz(),
528+
ESP_LCD_LT8912B_VIDEO_TIMING_1920x1080_30Hz()
529+
};
534530
lt8912b_vendor_config_t vendor_config = {
535-
#if CONFIG_BSP_LCD_HDMI_800x600_60HZ
536-
.video_timing = ESP_LCD_LT8912B_VIDEO_TIMING_800x600_60Hz(),
537-
#elif CONFIG_BSP_LCD_HDMI_1024x768_60HZ
538-
.video_timing = ESP_LCD_LT8912B_VIDEO_TIMING_1024x768_60Hz(),
539-
#elif CONFIG_BSP_LCD_HDMI_1280x720_60HZ
540-
.video_timing = ESP_LCD_LT8912B_VIDEO_TIMING_1280x720_60Hz(),
541-
#elif CONFIG_BSP_LCD_HDMI_1280x800_60HZ
542-
.video_timing = ESP_LCD_LT8912B_VIDEO_TIMING_1280x800_60Hz(),
543-
#elif CONFIG_BSP_LCD_HDMI_1920x1080_30HZ
544-
.video_timing = ESP_LCD_LT8912B_VIDEO_TIMING_1920x1080_30Hz(),
545-
#elif CONFIG_BSP_LCD_HDMI_1920x1080_60HZ
546-
/* This setting is not working yet, it is only for developing and testing */
547-
.video_timing = ESP_LCD_LT8912B_VIDEO_TIMING_1920x1080_60Hz(),
548-
#else
549-
#error Unsupported display type
550-
#endif
551531
.mipi_config = {
552532
.dsi_bus = mipi_dsi_bus,
553-
.dpi_config = &dpi_config,
554533
.lane_num = BSP_LCD_MIPI_DSI_LANE_NUM,
555534
},
556535
};
536+
537+
/* DPI config */
538+
switch (config->hdmi_resolution) {
539+
case BSP_HDMI_RES_800x600:
540+
ESP_LOGI(TAG, "HDMI configuration for 800x600@60HZ");
541+
vendor_config.mipi_config.dpi_config = &dpi_configs[0];
542+
memcpy(&vendor_config.video_timing, &video_timings[0], sizeof(esp_lcd_panel_lt8912b_video_timing_t));
543+
break;
544+
case BSP_HDMI_RES_1024x768:
545+
ESP_LOGI(TAG, "HDMI configuration for 1024x768@60HZ");
546+
vendor_config.mipi_config.dpi_config = &dpi_configs[1];
547+
memcpy(&vendor_config.video_timing, &video_timings[1], sizeof(esp_lcd_panel_lt8912b_video_timing_t));
548+
break;
549+
case BSP_HDMI_RES_1280x720:
550+
ESP_LOGI(TAG, "HDMI configuration for 1280x720@60HZ");
551+
vendor_config.mipi_config.dpi_config = &dpi_configs[2];
552+
memcpy(&vendor_config.video_timing, &video_timings[2], sizeof(esp_lcd_panel_lt8912b_video_timing_t));
553+
break;
554+
case BSP_HDMI_RES_1280x800:
555+
ESP_LOGI(TAG, "HDMI configuration for 1280x800@60HZ");
556+
vendor_config.mipi_config.dpi_config = &dpi_configs[3];
557+
memcpy(&vendor_config.video_timing, &video_timings[3], sizeof(esp_lcd_panel_lt8912b_video_timing_t));
558+
break;
559+
case BSP_HDMI_RES_1920x1080:
560+
ESP_LOGI(TAG, "HDMI configuration for 1920x1080@30HZ");
561+
vendor_config.mipi_config.dpi_config = &dpi_configs[4];
562+
memcpy(&vendor_config.video_timing, &video_timings[4], sizeof(esp_lcd_panel_lt8912b_video_timing_t));
563+
break;
564+
default:
565+
ESP_LOGE(TAG, "Unsupported display type (%d)", config->hdmi_resolution);
566+
}
567+
557568
const esp_lcd_panel_dev_config_t panel_config = {
558569
.bits_per_pixel = 24,
559570
.rgb_ele_order = BSP_LCD_COLOR_SPACE,
@@ -577,7 +588,7 @@ esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, bsp_l
577588
ret_handles->panel = disp_panel;
578589
ret_handles->control = NULL;
579590

580-
ESP_LOGI(TAG, "Display initialized with resolution %dx%d", BSP_LCD_H_RES, BSP_LCD_V_RES);
591+
ESP_LOGI(TAG, "Display initialized");
581592

582593
return ret;
583594

@@ -642,7 +653,41 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
642653
{
643654
assert(cfg != NULL);
644655
bsp_lcd_handles_t lcd_panels;
645-
BSP_ERROR_CHECK_RETURN_NULL(bsp_display_new_with_handles(NULL, &lcd_panels));
656+
BSP_ERROR_CHECK_RETURN_NULL(bsp_display_new_with_handles(&cfg->hw_cfg, &lcd_panels));
657+
658+
uint32_t display_hres = 0;
659+
uint32_t display_vres = 0;
660+
#if CONFIG_BSP_LCD_TYPE_HDMI
661+
switch (cfg->hw_cfg.hdmi_resolution) {
662+
case BSP_HDMI_RES_800x600:
663+
display_hres = 800;
664+
display_vres = 600;
665+
break;
666+
case BSP_HDMI_RES_1024x768:
667+
display_hres = 1024;
668+
display_vres = 768;
669+
break;
670+
case BSP_HDMI_RES_1280x720:
671+
display_hres = 1280;
672+
display_vres = 720;
673+
break;
674+
case BSP_HDMI_RES_1280x800:
675+
display_hres = 1280;
676+
display_vres = 800;
677+
break;
678+
case BSP_HDMI_RES_1920x1080:
679+
display_hres = 1920;
680+
display_vres = 1080;
681+
break;
682+
default:
683+
ESP_LOGE(TAG, "Unsupported HDMI resolution");
684+
}
685+
#else
686+
display_hres = BSP_LCD_H_RES;
687+
display_vres = BSP_LCD_V_RES;
688+
#endif
689+
690+
ESP_LOGI(TAG, "Display resolution %ldx%ld", display_hres, display_vres);
646691

647692
/* Add LCD screen */
648693
ESP_LOGD(TAG, "Add LCD screen");
@@ -652,8 +697,8 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
652697
.control_handle = lcd_panels.control,
653698
.buffer_size = cfg->buffer_size,
654699
.double_buffer = cfg->double_buffer,
655-
.hres = BSP_LCD_H_RES,
656-
.vres = BSP_LCD_V_RES,
700+
.hres = display_hres,
701+
.vres = display_vres,
657702
.monochrome = false,
658703
/* Rotation values must be same as used in esp_lcd for initial settings of the screen */
659704
.rotation = {
@@ -723,6 +768,25 @@ lv_display_t *bsp_display_start(void)
723768
.lvgl_port_cfg = ESP_LVGL_PORT_INIT_CONFIG(),
724769
.buffer_size = BSP_LCD_DRAW_BUFF_SIZE,
725770
.double_buffer = BSP_LCD_DRAW_BUFF_DOUBLE,
771+
.hw_cfg = {
772+
#if CONFIG_BSP_LCD_TYPE_HDMI
773+
#if CONFIG_BSP_LCD_HDMI_800x600_60HZ
774+
.hdmi_resolution = BSP_HDMI_RES_800x600,
775+
#elif CONFIG_BSP_LCD_HDMI_1280x720_60HZ
776+
.hdmi_resolution = BSP_HDMI_RES_1280x720,
777+
#elif CONFIG_BSP_LCD_HDMI_1280x800_60HZ
778+
.hdmi_resolution = BSP_HDMI_RES_1280x800,
779+
#elif CONFIG_BSP_LCD_HDMI_1920x1080_30HZ
780+
.hdmi_resolution = BSP_HDMI_RES_1920x1080,
781+
#endif
782+
#else
783+
.hdmi_resolution = BSP_HDMI_RES_NONE,
784+
#endif
785+
.dsi_bus = {
786+
.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
787+
.lane_bit_rate_mbps = BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS,
788+
}
789+
},
726790
.flags = {
727791
#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888
728792
.buff_dma = false,

bsp/esp32_p4_function_ev_board/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ dependencies:
2525
public: true
2626

2727
espressif/esp_lcd_lt8912b:
28-
version: ">=0.1.0,<1.0.0"
28+
version: ">=0.1.1,<1.0.0"
2929
override_path: "../../components/lcd/esp_lcd_lt8912b"

bsp/esp32_p4_function_ev_board/include/bsp/display.h

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -40,55 +40,10 @@
4040
/* LCD display definition 1024x600 */
4141
#define BSP_LCD_H_RES (1024)
4242
#define BSP_LCD_V_RES (600)
43-
44-
#define BSP_LCD_MIPI_DSI_LCD_HSYNC (1344)
45-
#define BSP_LCD_MIPI_DSI_LCD_HBP (160)
46-
#define BSP_LCD_MIPI_DSI_LCD_HFP (160)
47-
#define BSP_LCD_MIPI_DSI_LCD_VSYNC (635)
48-
#define BSP_LCD_MIPI_DSI_LCD_VBP (23)
49-
#define BSP_LCD_MIPI_DSI_LCD_VFP (12)
50-
51-
#elif CONFIG_BSP_LCD_TYPE_HDMI
52-
#if CONFIG_BSP_LCD_HDMI_800x600_60HZ
53-
/* LCD display definition 800x600 60Hz */
54-
#define BSP_LCD_H_RES (800)
55-
#define BSP_LCD_V_RES (600)
56-
#elif CONFIG_BSP_LCD_HDMI_1024x768_60HZ
57-
/* LCD display definition 1024x768 60Hz */
58-
#define BSP_LCD_H_RES (1024)
59-
#define BSP_LCD_V_RES (768)
60-
#elif CONFIG_BSP_LCD_HDMI_1280x720_60HZ
61-
/* LCD display definition 1280x720 60Hz */
62-
#define BSP_LCD_H_RES (1280)
63-
#define BSP_LCD_V_RES (720)
64-
#elif CONFIG_BSP_LCD_HDMI_1280x800_60HZ
65-
/* LCD display definition 1280x800 60Hz */
66-
#define BSP_LCD_H_RES (1280)
67-
#define BSP_LCD_V_RES (800)
68-
#elif CONFIG_BSP_LCD_HDMI_1920x1080_30HZ
69-
/* LCD display definition 1920x1080 30Hz */
70-
#define BSP_LCD_H_RES (1920)
71-
#define BSP_LCD_V_RES (1080)
72-
#elif CONFIG_BSP_LCD_HDMI_1920x1080_60HZ
73-
/* LCD display definition 1920x1080 60Hz */
74-
/* This setting is not working yet, it is only for developing and testing */
75-
#define BSP_LCD_H_RES (1920)
76-
#define BSP_LCD_V_RES (1080)
77-
#else
78-
#error Unsupported display type
79-
#endif
80-
8143
#else
8244
/* LCD display definition 1280x800 */
8345
#define BSP_LCD_H_RES (800)
8446
#define BSP_LCD_V_RES (1280)
85-
86-
#define BSP_LCD_MIPI_DSI_LCD_HSYNC (40)
87-
#define BSP_LCD_MIPI_DSI_LCD_HBP (140)
88-
#define BSP_LCD_MIPI_DSI_LCD_HFP (40)
89-
#define BSP_LCD_MIPI_DSI_LCD_VSYNC (4)
90-
#define BSP_LCD_MIPI_DSI_LCD_VBP (16)
91-
#define BSP_LCD_MIPI_DSI_LCD_VFP (16)
9247
#endif
9348

9449
#define BSP_LCD_MIPI_DSI_LANE_NUM (2) // 2 data lanes
@@ -101,12 +56,29 @@
10156
extern "C" {
10257
#endif
10358

59+
/**
60+
* @brief BSP HDMI resolution types
61+
*
62+
*/
63+
typedef enum {
64+
BSP_HDMI_RES_NONE = 0,
65+
BSP_HDMI_RES_800x600, /*!< 800x600@60HZ */
66+
BSP_HDMI_RES_1024x768, /*!< 1024x768@60HZ */
67+
BSP_HDMI_RES_1280x720, /*!< 1280x720@60HZ */
68+
BSP_HDMI_RES_1280x800, /*!< 1280x800@60HZ */
69+
BSP_HDMI_RES_1920x1080 /*!< 1920x1080@30HZ */
70+
} bsp_hdmi_resolution_t;
71+
10472
/**
10573
* @brief BSP display configuration structure
10674
*
10775
*/
10876
typedef struct {
109-
int dummy;
77+
bsp_hdmi_resolution_t hdmi_resolution; /*!< HDMI resolution selection */
78+
struct {
79+
mipi_dsi_phy_clock_source_t phy_clk_src; /*!< DSI bus config - clock source */
80+
uint32_t lane_bit_rate_mbps; /*!< DSI bus config - lane bit rate */
81+
} dsi_bus;
11082
} bsp_display_config_t;
11183

11284
/**

bsp/esp32_p4_function_ev_board/include/bsp/esp32_p4_function_ev_board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ typedef struct {
273273
lvgl_port_cfg_t lvgl_port_cfg; /*!< LVGL port configuration */
274274
uint32_t buffer_size; /*!< Size of the buffer for the screen in pixels */
275275
bool double_buffer; /*!< True, if should be allocated two buffers */
276+
bsp_display_config_t hw_cfg; /*!< Display HW configuration */
276277
struct {
277278
unsigned int buff_dma: 1; /*!< Allocated LVGL buffer will be DMA capable */
278279
unsigned int buff_spiram: 1; /*!< Allocated LVGL buffer will be in PSRAM */

components/lcd/esp_lcd_lt8912b/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.0"
1+
version: "0.1.1"
22
description: ESP LCD LT8912B (MIPI DSI - HDMI)
33
url: https://github.com/espressif/esp-bsp/tree/master/components/lcd/esp_lcd_lt8912b
44
repository: "https://github.com/espressif/esp-bsp.git"

0 commit comments

Comments
 (0)