diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42049d0..021ba41 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - board: [esp32_p4_function_ev_board] + board: [esp32_p4_function_ev_board, esp32_c3_lcdkit] fail-fast: false steps: @@ -41,6 +41,7 @@ jobs: esp-box) echo 'esp32s3';; m5stack_core_s3) echo 'esp32s3';; esp32_p4_function_ev_board) echo 'esp32p4';; + esp32_c3_lcdkit) echo 'esp32c3';; *) echo 'Unknown target'; exit 1;; esac)" >> $GITHUB_ENV diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07eec16..2425458 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,11 +6,11 @@ on: release_name: description: 'Name of the GitHub Release' required: true - default: 'v1.0.0' + default: 'v1.1.0' release_tag: description: 'Tag for the GitHub Release' required: true - default: 'v1.0.0' + default: 'v1.1.0' prefix: description: 'Prefix for binary name' required: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3940148..5833626 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - board: [esp32_p4_function_ev_board] + board: [esp32_p4_function_ev_board, esp32_c3_lcdkit] fail-fast: false steps: diff --git a/README.md b/README.md index 80cbace..7e5a2cf 100644 --- a/README.md +++ b/README.md @@ -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-P4. +Example of graphical application for ESP32-C3, ESP32-P4. Read more about Swift for ESP32 at [Espressif Developer Portal](https://developer.espressif.com/tags/swift/). @@ -14,10 +14,20 @@ Read more about Swift for ESP32 at [Espressif Developer Portal](https://develope ## Build +ESP32-P4-Function-Ev-Board: + ```shell idf.py @boards/esp32_p4_function_ev_board.cfg flash monitor ``` +ESP32-C3-LcdKit: + +![ESP32-C3-LcdKit](docs/img/esp32-c3-lcdkit.webp) + +```shell +idf.py @boards/e@boards/esp32_c3_lcdkit.cfg flash monitor +``` + ## Credits - Graphical assets: https://opengameart.org/content/platformer-tiles diff --git a/boards/esp32_c3_lcdkit.cfg b/boards/esp32_c3_lcdkit.cfg new file mode 100644 index 0000000..0135850 --- /dev/null +++ b/boards/esp32_c3_lcdkit.cfg @@ -0,0 +1 @@ +-DSDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32_c3_lcdkit;sdkconfig.defaults" -DBUILD_BOARD="esp32_c3_lcdkit" -DIDF_TARGET=esp32c3 -B build.esp32_c3_lcdkit diff --git a/boards/esp32_c3_lcdkit/diagram.json b/boards/esp32_c3_lcdkit/diagram.json new file mode 100644 index 0000000..73adcac --- /dev/null +++ b/boards/esp32_c3_lcdkit/diagram.json @@ -0,0 +1,35 @@ +{ + "version": 1, + "author": "Juraj Michálek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c3-devkitm-1", + "id": "esp", + "top": -494.32, + "left": -455.03, + "attrs": { "builder": "rust-std-esp32" } + }, + { "type": "wokwi-ili9341", "id": "lcd1", "top": -546.22, "left": -134.92, "attrs": {} }, + { "type": "wokwi-ky-040", "id": "encoder1", "top": -417.5, "left": -703.6, "attrs": {} } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "esp:3V3", "lcd1:VCC", "green", [] ], + [ "esp:GND.1", "lcd1:GND", "black", [ "v215.62", "h374.23" ] ], + [ "esp:1", "lcd1:SCK", "blue", [ "v215.62", "h422.24" ] ], + [ "esp:7", "lcd1:CS", "red", [ "v186.82", "h295.01" ] ], + [ "esp:2", "lcd1:D/C", "magenta", [ "v215.62", "h403.03" ] ], + [ "esp:0", "lcd1:MOSI", "orange", [ "v215.62", "h412.64" ] ], + [ "esp:3", "lcd1:LED", "white", [ "v234.82", "h431.84" ] ], + [ "lcd1:LED", "esp:3V3", "white", [] ], + [ "esp:10", "encoder1:DT", "green", [] ], + [ "esp:9", "encoder1:CLK", "blue", [] ], + [ "esp:3V3", "encoder1:VCC", "red", [] ], + [ "esp:GND.1", "encoder1:GND", "black", [] ], + [ "esp:8", "encoder1:SW", "yellow", [] ] + ], + "serialMonitor": { "display": "terminal", "newline": "lf", "convertEol": true }, + "dependencies": {} +} \ No newline at end of file diff --git a/boards/esp32_c3_lcdkit/wokwi.toml b/boards/esp32_c3_lcdkit/wokwi.toml new file mode 100644 index 0000000..e9da89c --- /dev/null +++ b/boards/esp32_c3_lcdkit/wokwi.toml @@ -0,0 +1,7 @@ +# Wokwi Configuration File +# Reference: https://docs.wokwi.com/vscode/project-config +[wokwi] +version = 1 +firmware = 'build.esp32_c3_lcdkit/flasher_args.json' +elf = 'build.esp32_c3_lcdkit/esp32-sdl3-swift-example.elf' +gdbServerPort=3333 diff --git a/docs/img/esp32-c3-lcdkit.webp b/docs/img/esp32-c3-lcdkit.webp new file mode 100644 index 0000000..3d4fcce Binary files /dev/null and b/docs/img/esp32-c3-lcdkit.webp differ diff --git a/main/Main.swift b/main/Main.swift index 6f60741..42abb66 100644 --- a/main/Main.swift +++ b/main/Main.swift @@ -24,7 +24,7 @@ func app_main() { var attr = pthread_attr_t() pthread_attr_init(&attr) - pthread_attr_setstacksize(&attr, 65536) // Set the stack size for the thread + pthread_attr_setstacksize(&attr, 32000) // Set the stack size for the thread // Create the SDL thread let ret = pthread_create(&sdl_pthread, &attr, sdl_thread_entry_point, nil) @@ -76,6 +76,15 @@ func sdl_thread_entry_point(arg: UnsafeMutableRawPointer?) -> UnsafeMutableRawPo return nil } + var width: Int32 = 0 + var height: Int32 = 0 + + // Get window size + SDL_GetWindowSize(window, &width, &height) + + // Print the resolution + print("Display resolution: \(width)x\(height)") + // Create SDL renderer guard let renderer = SDL_CreateRenderer(window, nil) else { print("Failed to create renderer") diff --git a/main/idf_component.yml b/main/idf_component.yml index fdcef1c..d7febfc 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: joltwallet/littlefs: "==1.14.8" - georgik/sdl: "^3.1.2~8" + georgik/sdl: "^3.1.2~9" georgik/sdl_ttf: "^3.0.0~3" idf: version: ">=5.1.0" @@ -10,3 +10,8 @@ dependencies: version: "3.0.1" rules: - if: "${BUILD_BOARD} == esp32_p4_function_ev_board_noglib" + + espressif/esp32_c3_lcdkit: + version: "^1.1.0~1" + rules: + - if: "${BUILD_BOARD} == esp32_c3_lcdkit" diff --git a/sdkconfig.defaults.esp32_c3_lcdkit b/sdkconfig.defaults.esp32_c3_lcdkit new file mode 100644 index 0000000..2cc19c0 --- /dev/null +++ b/sdkconfig.defaults.esp32_c3_lcdkit @@ -0,0 +1,23 @@ +# This file was generated using idf.py save-defconfig. It can be edited manually. +# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration +# +CONFIG_IDF_TARGET="esp32c3" +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_PARTITION_TABLE_CUSTOM=y + +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y +CONFIG_COMPILER_OPTIMIZATION_PERF=y +CONFIG_SPIRAM=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y +CONFIG_SPIRAM_RODATA=y +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_BSP_LCD_RGB_BUFFER_NUMS=2 +CONFIG_BSP_LCD_RGB_BOUNCE_BUFFER_MODE=y +CONFIG_SPIRAM_MODE_HEX=y +CONFIG_SPIRAM_SPEED_200M=y +CONFIG_IDF_EXPERIMENTAL_FEATURES=y + +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8912 +