Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ else()
set(ENV{BUILD_BOARD} ${BUILD_BOARD})
endif()

# Add BSP-specific configurations
if(BUILD_BOARD STREQUAL "m5stack_tab5")
add_compile_definitions(BSP_CONFIG_NO_GRAPHIC_LIB=1)
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp32-sdl3-swift-example)

get_filename_component(configName "${CMAKE_BINARY_DIR}" NAME)
list(APPEND EXTRA_COMPONENT_DIRS "${CMAKE_SOURCE_DIR}/components/esp_littlefs")
list(APPEND EXTRA_COMPONENT_DIRS "${CMAKE_SOURCE_DIR}/components")
littlefs_create_partition_image(assets assets FLASH_IN_PROJECT)
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Test Status](https://github.com/georgik/esp32-sdl3-swift-example/actions/workflows/test.yml/badge.svg)

Example of graphical application for ESP32-C3, ESP32-P4.
Example of graphical application for ESP32-C3, ESP32-C6, ESP32-P4 using Swift programming language with SDL3 graphics library.

Read more about Swift for ESP32 at [Espressif Developer Portal](https://developer.espressif.com/tags/swift/).

Expand All @@ -23,15 +23,50 @@ Read more about Swift for ESP32 at [Espressif Developer Portal](https://develope

```shell
source esp-idf/export.sh
```

If you want to use specific Swift toolchain, you can set the environment variable `TOOLCHAINS`.
The step is not required for Swift 6.1 and newer.
```shell
export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-10-30-a.xctoolchain/Info.plist)
```

### Build for ESP32-P4-Function-Ev-Board
## Supported Boards

This project supports multiple ESP32 development boards with different display configurations:

| Board | MCU | Display | Resolution | Interface | Status |
|-------|-----|---------|------------|-----------|--------|
| ESP32-P4 Function Evaluation Board | ESP32-P4 | RGB LCD | 480x480 | RGB | ✅ Working |
| M5Stack Tab5 | ESP32-P4 | MIPI-DSI LCD | 720x1280 | MIPI-DSI | ✅ Working |
| ESP32-C3 LCD Kit | ESP32-C3 | SPI LCD | 240x240 | SPI | ✅ Working |
| ESP32-C6 DevKit | ESP32-C6 | SPI LCD | 320x240 | SPI | ✅ Working |
| Waveshare ESP32-C6-LCD-1.47 | ESP32-C6 | SPI LCD | 172x320 | SPI | ✅ Working |

## Build Instructions

### Build for ESP32-P4 Function Evaluation Board

```shell
idf.py @boards/esp32_p4_function_ev_board.cfg flash monitor
```

### Build for M5Stack Tab5

![M5Stack Tab5](docs/img/m5stack-tab5.webp)

The M5Stack Tab5 is a premium ESP32-P4 tablet with a high-resolution 5-inch MIPI-DSI display (720x1280) and GT911 capacitive touch controller.

- **Board**: [M5Stack Tab5](https://shop.m5stack.com/products/m5stack-tab5-esp32-p4-tablet)
- **MCU**: ESP32-P4 RISC-V dual-core
- **Display**: 5-inch IPS LCD, 720x1280 resolution
- **Touch**: GT911 capacitive touch controller
- **Interface**: MIPI-DSI for display

```shell
idf.py @boards/m5stack_tab5.cfg flash monitor
```

### Build for ESP32-C3-LcdKit

![ESP32-C3-LcdKit](docs/img/esp32-c3-lcdkit.webp)
Expand Down
1 change: 1 addition & 0 deletions boards/m5stack_tab5.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults.m5stack_tab5;sdkconfig.defaults" -DBUILD_BOARD="m5stack_tab5" -DIDF_TARGET=esp32p4 -B build.m5stack_tab5
32 changes: 32 additions & 0 deletions boards/m5stack_tab5/diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": 1,
"author": "ESP32-SDL3-Swift Example",
"editor": "wokwi",
"parts": [
{
"type": "board-esp32-p4",
"id": "esp32p4",
"top": 0,
"left": 0,
"attrs": {
"psram": "16",
"flash": "16"
}
},
{
"type": "wokwi-ili9341",
"id": "lcd",
"top": 0,
"left": 300,
"attrs": {
"width": "720",
"height": "1280"
}
}
],
"connections": [
["esp32p4:GND", "lcd:GND", "black", []],
["esp32p4:3V3", "lcd:VCC", "red", []]
],
"dependencies": {}
}
15 changes: 15 additions & 0 deletions boards/m5stack_tab5/wokwi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[wokwi]
version = 1
elf = "../../build.m5stack_tab5/esp32-sdl3-swift-example.elf"
firmware = "../../build.m5stack_tab5/esp32-sdl3-swift-example.bin"

[esp32]
# M5Stack Tab5 ESP32-P4 configuration
# - Dual-core RISC-V
# - 16MB Flash, 32MB PSRAM
# - 1280x720 MIPI-DSI display
# - GT911 touch controller

[[esp32.chip]]
model = "esp32p4"
flash_size = "16MB"
13 changes: 13 additions & 0 deletions components/m5stack_tab5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

idf_component_register(
SRCS "m5stack_tab5.c"
INCLUDE_DIRS "include"
INCLUDE_DIRS "include/bsp"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES
driver
esp_lcd
esp_codec_dev
esp_lcd_ili9881c
PRIV_REQUIRES usb spiffs fatfs
)
126 changes: 126 additions & 0 deletions components/m5stack_tab5/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
menu "Board Support Package (ESP32-P4)"

config BSP_ERROR_CHECK
bool "Enable error check in BSP"
default y
help
Error check assert the application before returning the error code.

menu "I2C"
config BSP_I2C_NUM
int "I2C peripheral index"
default 1
range 0 1
help
ESP32P4 has two I2C peripherals, pick the one you want to use.

config BSP_I2C_FAST_MODE
bool "Enable I2C fast mode"
default y
help
I2C has two speed modes: normal (100kHz) and fast (400kHz).

config BSP_I2C_CLK_SPEED_HZ
int
default 400000 if BSP_I2C_FAST_MODE
default 100000
endmenu

menu "I2S"
config BSP_I2S_NUM
int "I2S peripheral index"
default 1
range 0 2
help
ESP32P4 has three I2S peripherals, pick the one you want to use.
endmenu

menu "uSD card - Virtual File System"
config BSP_SD_FORMAT_ON_MOUNT_FAIL
bool "Format uSD card if mounting fails"
default n
help
The SDMMC host will format (FAT) the uSD card if it fails to mount the filesystem.

config BSP_SD_MOUNT_POINT
string "uSD card mount point"
default "/sdcard"
help
Mount point of the uSD card in the Virtual File System

endmenu

menu "SPIFFS - Virtual File System"
config BSP_SPIFFS_FORMAT_ON_MOUNT_FAIL
bool "Format SPIFFS if mounting fails"
default n
help
Format SPIFFS if it fails to mount the filesystem.

config BSP_SPIFFS_MOUNT_POINT
string "SPIFFS mount point"
default "/spiffs"
help
Mount point of SPIFFS in the Virtual File System.

config BSP_SPIFFS_PARTITION_LABEL
string "Partition label of SPIFFS"
default "storage"
help
Partition label which stores SPIFFS.

config BSP_SPIFFS_MAX_FILES
int "Max files supported for SPIFFS VFS"
default 5
help
Supported max files for SPIFFS in the Virtual File System.
endmenu

menu "Display"
config BSP_LCD_DPI_BUFFER_NUMS
int "Set number of frame buffers"
default 1
range 1 3
help
Let DPI LCD driver create a specified number of frame-size buffers. Only when it is set to multiple can the avoiding tearing be turned on.

config BSP_DISPLAY_LVGL_AVOID_TEAR
bool "Avoid tearing effect"
depends on BSP_LCD_DPI_BUFFER_NUMS > 1
default "n"
help
Avoid tearing effect through LVGL buffer mode and double frame buffers of RGB LCD. This feature is only available for RGB LCD.

choice BSP_DISPLAY_LVGL_MODE
depends on BSP_DISPLAY_LVGL_AVOID_TEAR
prompt "Select LVGL buffer mode"
default BSP_DISPLAY_LVGL_FULL_REFRESH
config BSP_DISPLAY_LVGL_FULL_REFRESH
bool "Full refresh"
config BSP_DISPLAY_LVGL_DIRECT_MODE
bool "Direct mode"
endchoice

config BSP_DISPLAY_BRIGHTNESS_LEDC_CH
int "LEDC channel index"
default 1
range 0 7
help
LEDC channel is used to generate PWM signal that controls display brightness.
Set LEDC index that should be used.

choice BSP_LCD_COLOR_FORMAT
prompt "Select LCD color format"
default BSP_LCD_COLOR_FORMAT_RGB565
help
Select the LCD color format RGB565/RGB888.

config BSP_LCD_COLOR_FORMAT_RGB565
bool "RGB565"
config BSP_LCD_COLOR_FORMAT_RGB888
bool "RGB888"
endchoice

endmenu

endmenu
Loading