Skip to content

ESP32S3 8048 Touch LCD 7 — Board Support Package (BSP)

ESP32S3 8048 Touch LCD 7 — Board Support Package (BSP)

Section titled “ESP32S3 8048 Touch LCD 7 — Board Support Package (BSP)”

The esp32s3_8048_touch_lcd_7_bsp module is the hardware abstraction layer for the ESP32-S3 8048 Touch LCD 7” board — a 7-inch 800 × 480 capacitive-touch display board driven by an ST7262-compatible controller over a 16-bit RGB parallel interface. It initialises every hardware peripheral required by the pendant firmware, wires LVGL to the RGB panel and the GT911 touch controller, manages the CH422G I²C IO expander that provides the SD card chip-select line, implements a pixel-clock throttling patch for safe filesystem access, and registers board-specific custom LVGL control events consumed by the UI layer.

This board is distinguished from its 4.3-inch and 5-inch siblings by its 7-inch display panel, its CH422G IO expander for SD CS routing (no direct GPIO available), and the I²C shared bus that carries both touch and expander traffic. The parent board module is documented in esp32s3_8048_touch_lcd_7.


  1. Module Overview
  2. Hardware Specifications
  3. Architecture
  4. Component Breakdown
  5. Initialization Flow
  6. Display Subsystem
  7. Touch Subsystem
  8. SD Card and IO Expander Integration
  9. Filesystem Access Pixel-Clock Patch
  10. Custom Control Events
  11. Public API
  12. Compile-Time Feature Flags
  13. Sibling Modules and References

ItemValue
Board nameESP32S3-8048-TOUCH-LCD-7
MCUESP32-S3
DisplayST7262, 16-bit RGB565 parallel, 800 × 480 px, 7 inch
TouchGoodix GT911, capacitive, I²C
IO ExpanderCH422G (I²C, shared bus with touch) — SD card CS
StorageSD card via SPI2_HOST, CS asserted through CH422G EXIO3
Physical controlsNone (encoder, buttons, switch, potentiometer are NC)
Source directoryboards/esp32s3_8048_touch_lcd_7/components/bsp/
Key source filesboard_init.c, control_types.c
Key header filesboard_init.h, board_config.h, control_event.h, control_types.h, tasks_def.h, disp_st7262_def.h, touch_gt911_def.h, disp_backlight_def.h

The BSP is the only place in the firmware where hardware I/O details live for this board. The rest of the firmware (UI, GCode host, communication transports) is hardware-agnostic and addresses the board exclusively through the public API exposed by board_init.h and the LVGL handles returned by this module.


ParameterValue
ControllerST7262 (RGB parallel)
Interface16-bit RGB565 parallel (no SPI)
Physical size7 inch
Resolution800 × 480 px
Pixel clock (normal)DISPLAY_PCLK_FREQ_HZ (defined in board_config.h)
Pixel clock (FS access)DISPLAY_PATCH_FS_FREQ_HZ (reduced for SD/flash safety)
Color formatRGB565
Byte swapControlled by DISPLAY_SWAP_COLOR_FLAG
Frame buffer locationPSRAM (fb_in_psram = true)
LVGL draw bufferSingle or double, allocated in SPIRAM (MALLOC_CAP_SPIRAM)
LVGL render modeLV_DISPLAY_RENDER_MODE_PARTIAL
ParameterValue
ControlPWM (LEDC)
Default levelBACKLIGHT_DEFAULT_LEVEL_PCT (defined in board_config.h)
ParameterValue
ControllerGT911 (capacitive)
InterfaceI²C
Shared busYes — same I²C bus as CH422G expander
Read interval10 ms (LVGL indev timer period)
Coordinate mappingraw_x × DISPLAY_WIDTH_PX / gt911_get_x_max()
ParameterValue
InterfaceI²C (shared with GT911)
PurposeRoutes SD card CS (EXIO3) — no direct GPIO available
Initial output0x2E & ~(1<<3) = 0x26 — EXIO3 LOW, CS asserted
CS toggle neededNo — SPI2_HOST serves only the SD card
ParameterValue
SPI hostSPI2_HOST
CS signalCH422G EXIO3 (active-low, asserted once at init)
CLK / MOSI / MISODirect GPIO (defined in board_config.h)

All physical control GPIOs are set to GPIO_NUM_NC. There are no physical buttons, encoder, switch, buzzer, or potentiometer on this board. The control events framework is retained so that upper UI layers (shared across all boards) compile and operate without modification.


UI_Framework

Core_Platform

ESP-IDF / FreeRTOS

Hardware_Peripheral_Drivers

esp32s3_8048_touch_lcd_7_bsp

configures

configures

uses

configures

configures

registers VSYNC callback

creates tick timer

allocates buffers from

calls

logs via

snapshot hook in flush

creates lv_display_t

creates lv_indev_t

registers custom events

acquires lock, calls lv_timer_handler

calls board_init

board_init.c

control_types.c

control_event.h

disp_st7262

(RGB panel driver)

disp_backlight

(PWM backlight)

touch_gt911

(I2C touch)

bus_i2c

(shared I2C bus)

io_ch422g

(I2C IO expander)

esp_lcd_rgb_panel

esp_timer

LEDC / PWM

I2C driver

heap_caps (SPIRAM)

activity_manager

esp3d_log

esp3d_snapshot (optional)

LVGL

UIManager / tft_ui_task

Semaphores

LVGL Task - Core 1

ISR Context (VSYNC)

Take sem_gui_ready

Give sem_vsync_end

Give sem_gui_ready

Wait sem_vsync_end

esp_lcd_panel_draw_bitmap

lv_tick_inc every LVGL_TICK_PERIOD_MS

touch_gt911_read

activity_process_event

disp_on_vsync_event

lvgl_flush_cb

increase_lvgl_tick

touch_read_cb

sem_gui_ready

sem_vsync_end

RGB Panel DMA

LVGL core timer

GT911 driver

activity_manager


The central initialisation source file. Contains all internal state variables and all callback functions needed to drive LVGL on this board.

VariableTypePurpose
lvgl_api_lock_lock_tMutex protecting LVGL API calls from concurrent access
lvgl_displaylv_display_t *LVGL display handle
lvgl_buf1lv_color16_t *Primary LVGL draw buffer (SPIRAM)
lvgl_buf2lv_color16_t *Secondary draw buffer (SPIRAM, double-buffer mode only)
lvgl_tick_timeresp_timer_handle_tPeriodic timer driving lv_tick_inc()
touch_indevlv_indev_t *LVGL input device handle for the GT911
disp_panelesp_lcd_panel_handle_tESP-LCD RGB panel handle
sem_vsync_endSemaphoreHandle_tBinary semaphore: VSYNC ISR releases the flush pipeline
sem_gui_readySemaphoreHandle_tBinary semaphore: flush signals readiness to the VSYNC ISR
FunctionScopeDescription
board_init()PublicTop-level entry: initialises activity manager, backlight, ST7262, I²C bus, CH422G, GT911, LVGL, and control events
init_lvgl()StaticCreates LVGL display, allocates SPIRAM draw buffers, registers flush callback, starts tick timer, creates touch indev
init_touch_controller()StaticInitialises shared I²C bus, optionally configures CH422G (SD CS), then configures GT911
lvgl_flush_cb()StaticLVGL flush callback: optional snapshot write → color swap → VSYNC sync → draw_bitmap → flush_ready
disp_on_vsync_event()Static (ISR)RGB panel VSYNC ISR — synchronises with lvgl_flush_cb via the semaphore pair
touch_read_cb()StaticLVGL indev read callback — reads GT911, maps coordinates, handles wake-up touch suppression
increase_lvgl_tick()Staticesp_timer callback — calls lv_tick_inc(LVGL_TICK_PERIOD_MS)
bsp_accessFs()Public (conditional)Reduces pixel clock to DISPLAY_PATCH_FS_FREQ_HZ before flash/SD I/O
bsp_releaseFs()Public (conditional)Restores pixel clock to DISPLAY_PCLK_FREQ_HZ after flash/SD I/O
get_lvgl_display()PublicReturns lvgl_display handle for use by ESP3DXUi
get_lvgl_lock()PublicReturns &lvgl_api_lock for thread-safe LVGL access
get_touch_indev()PublicReturns touch_indev handle
board_get_name()PublicReturns board name string (BOARD_NAME_STR)
board_get_version()PublicReturns board version string (BOARD_VERSION_STR)

Defines the control_event_t structure — the common payload dispatched through the LVGL event system for all hardware input events.

typedef struct {
lv_indev_t *indev; // LVGL input device that generated the event
uint32_t btn_id; // Button / control index
lv_indev_type_t type; // LVGL indev type (pointer, button, encoder…)
control_family_t family_id; // Which hardware family generated the event
int32_t steps; // Encoder step count (signed)
uint32_t press_duration; // How long the control was held (ms)
} control_event_t;

Because all physical control GPIOs are GPIO_NUM_NC on this board, control_event_t events for CONTROL_FAMILY_BUTTONS, CONTROL_FAMILY_SWITCH, CONTROL_FAMILY_ENCODER, and CONTROL_FAMILY_POTENTIOMETER are only generated by emulated virtual controls in the upper UI layer.

Declares and registers three custom LVGL event codes beyond the built-in set. These are assigned real IDs by lv_event_register_id() inside control_events_init(), which board_init() calls at the end of its sequence — after lv_init() has run.

EventPurpose
LV_EVENT_SWITCH_PRESSEDPhysical 4-position switch moved to a new position
LV_EVENT_SWITCH_RELEASEDPhysical 4-position switch released
LV_EVENT_POTENTIOMETER_CHANGEDAnalog potentiometer value changed

All three are initialised to the sentinel LV_EVENT_ALL and receive valid IDs only after control_events_init() runs. Code that sends or receives these events must not be called before board_init() completes.

All hardware constants are separated into dedicated *_def.h headers so that board_init.c remains free of magic numbers.

HeaderContents
board_config.hAll GPIO assignments, pixel clock frequencies, display resolution, I²C pins and frequency, SD pins — the single authoritative pin-map for this board
tasks_def.hFreeRTOS task stack sizes, core affinities, priorities, LVGL_TICK_PERIOD_MS
disp_st7262_def.hComplete disp_st7262_config_t wired from board_config.h, including RGB timing parameters
touch_gt911_def.hComplete touch_gt911_config_t wired from board_config.h, including axis swap/mirror flags
disp_backlight_def.hbacklight_config_t wired from board_config.h, PWM timer/channel/frequency/resolution

control_events_init()init_lvgl()touch_gt911_configure()io_ch422g_configure()bus_i2c_init()init_touch_controller()disp_st7262_configure()backlightactivity_managerboard_init()app_main / ESP3DX::begin()control_events_init()init_lvgl()touch_gt911_configure()io_ch422g_configure()bus_i2c_init()init_touch_controller()disp_st7262_configure()backlightactivity_managerboard_init()app_main / ESP3DX::begin()board_init()activity_manager_init()ESP_OKbacklight_configure(&backlight_cfg)ESP_OKbacklight_set(0) ← screen off during initdisp_st7262_configure(&config, &disp_panel)disp_panel handleinit_touch_controller()bus_i2c_init(I2C_PORT_IDX, SDA, SCL, freq)ESP_OKio_ch422g_configure() ← EXIO3 LOW: SD CS assertedESP_OKtouch_gt911_configure(&config)ESP_OKESP_OKinit_lvgl()lv_init()xSemaphoreCreateBinary × 2register disp_on_vsync_event callbacklv_display_create(800, 480)heap_caps_malloc(SPIRAM) - buf1 [+ buf2]lv_display_set_buffers / flush_cb / color_formatesp_timer_start_periodic (lvgl_tick)lv_indev_create(POINTER) → touch_read_cb, 10 ms periodESP_OKbacklight_set(DEFAULT_LEVEL_PCT) ← screen oncontrol_events_init()event IDs registeredESP_OK

The ST7262 panel is driven over the ESP32-S3 RGB parallel interface. Unlike SPI panels where pixel transmission is fully software-controlled, the RGB DMA engine scans out pixel data continuously from a framebuffer. The BSP pipeline from LVGL to the panel is:

yes

no

yes

no

unblocks at safe VSYNC boundary

LVGL renders partial area

(Core 1 - LVGL task)

lvgl_flush_cb() invoked

with area rect + px_map

ESP3D_SNAPSHOT_FEATURE?

Write pixels to snapshot file

(120-byte chunks via fwrite)

DISPLAY_SWAP_COLOR_FLAG?

lv_draw_sw_rgb565_swap()

swap R/B byte order in-place

xSemaphoreGive(sem_gui_ready)

signal readiness to VSYNC ISR

xSemaphoreTake(sem_vsync_end, MAX)

block until VSYNC fires

esp_lcd_panel_draw_bitmap()

push buffer to panel DMA

lv_display_flush_ready()

notify LVGL - render next area

disp_on_vsync_event() [ISR]

xSemaphoreTake(sem_gui_ready)

xSemaphoreGive(sem_vsync_end)

RGB panels on the ESP32-S3 stream pixel data from a single shared frame buffer. If LVGL writes new pixels while a scanline is being output, tearing is visible. The BSP avoids this with a binary semaphore pair:

SemaphoreDirectionRole
sem_gui_readyflush → ISRSignals that the LVGL buffer contains new data ready for DMA transfer
sem_vsync_endISR → flushSignals that the VSYNC blanking window has opened — safe to transfer

lvgl_flush_cb gives sem_gui_ready, then blocks on sem_vsync_end. The VSYNC ISR (disp_on_vsync_event) takes sem_gui_ready and gives sem_vsync_end, releasing the flush exactly at the blanking window. This ensures every DMA transfer starts on a scanline boundary.

ISR constraint: disp_on_vsync_event runs in interrupt context. It uses xSemaphoreTakeFromISR / xSemaphoreGiveFromISR and returns the high_task_awoken flag so FreeRTOS can reschedule if a higher-priority task was unblocked.

Both draw buffers are allocated from SPIRAM (MALLOC_CAP_SPIRAM) to preserve the scarce internal DRAM for FreeRTOS stacks and the LVGL object heap.

Build flagBuffer countBehaviour
DISPLAY_USE_DOUBLE_BUFFER_FLAG = 01 × DISP_BUF_SIZE_BYTESSingle buffer — simpler, lower PSRAM usage
DISPLAY_USE_DOUBLE_BUFFER_FLAG = 12 × DISP_BUF_SIZE_BYTESDouble buffer — LVGL can render next area while DMA is active

Both buffers use LV_DISPLAY_RENDER_MODE_PARTIAL. LVGL divides the display into horizontal strips and calls lvgl_flush_cb once per strip.

When ESP3D_SNAPSHOT_FEATURE is enabled, lvgl_flush_cb writes pixel data to an open file (g_snapshot.file) for each rendered strip, building up a full-screen raw RGB565 capture. The capture uses 120-byte chunks to stay within the ESP32-S3’s DMA and stack constraints. The snapshot is marked complete when captured_pixels >= expected_pixels.


The GT911 is initialized via touch_gt911_configure() using the board-specific configuration in touch_gt911_def.h. The GT911’s native coordinate range may differ from the 800 × 480 panel; touch_read_cb normalises at read time:

x_px = raw_x × DISPLAY_WIDTH_PX / touch_gt911_get_x_max();
y_px = raw_y × DISPLAY_HEIGHT_PX / touch_gt911_get_y_max();

The LVGL indev read timer period is set to 10 ms for responsive touch tracking.

no

no

yes

yes (new press)

no (held down)

yes (waking screen)

no (screen active)

yes

no

LVGL indev timer fires (10 ms)

touch_read_cb() called

touch_gt911_read() → touch_data

is_pressed?

first press (last_pressed_state == false)?

activity_process_event()

Screen was idle?

(returns false if waking)

Mark touch_consumed_for_wakeup = true

Report RELEASED to LVGL

(wake-up touch is suppressed)

Store mapped x/y

Report PRESSED to LVGL

touch_consumed_for_wakeup?

Report RELEASED (drag ignored

during wakeup cycle)

Update x/y, report PRESSED

(continuing drag)

Release: activity_process_event()

Report RELEASED to LVGL

Release: wake-up cycle ends

Reset touch_consumed_for_wakeup

Wake-up isolation: The first touch after an idle period wakes the screen but is not passed to LVGL widgets. The touch_consumed_for_wakeup flag prevents the gesture that woke the screen from accidentally triggering a button or menu item. Subsequent touch events within the same press-release cycle are also suppressed until the finger is lifted.


The SD card’s chip-select (SD_CS) has no direct ESP32-S3 GPIO on this board; it is wired to EXIO3 on the CH422G I²C IO expander. The expander is initialized inside init_touch_controller() when ESP3D_SD_CARD_FEATURE is enabled, sharing the I²C bus that was just opened for the GT911.

SD Card (SPI)touch_gt911io_ch422gbus_i2cinit_touch_controller()SD Card (SPI)touch_gt911io_ch422gbus_i2cinit_touch_controller()EXIO3 = LOW → SD CS asserted (card selected)SD card is permanently selected via EXIO3SPI2_HOST has no other device - CS never needs to togglebus_i2c_init(port, SDA, SCL, freq)ESP_OK ← shared bus is readyio_ch422g_configure(CH422G_INITIAL_OUTPUT = 0x26)ESP_OKtouch_gt911_configure()ESP_OK
CH422G_INITIAL_OUTPUT = 0x2E & ~(1<<3) → 0x26
Bit 1 (EXIO1) = 1 → Touch/LCD reset — HIGH (no active reset pulse)
Bit 2 (EXIO2) = 1 → Touch/LCD reset — HIGH (no active reset pulse)
Bit 3 (EXIO3) = 0 → SD CS — LOW (card permanently selected)
Bit 5 (EXIO5) = 1 → Reserved — HIGH

Important: This constant must match between board_init.c and the factory app’s main.c. Any divergence will leave the SD card deselected and SD mounts will fail.


On boards with RGB parallel displays, simultaneous SD/flash SPI DMA and the RGB pixel-clock signal can cause electrical interference that corrupts the RGB framebuffer or produces SPI errors. The BSP implements a pixel-clock throttle gated by ESP3D_PATCH_FS_ACCESS_RELEASE.

esp_lcd_rgb_panelBSPFilesystem Layer\n(ESP3DFlash::accessFS / ESP3DSd::accessFS)esp_lcd_rgb_panelBSPFilesystem Layer\n(ESP3DFlash::accessFS / ESP3DSd::accessFS)bsp_accessFs()esp_lcd_rgb_panel_set_pclk(DISPLAY_PATCH_FS_FREQ_HZ)vTaskDelay(DISPLAY_PATCH_FS_DELAY_MS) ← panel re-syncs at lower clockESP_OKSD / flash read or writebsp_releaseFs()esp_lcd_rgb_panel_set_pclk(DISPLAY_PCLK_FREQ_HZ)vTaskDelay(DISPLAY_PATCH_FS_DELAY_MS) ← panel re-syncs at normal clockESP_OK

Both functions guard against a NULL panel handle — they return ESP_OK immediately if the display was not initialized, so the filesystem layer can call them unconditionally.

See docs/architecture/display_drivers.md for the underlying RGB driver architecture and a full explanation of the FS clock-patch rationale.


control_types.c registers three board-level custom LVGL event codes. These allow the upper application to dispatch hardware input events through the standard LVGL lv_event_send() / lv_obj_add_event_cb() API, even for input types that have no built-in LVGL equivalent.

Global variablePurpose
LV_EVENT_SWITCH_PRESSEDDispatched when a 4-position switch moves to a new position
LV_EVENT_SWITCH_RELEASEDDispatched when the switch is released
LV_EVENT_POTENTIOMETER_CHANGEDDispatched when an analog potentiometer value changes

All three are initialised to LV_EVENT_ALL (invalid sentinel) at file scope and receive valid IDs from lv_event_register_id() when control_events_init() is called. This function is called at the tail of board_init(), after lv_init() has run inside init_lvgl().

Because this board has no physical switch, encoder, or potentiometer, these events are defined for API compatibility with the shared upper-layer code and will not be generated by any hardware interrupt.


All symbols below are declared in board_init.h.

esp_err_t board_init(void);

Top-level board initialisation. Orchestrates the full hardware bringup in dependency order. Must be called once before any LVGL or hardware API is used.

Returns ESP_OK on success, or the first failing sub-system’s error code.


esp_err_t bsp_accessFs(void);

Throttles the RGB pixel clock to DISPLAY_PATCH_FS_FREQ_HZ and waits DISPLAY_PATCH_FS_DELAY_MS before a filesystem operation. Called by ESP3DFlash::accessFS() and ESP3DSd::accessFS().

Only compiled when ESP3D_PATCH_FS_ACCESS_RELEASE is enabled. Returns ESP_OK immediately if disp_panel is NULL.


esp_err_t bsp_releaseFs(void);

Restores the RGB pixel clock to DISPLAY_PCLK_FREQ_HZ after a filesystem operation completes. Must be paired with every bsp_accessFs() call.

Only compiled when ESP3D_PATCH_FS_ACCESS_RELEASE is enabled.


lv_display_t *get_lvgl_display(void);

Returns the LVGL display handle created during board_init(). Used by tft_ui_task in the UI Framework. Returns NULL when ESP3D_DISPLAY_FEATURE is disabled.


_lock_t *get_lvgl_lock(void);

Returns a pointer to the LVGL API mutex. The UI task acquires this lock around all lv_* API calls to protect against concurrent access from other tasks. Returns NULL when ESP3D_DISPLAY_FEATURE is disabled.


lv_indev_t *get_touch_indev(void);

Returns the LVGL touch input device handle. Only compiled when ESP3D_TOUCH_FEATURE is enabled.


const char *board_get_name(void);
const char *board_get_version(void);

Return the board identification strings defined in board_config.h. Used in log output and system-info screens.


void control_events_init(void);

Registers the three custom LVGL event IDs. Called automatically by board_init() — do not call directly.


FlagEffect when enabled
ESP3D_DISPLAY_FEATUREEnables the full display + LVGL pipeline
ESP3D_TOUCH_FEATUREEnables GT911 init, lv_indev registration, and touch_read_cb
ESP3D_BRIGHTNESS_CONTROL_FEATUREEnables PWM backlight control via disp_backlight
ESP3D_SD_CARD_FEATUREEnables CH422G init and SD CS assertion (EXIO3 LOW)
ESP3D_PATCH_FS_ACCESS_RELEASEEnables pixel-clock throttle during filesystem I/O
ESP3D_SNAPSHOT_FEATUREEnables in-flush pixel capture to SD file
DISPLAY_USE_DOUBLE_BUFFER_FLAGAllocates a second SPIRAM draw buffer for LVGL
DISPLAY_SWAP_COLOR_FLAGAdds an RGB565 byte-swap pass in lvgl_flush_cb

Sub-moduleDocumentationPurpose
Factory Appesp32s3_8048_touch_lcd_7_factoryRecovery partition: OTA flashing, UI resources update, touch-navigable menu
Build Scriptsesp32s3_8048_touch_lcd_7_build_scriptsVariant matrix, build automation, resource generation
BoardDisplayPanelCH422GFS patchDoc
esp32s3_8048_touch_lcd_77” 800×480ST7262YesYes(this doc)
esp32s3_8048s043c4.3” 800×480ST7262YesYesesp32s3_8048s043c
esp32s3_8048s050c5” 800×480ST7262YesYesesp32s3_8048s050c
esp32s3_8048s070c7” 800×480ST7262YesYesesp32s3_8048s070c
esp32s3_4827s043c4.3” 480×272ILI9485NoYesesp32s3_4827s043c_bsp

Key distinction from esp32s3_8048s043c/050c/070c: Those boards route SD CS through a direct GPIO. This board routes it through CH422G EXIO3, requiring the I²C expander to be initialised before any SD access and keeping the CS asserted for the lifetime of the application.

ConsumerUses from this BSP
UI Framework — esp3d_x_ui.cppget_lvgl_display(), get_lvgl_lock(), get_touch_indev()
Storage Layer — ESP3DFlash, ESP3DSdbsp_accessFs(), bsp_releaseFs()
Core Platform — main.cppboard_init(), board_get_name(), board_get_version()

components/bsp/lv_conf.h was regenerated from the LVGL 9.6.0 template (Configuration file for v9.6.0), and the sdkconfig files set CONFIG_LV_CONF_SKIP=n so this file is actually used (see Board_Support_Packages.md). The project values are kept (LV_MEM_SIZE 48 KB, monitors positions), LV_USE_COLOR_FILTER is 0 (color filters are not used: pressed feedback is a darker local style, see ui_components.md). LV_COLOR_DEPTH is no longer set in the file: LVGL takes CONFIG_LV_COLOR_DEPTH, or 16 by default.