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,
0 commit comments