From 497568f85ea68ede07749788feaec32ca1c2f964 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 20 Jun 2026 00:52:58 +0200 Subject: [PATCH 01/19] WIP --- .../cyd-2432s024c/Source/Configuration.cpp | 2 - .../cyd-2432s024c/Source/devices/SdCard.cpp | 34 ---- Devices/cyd-2432s024c/Source/devices/SdCard.h | 8 - Devices/cyd-2432s024c/cyd,2432s024c.dts | 16 +- .../cyd-2432s024r/Source/Configuration.cpp | 4 +- .../cyd-2432s024r/Source/devices/SdCard.cpp | 23 --- Devices/cyd-2432s024r/Source/devices/SdCard.h | 8 - Devices/cyd-2432s024r/cyd,2432s024r.dts | 16 +- .../cyd-2432s028r/Source/Configuration.cpp | 2 - .../cyd-2432s028r/Source/devices/SdCard.cpp | 25 --- Devices/cyd-2432s028r/Source/devices/SdCard.h | 8 - Devices/cyd-2432s028r/cyd,2432s028r.dts | 16 +- .../cyd-2432s028rv3/Source/Configuration.cpp | 2 - .../cyd-2432s028rv3/Source/devices/SdCard.cpp | 25 --- .../cyd-2432s028rv3/Source/devices/SdCard.h | 8 - Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts | 16 +- .../cyd-2432s032c/Source/Configuration.cpp | 2 - .../cyd-2432s032c/Source/devices/SdCard.cpp | 33 ---- Devices/cyd-2432s032c/Source/devices/SdCard.h | 8 - Devices/cyd-2432s032c/cyd,2432s032c.dts | 16 +- .../cyd-3248s035c/Source/Configuration.cpp | 66 ++++---- .../cyd-3248s035c/Source/devices/SdCard.cpp | 31 ---- Devices/cyd-3248s035c/Source/devices/SdCard.h | 8 - Devices/cyd-3248s035c/cyd,3248s035c.dts | 128 +++++++------- .../cyd-4848s040c/Source/Configuration.cpp | 2 - .../cyd-4848s040c/Source/devices/SdCard.cpp | 28 --- Devices/cyd-4848s040c/Source/devices/SdCard.h | 8 - Devices/cyd-4848s040c/cyd,4848s040c.dts | 7 + .../cyd-8048s043c/Source/Configuration.cpp | 2 - .../cyd-8048s043c/Source/devices/SdCard.cpp | 25 --- Devices/cyd-8048s043c/Source/devices/SdCard.h | 7 - Devices/cyd-8048s043c/cyd,8048s043c.dts | 7 + Devices/cyd-e32r28t/Source/Configuration.cpp | 2 - Devices/cyd-e32r28t/Source/devices/SdCard.cpp | 28 --- Devices/cyd-e32r28t/Source/devices/SdCard.h | 7 - Devices/cyd-e32r28t/cyd,e32r28t.dts | 16 +- Devices/cyd-e32r32p/Source/Configuration.cpp | 2 - Devices/cyd-e32r32p/Source/devices/SdCard.cpp | 29 ---- Devices/cyd-e32r32p/Source/devices/SdCard.h | 13 -- Devices/cyd-e32r32p/cyd,e32r32p.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 29 ---- .../Source/devices/SdCard.h | 7 - .../elecrow,crowpanel-advance-28.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 29 ---- .../Source/devices/SdCard.h | 7 - .../elecrow,crowpanel-advance-35.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 25 --- .../Source/devices/SdCard.h | 7 - .../elecrow,crowpanel-advance-50.dts | 9 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 28 --- .../Source/devices/SdCard.h | 7 - .../elecrow,crowpanel-basic-28.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 28 --- .../Source/devices/SdCard.h | 7 - .../elecrow,crowpanel-basic-35.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 24 --- .../Source/devices/SdCard.h | 7 - .../elecrow,crowpanel-basic-50.dts | 9 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 128 -------------- .../Source/devices/SdCard.h | 6 - .../guition,jc1060p470ciwy.dts | 13 ++ .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 31 ---- .../Source/devices/SdCard.h | 8 - .../guition,jc2432w328c.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 30 ---- .../Source/devices/SdCard.h | 7 - .../guition,jc3248w535c.dts | 11 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 24 --- .../Source/devices/SdCard.h | 7 - .../guition,jc8048w550c.dts | 7 + Devices/lilygo-tdeck/Source/Configuration.cpp | 2 - .../lilygo-tdeck/Source/devices/Sdcard.cpp | 34 ---- Devices/lilygo-tdeck/Source/devices/Sdcard.h | 7 - Devices/lilygo-tdeck/lilygo,tdeck.dts | 12 ++ Devices/lilygo-tdisplay/lilygo,tdisplay.dts | 5 + .../lilygo-tdongle-s3/lilygo,tdongle-s3.dts | 5 + .../Source/Configuration.cpp | 1 - .../Source/devices/SdCard.cpp | 36 ---- .../Source/devices/SdCard.h | 8 - .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 12 ++ .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 30 ---- .../Source/devices/SdCard.h | 8 - .../m5stack,cardputer-adv.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 29 ---- .../m5stack-cardputer/Source/devices/SdCard.h | 8 - .../m5stack-cardputer/m5stack,cardputer.dts | 16 +- .../m5stack-core2/Source/Configuration.cpp | 2 - .../m5stack-core2/Source/devices/SdCard.cpp | 32 ---- Devices/m5stack-core2/Source/devices/SdCard.h | 7 - Devices/m5stack-core2/m5stack,core2.dts | 12 ++ .../m5stack-cores3/Source/Configuration.cpp | 2 - .../m5stack-cores3/Source/devices/SdCard.cpp | 30 ---- .../m5stack-cores3/Source/devices/SdCard.h | 7 - Devices/m5stack-cores3/m5stack,cores3.dts | 12 ++ .../m5stack-papers3/Source/Configuration.cpp | 2 - .../m5stack-papers3/Source/devices/SdCard.cpp | 27 --- .../m5stack-papers3/Source/devices/SdCard.h | 7 - Devices/m5stack-papers3/m5stack,papers3.dts | 7 + .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 30 ---- .../m5stack-stackchan/Source/devices/SdCard.h | 7 - .../m5stack-stackchan/m5stack,stackchan.dts | 12 ++ .../m5stack,stickc-plus.dts | 5 + .../m5stack,stickc-plus2.dts | 5 + .../m5stack-sticks3/Source/Configuration.cpp | 2 - .../m5stack-sticks3/Source/devices/SdCard.cpp | 30 ---- .../m5stack-sticks3/Source/devices/SdCard.h | 8 - Devices/m5stack-sticks3/m5stack,sticks3.dts | 12 ++ Devices/m5stack-tab5/Source/Configuration.cpp | 2 - .../m5stack-tab5/Source/devices/SdCard.cpp | 26 --- Devices/m5stack-tab5/Source/devices/SdCard.h | 8 - Devices/m5stack-tab5/m5stack,tab5.dts | 9 +- Devices/unphone/Source/Configuration.cpp | 2 - Devices/unphone/Source/devices/SdCard.cpp | 36 ---- Devices/unphone/Source/devices/SdCard.h | 7 - Devices/unphone/unphone.dts | 7 + .../waveshare,esp32-s3-geek.dts | 5 + .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 28 --- .../Source/devices/SdCard.h | 7 - .../waveshare,s3-lcd-13.dts | 12 ++ .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 28 --- .../Source/devices/SdCard.h | 7 - .../waveshare,s3-touch-lcd-128.dts | 16 +- .../Source/Configuration.cpp | 2 - .../Source/devices/Sdcard.cpp | 30 ---- .../Source/devices/Sdcard.h | 7 - .../waveshare,s3-touch-lcd-147.dts | 11 +- .../Source/Configuration.cpp | 2 - .../Source/devices/SdCard.cpp | 26 --- .../Source/devices/SdCard.h | 7 - .../waveshare,s3-touch-lcd-43.dts | 7 + .../Source/Configuration.cpp | 46 +++-- .../Source/devices/SdCard.cpp | 28 --- .../Source/devices/SdCard.h | 7 - .../wireless-tag,wt32-sc01-plus.dts | 7 + .../bindings/espressif,esp32-sdspi.yaml | 27 +++ .../include/tactility/bindings/esp32_sdspi.h | 15 ++ .../include/tactility/drivers/esp32_sdcard.h | 21 +++ .../include/tactility/drivers/esp32_sdspi.h | 23 +++ .../tactility/drivers/esp32_sdspi_fs.h | 22 +++ .../source/drivers/esp32_sdcard.cpp | 27 +++ .../source/drivers/esp32_sdmmc.cpp | 1 + .../source/drivers/esp32_sdspi.cpp | 159 ++++++++++++++++++ .../source/drivers/esp32_sdspi_fs.cpp | 126 ++++++++++++++ Platforms/platform-esp32/source/module.cpp | 3 + .../Tactility/hal/sdcard/SpiSdCardDevice.h | 104 ------------ Tactility/Source/hal/sdcard/SdCard.cpp | 47 ++++-- .../Source/hal/sdcard/SpiSdCardDevice.cpp | 156 ----------------- Tactility/Source/hal/usb/Usb.cpp | 51 ++---- .../Source/service/statusbar/Statusbar.cpp | 23 ++- .../bindings/display-placeholder.yaml | 5 + TactilityKernel/bindings/spi-peripheral.yaml | 9 + .../tactility/bindings/display_placeholder.h | 15 ++ .../tactility/bindings/spi_peripheral.h | 15 ++ TactilityKernel/include/tactility/device.h | 7 + .../include/tactility/drivers/display.h | 14 ++ .../tactility/drivers/display_placeholder.h | 16 ++ .../tactility/drivers/spi_peripheral.h | 25 +++ .../tactility/filesystem/file_system.h | 14 ++ TactilityKernel/source/device.cpp | 4 + TactilityKernel/source/drivers/display.cpp | 10 ++ .../source/drivers/display_placeholder.cpp | 26 +++ .../source/drivers/spi_peripheral.cpp | 77 +++++++++ .../source/filesystem/file_system.cpp | 11 ++ TactilityKernel/source/kernel_init.cpp | 4 + 179 files changed, 1288 insertions(+), 1945 deletions(-) delete mode 100644 Devices/cyd-2432s024c/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-2432s024c/Source/devices/SdCard.h delete mode 100644 Devices/cyd-2432s024r/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-2432s024r/Source/devices/SdCard.h delete mode 100644 Devices/cyd-2432s028r/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-2432s028r/Source/devices/SdCard.h delete mode 100644 Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-2432s028rv3/Source/devices/SdCard.h delete mode 100644 Devices/cyd-2432s032c/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-2432s032c/Source/devices/SdCard.h delete mode 100644 Devices/cyd-3248s035c/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-3248s035c/Source/devices/SdCard.h delete mode 100644 Devices/cyd-4848s040c/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-4848s040c/Source/devices/SdCard.h delete mode 100644 Devices/cyd-8048s043c/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-8048s043c/Source/devices/SdCard.h delete mode 100644 Devices/cyd-e32r28t/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-e32r28t/Source/devices/SdCard.h delete mode 100644 Devices/cyd-e32r32p/Source/devices/SdCard.cpp delete mode 100644 Devices/cyd-e32r32p/Source/devices/SdCard.h delete mode 100644 Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp delete mode 100644 Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.h delete mode 100644 Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp delete mode 100644 Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.h delete mode 100644 Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp delete mode 100644 Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.h delete mode 100644 Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp delete mode 100644 Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.h delete mode 100644 Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp delete mode 100644 Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.h delete mode 100644 Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp delete mode 100644 Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.h delete mode 100644 Devices/guition-jc1060p470ciwy/Source/devices/SdCard.cpp delete mode 100644 Devices/guition-jc1060p470ciwy/Source/devices/SdCard.h delete mode 100644 Devices/guition-jc2432w328c/Source/devices/SdCard.cpp delete mode 100644 Devices/guition-jc2432w328c/Source/devices/SdCard.h delete mode 100644 Devices/guition-jc3248w535c/Source/devices/SdCard.cpp delete mode 100644 Devices/guition-jc3248w535c/Source/devices/SdCard.h delete mode 100644 Devices/guition-jc8048w550c/Source/devices/SdCard.cpp delete mode 100644 Devices/guition-jc8048w550c/Source/devices/SdCard.h delete mode 100644 Devices/lilygo-tdeck/Source/devices/Sdcard.cpp delete mode 100644 Devices/lilygo-tdeck/Source/devices/Sdcard.h delete mode 100644 Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp delete mode 100644 Devices/lilygo-tlora-pager/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-cardputer-adv/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-cardputer/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-cardputer/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-core2/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-core2/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-cores3/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-cores3/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-papers3/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-papers3/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-stackchan/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-stackchan/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-sticks3/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-sticks3/Source/devices/SdCard.h delete mode 100644 Devices/m5stack-tab5/Source/devices/SdCard.cpp delete mode 100644 Devices/m5stack-tab5/Source/devices/SdCard.h delete mode 100644 Devices/unphone/Source/devices/SdCard.cpp delete mode 100644 Devices/unphone/Source/devices/SdCard.h delete mode 100644 Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp delete mode 100644 Devices/waveshare-s3-lcd-13/Source/devices/SdCard.h delete mode 100644 Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp delete mode 100644 Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.h delete mode 100644 Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp delete mode 100644 Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.h delete mode 100644 Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp delete mode 100644 Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.h delete mode 100644 Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.cpp delete mode 100644 Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.h create mode 100644 Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml create mode 100644 Platforms/platform-esp32/include/tactility/bindings/esp32_sdspi.h create mode 100644 Platforms/platform-esp32/include/tactility/drivers/esp32_sdcard.h create mode 100644 Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h create mode 100644 Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h create mode 100644 Platforms/platform-esp32/source/drivers/esp32_sdcard.cpp create mode 100644 Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp create mode 100644 Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp delete mode 100644 Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h delete mode 100644 Tactility/Source/hal/sdcard/SpiSdCardDevice.cpp create mode 100644 TactilityKernel/bindings/display-placeholder.yaml create mode 100644 TactilityKernel/bindings/spi-peripheral.yaml create mode 100644 TactilityKernel/include/tactility/bindings/display_placeholder.h create mode 100644 TactilityKernel/include/tactility/bindings/spi_peripheral.h create mode 100644 TactilityKernel/include/tactility/drivers/display.h create mode 100644 TactilityKernel/include/tactility/drivers/display_placeholder.h create mode 100644 TactilityKernel/include/tactility/drivers/spi_peripheral.h create mode 100644 TactilityKernel/source/drivers/display.cpp create mode 100644 TactilityKernel/source/drivers/display_placeholder.cpp create mode 100644 TactilityKernel/source/drivers/spi_peripheral.cpp diff --git a/Devices/cyd-2432s024c/Source/Configuration.cpp b/Devices/cyd-2432s024c/Source/Configuration.cpp index 055d6deec..a6d9b6164 100644 --- a/Devices/cyd-2432s024c/Source/Configuration.cpp +++ b/Devices/cyd-2432s024c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -23,7 +22,6 @@ static bool initBoot() { static tt::hal::DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-2432s024c/Source/devices/SdCard.cpp b/Devices/cyd-2432s024c/Source/devices/SdCard.cpp deleted file mode 100644 index 7f102d97a..000000000 --- a/Devices/cyd-2432s024c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "SdCard.h" - -#define TAG "twodotfour_sdcard" - -#include -#include -#include - -constexpr auto SDCARD_SPI_HOST = SPI3_HOST; -constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SDCARD_SPI_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} - diff --git a/Devices/cyd-2432s024c/Source/devices/SdCard.h b/Devices/cyd-2432s024c/Source/devices/SdCard.h deleted file mode 100644 index 4da9f5b97..000000000 --- a/Devices/cyd-2432s024c/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index c1cace0f7..ccc1ad75d 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -4,6 +4,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -22,18 +24,28 @@ pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/cyd-2432s024r/Source/Configuration.cpp b/Devices/cyd-2432s024r/Source/Configuration.cpp index f6d5e149d..1f715033f 100644 --- a/Devices/cyd-2432s024r/Source/Configuration.cpp +++ b/Devices/cyd-2432s024r/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -14,8 +13,7 @@ static bool initBoot() { static DeviceVector createDevices() { return { - createDisplay(), - createSdCard() + createDisplay() }; } diff --git a/Devices/cyd-2432s024r/Source/devices/SdCard.cpp b/Devices/cyd-2432s024r/Source/devices/SdCard.cpp deleted file mode 100644 index cd8f648ab..000000000 --- a/Devices/cyd-2432s024r/Source/devices/SdCard.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "SdCard.h" -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto config = std::make_unique( - GPIO_NUM_5, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared(std::move(config), spi_controller); -} diff --git a/Devices/cyd-2432s024r/Source/devices/SdCard.h b/Devices/cyd-2432s024r/Source/devices/SdCard.h deleted file mode 100644 index 4da9f5b97..000000000 --- a/Devices/cyd-2432s024r/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-2432s024r/cyd,2432s024r.dts b/Devices/cyd-2432s024r/cyd,2432s024r.dts index 0c151b587..737cd00bc 100644 --- a/Devices/cyd-2432s024r/cyd,2432s024r.dts +++ b/Devices/cyd-2432s024r/cyd,2432s024r.dts @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include / { @@ -14,20 +16,30 @@ gpio-count = <40>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/cyd-2432s028r/Source/Configuration.cpp b/Devices/cyd-2432s028r/Source/Configuration.cpp index 5033e9759..bf458b5cb 100644 --- a/Devices/cyd-2432s028r/Source/Configuration.cpp +++ b/Devices/cyd-2432s028r/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -25,7 +24,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-2432s028r/Source/devices/SdCard.cpp b/Devices/cyd-2432s028r/Source/devices/SdCard.cpp deleted file mode 100644 index 85960aacb..000000000 --- a/Devices/cyd-2432s028r/Source/devices/SdCard.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto config = std::make_unique( - GPIO_NUM_5, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared(std::move(config), spi_controller); -} - diff --git a/Devices/cyd-2432s028r/Source/devices/SdCard.h b/Devices/cyd-2432s028r/Source/devices/SdCard.h deleted file mode 100644 index 4da9f5b97..000000000 --- a/Devices/cyd-2432s028r/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 2987df17c..4179d8e05 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -5,6 +5,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -23,20 +25,30 @@ pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/cyd-2432s028rv3/Source/Configuration.cpp b/Devices/cyd-2432s028rv3/Source/Configuration.cpp index 5033e9759..bf458b5cb 100644 --- a/Devices/cyd-2432s028rv3/Source/Configuration.cpp +++ b/Devices/cyd-2432s028rv3/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -25,7 +24,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp b/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp deleted file mode 100644 index 85960aacb..000000000 --- a/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto config = std::make_unique( - GPIO_NUM_5, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared(std::move(config), spi_controller); -} - diff --git a/Devices/cyd-2432s028rv3/Source/devices/SdCard.h b/Devices/cyd-2432s028rv3/Source/devices/SdCard.h deleted file mode 100644 index 4da9f5b97..000000000 --- a/Devices/cyd-2432s028rv3/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index 5425e99a3..6105b94a3 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -5,6 +5,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -23,20 +25,30 @@ pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/cyd-2432s032c/Source/Configuration.cpp b/Devices/cyd-2432s032c/Source/Configuration.cpp index af80ae199..52aaab007 100644 --- a/Devices/cyd-2432s032c/Source/Configuration.cpp +++ b/Devices/cyd-2432s032c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -39,7 +38,6 @@ static bool initBoot() { static tt::hal::DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-2432s032c/Source/devices/SdCard.cpp b/Devices/cyd-2432s032c/Source/devices/SdCard.cpp deleted file mode 100644 index 48e5a00d3..000000000 --- a/Devices/cyd-2432s032c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include -#include - -constexpr auto SDCARD_SPI_HOST = SPI3_HOST; -constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), - std::vector(), - SDCARD_SPI_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} - diff --git a/Devices/cyd-2432s032c/Source/devices/SdCard.h b/Devices/cyd-2432s032c/Source/devices/SdCard.h deleted file mode 100644 index fea58cef5..000000000 --- a/Devices/cyd-2432s032c/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 6dc9534e4..74beaf2da 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -4,6 +4,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -22,18 +24,28 @@ pin-scl = <&gpio1 32 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio1 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio1 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio1 23 GPIO_FLAG_NONE>; pin-miso = <&gpio1 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio1 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/cyd-3248s035c/Source/Configuration.cpp b/Devices/cyd-3248s035c/Source/Configuration.cpp index 123cfab3b..9734b668f 100644 --- a/Devices/cyd-3248s035c/Source/Configuration.cpp +++ b/Devices/cyd-3248s035c/Source/Configuration.cpp @@ -1,34 +1,32 @@ -#include "devices/Display.h" -#include "devices/SdCard.h" -#include - -#include -#include - -using namespace tt::hal; - -static bool initBoot() { - //Set the RGB Led Pins to output and turn them off - ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red - ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green - ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); //Blue - - //0 on, 1 off... yep it's backwards. - ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); //Red - ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); //Green - ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); //Blue - - return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT); -} - -static DeviceVector createDevices() { - return { - createDisplay(), - createSdCard() - }; -} - -extern const Configuration hardwareConfiguration = { - .initBoot = initBoot, - .createDevices = createDevices -}; +#include "devices/Display.h" +#include + +#include +#include + +using namespace tt::hal; + +static bool initBoot() { + //Set the RGB Led Pins to output and turn them off + ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red + ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green + ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); //Blue + + //0 on, 1 off... yep it's backwards. + ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); //Red + ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); //Green + ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); //Blue + + return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT); +} + +static DeviceVector createDevices() { + return { + createDisplay(), + }; +} + +extern const Configuration hardwareConfiguration = { + .initBoot = initBoot, + .createDevices = createDevices +}; diff --git a/Devices/cyd-3248s035c/Source/devices/SdCard.cpp b/Devices/cyd-3248s035c/Source/devices/SdCard.cpp deleted file mode 100644 index fd4e1989f..000000000 --- a/Devices/cyd-3248s035c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_SPI_HOST = SPI3_HOST; -constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SDCARD_SPI_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} - diff --git a/Devices/cyd-3248s035c/Source/devices/SdCard.h b/Devices/cyd-3248s035c/Source/devices/SdCard.h deleted file mode 100644 index 051907e1b..000000000 --- a/Devices/cyd-3248s035c/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-3248s035c/cyd,3248s035c.dts b/Devices/cyd-3248s035c/cyd,3248s035c.dts index 7463e6bb2..a4b8aea3f 100644 --- a/Devices/cyd-3248s035c/cyd,3248s035c.dts +++ b/Devices/cyd-3248s035c/cyd,3248s035c.dts @@ -1,58 +1,70 @@ -/dts-v1/; - -#include -#include -#include -#include -#include - -/ { - compatible = "root"; - model = "CYD 3248S035C"; - - gpio0 { - compatible = "espressif,esp32-gpio"; - gpio-count = <40>; - }; - - i2c_internal: i2c0 { - compatible = "espressif,esp32-i2c"; - port = ; - clock-frequency = <400000>; - pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; - pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; - }; - - // CN1 header - i2c_external: i2c1 { - compatible = "espressif,esp32-i2c"; - port = ; - clock-frequency = <400000>; - pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; - pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; - }; - - display_spi: spi0 { - compatible = "espressif,esp32-spi"; - host = ; - pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; - pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; - }; - - sdcard_spi: spi1 { - compatible = "espressif,esp32-spi"; - host = ; - pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; - pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; - pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - }; - - // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V - uart1 { - compatible = "espressif,esp32-uart"; - status = "disabled"; - port = ; - pin-tx = <&gpio0 22 GPIO_FLAG_NONE>; - pin-rx = <&gpio0 21 GPIO_FLAG_NONE>; - }; -}; +/dts-v1/; + +#include +#include +#include +#include +#include +#include +#include + +/ { + compatible = "root"; + model = "CYD 3248S035C"; + + gpio0 { + compatible = "espressif,esp32-gpio"; + gpio-count = <40>; + }; + + i2c_internal: i2c0 { + compatible = "espressif,esp32-i2c"; + port = ; + clock-frequency = <400000>; + pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; + }; + + // CN1 header + i2c_external: i2c1 { + compatible = "espressif,esp32-i2c"; + port = ; + clock-frequency = <400000>; + pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; + }; + + spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; + pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; + }; + + // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V + uart1 { + compatible = "espressif,esp32-uart"; + status = "disabled"; + port = ; + pin-tx = <&gpio0 22 GPIO_FLAG_NONE>; + pin-rx = <&gpio0 21 GPIO_FLAG_NONE>; + }; +}; diff --git a/Devices/cyd-4848s040c/Source/Configuration.cpp b/Devices/cyd-4848s040c/Source/Configuration.cpp index 6121b6af4..e8c7701d1 100644 --- a/Devices/cyd-4848s040c/Source/Configuration.cpp +++ b/Devices/cyd-4848s040c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/St7701Display.h" -#include "devices/SdCard.h" #include #include @@ -16,7 +15,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { std::make_shared(), - createSdCard() }; } diff --git a/Devices/cyd-4848s040c/Source/devices/SdCard.cpp b/Devices/cyd-4848s040c/Source/devices/SdCard.cpp deleted file mode 100644 index 4ad5857e5..000000000 --- a/Devices/cyd-4848s040c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto config = std::make_unique( - GPIO_NUM_42, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { GPIO_NUM_39 } - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(config), - spi_controller - ); -} - diff --git a/Devices/cyd-4848s040c/Source/devices/SdCard.h b/Devices/cyd-4848s040c/Source/devices/SdCard.h deleted file mode 100644 index 4da9f5b97..000000000 --- a/Devices/cyd-4848s040c/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/cyd-4848s040c/cyd,4848s040c.dts b/Devices/cyd-4848s040c/cyd,4848s040c.dts index 06dffdbd3..f9b4c5886 100644 --- a/Devices/cyd-4848s040c/cyd,4848s040c.dts +++ b/Devices/cyd-4848s040c/cyd,4848s040c.dts @@ -5,6 +5,7 @@ #include #include #include +#include / { compatible = "root"; @@ -34,5 +35,11 @@ pin-miso = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 48 GPIO_FLAG_NONE>; pin-hd = <&gpio0 42 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 42 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/cyd-8048s043c/Source/Configuration.cpp b/Devices/cyd-8048s043c/Source/Configuration.cpp index df1706ac7..d4fc2b98c 100644 --- a/Devices/cyd-8048s043c/Source/Configuration.cpp +++ b/Devices/cyd-8048s043c/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -15,7 +14,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-8048s043c/Source/devices/SdCard.cpp b/Devices/cyd-8048s043c/Source/devices/SdCard.cpp deleted file mode 100644 index 8b80cfc81..000000000 --- a/Devices/cyd-8048s043c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto config = std::make_unique( - GPIO_NUM_10, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(config), - spi_controller - ); -} diff --git a/Devices/cyd-8048s043c/Source/devices/SdCard.h b/Devices/cyd-8048s043c/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/cyd-8048s043c/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 9054bf0bc..222850fff 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { compatible = "root"; @@ -42,6 +43,12 @@ pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/cyd-e32r28t/Source/Configuration.cpp b/Devices/cyd-e32r28t/Source/Configuration.cpp index 4ba1576f8..387502f4b 100644 --- a/Devices/cyd-e32r28t/Source/Configuration.cpp +++ b/Devices/cyd-e32r28t/Source/Configuration.cpp @@ -1,4 +1,3 @@ -#include "devices/SdCard.h" #include "devices/Display.h" #include @@ -12,7 +11,6 @@ static bool initBoot() { static tt::hal::DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-e32r28t/Source/devices/SdCard.cpp b/Devices/cyd-e32r28t/Source/devices/SdCard.cpp deleted file mode 100644 index 40cf9caaf..000000000 --- a/Devices/cyd-e32r28t/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_5, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/cyd-e32r28t/Source/devices/SdCard.h b/Devices/cyd-e32r28t/Source/devices/SdCard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/cyd-e32r28t/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/cyd-e32r28t/cyd,e32r28t.dts b/Devices/cyd-e32r28t/cyd,e32r28t.dts index c002e4a4e..d79230fc4 100644 --- a/Devices/cyd-e32r28t/cyd,e32r28t.dts +++ b/Devices/cyd-e32r28t/cyd,e32r28t.dts @@ -3,6 +3,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -13,19 +15,29 @@ gpio-count = <40>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/cyd-e32r32p/Source/Configuration.cpp b/Devices/cyd-e32r32p/Source/Configuration.cpp index 452896b69..77ac6fbc9 100644 --- a/Devices/cyd-e32r32p/Source/Configuration.cpp +++ b/Devices/cyd-e32r32p/Source/Configuration.cpp @@ -1,4 +1,3 @@ -#include "devices/SdCard.h" #include "devices/Display.h" #include "devices/Power.h" #include @@ -17,7 +16,6 @@ static tt::hal::DeviceVector createDevices() { return { createPower(), createDisplay(), - createSdCard() }; } diff --git a/Devices/cyd-e32r32p/Source/devices/SdCard.cpp b/Devices/cyd-e32r32p/Source/devices/SdCard.cpp deleted file mode 100644 index 58de45419..000000000 --- a/Devices/cyd-e32r32p/Source/devices/SdCard.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; -using SdCardDevice = tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SD_CS_PIN, // CS pin (IO5 on the module) - GPIO_NUM_NC, // MOSI override: leave NC to use SPI host pins - GPIO_NUM_NC, // MISO override: leave NC - GPIO_NUM_NC, // SCLK override: leave NC - SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), - std::vector(), - SD_SPI_HOST // SPI host for SD card (SPI3_HOST) - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} \ No newline at end of file diff --git a/Devices/cyd-e32r32p/Source/devices/SdCard.h b/Devices/cyd-e32r32p/Source/devices/SdCard.h deleted file mode 100644 index dc381d79c..000000000 --- a/Devices/cyd-e32r32p/Source/devices/SdCard.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include -#include "driver/gpio.h" -#include "driver/spi_common.h" - -using tt::hal::sdcard::SdCardDevice; - -// SD card (microSD) -constexpr auto SD_CS_PIN = GPIO_NUM_5; -constexpr auto SD_SPI_HOST = SPI3_HOST; - -std::shared_ptr createSdCard(); diff --git a/Devices/cyd-e32r32p/cyd,e32r32p.dts b/Devices/cyd-e32r32p/cyd,e32r32p.dts index 61d9a1a14..da75b1a4a 100644 --- a/Devices/cyd-e32r32p/cyd,e32r32p.dts +++ b/Devices/cyd-e32r32p/cyd,e32r32p.dts @@ -4,6 +4,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -22,19 +24,29 @@ pin-scl = <&gpio0 25 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp index 09a0ca1f2..1cbf523da 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -14,7 +13,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp deleted file mode 100644 index a7308c95f..000000000 --- a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - CROWPANEL_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.h b/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index b0b50de79..cf8eaa1bb 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -6,6 +6,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -28,19 +30,29 @@ pin-scl = <&gpio0 16 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 42 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 7 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart0 { diff --git a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp index 33bdf3347..0e8b0418d 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -14,7 +13,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp deleted file mode 100644 index a7308c95f..000000000 --- a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -constexpr auto CROWPANEL_SDCARD_PIN_CS = GPIO_NUM_7; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - CROWPANEL_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.h b/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index f2abee9cf..0050ecd46 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -6,6 +6,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -28,19 +30,29 @@ pin-scl = <&gpio0 16 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 42 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 7 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart0 { diff --git a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp index 76b3a79da..73b8fca3c 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -25,7 +24,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp deleted file mode 100644 index 048f57ca3..000000000 --- a/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - // See https://github.com/Elecrow-RD/CrowPanel-Advance-HMI-ESP32-AI-Display/blob/master/5.0/factory_code/factory_code.ino - GPIO_NUM_0, // It's actually not connected, but in the demo pin 0 is used - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.h b/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index 17d236d36..6b27e4467 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { compatible = "root"; @@ -28,12 +29,18 @@ pin-scl = <&gpio0 16 GPIO_FLAG_NONE>; }; - sdcard_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 0 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart0 { diff --git a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp index d773cbaac..59cf64f6b 100644 --- a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -14,7 +13,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp deleted file mode 100644 index 38cfc75b7..000000000 --- a/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_5, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.h b/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index 377123adb..89c6e3213 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -5,6 +5,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -23,21 +25,31 @@ pin-scl = <&gpio0 21 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; max-transfer-size = <65536>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp index d773cbaac..59cf64f6b 100644 --- a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -14,7 +13,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp deleted file mode 100644 index 38cfc75b7..000000000 --- a/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_5, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.h b/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index e812efb02..8226b5e6d 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -5,6 +5,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -23,21 +25,31 @@ pin-scl = <&gpio0 21 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; max-transfer-size = <65536>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp index 9df5ad4af..7fbe23221 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -15,7 +14,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard(), }; } diff --git a/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp deleted file mode 100644 index dbf0f03f3..000000000 --- a/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_10, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.h b/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index e35ecd568..b5dae9648 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { compatible = "root"; @@ -28,12 +29,18 @@ pin-scl = <&gpio0 20 GPIO_FLAG_NONE>; }; - sdcard_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart0 { diff --git a/Devices/guition-jc1060p470ciwy/Source/Configuration.cpp b/Devices/guition-jc1060p470ciwy/Source/Configuration.cpp index e43b7a87e..ab3a805f2 100644 --- a/Devices/guition-jc1060p470ciwy/Source/Configuration.cpp +++ b/Devices/guition-jc1060p470ciwy/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "devices/Display.h" #include "devices/Power.h" -#include "devices/SdCard.h" #include @@ -9,7 +8,6 @@ using namespace tt::hal; static DeviceVector createDevices() { return { createDisplay(), - createSdCard(), createPower() }; } diff --git a/Devices/guition-jc1060p470ciwy/Source/devices/SdCard.cpp b/Devices/guition-jc1060p470ciwy/Source/devices/SdCard.cpp deleted file mode 100644 index 9bee001c8..000000000 --- a/Devices/guition-jc1060p470ciwy/Source/devices/SdCard.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -static const auto LOGGER = tt::Logger("JcSdCard"); - -// ESP32-P4 Slot 0 uses IO MUX (fixed pins, not manually configurable) -// CLK=43, CMD=44, D0=39, D1=40, D2=41, D3=42 (defined automatically by hardware) - -// TODO: Migrate to "espressif,esp32-sdmmc" driver (needs LDO code porting) -class SdCardDeviceImpl final : public SdCardDevice { - - class NoLock final : public tt::Lock { - bool lock(TickType_t timeout) const override { return true; } - void unlock() const override { /* NO-OP */ } - }; - - std::shared_ptr lock = std::make_shared(); - sdmmc_card_t* card = nullptr; - bool mounted = false; - std::string mountPath; - -public: - SdCardDeviceImpl() : SdCardDevice(MountBehaviour::AtBoot) {} - ~SdCardDeviceImpl() override { - if (mounted) { - unmount(); - } - } - - std::string getName() const override { return "SD Card"; } - std::string getDescription() const override { return "SD card via SDMMC host"; } - - bool mount(const std::string& newMountPath) override { - if (mounted) { - return true; - } - - esp_vfs_fat_sdmmc_mount_config_t mount_config = { - .format_if_mount_failed = false, - .max_files = 5, - .allocation_unit_size = 64 * 1024, - .disk_status_check_enable = false, - .use_one_fat = false, - }; - - sdmmc_host_t host = SDMMC_HOST_DEFAULT(); - host.slot = SDMMC_HOST_SLOT_0; - host.max_freq_khz = SDMMC_FREQ_DEFAULT; // 20MHz - more stable for initialization - host.flags = SDMMC_HOST_FLAG_4BIT; // Force 4-bit mode - // Configure LDO power supply for SD card (critical on ESP32-P4) - esp_ldo_channel_handle_t ldo_handle = nullptr; - esp_ldo_channel_config_t ldo_config = { - .chan_id = 4, // LDO channel 4 for SD power - .voltage_mv = 3300, // 3.3V - .flags { - .adjustable = 0, - .owned_by_hw = 0, - .bypass = 0 - } - }; - - esp_err_t ldo_ret = esp_ldo_acquire_channel(&ldo_config, &ldo_handle); - if (ldo_ret != ESP_OK) { - LOGGER.warn("Failed to acquire LDO for SD power: {} (continuing anyway)", esp_err_to_name(ldo_ret)); - } - - // Slot 0 uses IO MUX - pins are fixed and not specified - sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); - slot_config.width = 4; - slot_config.cd = SDMMC_SLOT_NO_CD; // No card detect - slot_config.wp = SDMMC_SLOT_NO_WP; // No write protect - slot_config.flags = 0; - - esp_err_t ret = esp_vfs_fat_sdmmc_mount(newMountPath.c_str(), &host, &slot_config, &mount_config, &card); - if (ret != ESP_OK) { - LOGGER.error("Failed to mount SD card: {}", esp_err_to_name(ret)); - card = nullptr; - return false; - } - - mountPath = newMountPath; - mounted = true; - LOGGER.info("SD card mounted at {}", mountPath); - return true; - } - - bool unmount() override { - if (!mounted) { - return true; - } - - esp_err_t ret = esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card); - if (ret != ESP_OK) { - LOGGER.error("Failed to unmount SD card: {}", esp_err_to_name(ret)); - return false; - } - card = nullptr; - mounted = false; - LOGGER.info("SD card unmounted"); - return true; - } - - std::string getMountPath() const override { - return mountPath; - } - - std::shared_ptr getLock() const override { return lock; } - - State getState(TickType_t /*timeout*/) const override { - return mounted ? State::Mounted : State::Unmounted; - } -}; - -std::shared_ptr createSdCard() { - return std::make_shared(); -} diff --git a/Devices/guition-jc1060p470ciwy/Source/devices/SdCard.h b/Devices/guition-jc1060p470ciwy/Source/devices/SdCard.h deleted file mode 100644 index 3e170a56b..000000000 --- a/Devices/guition-jc1060p470ciwy/Source/devices/SdCard.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include - -// Create SD card device for jc1060p470ciwy using SDMMC slot 0 (4-bit) -std::shared_ptr createSdCard(); diff --git a/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts b/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts index e328c0ee7..c84754d3f 100644 --- a/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts +++ b/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts @@ -5,6 +5,7 @@ #include #include #include +#include /** * For future reference: @@ -44,4 +45,16 @@ pin-data-in = <&gpio0 48 GPIO_FLAG_NONE>; pin-mclk = <&gpio0 13 GPIO_FLAG_NONE>; }; + + sdcard { + compatible = "espressif,esp32-sdmmc"; + pin-clk = <&gpio0 43 GPIO_FLAG_NONE>; + pin-cmd = <&gpio0 44 GPIO_FLAG_NONE>; + pin-d0 = <&gpio0 39 GPIO_FLAG_NONE>; + pin-d1 = <&gpio0 40 GPIO_FLAG_NONE>; + pin-d2 = <&gpio0 41 GPIO_FLAG_NONE>; + pin-d3 = <&gpio0 42 GPIO_FLAG_NONE>; + bus-width = <4>; + on-chip-ldo-chan = <4>; + }; }; diff --git a/Devices/guition-jc2432w328c/Source/Configuration.cpp b/Devices/guition-jc2432w328c/Source/Configuration.cpp index ee79f6c67..9734b668f 100644 --- a/Devices/guition-jc2432w328c/Source/Configuration.cpp +++ b/Devices/guition-jc2432w328c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -24,7 +23,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp b/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp deleted file mode 100644 index 45238df8c..000000000 --- a/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_SPI_HOST = SPI3_HOST; -constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SDCARD_SPI_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} - diff --git a/Devices/guition-jc2432w328c/Source/devices/SdCard.h b/Devices/guition-jc2432w328c/Source/devices/SdCard.h deleted file mode 100644 index fea58cef5..000000000 --- a/Devices/guition-jc2432w328c/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); - diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index adfc64c8e..78c3570ba 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -5,6 +5,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -32,19 +34,29 @@ pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V diff --git a/Devices/guition-jc3248w535c/Source/Configuration.cpp b/Devices/guition-jc3248w535c/Source/Configuration.cpp index 0ceef45ae..f35f8e659 100644 --- a/Devices/guition-jc3248w535c/Source/Configuration.cpp +++ b/Devices/guition-jc3248w535c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -10,7 +9,6 @@ using namespace tt::hal; static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp b/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp deleted file mode 100644 index e4b2e2345..000000000 --- a/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_SPI_HOST = SPI3_HOST; -constexpr auto SDCARD_PIN_CS = GPIO_NUM_10; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SDCARD_SPI_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/guition-jc3248w535c/Source/devices/SdCard.h b/Devices/guition-jc3248w535c/Source/devices/SdCard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/guition-jc3248w535c/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index 4749ddc35..f48fa1814 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -45,7 +46,7 @@ pin-data-out = <&gpio0 41 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 21 GPIO_FLAG_NONE>; @@ -55,12 +56,18 @@ pin-hd = <&gpio0 39 GPIO_FLAG_NONE>; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; // P1 header diff --git a/Devices/guition-jc8048w550c/Source/Configuration.cpp b/Devices/guition-jc8048w550c/Source/Configuration.cpp index 174ca14fa..f19ffaf92 100644 --- a/Devices/guition-jc8048w550c/Source/Configuration.cpp +++ b/Devices/guition-jc8048w550c/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -14,7 +13,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp b/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp deleted file mode 100644 index 1b44c476c..000000000 --- a/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "SdCard.h" - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto config = std::make_unique( - GPIO_NUM_10, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(config), - spi_controller - ); -} diff --git a/Devices/guition-jc8048w550c/Source/devices/SdCard.h b/Devices/guition-jc8048w550c/Source/devices/SdCard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/guition-jc8048w550c/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index 97ac59477..6000feaea 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -52,6 +53,12 @@ pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/lilygo-tdeck/Source/Configuration.cpp b/Devices/lilygo-tdeck/Source/Configuration.cpp index 4f620aced..3eca6c8e9 100644 --- a/Devices/lilygo-tdeck/Source/Configuration.cpp +++ b/Devices/lilygo-tdeck/Source/Configuration.cpp @@ -1,7 +1,6 @@ #include "devices/Display.h" #include "devices/KeyboardBacklight.h" #include "devices/Power.h" -#include "devices/Sdcard.h" #include "devices/TdeckKeyboard.h" #include "devices/TrackballDevice.h" @@ -23,7 +22,6 @@ static std::vector> createDevices() { std::make_shared(i2c_internal), std::make_shared(), std::make_shared(), - createSdCard() }; } diff --git a/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp b/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp deleted file mode 100644 index 6b926d794..000000000 --- a/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "Sdcard.h" - -#include - -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -constexpr auto TDECK_SDCARD_PIN_CS = GPIO_NUM_39; -constexpr auto TDECK_LCD_PIN_CS = GPIO_NUM_12; -constexpr auto TDECK_RADIO_PIN_CS = GPIO_NUM_9; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - TDECK_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { - TDECK_RADIO_PIN_CS, - TDECK_LCD_PIN_CS - } - ); - - ::Device* spiController = device_find_by_name("spi0"); - check(spiController != nullptr, "spi0 not found"); - return std::make_shared( - std::move(configuration), - spiController - ); -} diff --git a/Devices/lilygo-tdeck/Source/devices/Sdcard.h b/Devices/lilygo-tdeck/Source/devices/Sdcard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/lilygo-tdeck/Source/devices/Sdcard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index a60e6ef77..ad6bba49a 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -8,6 +8,8 @@ #include #include #include +#include +#include // Reference: https://wiki.lilygo.cc/get_started/en/Wearable/T-Deck-Plus/T-Deck-Plus.html#Pin-Overview / { @@ -45,6 +47,16 @@ pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 39 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; + + display { + compatible = "display-placeholder"; + }; }; uart0 { diff --git a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts index ecf6ca866..750ed3ec0 100644 --- a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts +++ b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts @@ -4,6 +4,7 @@ #include #include #include +#include / { compatible = "root"; @@ -19,5 +20,9 @@ host = ; pin-mosi = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; }; diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index 616fbb706..2c26cbb3e 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -34,6 +35,10 @@ host = ; pin-mosi = <&gpio0 3 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; sdmmc0 { diff --git a/Devices/lilygo-tlora-pager/Source/Configuration.cpp b/Devices/lilygo-tlora-pager/Source/Configuration.cpp index 363e0cc16..13bd752e2 100644 --- a/Devices/lilygo-tlora-pager/Source/Configuration.cpp +++ b/Devices/lilygo-tlora-pager/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/TpagerEncoder.h" #include "devices/TpagerKeyboard.h" #include "devices/TpagerPower.h" diff --git a/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp b/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp deleted file mode 100644 index eb8f48e9c..000000000 --- a/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -constexpr auto TPAGER_SDCARD_PIN_CS = GPIO_NUM_21; -constexpr auto TPAGER_LCD_PIN_CS = GPIO_NUM_38; -constexpr auto TPAGER_RADIO_PIN_CS = GPIO_NUM_36; -constexpr auto TPAGER_NFC_PIN_CS = GPIO_NUM_39; - -std::shared_ptr createTpagerSdCard() { - auto configuration = std::make_unique( - TPAGER_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { - TPAGER_RADIO_PIN_CS, - TPAGER_LCD_PIN_CS, - TPAGER_NFC_PIN_CS - } - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/lilygo-tlora-pager/Source/devices/SdCard.h b/Devices/lilygo-tlora-pager/Source/devices/SdCard.h deleted file mode 100644 index 7b830f875..000000000 --- a/Devices/lilygo-tlora-pager/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createTpagerSdCard(); diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index 45b12562e..6697036ce 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -7,6 +7,8 @@ #include #include #include +#include +#include // Reference: https://wiki.lilygo.cc/get_started/en/LoRa_GPS/T-LoraPager/T-LoraPager.html#Pin-Overview / { @@ -36,6 +38,16 @@ pin-mosi = <&gpio0 34 GPIO_FLAG_NONE>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 35 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 21 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; + + display { + compatible = "display-placeholder"; + }; }; // ES8311 diff --git a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp index bb8ca682d..41906807f 100644 --- a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/CardputerKeyboard.h" #include "devices/CardputerPower.h" #include @@ -19,7 +18,6 @@ static bool initBoot() { static DeviceVector createDevices() { auto tca8418 = std::make_shared(device_find_by_name("i2c_internal")); return { - createSdCard(), createDisplay(), tca8418, std::make_shared(tca8418), diff --git a/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp b/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp deleted file mode 100644 index abc1703e4..000000000 --- a/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_PIN_CS = GPIO_NUM_12; -constexpr auto EXPANSION_HEADER_PIN_CS = GPIO_NUM_5; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector { EXPANSION_HEADER_PIN_CS }, - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-cardputer-adv/Source/devices/SdCard.h b/Devices/m5stack-cardputer-adv/Source/devices/SdCard.h deleted file mode 100644 index 98b222fa6..000000000 --- a/Devices/m5stack-cardputer-adv/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index fefd953fc..155940187 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -9,6 +9,8 @@ #include #include #include +#include +#include // Reference: https://docs.m5stack.com/en/core/Cardputer-Adv / { @@ -47,19 +49,29 @@ i2cClockFrequency = <400000>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 12 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; // Speaker and microphone (ES8311) diff --git a/Devices/m5stack-cardputer/Source/Configuration.cpp b/Devices/m5stack-cardputer/Source/Configuration.cpp index 80989e044..d7f52ed0c 100644 --- a/Devices/m5stack-cardputer/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/CardputerEncoder.h" #include "devices/CardputerKeyboard.h" #include "devices/CardputerPower.h" @@ -16,7 +15,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { - createSdCard(), createDisplay(), std::make_shared(), std::make_shared(), diff --git a/Devices/m5stack-cardputer/Source/devices/SdCard.cpp b/Devices/m5stack-cardputer/Source/devices/SdCard.cpp deleted file mode 100644 index 7ab98cfa1..000000000 --- a/Devices/m5stack-cardputer/Source/devices/SdCard.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_PIN_CS = GPIO_NUM_12; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-cardputer/Source/devices/SdCard.h b/Devices/m5stack-cardputer/Source/devices/SdCard.h deleted file mode 100644 index 98b222fa6..000000000 --- a/Devices/m5stack-cardputer/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index dde6df8c6..1e205b35a 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -8,6 +8,8 @@ #include #include #include +#include +#include // Reference: https://docs.m5stack.com/en/core/Cardputer / { @@ -33,19 +35,29 @@ i2cClockFrequency = <400000>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 12 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; // Speaker and microphone diff --git a/Devices/m5stack-core2/Source/Configuration.cpp b/Devices/m5stack-core2/Source/Configuration.cpp index 7883adff4..c7059fe58 100644 --- a/Devices/m5stack-core2/Source/Configuration.cpp +++ b/Devices/m5stack-core2/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/Power.h" #include @@ -13,7 +12,6 @@ static bool initBoot() { static DeviceVector createDevices() { return { getAxp192(), - createSdCard(), createDisplay() }; } diff --git a/Devices/m5stack-core2/Source/devices/SdCard.cpp b/Devices/m5stack-core2/Source/devices/SdCard.cpp deleted file mode 100644 index 3d0a8e306..000000000 --- a/Devices/m5stack-core2/Source/devices/SdCard.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -constexpr auto CORE2_SDCARD_PIN_CS = GPIO_NUM_4; -constexpr auto CORE2_LCD_PIN_CS = GPIO_NUM_5; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - CORE2_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { - CORE2_LCD_PIN_CS - } - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-core2/Source/devices/SdCard.h b/Devices/m5stack-core2/Source/devices/SdCard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/m5stack-core2/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index 06aedc7de..7bd48e78d 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -9,6 +9,8 @@ #include #include #include +#include +#include // Reference: https://docs.m5stack.com/en/core/Core2 / { @@ -54,6 +56,16 @@ pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; + + display { + compatible = "display-placeholder"; + }; }; // NS4168: Speaker and microphone diff --git a/Devices/m5stack-cores3/Source/Configuration.cpp b/Devices/m5stack-cores3/Source/Configuration.cpp index d00a16c34..cad04d565 100644 --- a/Devices/m5stack-cores3/Source/Configuration.cpp +++ b/Devices/m5stack-cores3/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "InitBoot.h" #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -13,7 +12,6 @@ static DeviceVector createDevices() { axp2101, aw9523, std::make_shared(axp2101), - createSdCard(), createDisplay() }; } diff --git a/Devices/m5stack-cores3/Source/devices/SdCard.cpp b/Devices/m5stack-cores3/Source/devices/SdCard.cpp deleted file mode 100644 index 9083ef803..000000000 --- a/Devices/m5stack-cores3/Source/devices/SdCard.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -constexpr auto CORES3_SDCARD_PIN_CS = GPIO_NUM_4; -constexpr auto CORES3_LCD_PIN_CS = GPIO_NUM_3; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - CORES3_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { CORES3_LCD_PIN_CS } - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-cores3/Source/devices/SdCard.h b/Devices/m5stack-cores3/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/m5stack-cores3/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index 60b54a24c..4d4040f34 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -10,6 +10,8 @@ #include #include #include +#include +#include // Reference: https://docs.m5stack.com/en/core/CoreS3 / { @@ -79,6 +81,16 @@ pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; + + display { + compatible = "display-placeholder"; + }; }; // TODO: Enable speaker via ES7210 I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L417 diff --git a/Devices/m5stack-papers3/Source/Configuration.cpp b/Devices/m5stack-papers3/Source/Configuration.cpp index 3754d1437..f6d90bb50 100644 --- a/Devices/m5stack-papers3/Source/Configuration.cpp +++ b/Devices/m5stack-papers3/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/Power.h" #include @@ -12,7 +11,6 @@ static DeviceVector createDevices() { return { createPower(), createDisplay(), - createSdCard(), }; } diff --git a/Devices/m5stack-papers3/Source/devices/SdCard.cpp b/Devices/m5stack-papers3/Source/devices/SdCard.cpp deleted file mode 100644 index cc51ba7da..000000000 --- a/Devices/m5stack-papers3/Source/devices/SdCard.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -constexpr auto PAPERS3_SDCARD_PIN_CS = GPIO_NUM_47; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - PAPERS3_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-papers3/Source/devices/SdCard.h b/Devices/m5stack-papers3/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/m5stack-papers3/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-papers3/m5stack,papers3.dts b/Devices/m5stack-papers3/m5stack,papers3.dts index 9367a3aa2..946de1a79 100644 --- a/Devices/m5stack-papers3/m5stack,papers3.dts +++ b/Devices/m5stack-papers3/m5stack,papers3.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -46,5 +47,11 @@ pin-miso = <&gpio0 40 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; max-transfer-size = <4096>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 47 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/m5stack-stackchan/Source/Configuration.cpp b/Devices/m5stack-stackchan/Source/Configuration.cpp index dd3d0ef11..3a1eea9d5 100644 --- a/Devices/m5stack-stackchan/Source/Configuration.cpp +++ b/Devices/m5stack-stackchan/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "devices/Display.h" #include "devices/Power.h" -#include "devices/SdCard.h" #include #include @@ -243,7 +242,6 @@ static DeviceVector createDevices() { axp2101, std::make_shared(axp2101), createPower(), - createSdCard(), createDisplay(), }; } diff --git a/Devices/m5stack-stackchan/Source/devices/SdCard.cpp b/Devices/m5stack-stackchan/Source/devices/SdCard.cpp deleted file mode 100644 index 0fbc268b0..000000000 --- a/Devices/m5stack-stackchan/Source/devices/SdCard.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -constexpr auto STACKCHAN_SDCARD_PIN_CS = GPIO_NUM_4; -constexpr auto STACKCHAN_LCD_PIN_CS = GPIO_NUM_3; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - STACKCHAN_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { STACKCHAN_LCD_PIN_CS } - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-stackchan/Source/devices/SdCard.h b/Devices/m5stack-stackchan/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/m5stack-stackchan/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-stackchan/m5stack,stackchan.dts b/Devices/m5stack-stackchan/m5stack,stackchan.dts index 5440b6c1c..5659c2776 100644 --- a/Devices/m5stack-stackchan/m5stack,stackchan.dts +++ b/Devices/m5stack-stackchan/m5stack,stackchan.dts @@ -12,6 +12,8 @@ #include #include #include +#include +#include // Reference: https://docs.m5stack.com/en/StackChan / { @@ -113,6 +115,16 @@ pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; + + display { + compatible = "display-placeholder"; + }; }; // AW88298 speaker + ES7210 microphone diff --git a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts index 55bdbf6e7..86de033f8 100644 --- a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts +++ b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -48,6 +49,10 @@ host = ; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 13 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; uart_grove: uart1 { diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index 9f86c6800..e299548a3 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { compatible = "root"; @@ -47,6 +48,10 @@ host = ; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 13 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; uart_grove: uart1 { diff --git a/Devices/m5stack-sticks3/Source/Configuration.cpp b/Devices/m5stack-sticks3/Source/Configuration.cpp index 6743208c6..501726d02 100644 --- a/Devices/m5stack-sticks3/Source/Configuration.cpp +++ b/Devices/m5stack-sticks3/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/Power.h" #include @@ -104,7 +103,6 @@ static DeviceVector createDevices() { createPower(), ButtonControl::createTwoButtonControl(11, 12), // top button, side button createDisplay(), - createSdCard() }; } diff --git a/Devices/m5stack-sticks3/Source/devices/SdCard.cpp b/Devices/m5stack-sticks3/Source/devices/SdCard.cpp deleted file mode 100644 index 361dcf551..000000000 --- a/Devices/m5stack-sticks3/Source/devices/SdCard.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_SPI_HOST = SPI3_HOST; -constexpr auto SDCARD_PIN_CS = GPIO_NUM_7; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SDCARD_SPI_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-sticks3/Source/devices/SdCard.h b/Devices/m5stack-sticks3/Source/devices/SdCard.h deleted file mode 100644 index 98b222fa6..000000000 --- a/Devices/m5stack-sticks3/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-sticks3/m5stack,sticks3.dts b/Devices/m5stack-sticks3/m5stack,sticks3.dts index 4d194c8d9..34dc0155a 100644 --- a/Devices/m5stack-sticks3/m5stack,sticks3.dts +++ b/Devices/m5stack-sticks3/m5stack,sticks3.dts @@ -8,6 +8,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -53,6 +55,10 @@ host = ; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; //DIY SD Card - https://wiki.bruce.computer/wiring-diagrams/m5sticks3/sd-card/ @@ -62,6 +68,12 @@ pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 7 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; // Speaker and microphone (ES8311) diff --git a/Devices/m5stack-tab5/Source/Configuration.cpp b/Devices/m5stack-tab5/Source/Configuration.cpp index e1f3348d9..cb6be2316 100644 --- a/Devices/m5stack-tab5/Source/Configuration.cpp +++ b/Devices/m5stack-tab5/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include "devices/Power.h" #include "devices/Tab5Keyboard.h" @@ -17,7 +16,6 @@ static DeviceVector createDevices() { return { createPower(), createDisplay(), - createSdCard(), std::make_shared(i2c2) }; } diff --git a/Devices/m5stack-tab5/Source/devices/SdCard.cpp b/Devices/m5stack-tab5/Source/devices/SdCard.cpp deleted file mode 100644 index 639eed882..000000000 --- a/Devices/m5stack-tab5/Source/devices/SdCard.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "SdCard.h" - -#include -#include - -constexpr auto SDCARD_PIN_CS = GPIO_NUM_42; - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/m5stack-tab5/Source/devices/SdCard.h b/Devices/m5stack-tab5/Source/devices/SdCard.h deleted file mode 100644 index 98b222fa6..000000000 --- a/Devices/m5stack-tab5/Source/devices/SdCard.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/m5stack-tab5/m5stack,tab5.dts b/Devices/m5stack-tab5/m5stack,tab5.dts index 060b15c5c..aea748d8b 100644 --- a/Devices/m5stack-tab5/m5stack,tab5.dts +++ b/Devices/m5stack-tab5/m5stack,tab5.dts @@ -13,6 +13,7 @@ #include #include #include +#include / { compatible = "root"; @@ -78,12 +79,18 @@ pin-scl = <&gpio0 1 GPIO_FLAG_PULL_UP>; }; - sdcard_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 44 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 43 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 42 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; // ES8388 and ES7210 diff --git a/Devices/unphone/Source/Configuration.cpp b/Devices/unphone/Source/Configuration.cpp index e51ecfd1d..b32363ff9 100644 --- a/Devices/unphone/Source/Configuration.cpp +++ b/Devices/unphone/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "UnPhoneFeatures.h" #include "devices/Hx8357Display.h" -#include "devices/SdCard.h" #include @@ -9,7 +8,6 @@ bool initBoot(); static tt::hal::DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/unphone/Source/devices/SdCard.cpp b/Devices/unphone/Source/devices/SdCard.cpp deleted file mode 100644 index c75ca5638..000000000 --- a/Devices/unphone/Source/devices/SdCard.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -#define UNPHONE_SDCARD_PIN_CS GPIO_NUM_43 -#define UNPHONE_LCD_PIN_CS GPIO_NUM_48 -#define UNPHONE_LORA_PIN_CS GPIO_NUM_44 -#define UNPHONE_TOUCH_PIN_CS GPIO_NUM_38 - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - UNPHONE_SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector { - UNPHONE_LORA_PIN_CS, - UNPHONE_LCD_PIN_CS, - UNPHONE_TOUCH_PIN_CS - } - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/unphone/Source/devices/SdCard.h b/Devices/unphone/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/unphone/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/unphone/unphone.dts b/Devices/unphone/unphone.dts index 5dcc2ef58..e46ad3b2b 100644 --- a/Devices/unphone/unphone.dts +++ b/Devices/unphone/unphone.dts @@ -5,6 +5,7 @@ #include #include #include +#include / { compatible = "root"; @@ -34,5 +35,11 @@ pin-miso = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; max-transfer-size = <65536>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 43 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts index dc51c36f0..40ff3582d 100644 --- a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts +++ b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -34,6 +35,10 @@ host = ; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; sdmmc0 { diff --git a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp index aef2df4b9..b8d6553da 100644 --- a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp +++ b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -10,7 +9,6 @@ using namespace tt::hal; static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp b/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp deleted file mode 100644 index b01a45b4d..000000000 --- a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_17, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.h b/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts index 0d11d1bfa..7da91d261 100644 --- a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts +++ b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts @@ -6,6 +6,8 @@ #include #include #include +#include +#include // Reference: https://www.waveshare.com/wiki/ESP32-S3-LCD-1.3 / { @@ -39,6 +41,10 @@ host = ; pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; spi1 { @@ -47,5 +53,11 @@ pin-mosi = <&gpio0 18 GPIO_FLAG_NONE>; pin-miso = <&gpio0 16 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 21 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 17 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp index 5a2a1ca53..c78cfff15 100644 --- a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include @@ -10,7 +9,6 @@ using namespace tt::hal; static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp deleted file mode 100644 index e56e5361f..000000000 --- a/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_18, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.h b/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts index 5a781dd60..da213dbda 100644 --- a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts +++ b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts @@ -6,6 +6,8 @@ #include #include #include +#include +#include // Reference: https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.28 / { @@ -34,19 +36,29 @@ }; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 10 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 16 GPIO_FLAG_NONE>; pin-miso = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 17 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 18 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp index 8358fd2e9..dbd7799cf 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/Sdcard.h" #include @@ -10,7 +9,6 @@ using namespace tt::hal; static std::vector> createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp deleted file mode 100644 index f419562c0..000000000 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "Sdcard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -constexpr auto SDCARD_PIN_CS = GPIO_NUM_14; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector { }, - SPI3_HOST - ); - - auto* spi_controller = device_find_by_name("spi1"); - check(spi_controller, "spi1 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.h b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.h deleted file mode 100644 index 6f5443c78..000000000 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts index 8afd056cc..0877d8131 100644 --- a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts +++ b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts @@ -5,6 +5,7 @@ #include #include #include +#include // Reference: https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.47 / { @@ -28,18 +29,24 @@ pin-scl = <&gpio0 41 GPIO_FLAG_NONE>; }; - display_spi: spi0 { + spi0 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 38 GPIO_FLAG_NONE>; }; - sdcard_spi: spi1 { + spi1 { compatible = "espressif,esp32-spi"; host = ; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>; pin-miso = <&gpio0 17 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 16 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 14 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp index 7ec8c4ce4..3e32ef538 100644 --- a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include @@ -8,7 +7,6 @@ using namespace tt::hal; static DeviceVector createDevices() { return { createDisplay(), - createSdCard() }; } diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp b/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp deleted file mode 100644 index 891129943..000000000 --- a/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_10, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock() - ); - - auto* spi_controller = device_find_by_name("spi0"); - check(spi_controller, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spi_controller - ); -} diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.h b/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.h deleted file mode 100644 index 5cb65a735..000000000 --- a/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index 22513fa40..8be9aeb7d 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { compatible = "root"; @@ -34,6 +35,12 @@ pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; uart1 { diff --git a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp index b33fbb08a..ce0fb67f9 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp +++ b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp @@ -1,24 +1,22 @@ -#include "devices/Display.h" -#include "devices/SdCard.h" -#include - -#include -#include - -using namespace tt::hal; - -static DeviceVector createDevices() { - return { - createDisplay(), - createSdCard() - }; -} - -static bool initBoot() { - return driver::pwmbacklight::init(GPIO_NUM_45); -} - -extern const Configuration hardwareConfiguration = { - .initBoot = initBoot, - .createDevices = createDevices -}; +#include "devices/Display.h" +#include + +#include +#include + +using namespace tt::hal; + +static DeviceVector createDevices() { + return { + createDisplay(), + }; +} + +static bool initBoot() { + return driver::pwmbacklight::init(GPIO_NUM_45); +} + +extern const Configuration hardwareConfiguration = { + .initBoot = initBoot, + .createDevices = createDevices +}; diff --git a/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.cpp b/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.cpp deleted file mode 100644 index b2e4dc428..000000000 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "SdCard.h" - -#include -#include -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createSdCard() { - auto configuration = std::make_unique( - GPIO_NUM_41, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector(), - SPI2_HOST - ); - - ::Device* spiController = device_find_by_name("spi0"); - check(spiController != nullptr, "spi0 not found"); - - return std::make_shared( - std::move(configuration), - spiController - ); -} diff --git a/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.h b/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.h deleted file mode 100644 index b38d94894..000000000 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createSdCard(); diff --git a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts index 6beff46d9..a09f37a61 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts +++ b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts @@ -5,6 +5,7 @@ #include #include #include +#include / { compatible = "root"; @@ -33,5 +34,11 @@ pin-mosi = <&gpio0 40 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; + + sdcard { + compatible = "espressif,esp32-sdspi"; + pin-cs = <&gpio0 41 GPIO_FLAG_NONE>; + frequency-khz = <20000>; + }; }; }; diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml new file mode 100644 index 000000000..45c4d0e06 --- /dev/null +++ b/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml @@ -0,0 +1,27 @@ +description: ESP32 SD card over SPI + +compatible: "espressif,esp32-sdspi" + +bus: spi + +properties: + pin-cs: + type: phandle-array + required: true + description: Chip select GPIO + pin-cd: + type: phandle-array + default: GPIO_PIN_SPEC_NONE + description: Card detect GPIO + pin-wp: + type: phandle-array + default: GPIO_PIN_SPEC_NONE + description: Write protect GPIO + pin-int: + type: phandle-array + default: GPIO_PIN_SPEC_NONE + description: Interrupt GPIO + frequency-khz: + type: int + required: true + description: SPI clock frequency in kHz diff --git a/Platforms/platform-esp32/include/tactility/bindings/esp32_sdspi.h b/Platforms/platform-esp32/include/tactility/bindings/esp32_sdspi.h new file mode 100644 index 000000000..729d00330 --- /dev/null +++ b/Platforms/platform-esp32/include/tactility/bindings/esp32_sdspi.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(esp32_sdspi, struct Esp32SdspiConfig) + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_sdcard.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdcard.h new file mode 100644 index 000000000..6405c893f --- /dev/null +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdcard.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct Device; + +/** + * Try to get the sdmmc_card_t* for the given device. + * @param device any device. + * @return the sdmmc_card_t* if it is available for this device, otherwise return null + */ +sdmmc_card_t* esp32_sdcard_get_card(struct Device* device); + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h new file mode 100644 index 000000000..eba9b4161 --- /dev/null +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct Esp32SdspiConfig { + struct GpioPinSpec pin_cs; + struct GpioPinSpec pin_cd; + struct GpioPinSpec pin_wp; + struct GpioPinSpec pin_int; + uint32_t frequency_khz; +}; + +sdmmc_card_t* esp32_sdspi_get_card(struct Device* device); + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h b/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h new file mode 100644 index 000000000..bb50eff59 --- /dev/null +++ b/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct Esp32SdspiConfig; +typedef void* Esp32SdspiHandle; + +Esp32SdspiHandle esp32_sdspi_fs_alloc(const struct Esp32SdspiConfig* config, int spi_host, const char* mount_path); +void esp32_sdspi_fs_free(Esp32SdspiHandle handle); +sdmmc_card_t* esp32_sdspi_fs_get_card(Esp32SdspiHandle handle); + +extern const FileSystemApi esp32_sdspi_fs_api; + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdcard.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdcard.cpp new file mode 100644 index 000000000..0ca4eed16 --- /dev/null +++ b/Platforms/platform-esp32/source/drivers/esp32_sdcard.cpp @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + +#include +#if SOC_SDMMC_HOST_SUPPORTED +#include +#endif + +extern "C" { + +sdmmc_card_t* esp32_sdcard_get_card(Device* device) { + auto* driver = device_get_driver(device); + if (driver_is_compatible(driver, "espressif,esp32-sdspi")) { + return esp32_sdspi_get_card(device); + } +#if SOC_SDMMC_HOST_SUPPORTED + if (driver_is_compatible(driver, "espressif,esp32-sdmmc")) { + return esp32_sdmmc_get_card(device); + } +#endif + return nullptr; +} + +} diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp index d36fe5aeb..b1fe993ab 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp @@ -115,6 +115,7 @@ static error_t start(Device* device) { } data->file_system = file_system_add(&esp32_sdmmc_fs_api, data->esp32_sdmmc_fs_handle); + file_system_set_owner(data->file_system, device); if (file_system_mount(data->file_system) != ERROR_NONE) { // Error is not recoverable at the time, but it might be recoverable later, // so we don't return start() failure. diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp new file mode 100644 index 000000000..cb42d283c --- /dev/null +++ b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TAG "esp32_sdspi" + +#define GET_CONFIG(device) ((const struct Esp32SdspiConfig*)device->config) +#define GET_DATA(device) ((struct Esp32SdspiInternal*)device_get_driver_data(device)) + +extern "C" { + +struct Esp32SdspiInternal { + RecursiveMutex mutex = {}; + Esp32SdspiHandle fs_handle = nullptr; + FileSystem* file_system = nullptr; + GpioDescriptor* pin_cs_descriptor = nullptr; + GpioDescriptor* pin_cd_descriptor = nullptr; + GpioDescriptor* pin_wp_descriptor = nullptr; + GpioDescriptor* pin_int_descriptor = nullptr; + + Esp32SdspiInternal() { + recursive_mutex_construct(&mutex); + } + + ~Esp32SdspiInternal() { + cleanup_pins(); + recursive_mutex_destruct(&mutex); + if (fs_handle) esp32_sdspi_fs_free(fs_handle); + } + + void cleanup_pins() { + release_pin(&pin_cs_descriptor); + release_pin(&pin_cd_descriptor); + release_pin(&pin_wp_descriptor); + release_pin(&pin_int_descriptor); + } + + void lock() { recursive_mutex_lock(&mutex); } + void unlock() { recursive_mutex_unlock(&mutex); } +}; + +static error_t start(Device* device) { + LOG_I(TAG, "start %s", device->name); + + auto* parent = device_get_parent(device); + if (device_get_type(parent) != &SPI_CONTROLLER_TYPE) { + LOG_E(TAG, "Parent device is not an SPI controller"); + return ERROR_INVALID_STATE; + } + + auto* data = new (std::nothrow) Esp32SdspiInternal(); + if (!data) return ERROR_OUT_OF_MEMORY; + + data->lock(); + device_set_driver_data(device, data); + + auto* config = GET_CONFIG(device); + + bool pins_ok = + acquire_pin_or_set_null(config->pin_cs, &data->pin_cs_descriptor) && + acquire_pin_or_set_null(config->pin_cd, &data->pin_cd_descriptor) && + acquire_pin_or_set_null(config->pin_wp, &data->pin_wp_descriptor) && + acquire_pin_or_set_null(config->pin_int, &data->pin_int_descriptor); + + if (!pins_ok) { + LOG_E(TAG, "Failed to acquire one or more pins"); + data->cleanup_pins(); + device_set_driver_data(device, nullptr); + data->unlock(); + delete data; + return ERROR_RESOURCE; + } + + auto* spi_config = static_cast(parent->config); + data->fs_handle = esp32_sdspi_fs_alloc(config, spi_config->host, "/sdcard"); + if (!data->fs_handle) { + data->cleanup_pins(); + device_set_driver_data(device, nullptr); + data->unlock(); + delete data; + return ERROR_OUT_OF_MEMORY; + } + + data->file_system = file_system_add(&esp32_sdspi_fs_api, data->fs_handle); + file_system_set_owner(data->file_system, device); + if (file_system_mount(data->file_system) != ERROR_NONE) { + LOG_E(TAG, "Failed to mount SD card filesystem"); + } + + data->unlock(); + return ERROR_NONE; +} + +static error_t stop(Device* device) { + LOG_I(TAG, "stop %s", device->name); + auto* data = GET_DATA(device); + if (!data) return ERROR_NONE; + + data->lock(); + + if (file_system_is_mounted(data->file_system)) { + if (file_system_unmount(data->file_system) != ERROR_NONE) { + LOG_E(TAG, "Failed to unmount SD card filesystem"); + data->unlock(); + return ERROR_RESOURCE; + } + } + + file_system_remove(data->file_system); + data->file_system = nullptr; + + esp32_sdspi_fs_free(data->fs_handle); + data->fs_handle = nullptr; + + data->cleanup_pins(); + device_set_driver_data(device, nullptr); + + data->unlock(); + delete data; + return ERROR_NONE; +} + +sdmmc_card_t* esp32_sdspi_get_card(Device* device) { + if (!device_is_ready(device)) return nullptr; + auto* data = GET_DATA(device); + if (!data) return nullptr; + + data->lock(); + auto* card = esp32_sdspi_fs_get_card(data->fs_handle); + data->unlock(); + + return card; +} + +extern Module platform_esp32_module; + +Driver esp32_sdspi_driver = { + .name = "esp32_sdspi", + .compatible = (const char*[]) { "espressif,esp32-sdspi", nullptr }, + .start_device = start, + .stop_device = stop, + .api = nullptr, + .device_type = nullptr, + .owner = &platform_esp32_module, + .internal = nullptr +}; + +} // extern "C" diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp new file mode 100644 index 000000000..78d8282cb --- /dev/null +++ b/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + +#include +#include +#include +#include + +#define TAG "esp32_sdspi_fs" + +#define GET_DATA(data) static_cast(data) + +struct Esp32SdspiFsData { + const std::string mount_path; + const Esp32SdspiConfig* config; + int spi_host; + sdmmc_card_t* card; + + Esp32SdspiFsData(const Esp32SdspiConfig* config, int spi_host, const std::string& mount_path) : + mount_path(mount_path), + config(config), + spi_host(spi_host), + card(nullptr) + {} +}; + +static gpio_num_t to_native_pin(GpioPinSpec pin_spec) { + if (pin_spec.gpio_controller == nullptr) { return GPIO_NUM_NC; } + return static_cast(pin_spec.pin); +} + +extern "C" { + +Esp32SdspiHandle esp32_sdspi_fs_alloc(const Esp32SdspiConfig* config, int spi_host, const char* mount_path) { + return new(std::nothrow) Esp32SdspiFsData(config, spi_host, mount_path); +} + +void esp32_sdspi_fs_free(Esp32SdspiHandle handle) { + delete GET_DATA(handle); +} + +sdmmc_card_t* esp32_sdspi_fs_get_card(Esp32SdspiHandle handle) { + return GET_DATA(handle)->card; +} + +static error_t mount(void* data) { + auto* fs_data = GET_DATA(data); + auto* config = fs_data->config; + + LOG_I(TAG, "Mounting %s", fs_data->mount_path.c_str()); + + esp_vfs_fat_sdmmc_mount_config_t mount_config = { + .format_if_mount_failed = false, + .max_files = 4, + .allocation_unit_size = 0, + .disk_status_check_enable = false, + .use_one_fat = false + }; + + sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT(); + slot_config.host_id = static_cast(fs_data->spi_host); + slot_config.gpio_cs = to_native_pin(config->pin_cs); + slot_config.gpio_cd = to_native_pin(config->pin_cd); + slot_config.gpio_wp = to_native_pin(config->pin_wp); + slot_config.gpio_int = to_native_pin(config->pin_int); + + sdmmc_host_t host = SDSPI_HOST_DEFAULT(); + host.max_freq_khz = static_cast(config->frequency_khz); + host.slot = fs_data->spi_host; + + esp_err_t result = esp_vfs_fat_sdspi_mount( + fs_data->mount_path.c_str(), &host, &slot_config, &mount_config, &fs_data->card + ); + + if (result != ESP_OK || fs_data->card == nullptr) { + if (result == ESP_FAIL) { + LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT."); + } else { + LOG_E(TAG, "Mounting failed: %s", esp_err_to_name(result)); + } + return ERROR_UNDEFINED; + } + + sdmmc_card_print_info(stdout, fs_data->card); + LOG_I(TAG, "Mounted %s", fs_data->mount_path.c_str()); + return ERROR_NONE; +} + +static error_t unmount(void* data) { + auto* fs_data = GET_DATA(data); + LOG_I(TAG, "Unmounting %s", fs_data->mount_path.c_str()); + + if (esp_vfs_fat_sdcard_unmount(fs_data->mount_path.c_str(), fs_data->card) != ESP_OK) { + LOG_E(TAG, "Unmount failed for %s", fs_data->mount_path.c_str()); + return ERROR_UNDEFINED; + } + + fs_data->card = nullptr; + LOG_I(TAG, "Unmounted %s", fs_data->mount_path.c_str()); + return ERROR_NONE; +} + +static bool is_mounted(void* data) { + const auto* fs_data = GET_DATA(data); + if (fs_data->card == nullptr) return false; + return sdmmc_get_status(fs_data->card) == ESP_OK; +} + +static error_t get_path(void* data, char* out_path, size_t out_path_size) { + const auto* fs_data = GET_DATA(data); + if (fs_data->mount_path.size() >= out_path_size) return ERROR_BUFFER_OVERFLOW; + strncpy(out_path, fs_data->mount_path.c_str(), out_path_size); + return ERROR_NONE; +} + +const FileSystemApi esp32_sdspi_fs_api = { + .mount = mount, + .unmount = unmount, + .is_mounted = is_mounted, + .get_path = get_path +}; + +} // extern "C" diff --git a/Platforms/platform-esp32/source/module.cpp b/Platforms/platform-esp32/source/module.cpp index b6a3fc670..0bd3cfd30 100644 --- a/Platforms/platform-esp32/source/module.cpp +++ b/Platforms/platform-esp32/source/module.cpp @@ -18,6 +18,7 @@ extern Driver esp32_i2s_driver; #if SOC_SDMMC_HOST_SUPPORTED extern Driver esp32_sdmmc_driver; #endif +extern Driver esp32_sdspi_driver; extern Driver esp32_spi_driver; extern Driver esp32_uart_driver; extern Driver esp32_grove_driver; @@ -44,6 +45,7 @@ static error_t start() { #if SOC_SDMMC_HOST_SUPPORTED check(driver_construct_add(&esp32_sdmmc_driver) == ERROR_NONE); #endif + check(driver_construct_add(&esp32_sdspi_driver) == ERROR_NONE); check(driver_construct_add(&esp32_spi_driver) == ERROR_NONE); check(driver_construct_add(&esp32_uart_driver) == ERROR_NONE); check(driver_construct_add(&esp32_grove_driver) == ERROR_NONE); @@ -84,6 +86,7 @@ static error_t stop() { #if SOC_SDMMC_HOST_SUPPORTED check(driver_remove_destruct(&esp32_sdmmc_driver) == ERROR_NONE); #endif + check(driver_remove_destruct(&esp32_sdspi_driver) == ERROR_NONE); check(driver_remove_destruct(&esp32_spi_driver) == ERROR_NONE); check(driver_remove_destruct(&esp32_uart_driver) == ERROR_NONE); check(driver_remove_destruct(&esp32_grove_driver) == ERROR_NONE); diff --git a/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h b/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h deleted file mode 100644 index cb9d08158..000000000 --- a/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifdef ESP_PLATFORM - -#pragma once - -#include "SdCardDevice.h" -#include "Tactility/kernel/SpiDeviceLock.h" - -#include -#include - -#include -#include -#include - -namespace tt::hal::sdcard { - -/** - * SD card interface at the default SPI interface - */ -class SpiSdCardDevice final : public SdCardDevice { - -public: - - struct Config { - Config( - gpio_num_t spiPinCs, - gpio_num_t spiPinCd, - gpio_num_t spiPinWp, - gpio_num_t spiPinInt, - MountBehaviour mountBehaviourAtBoot, - /** When customLock is a nullptr, use the SPI default one */ - std::shared_ptr customLock = nullptr, - std::vector csPinWorkAround = std::vector(), - spi_host_device_t spiHost = SPI2_HOST, - int spiFrequencyKhz = SDMMC_FREQ_DEFAULT - ) : spiFrequencyKhz(spiFrequencyKhz), - spiPinCs(spiPinCs), - spiPinCd(spiPinCd), - spiPinWp(spiPinWp), - spiPinInt(spiPinInt), - mountBehaviourAtBoot(mountBehaviourAtBoot), - customLock(customLock ? std::move(customLock) : nullptr), - csPinWorkAround(std::move(csPinWorkAround)), - spiHost(spiHost) - {} - - int spiFrequencyKhz; - gpio_num_t spiPinCs; // Clock - gpio_num_t spiPinCd; // Card detect - gpio_num_t spiPinWp; // Write-protect - gpio_num_t spiPinInt; // Interrupt - MountBehaviour mountBehaviourAtBoot; - std::shared_ptr customLock; // can be nullptr - std::vector csPinWorkAround; - spi_host_device_t spiHost; - bool formatOnMountFailed = false; - uint16_t maxOpenFiles = 4; - uint16_t allocUnitSize = 16 * 1024; - bool statusCheckEnabled = false; - }; - -private: - - std::string mountPath; - sdmmc_card_t* card = nullptr; - std::shared_ptr config; - std::shared_ptr lock; - - bool applyGpioWorkAround(); - bool mountInternal(const std::string& mountPath); - -public: - - explicit SpiSdCardDevice(std::unique_ptr newConfig, ::Device* spiController) : SdCardDevice(newConfig->mountBehaviourAtBoot), - config(std::move(newConfig)) - { - if (config->customLock == nullptr) { - auto spi_lock = std::make_shared(spiController); - lock = std::static_pointer_cast(spi_lock); - } else { - lock = config->customLock; - } - } - - std::string getName() const override { return "SD Card"; } - std::string getDescription() const override { return "SD card via SPI interface"; } - - bool mount(const std::string& mountPath) override; - bool unmount() override; - std::string getMountPath() const override { return mountPath; } - - std::shared_ptr getLock() const override { - return lock; - } - - State getState(TickType_t timeout) const override; - - /** return card when mounted, otherwise return nullptr */ - sdmmc_card_t* getCard() { return card; } -}; - -} - -#endif diff --git a/Tactility/Source/hal/sdcard/SdCard.cpp b/Tactility/Source/hal/sdcard/SdCard.cpp index 8a284ea4f..63aaa74bc 100644 --- a/Tactility/Source/hal/sdcard/SdCard.cpp +++ b/Tactility/Source/hal/sdcard/SdCard.cpp @@ -1,26 +1,41 @@ -#include #include "Tactility/hal/sdcard/SdCardDevice.h" -namespace tt::hal::sdcard { +#include -std::shared_ptr find(const std::string& path) { - auto sdcards = findDevices(Device::Type::SdCard); - for (auto& sdcard : sdcards) { - if (sdcard->isMounted() && path.starts_with(sdcard->getMountPath())) { - return sdcard; - } - } +#include +#include - return nullptr; -} +#include +#include + +namespace tt::hal::sdcard { std::shared_ptr findSdCardLock(const std::string& path) { - auto sdcard = find(path); - if (sdcard != nullptr) { - return sdcard->getLock(); - } + struct Ctx { + const std::string& path; + std::shared_ptr result; + }; + Ctx ctx = { path, nullptr }; + + file_system_for_each(&ctx, [](FileSystem* fs, void* context) { + auto* c = static_cast(context); + char mount_path[64]; + if (file_system_get_path(fs, mount_path, sizeof(mount_path)) != ERROR_NONE) return true; + if (!c->path.starts_with(mount_path)) return true; + + auto* owner = file_system_get_owner(fs); + if (owner != nullptr) { + // Check for I2C controller: if it has more than 2 children, assume it's the display + // TODO: Improve this + auto* parent = device_get_parent(owner); + if (parent != nullptr && device_get_child_count(parent) >= 2) { + c->result = lvgl::getSyncLock(); + } + } + return false; + }); - return nullptr; + return ctx.result; } } diff --git a/Tactility/Source/hal/sdcard/SpiSdCardDevice.cpp b/Tactility/Source/hal/sdcard/SpiSdCardDevice.cpp deleted file mode 100644 index 7cdcc52bc..000000000 --- a/Tactility/Source/hal/sdcard/SpiSdCardDevice.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#ifdef ESP_PLATFORM - -#include -#include -#include - -#include -#include - -namespace tt::hal::sdcard { - -static const auto LOGGER = Logger("SpiSdCardDevice"); - -/** - * Before we can initialize the sdcard's SPI communications, we have to set all - * other SPI pins on the board high. - * See https://github.com/espressif/esp-idf/issues/1597 - * See https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino - * @return success result - */ -bool SpiSdCardDevice::applyGpioWorkAround() { - LOGGER.info("applyGpioWorkAround"); - - uint64_t pin_bit_mask = config->spiPinCs != GPIO_NUM_NC ? BIT64(config->spiPinCs) : 0; - for (auto const& pin: config->csPinWorkAround) { - pin_bit_mask |= BIT64(pin); - } - - // Nothing to do - if (pin_bit_mask == 0) { - return true; - } - - if (!gpio::configureWithPinBitmask(pin_bit_mask, gpio::Mode::Output, false, false)) { - LOGGER.error("GPIO work-around failed"); - return false; - } - - for (auto const& pin: config->csPinWorkAround) { - if (!gpio::setLevel(pin, true)) { - LOGGER.error("Failed to set board CS pin high"); - return false; - } - } - - return true; -} - -bool SpiSdCardDevice::mountInternal(const std::string& newMountPath) { - LOGGER.info("Mounting {}", newMountPath); - - esp_vfs_fat_sdmmc_mount_config_t mount_config = { - .format_if_mount_failed = config->formatOnMountFailed, - .max_files = config->maxOpenFiles, - .allocation_unit_size = config->allocUnitSize, - .disk_status_check_enable = config->statusCheckEnabled, - .use_one_fat = false - }; - - // Init without card detect (CD) and write protect (WD) - sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT(); - slot_config.host_id = config->spiHost; - slot_config.gpio_cs = config->spiPinCs; - slot_config.gpio_cd = config->spiPinCd; - slot_config.gpio_wp = config->spiPinWp; - slot_config.gpio_int = config->spiPinInt; - - sdmmc_host_t host = SDSPI_HOST_DEFAULT(); - // The following value is from T-Deck repo's UnitTest.ino project: - // https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/UnitTest/UnitTest.ino - // Observation: Using this automatically sets the bus to 20MHz - host.max_freq_khz = config->spiFrequencyKhz; - host.slot = config->spiHost; - - esp_err_t result = esp_vfs_fat_sdspi_mount(newMountPath.c_str(), &host, &slot_config, &mount_config, &card); - - if (result != ESP_OK || card == nullptr) { - if (result == ESP_FAIL) { - LOGGER.error("Mounting failed. Ensure the card is formatted with FAT."); - } else { - LOGGER.error("Mounting failed ({})", esp_err_to_name(result)); - } - return false; - } - - mountPath = newMountPath; - - return true; -} - -bool SpiSdCardDevice::mount(const std::string& newMountPath) { - auto lock = getLock()->asScopedLock(); - lock.lock(); - - if (!applyGpioWorkAround()) { - LOGGER.error("Failed to apply GPIO work-around"); - return false; - } - - if (mountInternal(newMountPath)) { - LOGGER.info("Mounted at {}", newMountPath); - sdmmc_card_print_info(stdout, card); - return true; - } else { - LOGGER.error("Mount failed for {}", newMountPath); - return false; - } -} - -bool SpiSdCardDevice::unmount() { - auto lock = getLock()->asScopedLock(); - lock.lock(); - - if (card == nullptr) { - LOGGER.error("Can't unmount: not mounted"); - return false; - } - - if (esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card) != ESP_OK) { - LOGGER.error("Unmount failed for {}", mountPath); - return false; - } - - LOGGER.info("Unmounted {}", mountPath); - mountPath = ""; - card = nullptr; - return true; -} - -// TODO: Refactor to "bool getStatus(Status* status)" method so that it can fail when the lvgl lock fails -SdCardDevice::State SpiSdCardDevice::getState(TickType_t timeout) const { - if (card == nullptr) { - return State::Unmounted; - } - - /** - * The SD card and the screen are on the same SPI bus. - * Writing and reading to the bus from 2 devices at the same time causes crashes. - * This work-around ensures that this check is only happening when LVGL isn't rendering. - */ - auto lock = getLock()->asScopedLock(); - bool locked = lock.lock(timeout); - if (!locked) { - return State::Timeout; - } - - if (sdmmc_get_status(card) != ESP_OK) { - return State::Error; - } - - return State::Mounted; -} - -} - -#endif \ No newline at end of file diff --git a/Tactility/Source/hal/usb/Usb.cpp b/Tactility/Source/hal/usb/Usb.cpp index c52a0c52a..4a5155e95 100644 --- a/Tactility/Source/hal/usb/Usb.cpp +++ b/Tactility/Source/hal/usb/Usb.cpp @@ -3,11 +3,12 @@ #include #include -#include #include #include -#include +#include +#include +#include namespace tt::hal::usb { @@ -24,41 +25,23 @@ static Mode currentMode = Mode::Default; static RTC_NOINIT_ATTR BootModeData bootModeData; sdmmc_card_t* getCard() { - sdmmc_card_t* sdcard = nullptr; - - // Find old HAL SD card device: - auto sdcards = findDevices(Device::Type::SdCard); - for (auto& device : sdcards) { - auto sdcard_device= std::static_pointer_cast(device); - if (sdcard_device != nullptr && sdcard_device->isMounted() && sdcard_device->getCard() != nullptr) { - sdcard = sdcard_device->getCard(); - break; - } - } - -#if SOC_SDMMC_HOST_SUPPORTED - // Find ESP32 SDMMC device: - if (sdcard == nullptr) { - device_for_each(&sdcard, [](auto* device, void* context) { - if (device_is_ready(device) && device_is_compatible(device, "espressif,esp32-sdmmc")) { - auto** sdcard = static_cast(context); - auto* sdmmc_card = esp32_sdmmc_get_card(device); - if (sdmmc_card) { - *sdcard = sdmmc_card; - return false; - } - return true; - } - return true; - }); - } -#endif - - if (sdcard == nullptr) { + sdmmc_card_t* card = nullptr; + + device_for_each(&card, [](auto* device, void* context) { + auto* driver = device_get_driver(device); + if (driver == nullptr) return true; + if (!driver_is_compatible(driver, "espressif,esp32-sdspi") && + !driver_is_compatible(driver, "espressif,esp32-sdmmc")) return true; + auto** out = static_cast(context); + *out = esp32_sdcard_get_card(device); + return *out == nullptr; + }); + + if (card == nullptr) { LOGGER.warn("Couldn't find a mounted SD card"); } - return sdcard; + return card; } static bool canStartNewMode() { diff --git a/Tactility/Source/service/statusbar/Statusbar.cpp b/Tactility/Source/service/statusbar/Statusbar.cpp index 7ae4619e6..20afd61ba 100644 --- a/Tactility/Source/service/statusbar/Statusbar.cpp +++ b/Tactility/Source/service/statusbar/Statusbar.cpp @@ -2,10 +2,9 @@ #include #include -#include #include #include -#include +#include #include #include #include @@ -239,11 +238,21 @@ class StatusbarService final : public Service { } void updateSdCardIcon() { - auto* sdcard_fs = findSdcardFileSystem(false); - // TODO: Support multiple SD cards - if (sdcard_fs != nullptr) { - auto mounted = file_system_is_mounted(sdcard_fs); - auto* desired_icon = getSdCardStatusIcon(mounted); + struct SdCardState { bool found; bool mounted; }; + SdCardState state = { false, false }; + + file_system_for_each(&state, [](FileSystem* fs, void* context) { + auto* s = static_cast(context); + char path[64]; + if (file_system_get_path(fs, path, sizeof(path)) != ERROR_NONE) return true; + if (strncmp(path, "/sdcard", 7) != 0) return true; + s->found = true; + s->mounted = file_system_is_mounted(fs); + return false; + }); + + if (state.found) { + auto* desired_icon = getSdCardStatusIcon(state.mounted); if (sdcard_last_icon != desired_icon) { lvgl::statusbar_icon_set_image(sdcard_icon_id, desired_icon); lvgl::statusbar_icon_set_visibility(sdcard_icon_id, true); diff --git a/TactilityKernel/bindings/display-placeholder.yaml b/TactilityKernel/bindings/display-placeholder.yaml new file mode 100644 index 000000000..aab1050c0 --- /dev/null +++ b/TactilityKernel/bindings/display-placeholder.yaml @@ -0,0 +1,5 @@ +description: Display placeholder + +compatible: "display-placeholder" + +properties: {} diff --git a/TactilityKernel/bindings/spi-peripheral.yaml b/TactilityKernel/bindings/spi-peripheral.yaml new file mode 100644 index 000000000..baa052a5b --- /dev/null +++ b/TactilityKernel/bindings/spi-peripheral.yaml @@ -0,0 +1,9 @@ +description: SPI peripheral with chip select + +compatible: "spi-peripheral" + +properties: + pin-cs: + type: phandle-array + required: true + description: Chip select GPIO diff --git a/TactilityKernel/include/tactility/bindings/display_placeholder.h b/TactilityKernel/include/tactility/bindings/display_placeholder.h new file mode 100644 index 000000000..9a7466c02 --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/display_placeholder.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(display_placeholder, struct DisplayPlaceholderConfig) + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/bindings/spi_peripheral.h b/TactilityKernel/include/tactility/bindings/spi_peripheral.h new file mode 100644 index 000000000..30cccd85f --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/spi_peripheral.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(spi_peripheral, struct SpiPeripheralConfig) + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/device.h b/TactilityKernel/include/tactility/device.h index e5313b7ee..1ebc97aaa 100644 --- a/TactilityKernel/include/tactility/device.h +++ b/TactilityKernel/include/tactility/device.h @@ -248,6 +248,13 @@ void device_for_each(void* callback_context, bool(*on_device)(struct Device* dev */ void device_for_each_child(struct Device* device, void* callback_context, bool(*on_device)(struct Device* device, void* context)); +/** + * @brief Get the number of child devices. + * @param[in] device non-null device pointer + * @return the number of children + */ +size_t device_get_child_count(struct Device* device); + /** * Iterate through all the known devices of a specific type * diff --git a/TactilityKernel/include/tactility/drivers/display.h b/TactilityKernel/include/tactility/drivers/display.h new file mode 100644 index 000000000..982e679ef --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/display.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +extern const struct DeviceType DISPLAY_TYPE; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/drivers/display_placeholder.h b/TactilityKernel/include/tactility/drivers/display_placeholder.h new file mode 100644 index 000000000..9415e8333 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/display_placeholder.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct DisplayPlaceholderConfig { + uint8_t _unused; +}; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/drivers/spi_peripheral.h b/TactilityKernel/include/tactility/drivers/spi_peripheral.h new file mode 100644 index 000000000..e7b1c3545 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/spi_peripheral.h @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct SpiPeripheralConfig { + struct GpioPinSpec pin_cs; +}; + +struct SpiPeripheralApi { + struct GpioDescriptor* (*get_cs_descriptor)(struct Device* device); +}; + +struct GpioDescriptor* spi_peripheral_get_cs_descriptor(struct Device* device); + +extern const struct DeviceType SPI_PERIPHERAL_TYPE; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/filesystem/file_system.h b/TactilityKernel/include/tactility/filesystem/file_system.h index 40a6bec75..4f7710155 100644 --- a/TactilityKernel/include/tactility/filesystem/file_system.h +++ b/TactilityKernel/include/tactility/filesystem/file_system.h @@ -101,6 +101,20 @@ bool file_system_is_mounted(struct FileSystem* fs); */ error_t file_system_get_path(struct FileSystem* fs, char* out_path, size_t out_path_size); +/** + * @brief Sets the owner device of the file system. + * @param[in] fs the FileSystem object + * @param[in] owner the owning device, or NULL + */ +void file_system_set_owner(struct FileSystem* fs, struct Device* owner); + +/** + * @brief Gets the owner device of the file system. + * @param[in] fs the FileSystem object + * @return the owning device, or NULL if not set + */ +struct Device* file_system_get_owner(struct FileSystem* fs); + #ifdef __cplusplus } #endif diff --git a/TactilityKernel/source/device.cpp b/TactilityKernel/source/device.cpp index d01cd192c..7bb7f100c 100644 --- a/TactilityKernel/source/device.cpp +++ b/TactilityKernel/source/device.cpp @@ -328,6 +328,10 @@ void device_for_each_child(Device* device, void* callbackContext, bool(*on_devic } } +size_t device_get_child_count(Device* device) { + return device->internal->children.size(); +} + void device_for_each_of_type(const DeviceType* type, void* callbackContext, bool(*on_device)(Device* device, void* context)) { ledger_lock(); for (auto* device : ledger.devices) { diff --git a/TactilityKernel/source/drivers/display.cpp b/TactilityKernel/source/drivers/display.cpp new file mode 100644 index 000000000..3b49e4963 --- /dev/null +++ b/TactilityKernel/source/drivers/display.cpp @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +extern "C" { + +const struct DeviceType DISPLAY_TYPE { + .name = "display" +}; + +} diff --git a/TactilityKernel/source/drivers/display_placeholder.cpp b/TactilityKernel/source/drivers/display_placeholder.cpp new file mode 100644 index 000000000..948acdd47 --- /dev/null +++ b/TactilityKernel/source/drivers/display_placeholder.cpp @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +extern "C" { + +static error_t start(Device*) { return ERROR_NONE; } +static error_t stop(Device*) { return ERROR_NONE; } + +extern Module root_module; + +Driver display_placeholder_driver = { + .name = "display_placeholder", + .compatible = (const char*[]) { "display-placeholder", nullptr }, + .start_device = start, + .stop_device = stop, + .api = nullptr, + .device_type = &DISPLAY_TYPE, + .owner = &root_module, + .internal = nullptr +}; + +} diff --git a/TactilityKernel/source/drivers/spi_peripheral.cpp b/TactilityKernel/source/drivers/spi_peripheral.cpp new file mode 100644 index 000000000..3b7b1b600 --- /dev/null +++ b/TactilityKernel/source/drivers/spi_peripheral.cpp @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include +#include + +#define TAG "spi_peripheral" + +#define GET_CONFIG(device) ((const struct SpiPeripheralConfig*)device->config) + +extern "C" { + +static error_t start(Device* device) { + auto* parent = device_get_parent(device); + if (parent == nullptr || device_get_type(parent) != &SPI_CONTROLLER_TYPE) { + LOG_E(TAG, "Parent is not an SPI controller"); + return ERROR_INVALID_STATE; + } + + auto* config = GET_CONFIG(device); + GpioDescriptor* cs = nullptr; + if (config->pin_cs.gpio_controller != nullptr) { + cs = gpio_descriptor_acquire(config->pin_cs.gpio_controller, config->pin_cs.pin, GPIO_OWNER_SPI); + if (cs == nullptr) { + LOG_E(TAG, "Failed to acquire CS pin"); + return ERROR_RESOURCE; + } + gpio_descriptor_set_flags(cs, GPIO_FLAG_DIRECTION_OUTPUT); + gpio_descriptor_set_level(cs, true); + } + + device_set_driver_data(device, cs); + return ERROR_NONE; +} + +static error_t stop(Device* device) { + auto* cs = static_cast(device_get_driver_data(device)); + if (cs != nullptr) { + gpio_descriptor_release(cs); + } + device_set_driver_data(device, nullptr); + return ERROR_NONE; +} + +static GpioDescriptor* get_cs_descriptor(Device* device) { + return static_cast(device_get_driver_data(device)); +} + +static const SpiPeripheralApi spi_peripheral_api = { + .get_cs_descriptor = get_cs_descriptor +}; + +GpioDescriptor* spi_peripheral_get_cs_descriptor(Device* device) { + auto* driver = device_get_driver(device); + return ((const SpiPeripheralApi*)driver->api)->get_cs_descriptor(device); +} + +const DeviceType SPI_PERIPHERAL_TYPE = { + .name = "spi_peripheral" +}; + +extern Module root_module; + +Driver spi_peripheral_driver = { + .name = "spi_peripheral", + .compatible = (const char*[]) { "spi-peripheral", nullptr }, + .start_device = start, + .stop_device = stop, + .api = &spi_peripheral_api, + .device_type = &SPI_PERIPHERAL_TYPE, + .owner = &root_module, + .internal = nullptr +}; + +} diff --git a/TactilityKernel/source/filesystem/file_system.cpp b/TactilityKernel/source/filesystem/file_system.cpp index d22dd31a7..453105abb 100644 --- a/TactilityKernel/source/filesystem/file_system.cpp +++ b/TactilityKernel/source/filesystem/file_system.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include #include #include @@ -10,6 +11,7 @@ struct FileSystem { const FileSystemApi* api; void* data; + Device* owner; }; // Global list of file systems and its mutex @@ -42,6 +44,7 @@ FileSystem* file_system_add(const FileSystemApi* fs_api, void* data) { check(fs != nullptr); fs->api = fs_api; fs->data = data; + fs->owner = nullptr; ledger.file_systems.push_back(fs); ledger.unlock(); @@ -90,4 +93,12 @@ error_t file_system_get_path(FileSystem* fs, char* out_path, size_t out_path_siz return fs->api->get_path(fs->data, out_path, out_path_size); } +void file_system_set_owner(FileSystem* fs, Device* owner) { + fs->owner = owner; +} + +Device* file_system_get_owner(FileSystem* fs) { + return fs->owner; +} + } diff --git a/TactilityKernel/source/kernel_init.cpp b/TactilityKernel/source/kernel_init.cpp index b13ed71b5..9c99278f2 100644 --- a/TactilityKernel/source/kernel_init.cpp +++ b/TactilityKernel/source/kernel_init.cpp @@ -14,6 +14,10 @@ extern const ModuleSymbol KERNEL_SYMBOLS[]; static error_t start() { extern Driver root_driver; if (driver_construct_add(&root_driver) != ERROR_NONE) return ERROR_RESOURCE; + extern Driver display_placeholder_driver; + if (driver_construct_add(&display_placeholder_driver) != ERROR_NONE) return ERROR_RESOURCE; + extern Driver spi_peripheral_driver; + if (driver_construct_add(&spi_peripheral_driver) != ERROR_NONE) return ERROR_RESOURCE; return ERROR_NONE; } From 7d786c2b6609a86a1f21787ff002137d55d94471 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 20 Jun 2026 01:08:30 +0200 Subject: [PATCH 02/19] Add support for device addresses --- Buildscripts/DevicetreeCompiler/source/generator.py | 2 ++ Buildscripts/DevicetreeCompiler/source/grammar.lark | 7 ++++--- Buildscripts/DevicetreeCompiler/source/models.py | 1 + Buildscripts/DevicetreeCompiler/source/transformer.py | 5 ++++- TactilityKernel/include/tactility/device.h | 3 +++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index bbbd3dc36..1f3af5b2e 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -178,7 +178,9 @@ def write_device_structs(file, device: Device, parent_device: Device, bindings: # Write config struct write_config(file, device, bindings, devices, type_name) # Write device struct + address_value = device.node_address if device.node_address is not None else "0" file.write(f"static struct Device {node_name}" " = {\n") + file.write(f"\t.address = {address_value},\n") file.write(f"\t.name = \"{device.node_name}\",\n") # Use original name file.write(f"\t.config = &{config_variable_name},\n") file.write(f"\t.parent = {parent_value},\n") diff --git a/Buildscripts/DevicetreeCompiler/source/grammar.lark b/Buildscripts/DevicetreeCompiler/source/grammar.lark index e2a0493ff..1b9fdeb0c 100644 --- a/Buildscripts/DevicetreeCompiler/source/grammar.lark +++ b/Buildscripts/DevicetreeCompiler/source/grammar.lark @@ -40,10 +40,11 @@ array: NUMBER+ property_value: quoted_text_array | QUOTED_TEXT | "<" value ">" | "<" values ">" | "[" array "]" | PHANDLE device_property: PROPERTY_NAME ["=" property_value] ";" -NODE_ALIAS: /[a-zA-Z0-9_\-\/@]+/ -NODE_NAME: /[a-zA-Z0-9_\-\/@]+/ +NODE_ALIAS: /[a-zA-Z0-9_\-\/]+/ +NODE_NAME: /[a-zA-Z0-9_\-\/]+/ +NODE_ADDRESS: /[0-9a-zA-Z_]+/ -device: (NODE_ALIAS ":")? NODE_NAME "{" (device | device_property)* "};" +device: (NODE_ALIAS ":")? NODE_NAME ("@" NODE_ADDRESS)? "{" (device | device_property)* "};" dts_version: /[0-9a-zA-Z\-]+/ diff --git a/Buildscripts/DevicetreeCompiler/source/models.py b/Buildscripts/DevicetreeCompiler/source/models.py index 47d063d90..761d25caf 100644 --- a/Buildscripts/DevicetreeCompiler/source/models.py +++ b/Buildscripts/DevicetreeCompiler/source/models.py @@ -8,6 +8,7 @@ class DtsVersion: class Device: node_name: str node_alias: str + node_address: str status: str properties: list devices: list diff --git a/Buildscripts/DevicetreeCompiler/source/transformer.py b/Buildscripts/DevicetreeCompiler/source/transformer.py index 7b2c2df25..076d5872e 100644 --- a/Buildscripts/DevicetreeCompiler/source/transformer.py +++ b/Buildscripts/DevicetreeCompiler/source/transformer.py @@ -29,6 +29,7 @@ def dts_version(self, tokens: List[Token]): def device(self, tokens: list): node_name = None node_alias = None + node_address = None status = None properties = list() child_devices = list() @@ -37,6 +38,8 @@ def device(self, tokens: list): node_name = item.value elif type(item) is Token and item.type == 'NODE_ALIAS': node_alias = item.value + elif type(item) is Token and item.type == 'NODE_ADDRESS': + node_address = item.value elif type(item) is DeviceProperty: if item.name == "status": status = item.value @@ -44,7 +47,7 @@ def device(self, tokens: list): properties.append(item) elif type(item) is Device: child_devices.append(item) - return Device(node_name, node_alias, status, properties, child_devices) + return Device(node_name, node_alias, node_address, status, properties, child_devices) def device_property(self, objects: List[object]): name = objects[0] # Boolean property has no value as the value is implied to be true diff --git a/TactilityKernel/include/tactility/device.h b/TactilityKernel/include/tactility/device.h index 1ebc97aaa..e60986d6f 100644 --- a/TactilityKernel/include/tactility/device.h +++ b/TactilityKernel/include/tactility/device.h @@ -26,6 +26,9 @@ struct DeviceType { /** Represents a piece of hardware */ struct Device { + /** Device address. Can represent an index, a memory address, or some kind of offset */ + int32_t address; + /** The name of the device. Valid characters: a-z a-Z 0-9 - _ . */ const char* name; From f93c04e0161fa65212d179fd8b5edced68c5e0f1 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 20 Jun 2026 22:30:35 +0200 Subject: [PATCH 03/19] Add addresses to SPI peripherals --- Devices/lilygo-tdeck/lilygo,tdeck.dts | 4 ++-- Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts | 4 ++-- Devices/m5stack-core2/m5stack,core2.dts | 4 ++-- Devices/m5stack-cores3/m5stack,cores3.dts | 4 ++-- Devices/m5stack-stackchan/m5stack,stackchan.dts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index ad6bba49a..baf70b04d 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -48,13 +48,13 @@ pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 39 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - display { + display@1 { compatible = "display-placeholder"; }; }; diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index 6697036ce..217a87af9 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -39,13 +39,13 @@ pin-miso = <&gpio0 33 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 35 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 21 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - display { + display@1 { compatible = "display-placeholder"; }; }; diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index 7bd48e78d..c14cf4d4f 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -57,13 +57,13 @@ pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - display { + display@1 { compatible = "display-placeholder"; }; }; diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index 4d4040f34..b7f69d858 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -82,13 +82,13 @@ pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - display { + display@1 { compatible = "display-placeholder"; }; }; diff --git a/Devices/m5stack-stackchan/m5stack,stackchan.dts b/Devices/m5stack-stackchan/m5stack,stackchan.dts index 5659c2776..f046ebf0f 100644 --- a/Devices/m5stack-stackchan/m5stack,stackchan.dts +++ b/Devices/m5stack-stackchan/m5stack,stackchan.dts @@ -116,13 +116,13 @@ pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - display { + display@1 { compatible = "display-placeholder"; }; }; From 019a8ee02607db347534be782c3eebc38ee188a5 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 20 Jun 2026 22:30:46 +0200 Subject: [PATCH 04/19] Add support for phandle arrays in DevicetreeCompiler --- Buildscripts/DevicetreeCompiler/source/generator.py | 1 + Buildscripts/DevicetreeCompiler/source/grammar.lark | 5 ++++- Buildscripts/DevicetreeCompiler/source/transformer.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index 1f3af5b2e..04f89eeeb 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -88,6 +88,7 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: value_list.append(property_to_string(DeviceProperty(name="", type=item.type, value=item.value), devices)) else: value_list.append(str(item)) + value_list.append("{ 0 }") return "{ " + ",".join(value_list) + " }" elif isinstance(property.value, str): # If it's a string, assume it's a #define and show it as-is diff --git a/Buildscripts/DevicetreeCompiler/source/grammar.lark b/Buildscripts/DevicetreeCompiler/source/grammar.lark index 1b9fdeb0c..3801eb13c 100644 --- a/Buildscripts/DevicetreeCompiler/source/grammar.lark +++ b/Buildscripts/DevicetreeCompiler/source/grammar.lark @@ -37,7 +37,10 @@ value: VALUE values: VALUE+ array: NUMBER+ -property_value: quoted_text_array | QUOTED_TEXT | "<" value ">" | "<" values ">" | "[" array "]" | PHANDLE +phandle_array_entry: "<" values ">" +phandle_array: phandle_array_entry ("," phandle_array_entry)+ + +property_value: quoted_text_array | QUOTED_TEXT | phandle_array | "<" value ">" | "<" values ">" | "[" array "]" | PHANDLE device_property: PROPERTY_NAME ["=" property_value] ";" NODE_ALIAS: /[a-zA-Z0-9_\-\/]+/ diff --git a/Buildscripts/DevicetreeCompiler/source/transformer.py b/Buildscripts/DevicetreeCompiler/source/transformer.py index 076d5872e..d6033b413 100644 --- a/Buildscripts/DevicetreeCompiler/source/transformer.py +++ b/Buildscripts/DevicetreeCompiler/source/transformer.py @@ -70,6 +70,10 @@ def value(self, object): if isinstance(object[0], PropertyValue): return object[0] return PropertyValue(type="value", value=object[0]) + def phandle_array_entry(self, tokens: list): + return tokens[0] + def phandle_array(self, tokens: list): + return PropertyValue(type="phandle-array", value=tokens) def array(self, object): return PropertyValue(type="array", value=object) def VALUE(self, token: Token): From 394b1e1957ba02fb3b7ce00d0113ffcfd32185c4 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 20 Jun 2026 22:30:52 +0200 Subject: [PATCH 05/19] Update docs to include Devicetree --- Documentation/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/README.md b/Documentation/README.md index 91471f994..c5935b80a 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -27,6 +27,12 @@ idf.py flash monitor # flash and monitor Device IDs are the folder names under `Devices/` (e.g. `lilygo-tdeck`, `m5stack-cores3`, `cyd-2432s028r`). +### Devicetree + +A device implementation has a `.dts` file. +The parser at `Buildscripts/DevicetreeCompiler/` converts DTS into C code. +It's called from the `Firmware/` build process. + ### Tests Tests use Doctest and run on simulator (POSIX) target only: From 9872825f6f7fbcda1dc4fe6dbaa8a5ef413d5660 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 20 Jun 2026 22:31:02 +0200 Subject: [PATCH 06/19] Add cs_gpios to esp32_spi driver --- Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml | 6 +++++- .../platform-esp32/include/tactility/drivers/esp32_spi.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml index 3c455f583..d2aa437d6 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml @@ -34,5 +34,9 @@ properties: type: int default: 0 description: | - Data transfer size limit in bytes. + Data transfer size limit in bytes. 0 means the platform decides the limit. + cs-gpios: + type: phandle-array + default: { 0 } + description: Null-terminated array of chip select GPIO pin specs for peripherals on this bus diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h index 6a52f4f1c..3de540b99 100644 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h @@ -23,6 +23,8 @@ struct Esp32SpiConfig { struct GpioPinSpec pin_hd; /** Data transfer size limit in bytes. 0 means the platform decides the limit. */ int max_transfer_size; + /** Null-terminated array of chip select GPIO pin specs */ + struct GpioPinSpec cs_gpios[]; }; #ifdef __cplusplus From 7f574a34b04a53c67aee3e6ade6e1149fe1a0289 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 00:03:23 +0200 Subject: [PATCH 07/19] Implement touch placeholder driver, implement cs-gpios. --- Devices/cyd-2432s024c/cyd,2432s024c.dts | 2 ++ Devices/cyd-2432s024r/cyd,2432s024r.dts | 10 ++++++- Devices/cyd-2432s028r/cyd,2432s028r.dts | 12 +++++++-- Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts | 10 ++++++- Devices/cyd-2432s032c/cyd,2432s032c.dts | 2 ++ Devices/cyd-3248s035c/cyd,3248s035c.dts | 2 ++ Devices/cyd-4848s040c/cyd,4848s040c.dts | 4 +-- Devices/cyd-8048s043c/cyd,8048s043c.dts | 1 + Devices/cyd-e32r28t/cyd,e32r28t.dts | 10 ++++++- Devices/cyd-e32r32p/cyd,e32r32p.dts | 10 ++++++- .../elecrow,crowpanel-advance-28.dts | 2 ++ .../elecrow,crowpanel-advance-35.dts | 2 ++ .../elecrow,crowpanel-advance-50.dts | 1 + .../elecrow,crowpanel-basic-28.dts | 10 ++++++- .../elecrow,crowpanel-basic-35.dts | 10 ++++++- .../elecrow,crowpanel-basic-50.dts | 1 + .../guition,jc2432w328c.dts | 2 ++ .../guition,jc3248w535c.dts | 5 ++++ .../guition,jc8048w550c.dts | 1 + Devices/lilygo-tdeck/lilygo,tdeck.dts | 14 +++++----- .../lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts | 9 ------- Devices/lilygo-tdisplay/lilygo,tdisplay.dts | 1 + .../lilygo-tdongle-s3/lilygo,tdongle-s3.dts | 1 + Devices/lilygo-thmi/lilygo,thmi.dts | 10 +++++++ .../Source/Configuration.cpp | 1 - .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 2 ++ .../m5stack,cardputer-adv.dts | 2 ++ .../m5stack-cardputer/m5stack,cardputer.dts | 2 ++ Devices/m5stack-core2/m5stack,core2.dts | 2 ++ Devices/m5stack-cores3/m5stack,cores3.dts | 2 ++ Devices/m5stack-papers3/m5stack,papers3.dts | 1 + .../m5stack-stackchan/m5stack,stackchan.dts | 6 +++-- .../m5stack,stickc-plus.dts | 1 + .../m5stack,stickc-plus2.dts | 1 + Devices/m5stack-sticks3/m5stack,sticks3.dts | 2 ++ Devices/m5stack-tab5/m5stack,tab5.dts | 1 + Devices/unphone/unphone.dts | 15 +++++++++-- .../waveshare,esp32-s3-geek.dts | 1 + .../waveshare,s3-lcd-13.dts | 2 ++ .../waveshare,s3-touch-lcd-128.dts | 2 ++ .../waveshare,s3-touch-lcd-147.dts | 5 ++++ .../waveshare,s3-touch-lcd-43.dts | 1 + .../wireless-tag,wt32-sc01-plus.dts | 1 + .../source/drivers/esp32_spi.cpp | 13 ++++++++++ .../bindings/touch-placeholder.yaml | 5 ++++ .../tactility/bindings/touch_placeholder.h | 15 +++++++++++ .../include/tactility/drivers/touch.h | 14 ++++++++++ .../tactility/drivers/touch_placeholder.h | 16 ++++++++++++ TactilityKernel/source/drivers/touch.cpp | 10 +++++++ .../source/drivers/touch_placeholder.cpp | 26 +++++++++++++++++++ TactilityKernel/source/kernel_init.cpp | 2 ++ 51 files changed, 253 insertions(+), 30 deletions(-) create mode 100644 TactilityKernel/bindings/touch-placeholder.yaml create mode 100644 TactilityKernel/include/tactility/bindings/touch_placeholder.h create mode 100644 TactilityKernel/include/tactility/drivers/touch.h create mode 100644 TactilityKernel/include/tactility/drivers/touch_placeholder.h create mode 100644 TactilityKernel/source/drivers/touch.cpp create mode 100644 TactilityKernel/source/drivers/touch_placeholder.cpp diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index ccc1ad75d..d9d390de9 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -27,6 +27,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; @@ -38,6 +39,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-2432s024r/cyd,2432s024r.dts b/Devices/cyd-2432s024r/cyd,2432s024r.dts index 737cd00bc..5ae5207bc 100644 --- a/Devices/cyd-2432s024r/cyd,2432s024r.dts +++ b/Devices/cyd-2432s024r/cyd,2432s024r.dts @@ -5,6 +5,7 @@ #include #include #include +#include #include / { @@ -22,10 +23,16 @@ pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 33 GPIO_FLAG_NONE>; // Touch - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { @@ -34,6 +41,7 @@ pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; sdcard { compatible = "espressif,esp32-sdspi"; diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 4179d8e05..41f635429 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -28,13 +29,19 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 33 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { @@ -43,7 +50,8 @@ pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; + sdcard { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index 6105b94a3..97ab5a6ec 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -28,18 +29,25 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 33 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 74beaf2da..796fbe273 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -27,6 +27,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>; pin-mosi = <&gpio1 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio1 14 GPIO_FLAG_NONE>; @@ -38,6 +39,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio1 23 GPIO_FLAG_NONE>; pin-miso = <&gpio1 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio1 18 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-3248s035c/cyd,3248s035c.dts b/Devices/cyd-3248s035c/cyd,3248s035c.dts index a4b8aea3f..f02d78794 100644 --- a/Devices/cyd-3248s035c/cyd,3248s035c.dts +++ b/Devices/cyd-3248s035c/cyd,3248s035c.dts @@ -37,6 +37,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; @@ -48,6 +49,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-4848s040c/cyd,4848s040c.dts b/Devices/cyd-4848s040c/cyd,4848s040c.dts index f9b4c5886..e3649e7c7 100644 --- a/Devices/cyd-4848s040c/cyd,4848s040c.dts +++ b/Devices/cyd-4848s040c/cyd,4848s040c.dts @@ -31,11 +31,11 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 42 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 47 GPIO_FLAG_NONE>; pin-miso = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 48 GPIO_FLAG_NONE>; - pin-hd = <&gpio0 42 GPIO_FLAG_NONE>; - + sdcard { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 42 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 222850fff..63e93d34a 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -40,6 +40,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-e32r28t/cyd,e32r28t.dts b/Devices/cyd-e32r28t/cyd,e32r28t.dts index d79230fc4..942205083 100644 --- a/Devices/cyd-e32r28t/cyd,e32r28t.dts +++ b/Devices/cyd-e32r28t/cyd,e32r28t.dts @@ -5,6 +5,7 @@ #include #include #include +#include / { compatible = "root"; @@ -18,18 +19,25 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 33 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/cyd-e32r32p/cyd,e32r32p.dts b/Devices/cyd-e32r32p/cyd,e32r32p.dts index da75b1a4a..383c8d879 100644 --- a/Devices/cyd-e32r32p/cyd,e32r32p.dts +++ b/Devices/cyd-e32r32p/cyd,e32r32p.dts @@ -6,6 +6,7 @@ #include #include #include +#include / { compatible = "root"; @@ -27,18 +28,25 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 33 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index cf8eaa1bb..166075d3d 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -33,6 +33,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 40 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 42 GPIO_FLAG_NONE>; @@ -44,6 +45,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 7 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index 0050ecd46..314594ed8 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -33,6 +33,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 40 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 42 GPIO_FLAG_NONE>; @@ -44,6 +45,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 7 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index 6b27e4467..f6e536231 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -32,6 +32,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 0 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index 89c6e3213..dc95198b9 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -28,19 +29,26 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 33 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; max-transfer-size = <65536>; - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index 8226b5e6d..11cf4f456 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -7,6 +7,7 @@ #include #include #include +#include / { compatible = "root"; @@ -28,19 +29,26 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>, // Display + <&gpio0 12 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; max-transfer-size = <65536>; - display { + display@0 { compatible = "display-placeholder"; }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index b5dae9648..2f8106745 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -32,6 +32,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index 78c3570ba..c96a6a8f7 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -37,6 +37,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; @@ -48,6 +49,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index f48fa1814..13a14ef43 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -49,11 +49,16 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 45 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 21 GPIO_FLAG_NONE>; pin-miso = <&gpio0 48 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 47 GPIO_FLAG_NONE>; pin-wp = <&gpio0 40 GPIO_FLAG_NONE>; pin-hd = <&gpio0 39 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; spi1 { diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index 6000feaea..dba67451e 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -50,6 +50,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index baf70b04d..331a7e99d 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -44,19 +44,21 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 12 GPIO_FLAG_NONE>, // Display + <&gpio0 39 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; - - sdcard@0 { + + display@0 { + compatible = "display-placeholder"; + }; + + sdcard@1 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 39 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - - display@1 { - compatible = "display-placeholder"; - }; }; uart0 { diff --git a/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts b/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts index d9822732e..3a21669a6 100644 --- a/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts +++ b/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts @@ -3,8 +3,6 @@ #include #include #include -#include -#include / { compatible = "root"; @@ -18,11 +16,4 @@ compatible = "espressif,esp32-gpio"; gpio-count = <49>; }; - - spi0 { - compatible = "espressif,esp32-spi"; - host = ; - pin-mosi = <&gpio0 7 GPIO_FLAG_NONE>; - pin-sclk = <&gpio0 6 GPIO_FLAG_NONE>; - }; }; diff --git a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts index 750ed3ec0..10350088c 100644 --- a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts +++ b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts @@ -18,6 +18,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index 2c26cbb3e..7e608f187 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -33,6 +33,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 3 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; diff --git a/Devices/lilygo-thmi/lilygo,thmi.dts b/Devices/lilygo-thmi/lilygo,thmi.dts index defb61d1c..93e080900 100644 --- a/Devices/lilygo-thmi/lilygo,thmi.dts +++ b/Devices/lilygo-thmi/lilygo,thmi.dts @@ -23,9 +23,19 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 6 GPIO_FLAG_NONE>, // Display + <&gpio0 2 GPIO_FLAG_NONE>; // Touch pin-mosi = <&gpio0 3 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 1 GPIO_FLAG_NONE>; + + display@0 { + compatible = "display-placeholder"; + }; + + touch@1 { + compatible = "touch-placeholder"; + }; }; sdmmc0 { diff --git a/Devices/lilygo-tlora-pager/Source/Configuration.cpp b/Devices/lilygo-tlora-pager/Source/Configuration.cpp index 13bd752e2..9be746363 100644 --- a/Devices/lilygo-tlora-pager/Source/Configuration.cpp +++ b/Devices/lilygo-tlora-pager/Source/Configuration.cpp @@ -27,7 +27,6 @@ static DeviceVector createDevices() { bq27220, std::make_shared(i2c), power, - createTpagerSdCard(), createDisplay(), keyboard, std::make_shared() diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index 217a87af9..d6b38f7ec 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -35,6 +35,8 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 21 GPIO_FLAG_NONE>, // SD card + <&gpio0 36 GPIO_FLAG_NONE>; // Display pin-mosi = <&gpio0 34 GPIO_FLAG_NONE>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 35 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index 155940187..a004ab1e9 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -52,6 +52,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 37 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; @@ -63,6 +64,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 12 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index 1e205b35a..f652eb60a 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -38,6 +38,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 37 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; @@ -49,6 +50,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 12 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index c14cf4d4f..0269b04dc 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -53,6 +53,8 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>, // SD card + <&gpio0 5 GPIO_FLAG_NONE>; // Display pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index b7f69d858..c6eba128b 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -78,6 +78,8 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>, // SD card + <&gpio0 3 GPIO_FLAG_NONE>; // Display pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-papers3/m5stack,papers3.dts b/Devices/m5stack-papers3/m5stack,papers3.dts index 946de1a79..3a3afde9e 100644 --- a/Devices/m5stack-papers3/m5stack,papers3.dts +++ b/Devices/m5stack-papers3/m5stack,papers3.dts @@ -43,6 +43,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 47 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 38 GPIO_FLAG_NONE>; pin-miso = <&gpio0 40 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-stackchan/m5stack,stackchan.dts b/Devices/m5stack-stackchan/m5stack,stackchan.dts index f046ebf0f..b81830f65 100644 --- a/Devices/m5stack-stackchan/m5stack,stackchan.dts +++ b/Devices/m5stack-stackchan/m5stack,stackchan.dts @@ -112,16 +112,18 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>, // SD card + <&gpio0 3 GPIO_FLAG_NONE>; // Display pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; - + sdcard@0 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; - + display@1 { compatible = "display-placeholder"; }; diff --git a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts index 86de033f8..4946efdcb 100644 --- a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts +++ b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts @@ -47,6 +47,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 13 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index e299548a3..5bfb45ebf 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -46,6 +46,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 13 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-sticks3/m5stack,sticks3.dts b/Devices/m5stack-sticks3/m5stack,sticks3.dts index 34dc0155a..14a3b34a4 100644 --- a/Devices/m5stack-sticks3/m5stack,sticks3.dts +++ b/Devices/m5stack-sticks3/m5stack,sticks3.dts @@ -53,6 +53,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 41 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; @@ -65,6 +66,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 7 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; diff --git a/Devices/m5stack-tab5/m5stack,tab5.dts b/Devices/m5stack-tab5/m5stack,tab5.dts index aea748d8b..c5d6d5428 100644 --- a/Devices/m5stack-tab5/m5stack,tab5.dts +++ b/Devices/m5stack-tab5/m5stack,tab5.dts @@ -82,6 +82,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 42 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 44 GPIO_FLAG_NONE>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 43 GPIO_FLAG_NONE>; diff --git a/Devices/unphone/unphone.dts b/Devices/unphone/unphone.dts index e46ad3b2b..99d7bd125 100644 --- a/Devices/unphone/unphone.dts +++ b/Devices/unphone/unphone.dts @@ -31,12 +31,23 @@ sdcard_spi: spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 48 GPIO_FLAG_NONE>, // Display + <&gpio0 38 GPIO_FLAG_NONE>, // Touch + <&gpio0 43 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 40 GPIO_FLAG_NONE>; pin-miso = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; max-transfer-size = <65536>; - - sdcard { + + display@0 { + compatible = "display-placeholder"; + }; + + touch@1 { + compatible = "touch-placeholder"; + }; + + sdcard@2 { compatible = "espressif,esp32-sdspi"; pin-cs = <&gpio0 43 GPIO_FLAG_NONE>; frequency-khz = <20000>; diff --git a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts index 40ff3582d..ef3db9a4b 100644 --- a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts +++ b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts @@ -33,6 +33,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; diff --git a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts index 7da91d261..85a10de7b 100644 --- a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts +++ b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts @@ -39,6 +39,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 39 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; @@ -50,6 +51,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 17 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 18 GPIO_FLAG_NONE>; pin-miso = <&gpio0 16 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 21 GPIO_FLAG_NONE>; diff --git a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts index da213dbda..22298c064 100644 --- a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts +++ b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts @@ -39,6 +39,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 9 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 10 GPIO_FLAG_NONE>; @@ -51,6 +52,7 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 18 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 16 GPIO_FLAG_NONE>; pin-miso = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 17 GPIO_FLAG_NONE>; diff --git a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts index 0877d8131..4f6ee5bd8 100644 --- a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts +++ b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts @@ -32,8 +32,13 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 21 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 38 GPIO_FLAG_NONE>; + + display { + compatible = "display-placeholder"; + }; }; spi1 { diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index 8be9aeb7d..b868a57b1 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -32,6 +32,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; diff --git a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts index a09f37a61..f0a6c2b65 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts +++ b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts @@ -31,6 +31,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 41 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 40 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; diff --git a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp index 14551a27c..e80297d33 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp @@ -6,6 +6,7 @@ #include "tactility/drivers/gpio_descriptor.h" #include +#include #include #include #include @@ -117,6 +118,18 @@ static error_t start(Device* device) { return ERROR_RESOURCE; } + // Deselect all CS pins (drive high) before any SPI communication + const GpioPinSpec* cs = dts_config->cs_gpios; + while (cs->gpio_controller != nullptr) { + GpioDescriptor* desc = gpio_descriptor_acquire(cs->gpio_controller, cs->pin, GPIO_OWNER_SPI); + if (desc != nullptr) { + gpio_descriptor_set_flags(desc, GPIO_FLAG_DIRECTION_OUTPUT); + gpio_descriptor_set_level(desc, true); + gpio_descriptor_release(desc); + } + cs++; + } + data->initialized = true; return ERROR_NONE; } diff --git a/TactilityKernel/bindings/touch-placeholder.yaml b/TactilityKernel/bindings/touch-placeholder.yaml new file mode 100644 index 000000000..e41b29659 --- /dev/null +++ b/TactilityKernel/bindings/touch-placeholder.yaml @@ -0,0 +1,5 @@ +description: Touch placeholder + +compatible: "touch-placeholder" + +properties: {} diff --git a/TactilityKernel/include/tactility/bindings/touch_placeholder.h b/TactilityKernel/include/tactility/bindings/touch_placeholder.h new file mode 100644 index 000000000..ac0524158 --- /dev/null +++ b/TactilityKernel/include/tactility/bindings/touch_placeholder.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(touch_placeholder, struct TouchPlaceholderConfig) + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/drivers/touch.h b/TactilityKernel/include/tactility/drivers/touch.h new file mode 100644 index 000000000..071aff778 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/touch.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +extern const struct DeviceType TOUCH_TYPE; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/include/tactility/drivers/touch_placeholder.h b/TactilityKernel/include/tactility/drivers/touch_placeholder.h new file mode 100644 index 000000000..62b46b91b --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/touch_placeholder.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct TouchPlaceholderConfig { + uint8_t _unused; +}; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/source/drivers/touch.cpp b/TactilityKernel/source/drivers/touch.cpp new file mode 100644 index 000000000..f324ebb8f --- /dev/null +++ b/TactilityKernel/source/drivers/touch.cpp @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +extern "C" { + +const struct DeviceType TOUCH_TYPE { + .name = "touch" +}; + +} diff --git a/TactilityKernel/source/drivers/touch_placeholder.cpp b/TactilityKernel/source/drivers/touch_placeholder.cpp new file mode 100644 index 000000000..4b76be3e2 --- /dev/null +++ b/TactilityKernel/source/drivers/touch_placeholder.cpp @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include +#include + +extern "C" { + +static error_t start(Device*) { return ERROR_NONE; } +static error_t stop(Device*) { return ERROR_NONE; } + +extern Module root_module; + +Driver touch_placeholder_driver = { + .name = "touch_placeholder", + .compatible = (const char*[]) { "touch-placeholder", nullptr }, + .start_device = start, + .stop_device = stop, + .api = nullptr, + .device_type = &TOUCH_TYPE, + .owner = &root_module, + .internal = nullptr +}; + +} diff --git a/TactilityKernel/source/kernel_init.cpp b/TactilityKernel/source/kernel_init.cpp index 9c99278f2..16d0be818 100644 --- a/TactilityKernel/source/kernel_init.cpp +++ b/TactilityKernel/source/kernel_init.cpp @@ -16,6 +16,8 @@ static error_t start() { if (driver_construct_add(&root_driver) != ERROR_NONE) return ERROR_RESOURCE; extern Driver display_placeholder_driver; if (driver_construct_add(&display_placeholder_driver) != ERROR_NONE) return ERROR_RESOURCE; + extern Driver touch_placeholder_driver; + if (driver_construct_add(&touch_placeholder_driver) != ERROR_NONE) return ERROR_RESOURCE; extern Driver spi_peripheral_driver; if (driver_construct_add(&spi_peripheral_driver) != ERROR_NONE) return ERROR_RESOURCE; return ERROR_NONE; From 8f55942f3ecca5574298edfea3335719e2f4b02b Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 00:18:01 +0200 Subject: [PATCH 08/19] Fix for test and devicetree compiler --- Buildscripts/DevicetreeCompiler/source/generator.py | 6 ++++-- .../DevicetreeCompiler/tests/data/expected_devicetree.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index 04f89eeeb..d372357bc 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -20,8 +20,10 @@ def write_define(file, define: DefineC, verbose: bool): def get_device_node_name_safe(device: Device): if device.node_name == "/": return "root" - else: - return device.node_name.replace("-", "_") + name = device.node_name.replace("-", "_") + if device.node_address is not None: + name += "_" + device.node_address.replace("-", "_") + return name def get_device_type_name(device: Device, bindings: list[Binding]): device_binding = find_device_binding(device, bindings) diff --git a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c index 207ecff44..866ed3544 100644 --- a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c +++ b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c @@ -10,6 +10,7 @@ static const root_config_dt root_config = { }; static struct Device root = { + .address = 0, .name = "/", .config = &root_config, .parent = NULL, From f42b3b30b002806e76399cfe9a0398618d36961a Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 00:22:03 +0200 Subject: [PATCH 09/19] Fix for test --- .../tests/data/expected_devicetree.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c index 866ed3544..925b6aff5 100644 --- a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c +++ b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c @@ -10,22 +10,23 @@ static const root_config_dt root_config = { }; static struct Device root = { - .address = 0, + .address = 0, .name = "/", .config = &root_config, .parent = NULL, .internal = NULL }; -static const generic_device_config_dt test_device@0_config = { +static const generic_device_config_dt test_device_0_config = { 0, 42, "hello" }; -static struct Device test_device@0 = { +static struct Device test_device_0 = { + .address = 0, .name = "test-device@0", - .config = &test_device@0_config, + .config = &test_device_0_config, .parent = &root, .internal = NULL }; @@ -47,7 +48,7 @@ static struct Device bool_test_device = { struct DtsDevice dts_devices[] = { { &root, "test,root", DTS_DEVICE_STATUS_OKAY }, - { &test_device@0, "test,generic-device", DTS_DEVICE_STATUS_OKAY }, + { &test_device_0, "test,generic-device", DTS_DEVICE_STATUS_OKAY }, { &bool_test_device, "test,bool-device", DTS_DEVICE_STATUS_OKAY }, DTS_DEVICE_TERMINATOR }; From 52736f8a678842d7ec225ac8c094f6df9b8fce82 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 00:26:27 +0200 Subject: [PATCH 10/19] Remove unused headers --- Devices/cyd-2432s024c/Source/Configuration.cpp | 1 - Devices/cyd-2432s024r/Source/Configuration.cpp | 2 -- Devices/cyd-2432s028r/Source/Configuration.cpp | 1 - Devices/cyd-2432s028rv3/Source/Configuration.cpp | 1 - Devices/cyd-4848s040c/Source/Configuration.cpp | 3 --- Devices/cyd-8048s043c/Source/Configuration.cpp | 1 - Devices/cyd-e32r28t/Source/Configuration.cpp | 1 - Devices/cyd-e32r32p/Source/Configuration.cpp | 2 -- Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp | 1 - Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp | 1 - Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp | 1 - Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp | 1 - Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp | 1 - Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp | 1 - .../guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp | 1 - Devices/guition-jc3248w535c/Source/Configuration.cpp | 1 - Devices/guition-jc8048w550c/Source/Configuration.cpp | 1 - Devices/lilygo-tdeck/Source/Configuration.cpp | 1 - Devices/lilygo-tlora-pager/Source/Configuration.cpp | 1 - Devices/m5stack-cardputer-adv/Source/Configuration.cpp | 1 - Devices/m5stack-cardputer/Source/Configuration.cpp | 1 - Devices/m5stack-cores3/Source/Configuration.cpp | 1 - Devices/m5stack-stackchan/Source/Configuration.cpp | 1 - Devices/m5stack-stickc-plus2/Source/Configuration.cpp | 1 - Devices/m5stack-sticks3/Source/Configuration.cpp | 1 - Devices/waveshare-s3-lcd-13/Source/Configuration.cpp | 1 - Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp | 1 - Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp | 1 - 28 files changed, 32 deletions(-) diff --git a/Devices/cyd-2432s024c/Source/Configuration.cpp b/Devices/cyd-2432s024c/Source/Configuration.cpp index a6d9b6164..1674ceca4 100644 --- a/Devices/cyd-2432s024c/Source/Configuration.cpp +++ b/Devices/cyd-2432s024c/Source/Configuration.cpp @@ -2,7 +2,6 @@ #include #include -#include #include static bool initBoot() { diff --git a/Devices/cyd-2432s024r/Source/Configuration.cpp b/Devices/cyd-2432s024r/Source/Configuration.cpp index 1f715033f..91782dd35 100644 --- a/Devices/cyd-2432s024r/Source/Configuration.cpp +++ b/Devices/cyd-2432s024r/Source/Configuration.cpp @@ -1,8 +1,6 @@ #include "devices/Display.h" -#include #include -#include #include using namespace tt::hal; diff --git a/Devices/cyd-2432s028r/Source/Configuration.cpp b/Devices/cyd-2432s028r/Source/Configuration.cpp index bf458b5cb..b979797e1 100644 --- a/Devices/cyd-2432s028r/Source/Configuration.cpp +++ b/Devices/cyd-2432s028r/Source/Configuration.cpp @@ -2,7 +2,6 @@ #include #include -#include #include using namespace tt::hal; diff --git a/Devices/cyd-2432s028rv3/Source/Configuration.cpp b/Devices/cyd-2432s028rv3/Source/Configuration.cpp index bf458b5cb..b979797e1 100644 --- a/Devices/cyd-2432s028rv3/Source/Configuration.cpp +++ b/Devices/cyd-2432s028rv3/Source/Configuration.cpp @@ -2,7 +2,6 @@ #include #include -#include #include using namespace tt::hal; diff --git a/Devices/cyd-4848s040c/Source/Configuration.cpp b/Devices/cyd-4848s040c/Source/Configuration.cpp index e8c7701d1..28f7637c3 100644 --- a/Devices/cyd-4848s040c/Source/Configuration.cpp +++ b/Devices/cyd-4848s040c/Source/Configuration.cpp @@ -1,9 +1,6 @@ #include "devices/St7701Display.h" -#include #include -#include -#include #include using namespace tt::hal; diff --git a/Devices/cyd-8048s043c/Source/Configuration.cpp b/Devices/cyd-8048s043c/Source/Configuration.cpp index d4fc2b98c..fb4a31a9d 100644 --- a/Devices/cyd-8048s043c/Source/Configuration.cpp +++ b/Devices/cyd-8048s043c/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include #include diff --git a/Devices/cyd-e32r28t/Source/Configuration.cpp b/Devices/cyd-e32r28t/Source/Configuration.cpp index 387502f4b..620a05fe5 100644 --- a/Devices/cyd-e32r28t/Source/Configuration.cpp +++ b/Devices/cyd-e32r28t/Source/Configuration.cpp @@ -1,7 +1,6 @@ #include "devices/Display.h" #include -#include #include static bool initBoot() { diff --git a/Devices/cyd-e32r32p/Source/Configuration.cpp b/Devices/cyd-e32r32p/Source/Configuration.cpp index 77ac6fbc9..a7a18f6a3 100644 --- a/Devices/cyd-e32r32p/Source/Configuration.cpp +++ b/Devices/cyd-e32r32p/Source/Configuration.cpp @@ -1,9 +1,7 @@ #include "devices/Display.h" #include "devices/Power.h" -#include #include -#include #include using namespace tt::hal; diff --git a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp index 1cbf523da..168fa4a68 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include #include diff --git a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp index 0e8b0418d..1e27e3438 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp index 73b8fca3c..42d3e88a3 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp index 59cf64f6b..f413f9d3e 100644 --- a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include #include diff --git a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp index 59cf64f6b..f413f9d3e 100644 --- a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include #include diff --git a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp index 7fbe23221..0d7f313eb 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp index e2c8bc4e0..762cd41ab 100644 --- a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp +++ b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/Devices/guition-jc3248w535c/Source/Configuration.cpp b/Devices/guition-jc3248w535c/Source/Configuration.cpp index f35f8e659..cf1a8f69c 100644 --- a/Devices/guition-jc3248w535c/Source/Configuration.cpp +++ b/Devices/guition-jc3248w535c/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/guition-jc8048w550c/Source/Configuration.cpp b/Devices/guition-jc8048w550c/Source/Configuration.cpp index f19ffaf92..3e384edb3 100644 --- a/Devices/guition-jc8048w550c/Source/Configuration.cpp +++ b/Devices/guition-jc8048w550c/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "PwmBacklight.h" #include "devices/Display.h" -#include #include diff --git a/Devices/lilygo-tdeck/Source/Configuration.cpp b/Devices/lilygo-tdeck/Source/Configuration.cpp index 3eca6c8e9..fc6af509b 100644 --- a/Devices/lilygo-tdeck/Source/Configuration.cpp +++ b/Devices/lilygo-tdeck/Source/Configuration.cpp @@ -5,7 +5,6 @@ #include "devices/TrackballDevice.h" #include -#include #include #include diff --git a/Devices/lilygo-tlora-pager/Source/Configuration.cpp b/Devices/lilygo-tlora-pager/Source/Configuration.cpp index 9be746363..5309e1aeb 100644 --- a/Devices/lilygo-tlora-pager/Source/Configuration.cpp +++ b/Devices/lilygo-tlora-pager/Source/Configuration.cpp @@ -2,7 +2,6 @@ #include "devices/TpagerEncoder.h" #include "devices/TpagerKeyboard.h" #include "devices/TpagerPower.h" -#include #include #include diff --git a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp index 41906807f..81001b2c2 100644 --- a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp @@ -1,7 +1,6 @@ #include "devices/Display.h" #include "devices/CardputerKeyboard.h" #include "devices/CardputerPower.h" -#include #include #include diff --git a/Devices/m5stack-cardputer/Source/Configuration.cpp b/Devices/m5stack-cardputer/Source/Configuration.cpp index d7f52ed0c..cb40a59d5 100644 --- a/Devices/m5stack-cardputer/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer/Source/Configuration.cpp @@ -2,7 +2,6 @@ #include "devices/CardputerEncoder.h" #include "devices/CardputerKeyboard.h" #include "devices/CardputerPower.h" -#include #include #include diff --git a/Devices/m5stack-cores3/Source/Configuration.cpp b/Devices/m5stack-cores3/Source/Configuration.cpp index cad04d565..f848637da 100644 --- a/Devices/m5stack-cores3/Source/Configuration.cpp +++ b/Devices/m5stack-cores3/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "InitBoot.h" #include "devices/Display.h" -#include #include #include diff --git a/Devices/m5stack-stackchan/Source/Configuration.cpp b/Devices/m5stack-stackchan/Source/Configuration.cpp index 3a1eea9d5..2faa63b30 100644 --- a/Devices/m5stack-stackchan/Source/Configuration.cpp +++ b/Devices/m5stack-stackchan/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "devices/Display.h" #include "devices/Power.h" -#include #include #include diff --git a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp index d6307a618..c4bc35148 100644 --- a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/m5stack-sticks3/Source/Configuration.cpp b/Devices/m5stack-sticks3/Source/Configuration.cpp index 501726d02..6a0fbf159 100644 --- a/Devices/m5stack-sticks3/Source/Configuration.cpp +++ b/Devices/m5stack-sticks3/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "devices/Display.h" #include "devices/Power.h" -#include #include #include diff --git a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp index b8d6553da..6b77798ba 100644 --- a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp +++ b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp index c78cfff15..626c12a9b 100644 --- a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include diff --git a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp index ce0fb67f9..5cb40ebcf 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp +++ b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp @@ -1,5 +1,4 @@ #include "devices/Display.h" -#include #include #include From c12f6e4a5bfd0dcadfa34d2b037e5b81960dda32 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 00:29:05 +0200 Subject: [PATCH 11/19] Fix for test --- .../DevicetreeCompiler/tests/data/expected_devicetree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c index 925b6aff5..3a3202f83 100644 --- a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c +++ b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c @@ -25,7 +25,7 @@ static const generic_device_config_dt test_device_0_config = { static struct Device test_device_0 = { .address = 0, - .name = "test-device@0", + .name = "test-device", .config = &test_device_0_config, .parent = &root, .internal = NULL @@ -40,6 +40,7 @@ static const bool_device_config_dt bool_test_device_config = { }; static struct Device bool_test_device = { + .address = 0, .name = "bool-test-device", .config = &bool_test_device_config, .parent = &root, From 9761296b92c9a161586f5c213d79357fa160e3d1 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 00:43:08 +0200 Subject: [PATCH 12/19] Fix for device name --- Devices/cyd-2432s032c/cyd,2432s032c.dts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 796fbe273..0f7cf44cb 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -11,7 +11,7 @@ compatible = "root"; model = "CYD 2432S032C"; - gpio1 { + gpio0 { compatible = "espressif,esp32-gpio"; gpio-count = <40>; }; @@ -20,16 +20,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <&gpio1 33 GPIO_FLAG_NONE>; - pin-scl = <&gpio1 32 GPIO_FLAG_NONE>; + pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; }; spi0 { compatible = "espressif,esp32-spi"; host = ; cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>; - pin-mosi = <&gpio1 13 GPIO_FLAG_NONE>; - pin-sclk = <&gpio1 14 GPIO_FLAG_NONE>; + pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; display { compatible = "display-placeholder"; @@ -40,9 +40,9 @@ compatible = "espressif,esp32-spi"; host = ; cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; - pin-mosi = <&gpio1 23 GPIO_FLAG_NONE>; - pin-miso = <&gpio1 19 GPIO_FLAG_NONE>; - pin-sclk = <&gpio1 18 GPIO_FLAG_NONE>; + pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; + pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; sdcard { compatible = "espressif,esp32-sdspi"; From 8711521a36a7a164b11bdcacf1ff72a2f5979df0 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 08:55:10 +0200 Subject: [PATCH 13/19] Trigger GitHub Action From 4909b7075b9474c70a6e97a1ef180c0d65169fcd Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 18:14:08 +0200 Subject: [PATCH 14/19] WIP --- .../source/binding_parser.py | 1 + .../DevicetreeCompiler/source/generator.py | 80 ++++++++++++++----- .../DevicetreeCompiler/source/models.py | 1 + Devices/cyd-2432s024c/cyd,2432s024c.dts | 3 +- Devices/cyd-2432s024r/cyd,2432s024r.dts | 3 +- Devices/cyd-2432s028r/cyd,2432s028r.dts | 3 +- Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts | 3 +- Devices/cyd-2432s032c/cyd,2432s032c.dts | 3 +- Devices/cyd-3248s035c/cyd,3248s035c.dts | 3 +- Devices/cyd-4848s040c/cyd,4848s040c.dts | 3 +- Devices/cyd-8048s043c/cyd,8048s043c.dts | 3 +- Devices/cyd-e32r28t/cyd,e32r28t.dts | 3 +- Devices/cyd-e32r32p/cyd,e32r32p.dts | 3 +- .../elecrow,crowpanel-advance-28.dts | 3 +- .../elecrow,crowpanel-advance-35.dts | 3 +- .../elecrow,crowpanel-advance-50.dts | 3 +- .../elecrow,crowpanel-basic-28.dts | 3 +- .../elecrow,crowpanel-basic-35.dts | 3 +- .../elecrow,crowpanel-basic-50.dts | 3 +- .../guition,jc2432w328c.dts | 3 +- .../guition,jc3248w535c.dts | 5 +- .../guition,jc8048w550c.dts | 3 +- Devices/lilygo-tdeck/Source/Init.cpp | 1 - Devices/lilygo-tdeck/lilygo,tdeck.dts | 4 +- Devices/lilygo-thmi/lilygo,thmi.dts | 2 + .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 1 - .../m5stack,cardputer-adv.dts | 3 +- .../m5stack-cardputer/m5stack,cardputer.dts | 3 +- Devices/m5stack-core2/m5stack,core2.dts | 1 - Devices/m5stack-cores3/m5stack,cores3.dts | 1 - Devices/m5stack-papers3/m5stack,papers3.dts | 3 +- .../m5stack-stackchan/m5stack,stackchan.dts | 1 - Devices/m5stack-sticks3/m5stack,sticks3.dts | 3 +- Devices/unphone/unphone.dts | 3 +- .../waveshare,s3-lcd-13.dts | 3 +- .../waveshare,s3-touch-lcd-128.dts | 3 +- .../waveshare,s3-touch-lcd-147.dts | 5 +- .../waveshare,s3-touch-lcd-43.dts | 3 +- .../wireless-tag,wt32-sc01-plus.dts | 3 +- .../bindings/espressif,esp32-grove.yaml | 4 +- .../bindings/espressif,esp32-i2c-master.yaml | 4 +- .../bindings/espressif,esp32-i2c.yaml | 4 +- .../bindings/espressif,esp32-i2s.yaml | 10 +-- .../bindings/espressif,esp32-sdmmc.yaml | 24 +++--- .../bindings/espressif,esp32-sdspi.yaml | 10 +-- .../bindings/espressif,esp32-spi.yaml | 13 +-- .../bindings/espressif,esp32-uart.yaml | 8 +- .../include/tactility/drivers/esp32_sdspi.h | 1 - .../include/tactility/drivers/esp32_spi.h | 23 +++++- .../tactility/drivers/esp32_sdspi_fs.h | 2 +- .../source/drivers/bluetooth/esp32_ble.cpp | 2 +- .../source/drivers/esp32_i2c.cpp | 3 +- .../source/drivers/esp32_sdspi.cpp | 22 ++++- .../source/drivers/esp32_sdspi_fs.cpp | 10 ++- .../source/drivers/esp32_spi.cpp | 38 +++++++-- TactilityKernel/bindings/spi-peripheral.yaml | 8 +- .../tactility/drivers/spi_peripheral.h | 10 +-- TactilityKernel/include/tactility/error.h | 1 + .../source/drivers/spi_peripheral.cpp | 55 +------------ 59 files changed, 227 insertions(+), 209 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/binding_parser.py b/Buildscripts/DevicetreeCompiler/source/binding_parser.py index 2b4889431..538d3c06d 100644 --- a/Buildscripts/DevicetreeCompiler/source/binding_parser.py +++ b/Buildscripts/DevicetreeCompiler/source/binding_parser.py @@ -45,6 +45,7 @@ def parse_binding(file_path: str, binding_dirs: list[str]) -> Binding: required=details.get('required', False), description=details.get('description', '').strip(), default=details.get('default', None), + element_type=details.get('element-type', None), ) properties_dict[name] = prop filename = os.path.basename(file_path) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index d372357bc..7980f31ce 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -20,10 +20,8 @@ def write_define(file, define: DefineC, verbose: bool): def get_device_node_name_safe(device: Device): if device.node_name == "/": return "root" - name = device.node_name.replace("-", "_") - if device.node_address is not None: - name += "_" + device.node_address.replace("-", "_") - return name + else: + return device.node_name.replace("-", "_") def get_device_type_name(device: Device, bindings: list[Binding]): device_binding = find_device_binding(device, bindings) @@ -82,7 +80,7 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: return "{ " + ",".join(value_list) + " }" elif type == "phandle": return find_phandle(devices, property.value) - elif type == "phandle-array": + elif type == "phandles": value_list = list() if isinstance(property.value, list): for item in property.value: @@ -90,16 +88,31 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: value_list.append(property_to_string(DeviceProperty(name="", type=item.type, value=item.value), devices)) else: value_list.append(str(item)) - value_list.append("{ 0 }") return "{ " + ",".join(value_list) + " }" elif isinstance(property.value, str): # If it's a string, assume it's a #define and show it as-is return property.value else: - raise Exception(f"Unsupported phandle-array type for {property.value}") + raise Exception(f"Unsupported phandles type for {property.name} with value {property.value} ") else: raise DevicetreeException(f"property_to_string() has an unsupported type: {type}") +def resolve_phandle_array_entries(device_property, devices): + """Convert a phandle-array DTS property into a list of C initializer strings.""" + entries = [] + if device_property.type == "phandle-array": + items = device_property.value + elif device_property.type == "values": + items = [PropertyValue(type="values", value=device_property.value)] + else: + return [] + for item in items: + if isinstance(item, PropertyValue): + entries.append(property_to_string(DeviceProperty(name="", type=item.type, value=item.value), devices)) + else: + entries.append(str(item)) + return entries + def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], devices: list[Device]) -> list: compatible_property = find_device_property(device, "compatible") if compatible_property is None: @@ -122,11 +135,32 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de if device_property.name not in binding_property_names: raise DevicetreeException(f"Device '{device.node_name}' has invalid property '{device_property.name}'") - # Allocate total expected configuration arguments - result = [0] * len(binding_properties) - for index, binding_property in enumerate(binding_properties): + node_name = get_device_node_name_safe(device) + result = [] + phandle_arrays = [] + for binding_property in binding_properties: device_property = find_device_property(device, binding_property.name) - # No property specified in DTS, use binding defaults + + if binding_property.type == "phandle-array": + if binding_property.element_type is None: + raise DevicetreeException(f"phandle-array property '{binding_property.name}' requires 'element-type' in binding") + prop_safe = binding_property.name.replace("-", "_") + array_var = f"{node_name}_{prop_safe}" + if device_property is not None: + entries = resolve_phandle_array_entries(device_property, devices) + phandle_arrays.append((array_var, binding_property.element_type, entries)) + result.append(f"({binding_property.element_type}*){array_var}") + result.append(str(len(entries))) + elif binding_property.default is not None: + result.append("NULL") + result.append("0") + elif binding_property.required: + raise DevicetreeException(f"device {device.node_name} doesn't have property '{binding_property.name}'") + else: + result.append("NULL") + result.append("0") + continue + if device_property is None: if binding_property.default is not None: temp_prop = DeviceProperty( @@ -134,30 +168,38 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de type=binding_property.type, value=binding_property.default ) - result[index] = property_to_string(temp_prop, devices) + result.append(property_to_string(temp_prop, devices)) elif binding_property.required: raise DevicetreeException(f"device {device.node_name} doesn't have property '{binding_property.name}'") elif binding_property.type == "bool" or binding_property.type == "boolean": if binding_property.default == "true" or binding_property.default == None: - result[index] = "true" - else: # Explicit or implied false - result[index] = "false" + result.append("true") + else: + result.append("false") else: raise DevicetreeException(f"Device {device.node_name} doesn't have property '{binding_property.name}' and no default value is set") else: - result[index] = property_to_string(device_property, devices) - return result + result.append(property_to_string(device_property, devices)) + + return result, phandle_arrays def write_config(file, device: Device, bindings: list[Binding], devices: list[Device], type_name: str): node_name = get_device_node_name_safe(device) config_type = f"{type_name}_config_dt" config_variable_name = f"{node_name}_config" + + config_params, phandle_arrays = resolve_parameters_from_bindings(device, bindings, devices) + + # Write phandle-array variables before the config struct + for array_var, element_type, entries in phandle_arrays: + entries_str = ", ".join(entries) + file.write(f"static {element_type} {array_var}[] = {{ {entries_str} }};\n") + file.write(f"static const {config_type} {config_variable_name}" " = {\n") - config_params = resolve_parameters_from_bindings(device, bindings, devices) # Indent all params for index, config_param in enumerate(config_params): config_params[index] = f"\t{config_param}" - # Join with command and newline + # Join with comma and newline if len(config_params) > 0: config_params_joined = ",\n".join(config_params) file.write(f"{config_params_joined}\n") diff --git a/Buildscripts/DevicetreeCompiler/source/models.py b/Buildscripts/DevicetreeCompiler/source/models.py index 761d25caf..e1b8aeabd 100644 --- a/Buildscripts/DevicetreeCompiler/source/models.py +++ b/Buildscripts/DevicetreeCompiler/source/models.py @@ -39,6 +39,7 @@ class BindingProperty: required: bool description: str default: object = None + element_type: str = None @dataclass class Binding: diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index d9d390de9..621aaca5d 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -44,9 +44,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-2432s024r/cyd,2432s024r.dts b/Devices/cyd-2432s024r/cyd,2432s024r.dts index 5ae5207bc..db1aaed33 100644 --- a/Devices/cyd-2432s024r/cyd,2432s024r.dts +++ b/Devices/cyd-2432s024r/cyd,2432s024r.dts @@ -43,9 +43,8 @@ pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 41f635429..8d27feee2 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -52,9 +52,8 @@ pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index 97ab5a6ec..492dba5cb 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -52,9 +52,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 0f7cf44cb..bd0f62bfd 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -44,9 +44,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-3248s035c/cyd,3248s035c.dts b/Devices/cyd-3248s035c/cyd,3248s035c.dts index f02d78794..2f71a5cf5 100644 --- a/Devices/cyd-3248s035c/cyd,3248s035c.dts +++ b/Devices/cyd-3248s035c/cyd,3248s035c.dts @@ -54,9 +54,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-4848s040c/cyd,4848s040c.dts b/Devices/cyd-4848s040c/cyd,4848s040c.dts index e3649e7c7..fa6cd8baf 100644 --- a/Devices/cyd-4848s040c/cyd,4848s040c.dts +++ b/Devices/cyd-4848s040c/cyd,4848s040c.dts @@ -36,9 +36,8 @@ pin-miso = <&gpio0 41 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 48 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 42 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 63e93d34a..730eb9884 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -45,9 +45,8 @@ pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-e32r28t/cyd,e32r28t.dts b/Devices/cyd-e32r28t/cyd,e32r28t.dts index 942205083..be36a8dac 100644 --- a/Devices/cyd-e32r28t/cyd,e32r28t.dts +++ b/Devices/cyd-e32r28t/cyd,e32r28t.dts @@ -42,9 +42,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/cyd-e32r32p/cyd,e32r32p.dts b/Devices/cyd-e32r32p/cyd,e32r32p.dts index 383c8d879..af6ade973 100644 --- a/Devices/cyd-e32r32p/cyd,e32r32p.dts +++ b/Devices/cyd-e32r32p/cyd,e32r32p.dts @@ -51,9 +51,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index 166075d3d..6388a74e9 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -50,9 +50,8 @@ pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 7 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index 314594ed8..ba9055274 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -50,9 +50,8 @@ pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 7 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index f6e536231..331297d1d 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -37,9 +37,8 @@ pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 0 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index dc95198b9..8ed72e950 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -53,9 +53,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index 11cf4f456..dfd3d36e3 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -53,9 +53,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index 2f8106745..9ce72f33f 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -37,9 +37,8 @@ pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index c96a6a8f7..2b7c7ac99 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -54,9 +54,8 @@ pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 5 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index 13a14ef43..f2d9542e3 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -8,6 +8,7 @@ #include #include #include +#include / { compatible = "root"; @@ -64,13 +65,13 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 10 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index dba67451e..31840e3dd 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -55,9 +55,8 @@ pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/lilygo-tdeck/Source/Init.cpp b/Devices/lilygo-tdeck/Source/Init.cpp index b0635dbe5..14386e363 100644 --- a/Devices/lilygo-tdeck/Source/Init.cpp +++ b/Devices/lilygo-tdeck/Source/Init.cpp @@ -11,7 +11,6 @@ static const auto LOGGER = tt::Logger("T-Deck"); -// Power on constexpr auto TDECK_POWERON_GPIO = GPIO_NUM_10; static bool powerOn() { diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index 331a7e99d..e5448ee00 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -45,6 +45,7 @@ compatible = "espressif,esp32-spi"; host = ; cs-gpios = <&gpio0 12 GPIO_FLAG_NONE>, // Display + <&gpio0 9 GPIO_FLAG_NONE>, // Radio <&gpio0 39 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; @@ -54,9 +55,8 @@ compatible = "display-placeholder"; }; - sdcard@1 { + sdcard@2 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 39 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/lilygo-thmi/lilygo,thmi.dts b/Devices/lilygo-thmi/lilygo,thmi.dts index 93e080900..256f06973 100644 --- a/Devices/lilygo-thmi/lilygo,thmi.dts +++ b/Devices/lilygo-thmi/lilygo,thmi.dts @@ -6,6 +6,8 @@ #include #include #include +#include +#include / { compatible = "root"; diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index d6b38f7ec..b72631095 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -43,7 +43,6 @@ sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 21 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index a004ab1e9..7d82145e2 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -69,9 +69,8 @@ pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 12 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index f652eb60a..024db4d38 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -55,9 +55,8 @@ pin-miso = <&gpio0 39 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 12 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index 0269b04dc..95c6c13b9 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -61,7 +61,6 @@ sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index c6eba128b..c9057f907 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -86,7 +86,6 @@ sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; diff --git a/Devices/m5stack-papers3/m5stack,papers3.dts b/Devices/m5stack-papers3/m5stack,papers3.dts index 3a3afde9e..6ff6dcd3c 100644 --- a/Devices/m5stack-papers3/m5stack,papers3.dts +++ b/Devices/m5stack-papers3/m5stack,papers3.dts @@ -49,9 +49,8 @@ pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; max-transfer-size = <4096>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 47 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/m5stack-stackchan/m5stack,stackchan.dts b/Devices/m5stack-stackchan/m5stack,stackchan.dts index b81830f65..b20828af4 100644 --- a/Devices/m5stack-stackchan/m5stack,stackchan.dts +++ b/Devices/m5stack-stackchan/m5stack,stackchan.dts @@ -120,7 +120,6 @@ sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 4 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; diff --git a/Devices/m5stack-sticks3/m5stack,sticks3.dts b/Devices/m5stack-sticks3/m5stack,sticks3.dts index 14a3b34a4..3b73d85b9 100644 --- a/Devices/m5stack-sticks3/m5stack,sticks3.dts +++ b/Devices/m5stack-sticks3/m5stack,sticks3.dts @@ -71,9 +71,8 @@ pin-miso = <&gpio0 4 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 7 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/unphone/unphone.dts b/Devices/unphone/unphone.dts index 99d7bd125..b7a53c21a 100644 --- a/Devices/unphone/unphone.dts +++ b/Devices/unphone/unphone.dts @@ -6,6 +6,8 @@ #include #include #include +#include +#include / { compatible = "root"; @@ -49,7 +51,6 @@ sdcard@2 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 43 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts index 85a10de7b..389d019b8 100644 --- a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts +++ b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts @@ -56,9 +56,8 @@ pin-miso = <&gpio0 16 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 21 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 17 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts index 22298c064..6240644bb 100644 --- a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts +++ b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts @@ -57,9 +57,8 @@ pin-miso = <&gpio0 15 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 17 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 18 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts index 4f6ee5bd8..c1dde4935 100644 --- a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts +++ b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts @@ -6,6 +6,7 @@ #include #include #include +#include // Reference: https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.47 / { @@ -44,13 +45,13 @@ spi1 { compatible = "espressif,esp32-spi"; host = ; + cs-gpios = <&gpio0 14 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>; pin-miso = <&gpio0 17 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 16 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 14 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index b868a57b1..49bca91be 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -37,9 +37,8 @@ pin-miso = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 10 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts index f0a6c2b65..e95def9c5 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts +++ b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts @@ -36,9 +36,8 @@ pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>; - sdcard { + sdcard@0 { compatible = "espressif,esp32-sdspi"; - pin-cs = <&gpio0 41 GPIO_FLAG_NONE>; frequency-khz = <20000>; }; }; diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-grove.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-grove.yaml index 7c6608736..34a76e7cd 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-grove.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-grove.yaml @@ -8,11 +8,11 @@ properties: required: true description: "One of enum Esp32GroveMode" pinSdaTx: - type: phandle-array + type: phandles required: true description: SDA (I2C) or TX (UART) pin pinSclRx: - type: phandle-array + type: phandles required: true description: SCL (I2C) or RX (UART) pin uartPort: diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-i2c-master.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-i2c-master.yaml index 7424f5787..ad8b7280e 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-i2c-master.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-i2c-master.yaml @@ -22,8 +22,8 @@ properties: Clock source for the I2C peripheral. If not specified, a default clock source will be used. pin-sda: - type: phandle-array + type: phandles required: true pin-scl: - type: phandle-array + type: phandles required: true diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-i2c.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-i2c.yaml index 96a2de0fc..8e49df801 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-i2c.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-i2c.yaml @@ -16,8 +16,8 @@ properties: required: true description: Initial clock frequency in Hz pin-sda: - type: phandle-array + type: phandles required: true pin-scl: - type: phandle-array + type: phandles required: true diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-i2s.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-i2s.yaml index a0f5c1862..6406e63e7 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-i2s.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-i2s.yaml @@ -12,22 +12,22 @@ properties: The port number, defined by i2s_port_t. Depending on the hardware, these values are available: I2S_NUM_0, I2S_NUM_1 pin-bclk: - type: phandle-array + type: phandles required: true description: Bit clock pin pin-ws: - type: phandle-array + type: phandles required: true description: Word (slot) select pin pin-data-out: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: Data output pin pin-data-in: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: Data input pin pin-mclk: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: Master clock pin diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml index 0de6815d7..2426c83a9 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml @@ -4,40 +4,40 @@ compatible: "espressif,esp32-sdmmc" properties: pin-clk: - type: phandle-array + type: phandles required: true pin-cmd: - type: phandle-array + type: phandles required: true pin-d0: - type: phandle-array + type: phandles required: true pin-d1: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-d2: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-d3: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-d4: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-d5: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-d6: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-d7: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-cd: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-wp: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE bus-width: type: int diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml index 45c4d0e06..5ad74507c 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-sdspi.yaml @@ -5,20 +5,16 @@ compatible: "espressif,esp32-sdspi" bus: spi properties: - pin-cs: - type: phandle-array - required: true - description: Chip select GPIO pin-cd: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: Card detect GPIO pin-wp: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: Write protect GPIO pin-int: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: Interrupt GPIO frequency-khz: diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml index d2aa437d6..95e16a878 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-spi.yaml @@ -12,22 +12,22 @@ properties: The SPI host (controller) to use. Defined by spi_host_device_t (e.g. SPI2_HOST, SPI3_HOST). pin-sclk: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE pin-mosi: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: MOSI (Data 0) pin pin-miso: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: MISO (Data 1) pin pin-wp: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: WP (Data 2) pin pin-hd: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: HD (Data 3) pin max-transfer-size: @@ -38,5 +38,6 @@ properties: 0 means the platform decides the limit. cs-gpios: type: phandle-array - default: { 0 } + element-type: "struct GpioPinSpec" + default: "{ }" description: Null-terminated array of chip select GPIO pin specs for peripherals on this bus diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-uart.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-uart.yaml index 2016a2267..0d83aa16c 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-uart.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-uart.yaml @@ -12,18 +12,18 @@ properties: The port number, defined by uart_port_t. Depending on the hardware, these values are available: UART_NUM_0, UART_NUM_1, UART_NUM_2 pin-tx: - type: phandle-array + type: phandles required: true description: TX pin pin-rx: - type: phandle-array + type: phandles required: true description: RX pin pin-cts: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: CTS pin pin-rts: - type: phandle-array + type: phandles default: GPIO_PIN_SPEC_NONE description: RTS pin diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h index eba9b4161..fc025ccf2 100644 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdspi.h @@ -9,7 +9,6 @@ extern "C" { #endif struct Esp32SdspiConfig { - struct GpioPinSpec pin_cs; struct GpioPinSpec pin_cd; struct GpioPinSpec pin_wp; struct GpioPinSpec pin_int; diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h index 3de540b99..c49051fae 100644 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_spi.h @@ -23,10 +23,29 @@ struct Esp32SpiConfig { struct GpioPinSpec pin_hd; /** Data transfer size limit in bytes. 0 means the platform decides the limit. */ int max_transfer_size; - /** Null-terminated array of chip select GPIO pin specs */ - struct GpioPinSpec cs_gpios[]; + /** Array of chip select GPIO pin specs */ + struct GpioPinSpec* cs_gpios; + /** The item count of cs_gpios */ + uint8_t cs_gpios_count; }; +/** + * @brief Get the CS pin spec for a child device on this SPI bus. + * Uses the child device's address as index into the parent's cs_gpios array. + * @param[in] child_device a child device of an SPI controller + * @param[out] out_pin the GPIO pin spec for the CS pin + * @retval ERROR_NONE on success + * @retval ERROR_INVALID_STATE if the parent is not an SPI controller + * @retval ERROR_OUT_OF_RANGE if the device address exceeds the cs_gpios array + */ +error_t esp32_spi_get_cs_pin(struct Device* child_device, struct GpioPinSpec* out_pin); + +/** + * @brief Drive all CS pins on this SPI bus high (deselected). + * @param[in] device the SPI controller device + */ +void esp32_spi_deselect_all_cs(struct Device* device); + #ifdef __cplusplus } #endif diff --git a/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h b/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h index bb50eff59..92880fb9f 100644 --- a/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h +++ b/Platforms/platform-esp32/private/tactility/drivers/esp32_sdspi_fs.h @@ -11,7 +11,7 @@ extern "C" { struct Esp32SdspiConfig; typedef void* Esp32SdspiHandle; -Esp32SdspiHandle esp32_sdspi_fs_alloc(const struct Esp32SdspiConfig* config, int spi_host, const char* mount_path); +Esp32SdspiHandle esp32_sdspi_fs_alloc(const struct Esp32SdspiConfig* config, int spi_host, int cs_pin, const char* mount_path); void esp32_sdspi_fs_free(Esp32SdspiHandle handle); sdmmc_card_t* esp32_sdspi_fs_get_card(Esp32SdspiHandle handle); diff --git a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp index 30bc10161..0c0585219 100644 --- a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp +++ b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp @@ -1000,7 +1000,7 @@ const BluetoothApi nimble_bluetooth_api = { static void create_child_device(struct Device* parent, const char* name, Driver* drv, struct Device*& out) { - out = new Device { .name = name, .config = nullptr, .parent = nullptr, .internal = nullptr }; + out = new Device { .address = 0, .name = name, .config = nullptr, .parent = nullptr, .internal = nullptr }; device_construct(out); device_set_parent(out, parent); device_set_driver(out, drv); diff --git a/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp b/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp index dcda02c6a..f1ac27270 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i2c.cpp @@ -238,7 +238,8 @@ static constexpr I2cControllerApi ESP32_I2C_API = { .write = write, .write_read = write_read, .read_register = read_register, - .write_register = write_register + .write_register = write_register, + .probe = nullptr }; extern Module platform_esp32_module; diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp index cb42d283c..38b542785 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp @@ -24,7 +24,6 @@ struct Esp32SdspiInternal { RecursiveMutex mutex = {}; Esp32SdspiHandle fs_handle = nullptr; FileSystem* file_system = nullptr; - GpioDescriptor* pin_cs_descriptor = nullptr; GpioDescriptor* pin_cd_descriptor = nullptr; GpioDescriptor* pin_wp_descriptor = nullptr; GpioDescriptor* pin_int_descriptor = nullptr; @@ -40,7 +39,6 @@ struct Esp32SdspiInternal { } void cleanup_pins() { - release_pin(&pin_cs_descriptor); release_pin(&pin_cd_descriptor); release_pin(&pin_wp_descriptor); release_pin(&pin_int_descriptor); @@ -68,7 +66,6 @@ static error_t start(Device* device) { auto* config = GET_CONFIG(device); bool pins_ok = - acquire_pin_or_set_null(config->pin_cs, &data->pin_cs_descriptor) && acquire_pin_or_set_null(config->pin_cd, &data->pin_cd_descriptor) && acquire_pin_or_set_null(config->pin_wp, &data->pin_wp_descriptor) && acquire_pin_or_set_null(config->pin_int, &data->pin_int_descriptor); @@ -82,8 +79,25 @@ static error_t start(Device* device) { return ERROR_RESOURCE; } + GpioPinSpec cs_pin_spec; + if (esp32_spi_get_cs_pin(device, &cs_pin_spec) != ERROR_NONE) { + LOG_E(TAG, "Failed to get CS pin from parent SPI controller"); + data->cleanup_pins(); + device_set_driver_data(device, nullptr); + data->unlock(); + delete data; + return ERROR_RESOURCE; + } + auto* spi_config = static_cast(parent->config); - data->fs_handle = esp32_sdspi_fs_alloc(config, spi_config->host, "/sdcard"); + + // Lower all CS pins + esp32_spi_deselect_all_cs(parent); + // Manually set the CS pin fo + gpio_set_direction(static_cast(cs_pin_spec.pin), GPIO_MODE_OUTPUT); + gpio_set_level(static_cast(cs_pin_spec.pin), 255); + + data->fs_handle = esp32_sdspi_fs_alloc(config, spi_config->host, cs_pin_spec.pin, "/sdcard"); if (!data->fs_handle) { data->cleanup_pins(); device_set_driver_data(device, nullptr); diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp index 78d8282cb..70d8ad832 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdspi_fs.cpp @@ -17,12 +17,14 @@ struct Esp32SdspiFsData { const std::string mount_path; const Esp32SdspiConfig* config; int spi_host; + int cs_pin; sdmmc_card_t* card; - Esp32SdspiFsData(const Esp32SdspiConfig* config, int spi_host, const std::string& mount_path) : + Esp32SdspiFsData(const Esp32SdspiConfig* config, int spi_host, int cs_pin, const std::string& mount_path) : mount_path(mount_path), config(config), spi_host(spi_host), + cs_pin(cs_pin), card(nullptr) {} }; @@ -34,8 +36,8 @@ static gpio_num_t to_native_pin(GpioPinSpec pin_spec) { extern "C" { -Esp32SdspiHandle esp32_sdspi_fs_alloc(const Esp32SdspiConfig* config, int spi_host, const char* mount_path) { - return new(std::nothrow) Esp32SdspiFsData(config, spi_host, mount_path); +Esp32SdspiHandle esp32_sdspi_fs_alloc(const Esp32SdspiConfig* config, int spi_host, int cs_pin, const char* mount_path) { + return new(std::nothrow) Esp32SdspiFsData(config, spi_host, cs_pin, mount_path); } void esp32_sdspi_fs_free(Esp32SdspiHandle handle) { @@ -62,7 +64,7 @@ static error_t mount(void* data) { sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT(); slot_config.host_id = static_cast(fs_data->spi_host); - slot_config.gpio_cs = to_native_pin(config->pin_cs); + slot_config.gpio_cs = static_cast(fs_data->cs_pin); slot_config.gpio_cd = to_native_pin(config->pin_cd); slot_config.gpio_wp = to_native_pin(config->pin_wp); slot_config.gpio_int = to_native_pin(config->pin_int); diff --git a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp index e80297d33..7d3542621 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #define TAG "esp32_spi" @@ -22,13 +23,16 @@ struct Esp32SpiInternal { RecursiveMutex mutex = {}; bool initialized = false; - // Pin descriptors + // Bus pin descriptors GpioDescriptor* sclk_descriptor = nullptr; GpioDescriptor* mosi_descriptor = nullptr; GpioDescriptor* miso_descriptor = nullptr; GpioDescriptor* wp_descriptor = nullptr; GpioDescriptor* hd_descriptor = nullptr; + // CS pin descriptors + std::vector cs_descriptors; + explicit Esp32SpiInternal() { recursive_mutex_construct(&mutex); } @@ -44,6 +48,10 @@ struct Esp32SpiInternal { release_pin(&miso_descriptor); release_pin(&wp_descriptor); release_pin(&hd_descriptor); + for (auto*& desc : cs_descriptors) { + release_pin(&desc); + } + cs_descriptors.clear(); } }; @@ -118,22 +126,30 @@ static error_t start(Device* device) { return ERROR_RESOURCE; } - // Deselect all CS pins (drive high) before any SPI communication - const GpioPinSpec* cs = dts_config->cs_gpios; - while (cs->gpio_controller != nullptr) { + // Acquire and deselect all CS pins (drive high) + for (uint8_t i = 0; i < dts_config->cs_gpios_count; i++) { + const GpioPinSpec* cs = &dts_config->cs_gpios[i]; + if (cs->gpio_controller == nullptr) continue; GpioDescriptor* desc = gpio_descriptor_acquire(cs->gpio_controller, cs->pin, GPIO_OWNER_SPI); if (desc != nullptr) { gpio_descriptor_set_flags(desc, GPIO_FLAG_DIRECTION_OUTPUT); gpio_descriptor_set_level(desc, true); - gpio_descriptor_release(desc); + data->cs_descriptors.push_back(desc); } - cs++; } data->initialized = true; return ERROR_NONE; } +void esp32_spi_deselect_all_cs(Device* device) { + auto* data = GET_DATA(device); + if (data == nullptr) return; + for (auto* desc : data->cs_descriptors) { + gpio_descriptor_set_level(desc, true); + } +} + static error_t stop(Device* device) { LOG_I(TAG, "stop %s", device->name); auto* driver_data = GET_DATA(device); @@ -149,6 +165,16 @@ static error_t stop(Device* device) { return ERROR_NONE; } +error_t esp32_spi_get_cs_pin(Device* child_device, GpioPinSpec* out_pin) { + auto* parent = device_get_parent(child_device); + if (parent == nullptr || device_get_type(parent) != &SPI_CONTROLLER_TYPE) return ERROR_INVALID_STATE; + auto* config = GET_CONFIG(parent); + int32_t index = child_device->address; + if (index < 0 || index >= config->cs_gpios_count) return ERROR_OUT_OF_RANGE; + *out_pin = config->cs_gpios[index]; + return ERROR_NONE; +} + const static struct SpiControllerApi esp32_spi_api = { .lock = lock, .try_lock = try_lock, diff --git a/TactilityKernel/bindings/spi-peripheral.yaml b/TactilityKernel/bindings/spi-peripheral.yaml index baa052a5b..623c671d8 100644 --- a/TactilityKernel/bindings/spi-peripheral.yaml +++ b/TactilityKernel/bindings/spi-peripheral.yaml @@ -1,9 +1,5 @@ -description: SPI peripheral with chip select +description: SPI peripheral compatible: "spi-peripheral" -properties: - pin-cs: - type: phandle-array - required: true - description: Chip select GPIO +properties: {} diff --git a/TactilityKernel/include/tactility/drivers/spi_peripheral.h b/TactilityKernel/include/tactility/drivers/spi_peripheral.h index e7b1c3545..fa725569c 100644 --- a/TactilityKernel/include/tactility/drivers/spi_peripheral.h +++ b/TactilityKernel/include/tactility/drivers/spi_peripheral.h @@ -1,23 +1,17 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#include #include -#include #ifdef __cplusplus extern "C" { #endif struct SpiPeripheralConfig { - struct GpioPinSpec pin_cs; + uint8_t _unused; }; -struct SpiPeripheralApi { - struct GpioDescriptor* (*get_cs_descriptor)(struct Device* device); -}; - -struct GpioDescriptor* spi_peripheral_get_cs_descriptor(struct Device* device); - extern const struct DeviceType SPI_PERIPHERAL_TYPE; #ifdef __cplusplus diff --git a/TactilityKernel/include/tactility/error.h b/TactilityKernel/include/tactility/error.h index 094a4c92f..58aa77b64 100644 --- a/TactilityKernel/include/tactility/error.h +++ b/TactilityKernel/include/tactility/error.h @@ -24,6 +24,7 @@ typedef int error_t; #define ERROR_NOT_SUPPORTED 10 #define ERROR_NOT_ALLOWED 11 #define ERROR_BUFFER_OVERFLOW 12 +#define ERROR_OUT_OF_RANGE 13 /** Convert an error_t to a human-readable text. Useful for logging. */ const char* error_to_string(error_t error); diff --git a/TactilityKernel/source/drivers/spi_peripheral.cpp b/TactilityKernel/source/drivers/spi_peripheral.cpp index 3b7b1b600..8e9a3956b 100644 --- a/TactilityKernel/source/drivers/spi_peripheral.cpp +++ b/TactilityKernel/source/drivers/spi_peripheral.cpp @@ -1,61 +1,12 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include -#include #include #include -#include - -#define TAG "spi_peripheral" - -#define GET_CONFIG(device) ((const struct SpiPeripheralConfig*)device->config) extern "C" { -static error_t start(Device* device) { - auto* parent = device_get_parent(device); - if (parent == nullptr || device_get_type(parent) != &SPI_CONTROLLER_TYPE) { - LOG_E(TAG, "Parent is not an SPI controller"); - return ERROR_INVALID_STATE; - } - - auto* config = GET_CONFIG(device); - GpioDescriptor* cs = nullptr; - if (config->pin_cs.gpio_controller != nullptr) { - cs = gpio_descriptor_acquire(config->pin_cs.gpio_controller, config->pin_cs.pin, GPIO_OWNER_SPI); - if (cs == nullptr) { - LOG_E(TAG, "Failed to acquire CS pin"); - return ERROR_RESOURCE; - } - gpio_descriptor_set_flags(cs, GPIO_FLAG_DIRECTION_OUTPUT); - gpio_descriptor_set_level(cs, true); - } - - device_set_driver_data(device, cs); - return ERROR_NONE; -} - -static error_t stop(Device* device) { - auto* cs = static_cast(device_get_driver_data(device)); - if (cs != nullptr) { - gpio_descriptor_release(cs); - } - device_set_driver_data(device, nullptr); - return ERROR_NONE; -} - -static GpioDescriptor* get_cs_descriptor(Device* device) { - return static_cast(device_get_driver_data(device)); -} - -static const SpiPeripheralApi spi_peripheral_api = { - .get_cs_descriptor = get_cs_descriptor -}; - -GpioDescriptor* spi_peripheral_get_cs_descriptor(Device* device) { - auto* driver = device_get_driver(device); - return ((const SpiPeripheralApi*)driver->api)->get_cs_descriptor(device); -} +static error_t start(Device*) { return ERROR_NONE; } +static error_t stop(Device*) { return ERROR_NONE; } const DeviceType SPI_PERIPHERAL_TYPE = { .name = "spi_peripheral" @@ -68,7 +19,7 @@ Driver spi_peripheral_driver = { .compatible = (const char*[]) { "spi-peripheral", nullptr }, .start_device = start, .stop_device = stop, - .api = &spi_peripheral_api, + .api = nullptr, .device_type = &SPI_PERIPHERAL_TYPE, .owner = &root_module, .internal = nullptr From fb6f1c31d270c807e00ec9906a65cdca1c046717 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 20:07:20 +0200 Subject: [PATCH 15/19] Fixes --- Devices/lilygo-tdeck/lilygo,tdeck.dts | 7 +- .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 17 ++-- Devices/m5stack-core2/m5stack,core2.dts | 15 ++-- Devices/m5stack-cores3/m5stack,cores3.dts | 17 ++-- .../m5stack-stackchan/m5stack,stackchan.dts | 15 ++-- Devices/simulator/Source/Simulator.cpp | 3 - .../simulator/Source/hal/SimulatorSdCard.h | 42 ---------- .../source/drivers/esp32_sdmmc.cpp | 3 +- .../source/drivers/esp32_sdspi.cpp | 3 +- .../Tactility/hal/sdcard/SdCardDevice.h | 84 ------------------- Tactility/Private/Tactility/hal/SdCard.h | 20 +++++ .../Tactility/hal/sdcard/SdCardMounting.h | 7 -- Tactility/Source/app/files/State.cpp | 1 - Tactility/Source/app/fileselection/State.cpp | 1 - Tactility/Source/file/FileLock.cpp | 3 +- Tactility/Source/hal/Hal.cpp | 2 +- Tactility/Source/hal/sdcard/SdCard.cpp | 15 +++- Tactility/Source/hal/sdcard/SdCardDevice.cpp | 52 ------------ .../Source/hal/sdcard/SdCardMounting.cpp | 36 -------- .../service/webserver/WebServerService.cpp | 1 - .../service/wifi/WifiBootSplashInit.cpp | 1 - Tactility/Source/settings/BootSettings.cpp | 1 - .../include/tactility/drivers/sdcard.h | 14 ++++ TactilityKernel/source/drivers/sdcard.cpp | 10 +++ 24 files changed, 100 insertions(+), 270 deletions(-) delete mode 100644 Devices/simulator/Source/hal/SimulatorSdCard.h delete mode 100644 Tactility/Include/Tactility/hal/sdcard/SdCardDevice.h create mode 100644 Tactility/Private/Tactility/hal/SdCard.h delete mode 100644 Tactility/Private/Tactility/hal/sdcard/SdCardMounting.h delete mode 100644 Tactility/Source/hal/sdcard/SdCardDevice.cpp delete mode 100644 Tactility/Source/hal/sdcard/SdCardMounting.cpp create mode 100644 TactilityKernel/include/tactility/drivers/sdcard.h create mode 100644 TactilityKernel/source/drivers/sdcard.cpp diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index e5448ee00..adccef932 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -45,8 +45,8 @@ compatible = "espressif,esp32-spi"; host = ; cs-gpios = <&gpio0 12 GPIO_FLAG_NONE>, // Display - <&gpio0 9 GPIO_FLAG_NONE>, // Radio - <&gpio0 39 GPIO_FLAG_NONE>; // SD card + <&gpio0 39 GPIO_FLAG_NONE>, // SD card + <&gpio0 9 GPIO_FLAG_NONE>; // Radio pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>; @@ -55,8 +55,9 @@ compatible = "display-placeholder"; }; - sdcard@2 { + sdcard@1 { compatible = "espressif,esp32-sdspi"; + status = "disabled"; // Must be started after display frequency-khz = <20000>; }; }; diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index b72631095..94dde1ebb 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -35,20 +35,21 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; - cs-gpios = <&gpio0 21 GPIO_FLAG_NONE>, // SD card - <&gpio0 36 GPIO_FLAG_NONE>; // Display + cs-gpios = <&gpio0 36 GPIO_FLAG_NONE>, // Display + <&gpio0 21 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 34 GPIO_FLAG_NONE>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 35 GPIO_FLAG_NONE>; - - sdcard@0 { + + display@0 { + compatible = "display-placeholder"; + }; + + sdcard@1 { compatible = "espressif,esp32-sdspi"; + status = "disabled"; // Must be started after display frequency-khz = <20000>; }; - - display@1 { - compatible = "display-placeholder"; - }; }; // ES8311 diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index 95c6c13b9..0d166c2e8 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -53,20 +53,21 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; - cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>, // SD card - <&gpio0 5 GPIO_FLAG_NONE>; // Display + cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>, // Display + <&gpio0 4 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; - sdcard@0 { + display@0 { + compatible = "display-placeholder"; + }; + + sdcard@1 { compatible = "espressif,esp32-sdspi"; + status = "disabled"; // Must be started after display frequency-khz = <20000>; }; - - display@1 { - compatible = "display-placeholder"; - }; }; // NS4168: Speaker and microphone diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index c9057f907..e9d49036c 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -78,20 +78,21 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; - cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>, // SD card - <&gpio0 3 GPIO_FLAG_NONE>; // Display + cs-gpios = <&gpio0 3 GPIO_FLAG_NONE>, // Display + <&gpio0 4 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; - - sdcard@0 { + + display@0 { + compatible = "display-placeholder"; + }; + + sdcard@1 { compatible = "espressif,esp32-sdspi"; + status = "disabled"; // Must be started after display frequency-khz = <20000>; }; - - display@1 { - compatible = "display-placeholder"; - }; }; // TODO: Enable speaker via ES7210 I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L417 diff --git a/Devices/m5stack-stackchan/m5stack,stackchan.dts b/Devices/m5stack-stackchan/m5stack,stackchan.dts index b20828af4..3029e89ea 100644 --- a/Devices/m5stack-stackchan/m5stack,stackchan.dts +++ b/Devices/m5stack-stackchan/m5stack,stackchan.dts @@ -112,19 +112,20 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; - cs-gpios = <&gpio0 4 GPIO_FLAG_NONE>, // SD card - <&gpio0 3 GPIO_FLAG_NONE>; // Display + cs-gpios = <&gpio0 3 GPIO_FLAG_NONE>, // Display + <&gpio0 4 GPIO_FLAG_NONE>; // SD card pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>; - sdcard@0 { - compatible = "espressif,esp32-sdspi"; - frequency-khz = <20000>; + display@0 { + compatible = "display-placeholder"; }; - display@1 { - compatible = "display-placeholder"; + sdcard@1 { + compatible = "espressif,esp32-sdspi"; + status = "disabled"; // Must be started after display + frequency-khz = <20000>; }; }; diff --git a/Devices/simulator/Source/Simulator.cpp b/Devices/simulator/Source/Simulator.cpp index b60d84566..0e44471d3 100644 --- a/Devices/simulator/Source/Simulator.cpp +++ b/Devices/simulator/Source/Simulator.cpp @@ -1,9 +1,7 @@ #include "hal/SdlDisplay.h" #include "hal/SdlKeyboard.h" #include "hal/SimulatorPower.h" -#include "hal/SimulatorSdCard.h" -#include // LVGL #include #define TAG "hardware" @@ -15,7 +13,6 @@ static std::vector> createDevices() { std::make_shared(), std::make_shared(), std::make_shared(), - std::make_shared() }; } diff --git a/Devices/simulator/Source/hal/SimulatorSdCard.h b/Devices/simulator/Source/hal/SimulatorSdCard.h deleted file mode 100644 index 796a35fcd..000000000 --- a/Devices/simulator/Source/hal/SimulatorSdCard.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" -#include -#include - -using tt::hal::sdcard::SdCardDevice; - -class SimulatorSdCard final : public SdCardDevice { - - State state; - std::shared_ptr lock; - std::string mountPath; - -public: - - SimulatorSdCard() : SdCardDevice(MountBehaviour::AtBoot), - state(State::Unmounted), - lock(std::make_shared()) - {} - - std::string getName() const override { return "Mock SD Card"; } - std::string getDescription() const override { return ""; } - - bool mount(const std::string& newMountPath) override { - state = State::Mounted; - mountPath = newMountPath; - return true; - } - - bool unmount() override { - state = State::Unmounted; - mountPath = ""; - return true; - } - - std::string getMountPath() const override { return mountPath; } - - std::shared_ptr getLock() const override { return lock; } - - State getState(TickType_t timeout) const override { return state; } -}; diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp index b1fe993ab..4e259c40a 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -177,7 +178,7 @@ Driver esp32_sdmmc_driver = { .start_device = start, .stop_device = stop, .api = nullptr, - .device_type = nullptr, + .device_type = &SDCARD_TYPE, .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp index 38b542785..7b4bf1531 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -165,7 +166,7 @@ Driver esp32_sdspi_driver = { .start_device = start, .stop_device = stop, .api = nullptr, - .device_type = nullptr, + .device_type = &SDCARD_TYPE, .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Tactility/Include/Tactility/hal/sdcard/SdCardDevice.h b/Tactility/Include/Tactility/hal/sdcard/SdCardDevice.h deleted file mode 100644 index d57ffdb73..000000000 --- a/Tactility/Include/Tactility/hal/sdcard/SdCardDevice.h +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include - -#include -#include - - -struct FileSystem; -namespace tt::hal::sdcard { - -/** - * Warning: getLock() does not have to be used when calling any of the functions of this class. - * The lock is only used for file access on the path where the SD card is mounted. - * This is mainly used when accessing the SD card on a shared SPI bus. - */ -class SdCardDevice : public Device { - -public: - - enum class State { - Mounted, - Unmounted, - Error, - Timeout // Failed to retrieve state due to timeout - }; - - enum class MountBehaviour { - AtBoot, /** Only mount at boot */ - Anytime /** Mount/dismount any time */ - }; - -private: - - MountBehaviour mountBehaviour; - FileSystem* fileSystem; - -public: - - explicit SdCardDevice(MountBehaviour mountBehaviour); - ~SdCardDevice() override; - - Type getType() const final { return Type::SdCard; }; - - /** - * Mount the device. - * @param mountPath the path to mount at - * @return true on successful mount - */ - virtual bool mount(const std::string& mountPath) = 0; - - /** - * Unmount the device. - * @return true on successful unmount - */ - virtual bool unmount() = 0; - - virtual State getState(TickType_t timeout = kernel::MAX_TICKS) const = 0; - - /** @return empty string when not mounted or the mount path if mounted */ - virtual std::string getMountPath() const = 0; - - /** @return non-null lock, used by code that wants to access files on the mount path of this SD card */ - virtual std::shared_ptr getLock() const = 0; - - /** @return the MountBehaviour of this device */ - virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; } - - /** @return true if the SD card was mounted, returns false when it was not or when a timeout happened. */ - bool isMounted(TickType_t timeout = kernel::MAX_TICKS) const { return getState(timeout) == State::Mounted; } -}; - -/** Return the SdCard device if the path is within the SdCard mounted path (path std::string::starts_with() check), otherwise return nullptr */ -std::shared_ptr find(const std::string& path); - -/** - * Attempt to find an SD card that the specified belongs to, - * and returns its lock if the SD card is mounted. Otherwise it returns nullptr. - * @param[in] a path on a file system (e.g. file, directory, etc.) - * @return the lock of a mounted SD card or otherwise null - */ -std::shared_ptr findSdCardLock(const std::string& path); - -} // namespace tt::hal diff --git a/Tactility/Private/Tactility/hal/SdCard.h b/Tactility/Private/Tactility/hal/SdCard.h new file mode 100644 index 000000000..d09379a44 --- /dev/null +++ b/Tactility/Private/Tactility/hal/SdCard.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include + +namespace tt::hal::sdcard { + +/** + * Attempt to find an SD card that the specified belongs to, + * and returns its lock if the SD card is mounted. Otherwise it returns nullptr. + * @param[in] a path on a file system (e.g. file, directory, etc.) + * @return the lock of a mounted SD card or otherwise null + */ +std::shared_ptr findSdCardLock(const std::string& path); + +void mountAll(); + +} diff --git a/Tactility/Private/Tactility/hal/sdcard/SdCardMounting.h b/Tactility/Private/Tactility/hal/sdcard/SdCardMounting.h deleted file mode 100644 index 163e5a7ed..000000000 --- a/Tactility/Private/Tactility/hal/sdcard/SdCardMounting.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace tt::hal::sdcard { - -void mountAll(); - -} diff --git a/Tactility/Source/app/files/State.cpp b/Tactility/Source/app/files/State.cpp index 86f88a594..033746e3c 100644 --- a/Tactility/Source/app/files/State.cpp +++ b/Tactility/Source/app/files/State.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/Tactility/Source/app/fileselection/State.cpp b/Tactility/Source/app/fileselection/State.cpp index 7dfa38ca8..0e2419bd5 100644 --- a/Tactility/Source/app/fileselection/State.cpp +++ b/Tactility/Source/app/fileselection/State.cpp @@ -1,7 +1,6 @@ #include "Tactility/app/fileselection/State.h" #include -#include "Tactility/hal/sdcard/SdCardDevice.h" #include #include #include diff --git a/Tactility/Source/file/FileLock.cpp b/Tactility/Source/file/FileLock.cpp index 3af36820b..17715cab8 100644 --- a/Tactility/Source/file/FileLock.cpp +++ b/Tactility/Source/file/FileLock.cpp @@ -1,7 +1,6 @@ #include "Tactility/file/FileLock.h" -#include -#include +#include namespace tt::file { diff --git a/Tactility/Source/hal/Hal.cpp b/Tactility/Source/hal/Hal.cpp index df7840ac3..7f7af1c07 100644 --- a/Tactility/Source/hal/Hal.cpp +++ b/Tactility/Source/hal/Hal.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include diff --git a/Tactility/Source/hal/sdcard/SdCard.cpp b/Tactility/Source/hal/sdcard/SdCard.cpp index 63aaa74bc..38339593d 100644 --- a/Tactility/Source/hal/sdcard/SdCard.cpp +++ b/Tactility/Source/hal/sdcard/SdCard.cpp @@ -1,12 +1,11 @@ -#include "Tactility/hal/sdcard/SdCardDevice.h" - #include #include +#include #include -#include #include +#include namespace tt::hal::sdcard { @@ -38,4 +37,14 @@ std::shared_ptr findSdCardLock(const std::string& path) { return ctx.result; } +void mountAll() { + device_for_each_of_type(&SDCARD_TYPE, nullptr, [](::Device* device, void*) -> bool { + if (!device_is_ready(device)) { + if (device_start(device) != ERROR_NONE) { + } + } + return true; + }); +} + } diff --git a/Tactility/Source/hal/sdcard/SdCardDevice.cpp b/Tactility/Source/hal/sdcard/SdCardDevice.cpp deleted file mode 100644 index 44fbd2843..000000000 --- a/Tactility/Source/hal/sdcard/SdCardDevice.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include - -#include - -#include - -namespace tt::hal::sdcard { - -static error_t mount(void* data) { - auto* device = static_cast(data); - auto path = device->getMountPath(); - if (!device->mount(path)) return ERROR_UNDEFINED; - return ERROR_NONE; -} - -static error_t unmount(void* data) { - auto* device = static_cast(data); - if (!device->unmount()) return ERROR_UNDEFINED; - return ERROR_NONE; -} - -static bool is_mounted(void* data) { - auto* device = static_cast(data); - return device->isMounted(); -} - -static error_t get_path(void* data, char* out_path, size_t out_path_size) { - auto* device = static_cast(data); - const auto mount_path = device->getMountPath(); - if (mount_path.size() >= out_path_size) return ERROR_BUFFER_OVERFLOW; - if (mount_path.empty()) return ERROR_INVALID_STATE; - strncpy(out_path, mount_path.c_str(), out_path_size); - return ERROR_NONE; -} - -FileSystemApi sdCardDeviceApi = { - .mount = mount, - .unmount = unmount, - .is_mounted = is_mounted, - .get_path = get_path -}; - -SdCardDevice::SdCardDevice(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) { - fileSystem = file_system_add(&sdCardDeviceApi, this); - check(fileSystem != nullptr); -} - -SdCardDevice::~SdCardDevice() { - file_system_remove(fileSystem); -} - -} diff --git a/Tactility/Source/hal/sdcard/SdCardMounting.cpp b/Tactility/Source/hal/sdcard/SdCardMounting.cpp deleted file mode 100644 index b7152117c..000000000 --- a/Tactility/Source/hal/sdcard/SdCardMounting.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -#include - -#include - -namespace tt::hal::sdcard { - -static const auto LOGGER = Logger("SdCardMounting"); -constexpr auto* TT_SDCARD_MOUNT_POINT = "/sdcard"; - -static void mount(const std::shared_ptr& sdcard, const std::string& path) { - LOGGER.info("Mounting sdcard at {}", path); - if (!sdcard->mount(path)) { - LOGGER.warn("SD card mount failed for {} (init can continue)", path); - } -} - -static std::string getMountPath(int index, int count) { - return (count == 1) ? TT_SDCARD_MOUNT_POINT : std::format("{}{}", TT_SDCARD_MOUNT_POINT, index); -} - -void mountAll() { - const auto sdcards = hal::findDevices(Device::Type::SdCard); - // Numbered mount path name - for (int i = 0; i < sdcards.size(); i++) { - auto sdcard = sdcards[i]; - if (!sdcard->isMounted() && sdcard->getMountBehaviour() == SdCardDevice::MountBehaviour::AtBoot) { - std::string mount_path = getMountPath(i, sdcards.size()); - mount(sdcard, mount_path); - } - } -} - -} diff --git a/Tactility/Source/service/webserver/WebServerService.cpp b/Tactility/Source/service/webserver/WebServerService.cpp index 95aeebb67..5675f689b 100644 --- a/Tactility/Source/service/webserver/WebServerService.cpp +++ b/Tactility/Source/service/webserver/WebServerService.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/Tactility/Source/service/wifi/WifiBootSplashInit.cpp b/Tactility/Source/service/wifi/WifiBootSplashInit.cpp index 86625684c..1f7fa261f 100644 --- a/Tactility/Source/service/wifi/WifiBootSplashInit.cpp +++ b/Tactility/Source/service/wifi/WifiBootSplashInit.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/Tactility/Source/settings/BootSettings.cpp b/Tactility/Source/settings/BootSettings.cpp index 29cdbcf42..061e35933 100644 --- a/Tactility/Source/settings/BootSettings.cpp +++ b/Tactility/Source/settings/BootSettings.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include diff --git a/TactilityKernel/include/tactility/drivers/sdcard.h b/TactilityKernel/include/tactility/drivers/sdcard.h new file mode 100644 index 000000000..6931f1683 --- /dev/null +++ b/TactilityKernel/include/tactility/drivers/sdcard.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +extern const struct DeviceType SDCARD_TYPE; + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/source/drivers/sdcard.cpp b/TactilityKernel/source/drivers/sdcard.cpp new file mode 100644 index 000000000..c49a8d78f --- /dev/null +++ b/TactilityKernel/source/drivers/sdcard.cpp @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +#include + +extern "C" { + +const struct DeviceType SDCARD_TYPE { + .name = "sdcard" +}; + +} From 1c25ebca7318ca3e001ea359458ff63c52b30b07 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 20:45:42 +0200 Subject: [PATCH 16/19] Cleanup --- Devices/m5stack-tab5/m5stack,tab5.dts | 1 - 1 file changed, 1 deletion(-) diff --git a/Devices/m5stack-tab5/m5stack,tab5.dts b/Devices/m5stack-tab5/m5stack,tab5.dts index f618daee7..0b1ebcca9 100644 --- a/Devices/m5stack-tab5/m5stack,tab5.dts +++ b/Devices/m5stack-tab5/m5stack,tab5.dts @@ -13,7 +13,6 @@ #include #include #include -#include / { compatible = "root"; From 5090a4bf4a749b85acc33b9f7c48d322a5e3b662 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 22:26:11 +0200 Subject: [PATCH 17/19] Fix test --- .../DevicetreeCompiler/tests/data/expected_devicetree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c index 3a3202f83..9ec715e4d 100644 --- a/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c +++ b/Buildscripts/DevicetreeCompiler/tests/data/expected_devicetree.c @@ -17,16 +17,16 @@ static struct Device root = { .internal = NULL }; -static const generic_device_config_dt test_device_0_config = { +static const generic_device_config_dt test_device_config = { 0, 42, "hello" }; -static struct Device test_device_0 = { +static struct Device test_device = { .address = 0, .name = "test-device", - .config = &test_device_0_config, + .config = &test_device_config, .parent = &root, .internal = NULL }; @@ -49,7 +49,7 @@ static struct Device bool_test_device = { struct DtsDevice dts_devices[] = { { &root, "test,root", DTS_DEVICE_STATUS_OKAY }, - { &test_device_0, "test,generic-device", DTS_DEVICE_STATUS_OKAY }, + { &test_device, "test,generic-device", DTS_DEVICE_STATUS_OKAY }, { &bool_test_device, "test,bool-device", DTS_DEVICE_STATUS_OKAY }, DTS_DEVICE_TERMINATOR }; From 0098a8be8afa734f1de2942f50f94c0098514537 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 23:13:21 +0200 Subject: [PATCH 18/19] Fix for driver init --- Drivers/GT911/Source/Gt911Touch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Drivers/GT911/Source/Gt911Touch.cpp b/Drivers/GT911/Source/Gt911Touch.cpp index 08e1ee4e2..20735047d 100644 --- a/Drivers/GT911/Source/Gt911Touch.cpp +++ b/Drivers/GT911/Source/Gt911Touch.cpp @@ -22,12 +22,13 @@ bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { io_config.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS; } else if (i2c_controller_has_device_at_address(i2c, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP, pdMS_TO_TICKS(10)) == ERROR_NONE) { io_config.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP; - io_config.scl_speed_hz = esp32_i2c_master_get_clock_frequency(configuration->i2cController); } else { LOGGER.error("No device found on I2C bus"); return false; } + io_config.scl_speed_hz = esp32_i2c_master_get_clock_frequency(configuration->i2cController); + auto* driver = device_get_driver(i2c); if (driver_is_compatible(driver, "espressif,esp32-i2c")) { auto port = static_cast(i2c->config)->port; From 3220b1fd3a855c500e30a867650c5c513d45117d Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 21 Jun 2026 23:24:32 +0200 Subject: [PATCH 19/19] Cleanup --- Drivers/GT911/Source/Gt911Touch.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Drivers/GT911/Source/Gt911Touch.cpp b/Drivers/GT911/Source/Gt911Touch.cpp index 20735047d..e323f4c93 100644 --- a/Drivers/GT911/Source/Gt911Touch.cpp +++ b/Drivers/GT911/Source/Gt911Touch.cpp @@ -29,12 +29,16 @@ bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { io_config.scl_speed_hz = esp32_i2c_master_get_clock_frequency(configuration->i2cController); + // Legacy I2C implementation auto* driver = device_get_driver(i2c); if (driver_is_compatible(driver, "espressif,esp32-i2c")) { auto port = static_cast(i2c->config)->port; return esp_lcd_new_panel_io_i2c_v1(port, &io_config, &outHandle) == ESP_OK; - } else if (driver_is_compatible(driver, "espressif,esp32-i2c-master")) { - auto bus = esp32_i2c_master_get_bus_handle(i2c); + } + + // Target I2C implementation + if (driver_is_compatible(driver, "espressif,esp32-i2c-master")) { + auto* bus = esp32_i2c_master_get_bus_handle(i2c); return esp_lcd_new_panel_io_i2c_v2(bus, &io_config, &outHandle) == ESP_OK; } @@ -57,9 +61,9 @@ esp_lcd_touch_config_t Gt911Touch::createEspLcdTouchConfig() { .interrupt = configuration->pinInterruptLevel, }, .flags = { - .swap_xy = configuration->swapXy, - .mirror_x = configuration->mirrorX, - .mirror_y = configuration->mirrorY, + .swap_xy = static_cast(configuration->swapXy), + .mirror_x = static_cast(configuration->mirrorX), + .mirror_y = static_cast(configuration->mirrorY), }, .process_coordinates = nullptr, .interrupt_callback = nullptr,