├── README.md └── example ├── .gitignore ├── CMakeLists.txt ├── main ├── CMakeLists.txt ├── bsp.h ├── idf_component.yml └── main.c ├── partitions.csv └── sdkconfig.defaults /README.md: -------------------------------------------------------------------------------- 1 | # esp32-8048s070-example 2 | esp32-8048s070 example with latest versions of esp-idf(5.3.1), lvgl(9.2), making use of lv_port_esp32, without reinventing the wheel. 3 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | sdkconfig 3 | sdkconfig.old 4 | managed_components/ 5 | build/ 6 | dependencies.lock 7 | -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about build system see 2 | # https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html 3 | # The following five lines of boilerplate have to be in your project's 4 | # CMakeLists in this exact order for cmake to work correctly 5 | cmake_minimum_required(VERSION 3.16) 6 | 7 | set(IDF_TARGET esp32s3) 8 | 9 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 10 | project(rgb_panel_v2) 11 | -------------------------------------------------------------------------------- /example/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS main.c 2 | INCLUDE_DIRS . 3 | REQUIRES esp_lcd driver) 4 | -------------------------------------------------------------------------------- /example/main/bsp.h: -------------------------------------------------------------------------------- 1 | #ifndef BSP_H 2 | #define BSP_H 3 | 4 | #include "driver/gpio.h" 5 | #include "esp_lcd_panel_rgb.h" 6 | #include "esp_lcd_touch_gt911.h" 7 | 8 | #define BSP_LCD_BK_LIGHT_ON_LEVEL 1 9 | #define BSP_LCD_BK_LIGHT_OFF_LEVEL (!BSP_LCD_BK_LIGHT_ON_LEVEL) 10 | #define BSP_LCD_GPIO_BK_LIGHT GPIO_NUM_2 11 | #define BSP_LCD_GPIO_HSYNC GPIO_NUM_39 12 | #define BSP_LCD_GPIO_VSYNC GPIO_NUM_40 13 | #define BSP_LCD_GPIO_DE GPIO_NUM_41 14 | #define BSP_LCD_GPIO_PCLK GPIO_NUM_42 15 | #define BSP_LCD_GPIO_DATA() { \ 16 | GPIO_NUM_15, \ 17 | GPIO_NUM_7, \ 18 | GPIO_NUM_6, \ 19 | GPIO_NUM_5, \ 20 | GPIO_NUM_4, \ 21 | GPIO_NUM_9, \ 22 | GPIO_NUM_46, \ 23 | GPIO_NUM_3, \ 24 | GPIO_NUM_8, \ 25 | GPIO_NUM_16, \ 26 | GPIO_NUM_1, \ 27 | GPIO_NUM_14, \ 28 | GPIO_NUM_21, \ 29 | GPIO_NUM_47, \ 30 | GPIO_NUM_48, \ 31 | GPIO_NUM_45, \ 32 | } 33 | #define BSP_LCD_GPIO_DISP GPIO_NUM_NC 34 | 35 | // The pixel number in horizontal and vertical 36 | #define BSP_LCD_H_RES 800 37 | #define BSP_LCD_V_RES 480 38 | 39 | #define BSP_LCD_PANEL_TIMING() \ 40 | (esp_lcd_rgb_timing_t) \ 41 | { \ 42 | .pclk_hz = 16000000, \ 43 | .h_res = BSP_LCD_H_RES, \ 44 | .v_res = BSP_LCD_V_RES, \ 45 | .hsync_pulse_width = 30, \ 46 | .hsync_back_porch = 16, \ 47 | .hsync_front_porch = 20, \ 48 | .vsync_pulse_width = 13, \ 49 | .vsync_back_porch = 10, \ 50 | .vsync_front_porch = 22, \ 51 | .flags.pclk_active_neg = true, \ 52 | } 53 | 54 | #define BSP_TOUCH_GPIO_SCL GPIO_NUM_20 55 | #define BSP_TOUCH_GPIO_SDA GPIO_NUM_19 56 | #define BSP_TOUCH_GPIO_INT GPIO_NUM_NC 57 | #define BSP_TOUCH_GPIO_RST GPIO_NUM_38 58 | 59 | #endif -------------------------------------------------------------------------------- /example/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | lvgl/lvgl: "==9.2.2" 3 | espressif/esp_lvgl_port: "==2.3.2" 4 | esp_lcd_touch_gt911: "==1.1.0" 5 | idf: 6 | version: ">=5.3" 7 | -------------------------------------------------------------------------------- /example/main/main.c: -------------------------------------------------------------------------------- 1 | #include "esp_check.h" 2 | 3 | #include "bsp.h" 4 | 5 | #include "esp_lvgl_port.h" 6 | 7 | #include "driver/i2c_master.h" 8 | 9 | #include "lv_examples.h" 10 | #include "lv_demos.h" 11 | 12 | /* LCD settings */ 13 | #define APP_LCD_LVGL_FULL_REFRESH (0) 14 | #define APP_LCD_LVGL_DIRECT_MODE (1) 15 | #define APP_LCD_LVGL_AVOID_TEAR (1) 16 | #define APP_LCD_RGB_BOUNCE_BUFFER_MODE (1) 17 | #define APP_LCD_DRAW_BUFF_DOUBLE (0) 18 | #define APP_LCD_DRAW_BUFF_HEIGHT (100) 19 | #define APP_LCD_RGB_BUFFER_NUMS (2) 20 | #define APP_LCD_RGB_BOUNCE_BUFFER_HEIGHT (10) 21 | 22 | static esp_lcd_panel_handle_t lcd_panel = NULL; 23 | 24 | static i2c_master_bus_handle_t my_bus = NULL; 25 | static esp_lcd_panel_io_handle_t touch_io_handle = NULL; 26 | static esp_lcd_touch_handle_t touch_handle = NULL; 27 | 28 | /* LVGL display and touch */ 29 | static lv_display_t *lvgl_disp = NULL; 30 | static lv_indev_t *lvgl_touch_indev = NULL; 31 | 32 | static const char TAG[] = "rgb_panel_v2"; 33 | 34 | static esp_err_t app_lcd_init(esp_lcd_panel_handle_t *lp) 35 | { 36 | esp_err_t ret = ESP_OK; 37 | 38 | ESP_LOGI(TAG, "Initialize RGB panel"); 39 | const esp_lcd_rgb_panel_config_t conf = { 40 | .clk_src = LCD_CLK_SRC_DEFAULT, 41 | .timings = BSP_LCD_PANEL_TIMING(), 42 | .data_width = 16, 43 | .num_fbs = APP_LCD_RGB_BUFFER_NUMS, 44 | #ifdef APP_LCD_RGB_BOUNCE_BUFFER_MODE 45 | .bounce_buffer_size_px = BSP_LCD_H_RES * APP_LCD_RGB_BOUNCE_BUFFER_HEIGHT, 46 | #endif 47 | .hsync_gpio_num = BSP_LCD_GPIO_HSYNC, 48 | .vsync_gpio_num = BSP_LCD_GPIO_VSYNC, 49 | .de_gpio_num = BSP_LCD_GPIO_DE, 50 | .pclk_gpio_num = BSP_LCD_GPIO_PCLK, 51 | .disp_gpio_num = BSP_LCD_GPIO_DISP, 52 | .data_gpio_nums = BSP_LCD_GPIO_DATA(), 53 | .flags.fb_in_psram = 1, 54 | }; 55 | ESP_GOTO_ON_ERROR(esp_lcd_new_rgb_panel(&conf, lp), 56 | err, TAG, "RGB init failed"); 57 | ESP_GOTO_ON_ERROR(esp_lcd_panel_init(*lp), 58 | err, TAG, "LCD init failed"); 59 | return ret; 60 | 61 | err: 62 | if (*lp) 63 | { 64 | esp_lcd_panel_del(*lp); 65 | } 66 | return ret; 67 | } 68 | 69 | static esp_err_t app_touch_init(i2c_master_bus_handle_t *bus, 70 | esp_lcd_panel_io_handle_t *tp_io, 71 | esp_lcd_touch_handle_t *tp) 72 | { 73 | if (!*bus) 74 | { 75 | ESP_LOGI(TAG, "creating i2c master bus"); 76 | const i2c_master_bus_config_t i2c_conf = { 77 | .i2c_port = -1, 78 | .sda_io_num = BSP_TOUCH_GPIO_SDA, 79 | .scl_io_num = BSP_TOUCH_GPIO_SCL, 80 | .clk_source = I2C_CLK_SRC_DEFAULT, 81 | .glitch_ignore_cnt = 7, 82 | .flags.enable_internal_pullup = 1, 83 | }; 84 | ESP_RETURN_ON_ERROR(i2c_new_master_bus(&i2c_conf, bus), 85 | TAG, "failed to create i2c master bus"); 86 | } 87 | 88 | if (!*tp_io) 89 | { 90 | ESP_LOGI(TAG, "creating touch panel io"); 91 | esp_lcd_panel_io_i2c_config_t tp_io_cfg = 92 | ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); 93 | tp_io_cfg.scl_speed_hz = 400000; 94 | ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c_v2(*bus, &tp_io_cfg, tp_io), 95 | TAG, "Failed to crate touch panel io"); 96 | } 97 | 98 | const esp_lcd_touch_config_t tp_cfg = { 99 | .x_max = BSP_LCD_H_RES, 100 | .y_max = BSP_LCD_V_RES, 101 | .rst_gpio_num = BSP_TOUCH_GPIO_RST, 102 | .int_gpio_num = BSP_TOUCH_GPIO_INT, 103 | }; 104 | 105 | return esp_lcd_touch_new_i2c_gt911(*tp_io, &tp_cfg, tp); 106 | } 107 | 108 | static esp_err_t app_lvgl_init(esp_lcd_panel_handle_t lp, esp_lcd_touch_handle_t tp, 109 | lv_display_t **lv_disp, lv_indev_t **lv_touch_indev) 110 | { 111 | /* Initialize LVGL */ 112 | const lvgl_port_cfg_t lvgl_cfg = { 113 | .task_priority = 4, /* LVGL task priority */ 114 | .task_stack = 8192, /* LVGL task stack size */ 115 | .task_affinity = -1, /* LVGL task pinned to core (-1 is no affinity) */ 116 | .task_max_sleep_ms = 500, /* Maximum sleep in LVGL task */ 117 | .timer_period_ms = 5 /* LVGL timer tick period in ms */ 118 | }; 119 | ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed"); 120 | 121 | uint32_t buff_size = BSP_LCD_H_RES * APP_LCD_DRAW_BUFF_HEIGHT; 122 | #if APP_LCD_LVGL_FULL_REFRESH || APP_LCD_LVGL_DIRECT_MODE 123 | buff_size = BSP_LCD_H_RES * BSP_LCD_V_RES; 124 | #endif 125 | 126 | /* Add LCD screen */ 127 | ESP_LOGD(TAG, "Add LCD screen"); 128 | const lvgl_port_display_cfg_t disp_cfg = { 129 | .panel_handle = lp, 130 | .buffer_size = buff_size, 131 | .double_buffer = APP_LCD_DRAW_BUFF_DOUBLE, 132 | .hres = BSP_LCD_H_RES, 133 | .vres = BSP_LCD_V_RES, 134 | .monochrome = false, 135 | #if LVGL_VERSION_MAJOR >= 9 136 | .color_format = LV_COLOR_FORMAT_RGB565, 137 | #endif 138 | .rotation = { 139 | .swap_xy = false, 140 | .mirror_x = false, 141 | .mirror_y = false, 142 | }, 143 | .flags = { 144 | .buff_dma = false, 145 | .buff_spiram = false, 146 | #if APP_LCD_LVGL_FULL_REFRESH 147 | .full_refresh = true, 148 | #elif APP_LCD_LVGL_DIRECT_MODE 149 | .direct_mode = true, 150 | #endif 151 | #if LVGL_VERSION_MAJOR >= 9 152 | .swap_bytes = false, 153 | #endif 154 | } 155 | }; 156 | const lvgl_port_display_rgb_cfg_t rgb_cfg = { 157 | .flags = { 158 | #if APP_LCD_RGB_BOUNCE_BUFFER_MODE 159 | .bb_mode = true, 160 | #else 161 | .bb_mode = false, 162 | #endif 163 | #if APP_LCD_LVGL_AVOID_TEAR 164 | .avoid_tearing = true, 165 | #else 166 | .avoid_tearing = false, 167 | #endif 168 | } 169 | }; 170 | *lv_disp = lvgl_port_add_disp_rgb(&disp_cfg, &rgb_cfg); 171 | 172 | /* Add touch input (for selected screen) */ 173 | const lvgl_port_touch_cfg_t touch_cfg = { 174 | .disp = *lv_disp, 175 | .handle = tp, 176 | }; 177 | *lv_touch_indev = lvgl_port_add_touch(&touch_cfg); 178 | 179 | return ESP_OK; 180 | } 181 | 182 | void app_main(void) 183 | { 184 | ESP_ERROR_CHECK(app_lcd_init(&lcd_panel)); 185 | ESP_ERROR_CHECK(app_touch_init(&my_bus, &touch_io_handle, &touch_handle)); 186 | ESP_ERROR_CHECK(app_lvgl_init(lcd_panel, touch_handle, &lvgl_disp, &lvgl_touch_indev)); 187 | 188 | const gpio_config_t bk_light = { 189 | .pin_bit_mask = (1 << BSP_LCD_GPIO_BK_LIGHT), 190 | .mode = GPIO_MODE_OUTPUT, 191 | .pull_up_en = GPIO_PULLUP_DISABLE, 192 | .pull_down_en = GPIO_PULLDOWN_DISABLE, 193 | .intr_type = GPIO_INTR_DISABLE, 194 | }; 195 | ESP_ERROR_CHECK(gpio_config(&bk_light)); 196 | gpio_set_level(BSP_LCD_GPIO_BK_LIGHT, BSP_LCD_BK_LIGHT_ON_LEVEL); 197 | 198 | lvgl_port_lock(0); 199 | lv_demo_widgets(); 200 | lvgl_port_unlock(); 201 | } 202 | -------------------------------------------------------------------------------- /example/partitions.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 2M, 6 | -------------------------------------------------------------------------------- /example/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_TARGET="esp32s3" 2 | CONFIG_ESPTOOLPY_FLASHMODE_QIO=y 3 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 4 | CONFIG_PARTITION_TABLE_CUSTOM=y 5 | CONFIG_COMPILER_OPTIMIZATION_PERF=y 6 | CONFIG_SPIRAM=y 7 | CONFIG_SPIRAM_MODE_OCT=y 8 | CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y 9 | CONFIG_SPIRAM_RODATA=y 10 | CONFIG_SPIRAM_SPEED_80M=y 11 | CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y 12 | CONFIG_ESP32S3_DATA_CACHE_LINE_64B=y 13 | CONFIG_FREERTOS_HZ=1000 14 | CONFIG_LV_MEM_CUSTOM=y 15 | CONFIG_LV_MEMCPY_MEMSET_STD=y 16 | CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y 17 | CONFIG_LV_FONT_MONTSERRAT_12=y 18 | CONFIG_LV_FONT_MONTSERRAT_16=y 19 | CONFIG_LV_USE_DEMO_WIDGETS=y 20 | CONFIG_LV_USE_DEMO_BENCHMARK=y 21 | CONFIG_LV_USE_DEMO_STRESS=y 22 | CONFIG_LV_USE_DEMO_MUSIC=y 23 | # CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y 24 | 25 | ## LVGL8 ## 26 | CONFIG_LV_MEM_SIZE_KILOBYTES=48 27 | CONFIG_LV_USE_PERF_MONITOR=y 28 | 29 | ## LVGL9 ## 30 | CONFIG_LV_CONF_SKIP=y 31 | 32 | #CLIB default 33 | CONFIG_LV_USE_CLIB_MALLOC=y 34 | CONFIG_LV_USE_CLIB_SPRINTF=y 35 | CONFIG_LV_USE_CLIB_STRING=y 36 | 37 | # Performance monitor 38 | CONFIG_LV_USE_OBSERVER=y 39 | CONFIG_LV_USE_SYSMON=y 40 | CONFIG_LV_USE_PERF_MONITOR=y 41 | --------------------------------------------------------------------------------