From 933f8ad0b28779e1342fdfb7acfafdd2037c3f2b Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 00:27:15 +0100 Subject: [PATCH 1/9] SPI device migration --- .../bigtreetech,panda-touch.dts | 4 +- .../cyd-2432s024c/Source/Configuration.cpp | 50 +----- .../cyd-2432s024c/Source/devices/SdCard.cpp | 9 +- Devices/cyd-2432s024c/cyd,2432s024c.dts | 23 +++ .../cyd-2432s028r/Source/Configuration.cpp | 52 +------ .../cyd-2432s028r/Source/devices/SdCard.cpp | 7 +- Devices/cyd-2432s028r/cyd,2432s028r.dts | 23 +++ .../cyd-2432s028rv3/Source/Configuration.cpp | 52 +------ .../cyd-2432s028rv3/Source/devices/SdCard.cpp | 7 +- Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts | 23 +++ .../cyd-2432s032c/Source/Configuration.cpp | 52 +------ .../cyd-2432s032c/Source/devices/SdCard.cpp | 7 +- Devices/cyd-2432s032c/cyd,2432s032c.dts | 23 +++ .../cyd-4848s040c/Source/Configuration.cpp | 28 +--- .../cyd-4848s040c/Source/devices/SdCard.cpp | 11 +- .../Source/devices/St7701Display.h | 2 +- Devices/cyd-4848s040c/cyd,4848s040c.dts | 12 ++ .../cyd-8048s043c/Source/Configuration.cpp | 28 +--- .../cyd-8048s043c/Source/devices/SdCard.cpp | 11 +- Devices/cyd-8048s043c/cyd,8048s043c.dts | 12 ++ Devices/cyd-e32r28t/Source/Configuration.cpp | 52 +------ Devices/cyd-e32r28t/Source/devices/SdCard.cpp | 10 +- Devices/cyd-e32r28t/cyd,e32r28t.dts | 23 +++ Devices/cyd-e32r32p/Source/Configuration.cpp | 53 +------ Devices/cyd-e32r32p/Source/devices/SdCard.cpp | 8 +- Devices/cyd-e32r32p/cyd,e32r32p.dts | 23 +++ .../Source/Axs15231b/Axs15231bDisplay.h | 5 +- Devices/lilygo-tdeck/Source/Configuration.cpp | 28 +--- .../lilygo-tdeck/Source/devices/Sdcard.cpp | 7 +- Devices/lilygo-tdeck/lilygo,tdeck.dts | 12 ++ Devices/lilygo-tdisplay-s3/Source/Init.cpp | 3 +- .../unphone/Source/devices/Hx8357Display.h | 4 +- .../Source/devices/Jd9853Display.h | 3 +- Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp | 1 - Drivers/EspLcdCompat/Source/EspLcdDisplay.h | 5 +- .../EspLcdCompat/Source/EspLcdDisplayDriver.h | 7 +- .../EspLcdCompat/Source/EspLcdDisplayV2.cpp | 1 - Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h | 8 +- .../EspLcdCompat/Source/EspLcdSpiDisplay.h | 5 +- Drivers/GC9A01/Source/Gc9a01Display.h | 3 +- Drivers/ILI934x/Source/Ili934xDisplay.h | 2 - Drivers/ILI9488/Source/Ili9488Display.h | 2 +- Drivers/ST7735/Source/St7735Display.h | 3 +- Drivers/ST7789/Source/St7789Display.h | 2 - Drivers/ST7796/Source/St7796Display.h | 2 +- .../Bindings/espressif,esp32-spi.yaml | 36 +++++ .../Include/tactility/bindings/esp32_gpio.h | 1 + .../Include/tactility/bindings/esp32_spi.h | 15 ++ .../Include/tactility/drivers/esp32_spi.h | 6 + .../Source/drivers/esp32_spi.cpp | 14 +- .../Include/Tactility/hal/Configuration.h | 4 - .../Tactility/hal/display/DisplayDriver.h | 1 - .../Tactility/hal/sdcard/SdmmcDevice.h | 1 - .../Tactility/hal/sdcard/SpiSdCardDevice.h | 26 ++-- Tactility/Include/Tactility/hal/spi/Spi.h | 51 ------ .../Include/Tactility/hal/spi/SpiCompat.h | 21 --- Tactility/Private/Tactility/hal/spi/SpiInit.h | 17 -- Tactility/Source/hal/Hal.cpp | 3 - Tactility/Source/hal/spi/Spi.cpp | 146 ------------------ TactilityC/Source/tt_hal_display.cpp | 7 +- .../Include/Tactility/kernel/SpiDeviceLock.h | 24 +++ TactilityKernel/Bindings/spi-controller.yaml | 1 + 62 files changed, 369 insertions(+), 713 deletions(-) create mode 100644 Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml create mode 100644 Platforms/PlatformEsp32/Include/tactility/bindings/esp32_spi.h delete mode 100644 Tactility/Include/Tactility/hal/spi/Spi.h delete mode 100644 Tactility/Include/Tactility/hal/spi/SpiCompat.h delete mode 100644 Tactility/Private/Tactility/hal/spi/SpiInit.h delete mode 100644 Tactility/Source/hal/spi/Spi.cpp create mode 100644 TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h create mode 100644 TactilityKernel/Bindings/spi-controller.yaml diff --git a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts index 9d5d8145f..e19626de9 100644 --- a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts +++ b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts @@ -14,7 +14,7 @@ gpio-count = <49>; }; - i2c_internal { + i2c_internal: i2c0 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; @@ -24,7 +24,7 @@ pin-scl-pullup; }; - i2c_external { + i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; diff --git a/Devices/cyd-2432s024c/Source/Configuration.cpp b/Devices/cyd-2432s024c/Source/Configuration.cpp index fdb0ef5d4..055d6deec 100644 --- a/Devices/cyd-2432s024c/Source/Configuration.cpp +++ b/Devices/cyd-2432s024c/Source/Configuration.cpp @@ -29,53 +29,5 @@ static tt::hal::DeviceVector createDevices() { extern const tt::hal::Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - tt::hal::spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - tt::hal::spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - }, - } + .createDevices = createDevices }; diff --git a/Devices/cyd-2432s024c/Source/devices/SdCard.cpp b/Devices/cyd-2432s024c/Source/devices/SdCard.cpp index ad79ca1b5..7f102d97a 100644 --- a/Devices/cyd-2432s024c/Source/devices/SdCard.cpp +++ b/Devices/cyd-2432s024c/Source/devices/SdCard.cpp @@ -2,6 +2,7 @@ #define TAG "twodotfour_sdcard" +#include #include #include @@ -17,13 +18,17 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index 3791a4b52..d925d05fa 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -20,4 +21,26 @@ pin-sda = <33>; pin-scl = <32>; }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = ; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/cyd-2432s028r/Source/Configuration.cpp b/Devices/cyd-2432s028r/Source/Configuration.cpp index 316446135..5033e9759 100644 --- a/Devices/cyd-2432s028r/Source/Configuration.cpp +++ b/Devices/cyd-2432s028r/Source/Configuration.cpp @@ -31,55 +31,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_12, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - // SDCard - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - } + .createDevices = createDevices }; diff --git a/Devices/cyd-2432s028r/Source/devices/SdCard.cpp b/Devices/cyd-2432s028r/Source/devices/SdCard.cpp index e0e4072a8..fa96aa264 100644 --- a/Devices/cyd-2432s028r/Source/devices/SdCard.cpp +++ b/Devices/cyd-2432s028r/Source/devices/SdCard.cpp @@ -1,4 +1,6 @@ #include "SdCard.h" + +#include #include #include #include @@ -17,6 +19,9 @@ std::shared_ptr createSdCard() { SPI3_HOST ); - return std::make_shared(std::move(config)); + 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/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index 177e55ec3..34b3f218c 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -22,6 +23,28 @@ pin-scl = <22>; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = <12>; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/cyd-2432s028rv3/Source/Configuration.cpp b/Devices/cyd-2432s028rv3/Source/Configuration.cpp index 316446135..5033e9759 100644 --- a/Devices/cyd-2432s028rv3/Source/Configuration.cpp +++ b/Devices/cyd-2432s028rv3/Source/Configuration.cpp @@ -31,55 +31,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_12, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - // SDCard - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - } + .createDevices = createDevices }; diff --git a/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp b/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp index e0e4072a8..fa96aa264 100644 --- a/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp +++ b/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp @@ -1,4 +1,6 @@ #include "SdCard.h" + +#include #include #include #include @@ -17,6 +19,9 @@ std::shared_ptr createSdCard() { SPI3_HOST ); - return std::make_shared(std::move(config)); + 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/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index d956bcfc3..14f9b551c 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -4,6 +4,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,6 +23,28 @@ pin-scl = <22>; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = <12>; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/cyd-2432s032c/Source/Configuration.cpp b/Devices/cyd-2432s032c/Source/Configuration.cpp index 2b1478e16..5308ea91f 100644 --- a/Devices/cyd-2432s032c/Source/Configuration.cpp +++ b/Devices/cyd-2432s032c/Source/Configuration.cpp @@ -45,55 +45,5 @@ static tt::hal::DeviceVector createDevices() { extern const tt::hal::Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - tt::hal::spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card - tt::hal::spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - }, - } + .createDevices = createDevices }; diff --git a/Devices/cyd-2432s032c/Source/devices/SdCard.cpp b/Devices/cyd-2432s032c/Source/devices/SdCard.cpp index 84360cfae..48e5a00d3 100644 --- a/Devices/cyd-2432s032c/Source/devices/SdCard.cpp +++ b/Devices/cyd-2432s032c/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include #include @@ -21,8 +22,12 @@ std::shared_ptr createSdCard() { SDCARD_SPI_HOST ); + auto* spi_controller = device_find_by_name("spi1"); + check(spi_controller, "spi1 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 3b9864d66..4333ca03e 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -20,4 +21,26 @@ pin-sda = <33>; pin-scl = <32>; }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = ; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/cyd-4848s040c/Source/Configuration.cpp b/Devices/cyd-4848s040c/Source/Configuration.cpp index e8500904e..6121b6af4 100644 --- a/Devices/cyd-4848s040c/Source/Configuration.cpp +++ b/Devices/cyd-4848s040c/Source/Configuration.cpp @@ -22,31 +22,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // SD Card & display init - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_47, - .miso_io_num = GPIO_NUM_41, - .sclk_io_num = GPIO_NUM_48, - .quadwp_io_num = -1, - .quadhd_io_num = GPIO_NUM_42, - .data4_io_num = -1, - .data5_io_num = -1, - .data6_io_num = -1, - .data7_io_num = -1, - .data_io_default_level = false, - .max_transfer_sz = 1024 * 128, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - } - } + .createDevices = createDevices }; diff --git a/Devices/cyd-4848s040c/Source/devices/SdCard.cpp b/Devices/cyd-4848s040c/Source/devices/SdCard.cpp index e8def0e4e..4ad5857e5 100644 --- a/Devices/cyd-4848s040c/Source/devices/SdCard.cpp +++ b/Devices/cyd-4848s040c/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -16,10 +17,12 @@ std::shared_ptr createSdCard() { std::vector { GPIO_NUM_39 } ); - auto sdcard = std::make_shared( - std::move(config) - ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); - return std::static_pointer_cast(sdcard); + return std::make_shared( + std::move(config), + spi_controller + ); } diff --git a/Devices/cyd-4848s040c/Source/devices/St7701Display.h b/Devices/cyd-4848s040c/Source/devices/St7701Display.h index 49efa45e4..104e725a5 100644 --- a/Devices/cyd-4848s040c/Source/devices/St7701Display.h +++ b/Devices/cyd-4848s040c/Source/devices/St7701Display.h @@ -21,7 +21,7 @@ class St7701Display final : public EspLcdDisplay { public: - St7701Display() : EspLcdDisplay(std::make_shared()) {} + St7701Display() : EspLcdDisplay() {} std::string getName() const override { return "ST7701S"; } diff --git a/Devices/cyd-4848s040c/cyd,4848s040c.dts b/Devices/cyd-4848s040c/cyd,4848s040c.dts index ac13b2e35..049c6072b 100644 --- a/Devices/cyd-4848s040c/cyd,4848s040c.dts +++ b/Devices/cyd-4848s040c/cyd,4848s040c.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -22,4 +23,15 @@ pin-sda-pullup; pin-scl-pullup; }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <47>; + pin-miso = <41>; + pin-sclk = <48>; + pin-wp = ; + pin-hd = <42>; + max-transfer-size = <0>; + }; }; diff --git a/Devices/cyd-8048s043c/Source/Configuration.cpp b/Devices/cyd-8048s043c/Source/Configuration.cpp index 51baa0972..df1706ac7 100644 --- a/Devices/cyd-8048s043c/Source/Configuration.cpp +++ b/Devices/cyd-8048s043c/Source/Configuration.cpp @@ -21,31 +21,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // SD Card - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_13, - .sclk_io_num = GPIO_NUM_12, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/cyd-8048s043c/Source/devices/SdCard.cpp b/Devices/cyd-8048s043c/Source/devices/SdCard.cpp index 3a116b927..8b80cfc81 100644 --- a/Devices/cyd-8048s043c/Source/devices/SdCard.cpp +++ b/Devices/cyd-8048s043c/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -14,9 +15,11 @@ std::shared_ptr createSdCard() { SdCardDevice::MountBehaviour::AtBoot ); - auto sdcard = std::make_shared( - std::move(config) - ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); - return std::static_pointer_cast(sdcard); + return std::make_shared( + std::move(config), + spi_controller + ); } diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index a952c4a40..446ab501b 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -4,6 +4,7 @@ #include #include #include +#include / { compatible = "root"; @@ -32,6 +33,17 @@ pin-scl = <18>; }; + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = <13>; + pin-sclk = <12>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/cyd-e32r28t/Source/Configuration.cpp b/Devices/cyd-e32r28t/Source/Configuration.cpp index 4e4e91498..4ba1576f8 100644 --- a/Devices/cyd-e32r28t/Source/Configuration.cpp +++ b/Devices/cyd-e32r28t/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "devices/SdCard.h" #include "devices/Display.h" -#include #include #include @@ -19,54 +18,5 @@ static tt::hal::DeviceVector createDevices() { extern const tt::hal::Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi = { - tt::hal::spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_12, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - tt::hal::spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - - } + .createDevices = createDevices }; diff --git a/Devices/cyd-e32r28t/Source/devices/SdCard.cpp b/Devices/cyd-e32r28t/Source/devices/SdCard.cpp index 86f08b1c4..40cf9caaf 100644 --- a/Devices/cyd-e32r28t/Source/devices/SdCard.cpp +++ b/Devices/cyd-e32r28t/Source/devices/SdCard.cpp @@ -1,4 +1,6 @@ #include "SdCard.h" + +#include #include #include @@ -11,12 +13,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/cyd-e32r28t/cyd,e32r28t.dts b/Devices/cyd-e32r28t/cyd,e32r28t.dts index 3693ecf0b..49dd689be 100644 --- a/Devices/cyd-e32r28t/cyd,e32r28t.dts +++ b/Devices/cyd-e32r28t/cyd,e32r28t.dts @@ -2,6 +2,7 @@ #include #include +#include / { compatible = "root"; @@ -11,4 +12,26 @@ compatible = "espressif,esp32-gpio"; gpio-count = <40>; }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = <12>; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/cyd-e32r32p/Source/Configuration.cpp b/Devices/cyd-e32r32p/Source/Configuration.cpp index f21b7c68f..452896b69 100644 --- a/Devices/cyd-e32r32p/Source/Configuration.cpp +++ b/Devices/cyd-e32r32p/Source/Configuration.cpp @@ -23,56 +23,5 @@ static tt::hal::DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - // Display - .spi = { - tt::hal::spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_12, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = DISPLAY_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - // SD Card - tt::hal::spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - }, - - } + .createDevices = createDevices }; \ No newline at end of file diff --git a/Devices/cyd-e32r32p/Source/devices/SdCard.cpp b/Devices/cyd-e32r32p/Source/devices/SdCard.cpp index a86ef14e8..58de45419 100644 --- a/Devices/cyd-e32r32p/Source/devices/SdCard.cpp +++ b/Devices/cyd-e32r32p/Source/devices/SdCard.cpp @@ -1,4 +1,6 @@ #include "SdCard.h" + +#include #include #include @@ -17,7 +19,11 @@ std::shared_ptr createSdCard() { 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) + std::move(configuration), + spi_controller ); } \ No newline at end of file diff --git a/Devices/cyd-e32r32p/cyd,e32r32p.dts b/Devices/cyd-e32r32p/cyd,e32r32p.dts index e673b9239..720ffc1ec 100644 --- a/Devices/cyd-e32r32p/cyd,e32r32p.dts +++ b/Devices/cyd-e32r32p/cyd,e32r32p.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -20,4 +21,26 @@ pin-sda = <32>; pin-scl = <25>; }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = <12>; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h index 1f8a53dfa..397d03880 100644 --- a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h +++ b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h @@ -1,11 +1,10 @@ #pragma once -#include - #include #include #include +#include #include #include #include @@ -26,7 +25,7 @@ class Axs15231bDisplay final : public tt::hal::display::DisplayDevice { gpio_num_t csPin, gpio_num_t dcPin, gpio_num_t resetPin, - gpio_num_t tePin, + unsigned int horizontalResolution, unsigned int verticalResolution, std::shared_ptr touch, diff --git a/Devices/lilygo-tdeck/Source/Configuration.cpp b/Devices/lilygo-tdeck/Source/Configuration.cpp index 49e21597b..615b7b7a5 100644 --- a/Devices/lilygo-tdeck/Source/Configuration.cpp +++ b/Devices/lilygo-tdeck/Source/Configuration.cpp @@ -4,7 +4,6 @@ #include "devices/Sdcard.h" #include "devices/TdeckKeyboard.h" #include "devices/TrackballDevice.h" -#include #include #include @@ -26,30 +25,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_41, - .miso_io_num = GPIO_NUM_38, - .sclk_io_num = GPIO_NUM_40, - .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; diff --git a/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp b/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp index ce9a9d53b..6b926d794 100644 --- a/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp +++ b/Devices/lilygo-tdeck/Source/devices/Sdcard.cpp @@ -1,5 +1,7 @@ #include "Sdcard.h" +#include + #include #include @@ -23,7 +25,10 @@ std::shared_ptr createSdCard() { } ); + ::Device* spiController = device_find_by_name("spi0"); + check(spiController != nullptr, "spi0 not found"); return std::make_shared( - std::move(configuration) + std::move(configuration), + spiController ); } diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index fd8c22b9f..eca24c0fd 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -4,6 +4,7 @@ #include #include #include +#include #include // Reference: https://wiki.lilygo.cc/get_started/en/Wearable/T-Deck-Plus/T-Deck-Plus.html#Pin-Overview @@ -42,6 +43,17 @@ pin-mclk = ; }; + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <41>; + pin-miso = <38>; + pin-sclk = <40>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/lilygo-tdisplay-s3/Source/Init.cpp b/Devices/lilygo-tdisplay-s3/Source/Init.cpp index 4e25f1c02..754b72f50 100644 --- a/Devices/lilygo-tdisplay-s3/Source/Init.cpp +++ b/Devices/lilygo-tdisplay-s3/Source/Init.cpp @@ -4,7 +4,6 @@ #include "PwmBacklight.h" #include "Tactility/kernel/SystemEvents.h" #include -#include #define TAG "tdisplay-s3" @@ -28,7 +27,7 @@ static bool powerOn() { return false; } - return true; + } bool initBoot() { diff --git a/Devices/unphone/Source/devices/Hx8357Display.h b/Devices/unphone/Source/devices/Hx8357Display.h index 3414d2be7..9dea80f1a 100644 --- a/Devices/unphone/Source/devices/Hx8357Display.h +++ b/Devices/unphone/Source/devices/Hx8357Display.h @@ -7,7 +7,7 @@ #include #include -#include +#include #define UNPHONE_LCD_SPI_HOST SPI2_HOST #define UNPHONE_LCD_PIN_CS GPIO_NUM_48 @@ -27,13 +27,11 @@ class Hx8357Display : public tt::hal::display::DisplayDevice { std::shared_ptr nativeDisplay; class Hx8357Driver : public tt::hal::display::DisplayDriver { - std::shared_ptr lock = tt::hal::spi::getLock(SPI2_HOST); public: tt::hal::display::ColorFormat getColorFormat() const override { return tt::hal::display::ColorFormat::RGB888; } uint16_t getPixelWidth() const override { return UNPHONE_LCD_HORIZONTAL_RESOLUTION; } uint16_t getPixelHeight() const override { return UNPHONE_LCD_VERTICAL_RESOLUTION; } bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) override; - std::shared_ptr getLock() const override { return lock; } }; public: diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h index fd06223b1..aec2e5c2e 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h +++ b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h @@ -1,11 +1,11 @@ #pragma once #include -#include #include #include +#include #include #include #include @@ -83,7 +83,6 @@ class Jd9853Display final : public EspLcdDisplay { public: explicit Jd9853Display(std::unique_ptr inConfiguration) : - EspLcdDisplay(tt::hal::spi::getLock(inConfiguration->spiHostDevice)), configuration(std::move(inConfiguration) ) { assert(configuration != nullptr); diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp b/Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp index 07c108bca..95fa9d14f 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp @@ -121,7 +121,6 @@ std::shared_ptr EspLcdDisplay::getDisplayDriver displayDriver = std::make_shared( panelHandle, - lock, lvgl_port_config.hres, lvgl_port_config.vres, color_format diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplay.h b/Drivers/EspLcdCompat/Source/EspLcdDisplay.h index 2819acd07..0c26a2e7c 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplay.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplay.h @@ -14,7 +14,6 @@ class EspLcdDisplay : public tt::hal::display::DisplayDevice { esp_lcd_panel_handle_t panelHandle = nullptr; lv_display_t* lvglDisplay = nullptr; std::shared_ptr displayDriver; - std::shared_ptr lock; lcd_rgb_element_order_t rgbElementOrder; protected: @@ -34,12 +33,10 @@ class EspLcdDisplay : public tt::hal::display::DisplayDevice { public: - EspLcdDisplay(std::shared_ptr lock) : lock(lock) {} + EspLcdDisplay() = default; ~EspLcdDisplay() override; - std::shared_ptr getLock() const { return lock; } - bool start() final; bool stop() final; diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplayDriver.h b/Drivers/EspLcdCompat/Source/EspLcdDisplayDriver.h index 4192f1de6..ce4b91376 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplayDriver.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplayDriver.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -8,7 +7,6 @@ class EspLcdDisplayDriver : public tt::hal::display::DisplayDriver { esp_lcd_panel_handle_t panelHandle; - std::shared_ptr lock; uint16_t hRes; uint16_t vRes; tt::hal::display::ColorFormat colorFormat; @@ -17,11 +15,10 @@ class EspLcdDisplayDriver : public tt::hal::display::DisplayDriver { EspLcdDisplayDriver( esp_lcd_panel_handle_t panelHandle, - std::shared_ptr lock, uint16_t hRes, uint16_t vRes, tt::hal::display::ColorFormat colorFormat - ) : panelHandle(panelHandle), lock(lock), hRes(hRes), vRes(vRes), colorFormat(colorFormat) {} + ) : panelHandle(panelHandle), hRes(hRes), vRes(vRes), colorFormat(colorFormat) {} tt::hal::display::ColorFormat getColorFormat() const override { return colorFormat; @@ -35,6 +32,4 @@ class EspLcdDisplayDriver : public tt::hal::display::DisplayDriver { uint16_t getPixelWidth() const override { return hRes; } uint16_t getPixelHeight() const override { return vRes; } - - std::shared_ptr getLock() const override { return lock; } }; diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.cpp b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.cpp index cc316a4a3..27061170f 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.cpp +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.cpp @@ -221,7 +221,6 @@ std::shared_ptr EspLcdDisplayV2::getDisplayDriv displayDriver = std::make_shared( panelHandle, - lock, lvgl_port_config.hres, lvgl_port_config.vres, color_format diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h index fc318d87d..2f3ca2076 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -35,7 +34,6 @@ class EspLcdDisplayV2 : public tt::hal::display::DisplayDevice { esp_lcd_panel_handle_t _Nullable panelHandle = nullptr; lv_display_t* _Nullable lvglDisplay = nullptr; std::shared_ptr _Nullable displayDriver; - std::shared_ptr lock; std::shared_ptr configuration; bool applyConfiguration() const; @@ -67,18 +65,14 @@ class EspLcdDisplayV2 : public tt::hal::display::DisplayDevice { public: - EspLcdDisplayV2(const std::shared_ptr& configuration, const std::shared_ptr& lock) : - lock(lock), + EspLcdDisplayV2(const std::shared_ptr& configuration) : configuration(configuration) { assert(configuration != nullptr); - assert(lock != nullptr); } ~EspLcdDisplayV2() override; - std::shared_ptr getLock() const { return lock; } - bool start() final; bool stop() final; diff --git a/Drivers/EspLcdCompat/Source/EspLcdSpiDisplay.h b/Drivers/EspLcdCompat/Source/EspLcdSpiDisplay.h index 0ef5eb0ee..1e855aff7 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdSpiDisplay.h +++ b/Drivers/EspLcdCompat/Source/EspLcdSpiDisplay.h @@ -1,7 +1,8 @@ #pragma once #include "EspLcdDisplayV2.h" -#include + +#include #include #include @@ -23,7 +24,7 @@ class EspLcdSpiDisplay : public EspLcdDisplayV2 { }; explicit EspLcdSpiDisplay(const std::shared_ptr& configuration, const std::shared_ptr spiConfiguration, int gammaCurveCount) : - EspLcdDisplayV2(configuration, tt::hal::spi::getLock(spiConfiguration->spiHostDevice)), + EspLcdDisplayV2(configuration), spiConfiguration(spiConfiguration), gammaCurveCount(gammaCurveCount) {} diff --git a/Drivers/GC9A01/Source/Gc9a01Display.h b/Drivers/GC9A01/Source/Gc9a01Display.h index d5dc64784..f62361233 100644 --- a/Drivers/GC9A01/Source/Gc9a01Display.h +++ b/Drivers/GC9A01/Source/Gc9a01Display.h @@ -1,11 +1,10 @@ #pragma once -#include "Tactility/hal/spi/Spi.h" - #include #include #include +#include #include #include #include diff --git a/Drivers/ILI934x/Source/Ili934xDisplay.h b/Drivers/ILI934x/Source/Ili934xDisplay.h index 9337e5f6e..1e1845197 100644 --- a/Drivers/ILI934x/Source/Ili934xDisplay.h +++ b/Drivers/ILI934x/Source/Ili934xDisplay.h @@ -8,8 +8,6 @@ class Ili934xDisplay final : public EspLcdSpiDisplay { - std::shared_ptr lock; - public: /** Minimal set of overrides for EspLcdConfiguration */ diff --git a/Drivers/ILI9488/Source/Ili9488Display.h b/Drivers/ILI9488/Source/Ili9488Display.h index 06c71fa14..81ba0c0da 100644 --- a/Drivers/ILI9488/Source/Ili9488Display.h +++ b/Drivers/ILI9488/Source/Ili9488Display.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include diff --git a/Drivers/ST7735/Source/St7735Display.h b/Drivers/ST7735/Source/St7735Display.h index 13f64af35..ba90864f9 100644 --- a/Drivers/ST7735/Source/St7735Display.h +++ b/Drivers/ST7735/Source/St7735Display.h @@ -1,11 +1,10 @@ #pragma once -#include "Tactility/hal/spi/Spi.h" - #include #include #include +#include #include #include #include diff --git a/Drivers/ST7789/Source/St7789Display.h b/Drivers/ST7789/Source/St7789Display.h index 79bca3bd0..fe227af65 100644 --- a/Drivers/ST7789/Source/St7789Display.h +++ b/Drivers/ST7789/Source/St7789Display.h @@ -8,8 +8,6 @@ class St7789Display final : public EspLcdSpiDisplay { - std::shared_ptr lock; - public: /** Minimal set of overrides for EspLcdConfiguration */ diff --git a/Drivers/ST7796/Source/St7796Display.h b/Drivers/ST7796/Source/St7796Display.h index cbee37537..195cbd0f3 100644 --- a/Drivers/ST7796/Source/St7796Display.h +++ b/Drivers/ST7796/Source/St7796Display.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml new file mode 100644 index 000000000..d6555dbc1 --- /dev/null +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml @@ -0,0 +1,36 @@ +description: ESP32 SPI Controller + +include: ["spi-controller.yaml"] + +compatible: "espressif,esp32-spi" + +properties: + host: + type: int + required: true + description: | + The SPI host (controller) to use. + Defined by spi_host_device_t (e.g. SPI2_HOST, SPI3_HOST). + pin-mosi: + type: int + required: true + description: MOSI (Data 0) pin + pin-miso: + type: int + required: true + description: MISO (Data 1) pin + pin-sclk: + type: int + required: true + description: Clock pin + pin-wp: + type: int + description: WP (Data 2) pin + pin-hd: + type: int + description: HD (Data 3) pin + max-transfer-size: + type: int + description: | + Data transfer size limit in bytes. + 0 means the platform decides the limit. diff --git a/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h index 03b3cf69a..2b09708a4 100644 --- a/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h +++ b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include #ifdef __cplusplus diff --git a/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_spi.h b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_spi.h new file mode 100644 index 000000000..28f891f83 --- /dev/null +++ b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_spi.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(esp32_spi, struct Esp32SpiConfig) + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h index e008805b1..bf1dae183 100644 --- a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h +++ b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_spi.h @@ -10,11 +10,17 @@ extern "C" { struct Esp32SpiConfig { spi_host_device_t host; + /** Data 0 pin */ int pin_mosi; + /** Data 1 pin */ int pin_miso; + /** Clock pin */ int pin_sclk; + /** Data 2 pin */ int pin_wp; + /** Data 3 pin */ int pin_hd; + /** Data transfer size limit in bytes. 0 means the platform decides the limit. */ int max_transfer_size; }; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index dcc205320..e1982eb79 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 #include #include -#include +#include #include #include @@ -16,27 +16,27 @@ extern "C" { struct Esp32SpiInternal { - Mutex mutex; + RecursiveMutex mutex = {}; bool initialized = false; Esp32SpiInternal() { - mutex_construct(&mutex); + recursive_mutex_construct(&mutex); } ~Esp32SpiInternal() { - mutex_destruct(&mutex); + recursive_mutex_destruct(&mutex); } }; static error_t lock(Device* device) { auto* driver_data = GET_DATA(device); - mutex_lock(&driver_data->mutex); + recursive_mutex_lock(&driver_data->mutex); return ERROR_NONE; } static error_t try_lock(Device* device, TickType_t timeout) { auto* driver_data = GET_DATA(device); - if (mutex_try_lock(&driver_data->mutex, timeout)) { + if (recursive_mutex_try_lock(&driver_data->mutex, timeout)) { return ERROR_NONE; } return ERROR_TIMEOUT; @@ -44,7 +44,7 @@ static error_t try_lock(Device* device, TickType_t timeout) { static error_t unlock(Device* device) { auto* driver_data = GET_DATA(device); - mutex_unlock(&driver_data->mutex); + recursive_mutex_unlock(&driver_data->mutex); return ERROR_NONE; } diff --git a/Tactility/Include/Tactility/hal/Configuration.h b/Tactility/Include/Tactility/hal/Configuration.h index 3dc8f86fa..385bd322d 100644 --- a/Tactility/Include/Tactility/hal/Configuration.h +++ b/Tactility/Include/Tactility/hal/Configuration.h @@ -1,7 +1,6 @@ #pragma once #include -#include namespace tt::hal { @@ -38,9 +37,6 @@ struct Configuration { const UiScale uiScale = UiScale::Default; std::function createDevices = [] { return std::vector>(); }; - - /** A list of SPI interface configurations */ - const std::vector spi = {}; }; } // namespace diff --git a/Tactility/Include/Tactility/hal/display/DisplayDriver.h b/Tactility/Include/Tactility/hal/display/DisplayDriver.h index a11328cb9..b400223cb 100644 --- a/Tactility/Include/Tactility/hal/display/DisplayDriver.h +++ b/Tactility/Include/Tactility/hal/display/DisplayDriver.h @@ -24,7 +24,6 @@ class DisplayDriver { virtual uint16_t getPixelWidth() const = 0; virtual uint16_t getPixelHeight() const = 0; virtual bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) = 0; - virtual std::shared_ptr getLock() const = 0; }; } \ No newline at end of file diff --git a/Tactility/Include/Tactility/hal/sdcard/SdmmcDevice.h b/Tactility/Include/Tactility/hal/sdcard/SdmmcDevice.h index 0fab8a40b..dc490678b 100644 --- a/Tactility/Include/Tactility/hal/sdcard/SdmmcDevice.h +++ b/Tactility/Include/Tactility/hal/sdcard/SdmmcDevice.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include diff --git a/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h b/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h index 61c80efdd..cb9d08158 100644 --- a/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h +++ b/Tactility/Include/Tactility/hal/sdcard/SpiSdCardDevice.h @@ -3,14 +3,14 @@ #pragma once #include "SdCardDevice.h" +#include "Tactility/kernel/SpiDeviceLock.h" -#include +#include +#include #include #include #include -#include -#include namespace tt::hal::sdcard { @@ -64,15 +64,23 @@ class SpiSdCardDevice final : public SdCardDevice { 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 config) : SdCardDevice(config->mountBehaviourAtBoot), - config(std::move(config)) - {} + 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"; } @@ -82,11 +90,7 @@ class SpiSdCardDevice final : public SdCardDevice { std::string getMountPath() const override { return mountPath; } std::shared_ptr getLock() const override { - if (config->customLock != nullptr) { - return config->customLock; - } else { - return spi::getLock(config->spiHost); - } + return lock; } State getState(TickType_t timeout) const override; diff --git a/Tactility/Include/Tactility/hal/spi/Spi.h b/Tactility/Include/Tactility/hal/spi/Spi.h deleted file mode 100644 index 2a48acd22..000000000 --- a/Tactility/Include/Tactility/hal/spi/Spi.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "SpiCompat.h" - -#include -#include - -namespace tt::hal::spi { - -constexpr TickType_t defaultTimeout = 10 / portTICK_PERIOD_MS; - -enum class InitMode { - ByTactility, // Tactility will initialize it in the correct bootup phase - ByExternal, // The device is already initialized and Tactility should assume it works - Disabled // Not initialized by default -}; - -struct Configuration { - spi_host_device_t device; - spi_common_dma_t dma; - spi_bus_config_t config; - /** Whether this bus should be initialized when device starts up */ - InitMode initMode; - /** Whether configuration can be changed. */ - bool isMutable; - /** Optional custom lock - otherwise creates one internally */ - std::shared_ptr lock; -}; - -enum class Status { - Started, - Stopped, - Unknown -}; - -/** Start communications */ -bool start(spi_host_device_t device); - -/** Stop communications */ -bool stop(spi_host_device_t device); - -/** @return true if communications were started successfully */ -bool isStarted(spi_host_device_t device); - -/** - * Return the lock for the specified SPI device. Never returns nullptr. - * @return the lock that represents the specified device. Can be used with third party SPI implementations or native API calls (e.g. ESP-IDF). - */ -std::shared_ptr getLock(spi_host_device_t device); - -} // namespace tt::hal::spi diff --git a/Tactility/Include/Tactility/hal/spi/SpiCompat.h b/Tactility/Include/Tactility/hal/spi/SpiCompat.h deleted file mode 100644 index a71a94c59..000000000 --- a/Tactility/Include/Tactility/hal/spi/SpiCompat.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "../gpio/Gpio.h" - -#ifdef ESP_PLATFORM -#include -#else - -#define SPI_HOST_MAX 3 - -typedef tt::hal::gpio::Pin gpio_num_t; - -typedef int spi_host_device_t; -struct spi_bus_config_t { - gpio_num_t miso_io_num; - gpio_num_t mosi_io_num; - gpio_num_t sclk_io_num; -}; -struct spi_common_dma_t {}; - -#endif \ No newline at end of file diff --git a/Tactility/Private/Tactility/hal/spi/SpiInit.h b/Tactility/Private/Tactility/hal/spi/SpiInit.h deleted file mode 100644 index b3858a81c..000000000 --- a/Tactility/Private/Tactility/hal/spi/SpiInit.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include - -#include -#include - -namespace tt::hal::spi { - -/** - * Called by main HAL init to ready the internal state of the SPI HAL. - * @param[in] configurations HAL configuration for a board - * @return true on success - */ -bool init(const std::vector& configurations); - -} diff --git a/Tactility/Source/hal/Hal.cpp b/Tactility/Source/hal/Hal.cpp index b392e1a47..df7840ac3 100644 --- a/Tactility/Source/hal/Hal.cpp +++ b/Tactility/Source/hal/Hal.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -64,8 +63,6 @@ static void startDisplays() { void init(const Configuration& configuration) { kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin); - check(spi::init(configuration.spi), "SPI init failed"); - if (configuration.initBoot != nullptr) { check(configuration.initBoot(), "Init boot failed"); } diff --git a/Tactility/Source/hal/spi/Spi.cpp b/Tactility/Source/hal/spi/Spi.cpp deleted file mode 100644 index 06166419b..000000000 --- a/Tactility/Source/hal/spi/Spi.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include - -#include -#include - -namespace tt::hal::spi { - -static const auto LOGGER = Logger("SPI"); - -struct Data { - std::shared_ptr lock; - bool isConfigured = false; - bool isStarted = false; - Configuration configuration; -}; - -static Data dataArray[SPI_HOST_MAX]; - -bool init(const std::vector& configurations) { - LOGGER.info("Init"); - for (const auto& configuration: configurations) { - Data& data = dataArray[configuration.device]; - data.configuration = configuration; - data.isConfigured = true; - if (configuration.lock != nullptr) { - data.lock = configuration.lock; - } else { - data.lock = std::make_shared(); - } - } - - for (const auto& config: configurations) { - if (config.initMode == InitMode::ByTactility) { - if (!start(config.device)) { - return false; - } - } else if (config.initMode == InitMode::ByExternal) { - dataArray[config.device].isStarted = true; - } - } - - return true; -} - -bool configure(spi_host_device_t device, const spi_bus_config_t& configuration) { - auto lock = getLock(device)->asScopedLock(); - lock.lock(); - - Data& data = dataArray[device]; - if (data.isStarted) { - LOGGER.error("({}) Cannot reconfigure while interface is started", static_cast(device)); - return false; - } else if (!data.configuration.isMutable) { - LOGGER.error("({}) Mutation not allowed by original configuration", static_cast(device)); - return false; - } else { - data.configuration.config = configuration; - return true; - } -} - -bool start(spi_host_device_t device) { - auto lock = getLock(device)->asScopedLock(); - lock.lock(); - - Data& data = dataArray[device]; - - if (data.isStarted) { - LOGGER.error("({}) Starting: Already started", static_cast(device)); - return false; - } - - if (!data.isConfigured) { - LOGGER.error("({}) Starting: Not configured", static_cast(device)); - return false; - } - -#ifdef ESP_PLATFORM - - auto result = spi_bus_initialize(device, &data.configuration.config, data.configuration.dma); - if (result != ESP_OK) { - LOGGER.error("({}) Starting: Failed to initialize: {}", static_cast(device), esp_err_to_name(result)); - return false; - } else { - data.isStarted = true; - } - -#else - - data.isStarted = true; - -#endif - - LOGGER.info("({}) Started", static_cast(device)); - return true; -} - -bool stop(spi_host_device_t device) { - auto lock = getLock(device)->asScopedLock(); - lock.lock(); - - Data& data = dataArray[device]; - Configuration& config = data.configuration; - - if (!config.isMutable) { - LOGGER.error("({}) Stopping: Not allowed, immutable", static_cast(device)); - return false; - } - - if (!data.isStarted) { - LOGGER.error("({}) Stopping: Not started", static_cast(device)); - return false; - } - -#ifdef ESP_PLATFORM - - auto result = spi_bus_free(device); - if (result != ESP_OK) { - LOGGER.error("({}) Stopping: Failed to free device: {}", static_cast(device), esp_err_to_name(result)); - return false; - } else { - data.isStarted = false; - } - -#else - - data.isStarted = false; - -#endif - - LOGGER.info("({}) Stopped", static_cast(device)); - return true; -} - -bool isStarted(spi_host_device_t device) { - auto lock = getLock(device)->asScopedLock(); - lock.lock(); - - return dataArray[device].isStarted; -} - -std::shared_ptr getLock(spi_host_device_t device) { - return dataArray[device].lock; -} - -} diff --git a/TactilityC/Source/tt_hal_display.cpp b/TactilityC/Source/tt_hal_display.cpp index d8e4b375e..48f16aff9 100644 --- a/TactilityC/Source/tt_hal_display.cpp +++ b/TactilityC/Source/tt_hal_display.cpp @@ -57,13 +57,12 @@ void tt_hal_display_driver_free(DisplayDriverHandle handle) { } bool tt_hal_display_driver_lock(DisplayDriverHandle handle, TickType_t timeout) { - auto wrapper = static_cast(handle); - return wrapper->driver->getLock()->lock(timeout); + // TODO: re-implement with SPI lock + return true; } void tt_hal_display_driver_unlock(DisplayDriverHandle handle) { - auto wrapper = static_cast(handle); - wrapper->driver->getLock()->unlock(); + // TODO: re-implement with SPI lock } ColorFormat tt_hal_display_driver_get_colorformat(DisplayDriverHandle handle) { diff --git a/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h b/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h new file mode 100644 index 000000000..09e7b93d2 --- /dev/null +++ b/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include + +namespace tt { + +class SpiDeviceLock : public Lock { + ::Device* device; +public: + SpiDeviceLock(::Device* device) : device(device) { } + + bool lock(TickType_t timeout) const override { + return spi_controller_try_lock(device, timeout) == ERROR_NONE; + } + + void unlock() const override { + spi_controller_unlock(device); + } +}; + +} diff --git a/TactilityKernel/Bindings/spi-controller.yaml b/TactilityKernel/Bindings/spi-controller.yaml new file mode 100644 index 000000000..6366ceff8 --- /dev/null +++ b/TactilityKernel/Bindings/spi-controller.yaml @@ -0,0 +1 @@ +description: SPI controller From f4df5f6890707385acdd38376b6f76bd28e079c9 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 15:37:12 +0100 Subject: [PATCH 2/9] WIP --- .../cyd-2432s024c/Source/devices/Display.h | 1 - .../cyd-2432s028r/Source/devices/Display.h | 1 - .../cyd-2432s028rv3/Source/devices/Display.h | 1 - .../cyd-2432s032c/Source/devices/Display.h | 1 - Devices/cyd-e32r28t/Source/devices/Display.h | 1 - Devices/cyd-e32r32p/Source/devices/Display.h | 1 - .../Source/Configuration.cpp | 53 +-------- .../Source/devices/Display.h | 1 - .../Source/devices/SdCard.cpp | 7 +- .../elecrow,crowpanel-advance-28.dts | 23 ++++ .../Source/Configuration.cpp | 55 +-------- .../Source/devices/SdCard.cpp | 7 +- .../elecrow,crowpanel-advance-35.dts | 23 ++++ .../Source/Configuration.cpp | 28 +---- .../Source/devices/SdCard.cpp | 8 +- .../elecrow,crowpanel-advance-50.dts | 12 ++ .../Source/Configuration.cpp | 57 +--------- .../Source/devices/SdCard.cpp | 7 +- .../elecrow,crowpanel-basic-28.dts | 23 ++++ .../Source/Configuration.cpp | 59 +--------- .../Source/devices/SdCard.cpp | 7 +- .../elecrow,crowpanel-basic-35.dts | 23 ++++ .../Source/Configuration.cpp | 28 +---- .../Source/devices/SdCard.cpp | 7 +- .../elecrow,crowpanel-basic-50.dts | 12 ++ .../Source/Configuration.cpp | 53 +-------- .../Source/devices/Display.h | 1 - .../Source/devices/SdCard.cpp | 11 +- .../guition,jc2432w328c.dts | 23 ++++ .../Source/Axs15231b/Axs15231bDisplay.cpp | 1 - .../Source/Axs15231b/Axs15231bDisplay.h | 2 +- .../Source/Configuration.cpp | 57 +--------- .../Source/devices/SdCard.cpp | 10 +- .../guition,jc3248w535c.dts | 23 ++++ .../Source/Configuration.cpp | 28 +---- .../Source/devices/SdCard.cpp | 13 ++- .../guition,jc8048w550c.dts | 12 ++ .../Source/Configuration.cpp | 15 +-- .../Source/Configuration.cpp | 20 +--- Devices/lilygo-tdisplay-s3/Source/Init.cpp | 5 +- .../lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts | 12 ++ .../lilygo-tdisplay/Source/Configuration.cpp | 28 +---- .../lilygo-tdisplay/Source/devices/Display.h | 1 - Devices/lilygo-tdisplay/lilygo,tdisplay.dts | 12 ++ .../Source/Configuration.cpp | 30 +---- .../Source/devices/Display.cpp | 2 +- .../lilygo-tdongle-s3/lilygo,tdongle-s3.dts | 12 ++ Devices/unphone/Source/Configuration.cpp | 2 - .../Source/Configuration.cpp | 2 +- Documentation/ideas.md | 3 + Drivers/ILI9488/Source/Ili9488Display.h | 1 - Drivers/RgbDisplay/Source/RgbDisplay.h | 7 +- Drivers/SSD1306/Source/Ssd1306Display.h | 1 - Drivers/ST7735/Source/St7735Display.h | 6 +- Drivers/XPT2046/Source/Xpt2046Power.cpp | 105 ------------------ Drivers/XPT2046/Source/Xpt2046Power.h | 28 ----- Drivers/XPT2046/Source/Xpt2046Touch.cpp | 16 --- Drivers/XPT2046/Source/Xpt2046Touch.h | 2 - Firmware/idf_component.yml | 2 +- Modules/lvgl-module/Source/arch/lvgl_esp32.c | 4 +- .../Include/Tactility/hal/Configuration.h | 10 +- Tactility/Source/service/wifi/WifiEsp.cpp | 28 +---- TactilityC/Source/tt_init.cpp | 18 ++- .../tactility/concurrent/recursive_mutex.h | 3 +- 64 files changed, 322 insertions(+), 733 deletions(-) delete mode 100644 Drivers/XPT2046/Source/Xpt2046Power.cpp delete mode 100644 Drivers/XPT2046/Source/Xpt2046Power.h diff --git a/Devices/cyd-2432s024c/Source/devices/Display.h b/Devices/cyd-2432s024c/Source/devices/Display.h index f030fafa9..da6b56e62 100644 --- a/Devices/cyd-2432s024c/Source/devices/Display.h +++ b/Devices/cyd-2432s024c/Source/devices/Display.h @@ -14,6 +14,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); diff --git a/Devices/cyd-2432s028r/Source/devices/Display.h b/Devices/cyd-2432s028r/Source/devices/Display.h index 75b1c3552..d3428a78c 100644 --- a/Devices/cyd-2432s028r/Source/devices/Display.h +++ b/Devices/cyd-2432s028r/Source/devices/Display.h @@ -13,7 +13,6 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; // Display backlight (PWM) constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_21; diff --git a/Devices/cyd-2432s028rv3/Source/devices/Display.h b/Devices/cyd-2432s028rv3/Source/devices/Display.h index 368b6aeb5..67a097996 100644 --- a/Devices/cyd-2432s028rv3/Source/devices/Display.h +++ b/Devices/cyd-2432s028rv3/Source/devices/Display.h @@ -16,7 +16,6 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; // Touch (Software SPI) constexpr auto TOUCH_MISO_PIN = GPIO_NUM_39; diff --git a/Devices/cyd-2432s032c/Source/devices/Display.h b/Devices/cyd-2432s032c/Source/devices/Display.h index 541c3498c..8a54f1e1a 100644 --- a/Devices/cyd-2432s032c/Source/devices/Display.h +++ b/Devices/cyd-2432s032c/Source/devices/Display.h @@ -14,6 +14,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); diff --git a/Devices/cyd-e32r28t/Source/devices/Display.h b/Devices/cyd-e32r28t/Source/devices/Display.h index b8cca6202..fbe79f5a3 100644 --- a/Devices/cyd-e32r28t/Source/devices/Display.h +++ b/Devices/cyd-e32r28t/Source/devices/Display.h @@ -13,7 +13,6 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = (LCD_VERTICAL_RESOLUTION / 10); constexpr auto LCD_BUFFER_SIZE = (LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT); -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; // Touch (Software SPI) constexpr auto TOUCH_MISO_PIN = GPIO_NUM_39; diff --git a/Devices/cyd-e32r32p/Source/devices/Display.h b/Devices/cyd-e32r32p/Source/devices/Display.h index 90eae75ae..0106b0913 100644 --- a/Devices/cyd-e32r32p/Source/devices/Display.h +++ b/Devices/cyd-e32r32p/Source/devices/Display.h @@ -14,7 +14,6 @@ constexpr auto DISPLAY_VERTICAL_RESOLUTION = 320; constexpr auto DISPLAY_DRAW_BUFFER_HEIGHT = (DISPLAY_VERTICAL_RESOLUTION / 10); constexpr auto DISPLAY_DRAW_BUFFER_SIZE = (DISPLAY_HORIZONTAL_RESOLUTION * DISPLAY_DRAW_BUFFER_HEIGHT); constexpr auto DISPLAY_BACKLIGHT_PIN = GPIO_NUM_27; -constexpr auto DISPLAY_SPI_TRANSFER_SIZE_LIMIT = DISPLAY_DRAW_BUFFER_SIZE * sizeof(lv_color_t); // Touch (XPT2046, resistive, shared SPI with display) constexpr auto TOUCH_MISO_PIN = GPIO_NUM_12; diff --git a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp index 51cc6e32d..09a0ca1f2 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/Configuration.cpp @@ -4,7 +4,6 @@ #include #include -#include using namespace tt::hal; @@ -21,55 +20,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_39, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_42, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_6, - .miso_io_num = GPIO_NUM_4, - .sclk_io_num = GPIO_NUM_5, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/elecrow-crowpanel-advance-28/Source/devices/Display.h b/Devices/elecrow-crowpanel-advance-28/Source/devices/Display.h index 6f986d05a..7d579c125 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/devices/Display.h +++ b/Devices/elecrow-crowpanel-advance-28/Source/devices/Display.h @@ -12,6 +12,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); diff --git a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp index 1c011c3c1..aba0191cd 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -19,7 +20,11 @@ std::shared_ptr createSdCard() { SPI3_HOST ); + auto* spi_controller = device_find_by_name("spi1"); + check(spi_controller, "spi1 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } 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 9e729f0a5..b798d91a6 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,28 @@ pin-scl-pullup; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <39>; + pin-miso = ; + pin-sclk = <42>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <6>; + pin-miso = <4>; + pin-sclk = <5>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart0 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp index 90f32beb0..33bdf3347 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/Configuration.cpp @@ -3,11 +3,8 @@ #include #include -#include #include -#define CROWPANEL_SPI_TRANSFER_SIZE_LIMIT (CROWPANEL_LCD_HORIZONTAL_RESOLUTION * CROWPANEL_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8)) - using namespace tt::hal; static bool initBoot() { @@ -23,55 +20,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_39, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_42, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = CROWPANEL_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_6, - .miso_io_num = GPIO_NUM_4, - .sclk_io_num = GPIO_NUM_5, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp index 1c011c3c1..aba0191cd 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -19,7 +20,11 @@ std::shared_ptr createSdCard() { SPI3_HOST ); + auto* spi_controller = device_find_by_name("spi1"); + check(spi_controller, "spi1 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } 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 ba5260fad..ae6afc605 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,28 @@ pin-scl-pullup; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <39>; + pin-miso = ; + pin-sclk = <42>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <6>; + pin-miso = <4>; + pin-sclk = <5>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart0 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp index 293c1f30d..76b3a79da 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/Configuration.cpp @@ -31,31 +31,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // SD card - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_6, - .miso_io_num = GPIO_NUM_4, - .sclk_io_num = GPIO_NUM_5, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp index 3087262a4..048f57ca3 100644 --- a/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-advance-50/Source/devices/SdCard.cpp @@ -1,7 +1,7 @@ #include "SdCard.h" +#include #include -#include using tt::hal::sdcard::SpiSdCardDevice; @@ -15,7 +15,11 @@ std::shared_ptr createSdCard() { SdCardDevice::MountBehaviour::AtBoot ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } 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 ef5932566..ef5d45543 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,17 @@ pin-scl-pullup; }; + sdcard_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <6>; + pin-miso = <4>; + pin-sclk = <5>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart0 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp index f81c3f785..d773cbaac 100644 --- a/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-28/Source/Configuration.cpp @@ -4,8 +4,6 @@ #include #include -#include -#include using namespace tt::hal; @@ -15,63 +13,12 @@ static bool initBoot() { static DeviceVector createDevices() { return { - std::make_shared(), createDisplay(), - createSdCard(), + createSdCard() }; } extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_12, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp index 3103ad3d9..38cfc75b7 100644 --- a/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-basic-28/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -17,7 +18,11 @@ std::shared_ptr createSdCard() { SPI3_HOST ); + auto* spi_controller = device_find_by_name("spi1"); + check(spi_controller, "spi1 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } 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 5b60dbab6..e151ef588 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,28 @@ pin-scl-pullup; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = <12>; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp index 882444207..d773cbaac 100644 --- a/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-35/Source/Configuration.cpp @@ -1,13 +1,9 @@ #include "PwmBacklight.h" -#include "Tactility/lvgl/LvglSync.h" #include "devices/Display.h" #include "devices/SdCard.h" #include #include -#include - -constexpr auto CROWPANEL_SPI_TRANSFER_SIZE_LIMIT = (CROWPANEL_LCD_HORIZONTAL_RESOLUTION * CROWPANEL_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8)); using namespace tt::hal; @@ -17,63 +13,12 @@ static bool initBoot() { static DeviceVector createDevices() { return { - std::make_shared(), createDisplay(), - createSdCard(), + createSdCard() }; } extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_33, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = CROWPANEL_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp index 3103ad3d9..38cfc75b7 100644 --- a/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-basic-35/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -17,7 +18,11 @@ std::shared_ptr createSdCard() { SPI3_HOST ); + auto* spi_controller = device_find_by_name("spi1"); + check(spi_controller, "spi1 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } 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 1978876e6..aada9daa6 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,28 @@ pin-scl-pullup; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = <33>; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp index b9da4fd23..9df5ad4af 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/Configuration.cpp @@ -21,31 +21,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // SD card - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_13, - .sclk_io_num = GPIO_NUM_12, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp index a27db36cb..dbf0f03f3 100644 --- a/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-basic-50/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include using tt::hal::sdcard::SpiSdCardDevice; @@ -13,7 +14,11 @@ std::shared_ptr createSdCard() { SdCardDevice::MountBehaviour::AtBoot ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } 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 43493e3a7..02d145481 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,17 @@ pin-scl-pullup; }; + sdcard_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = <13>; + pin-sclk = <12>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart0 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/guition-jc2432w328c/Source/Configuration.cpp b/Devices/guition-jc2432w328c/Source/Configuration.cpp index 4ad1382ac..ee79f6c67 100644 --- a/Devices/guition-jc2432w328c/Source/Configuration.cpp +++ b/Devices/guition-jc2432w328c/Source/Configuration.cpp @@ -4,7 +4,6 @@ #include #include -#include using namespace tt::hal; @@ -31,55 +30,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - //Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_13, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_14, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - //SD Card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_19, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/guition-jc2432w328c/Source/devices/Display.h b/Devices/guition-jc2432w328c/Source/devices/Display.h index 5a00ee0c6..26e2214a8 100644 --- a/Devices/guition-jc2432w328c/Source/devices/Display.h +++ b/Devices/guition-jc2432w328c/Source/devices/Display.h @@ -18,6 +18,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 320; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); diff --git a/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp b/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp index 84360cfae..45238df8c 100644 --- a/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp +++ b/Devices/guition-jc2432w328c/Source/devices/SdCard.cpp @@ -1,8 +1,7 @@ #include "SdCard.h" +#include #include -#include -#include constexpr auto SDCARD_SPI_HOST = SPI3_HOST; constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; @@ -16,13 +15,17 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index 24c50b625..82735e0cd 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -31,6 +32,28 @@ pin-scl = <22>; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <13>; + pin-miso = ; + pin-sclk = <14>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <19>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V uart1 { compatible = "espressif,esp32-uart"; diff --git a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp index 644dfa447..e2c8bc4e0 100644 --- a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp +++ b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp @@ -485,7 +485,6 @@ std::shared_ptr Axs15231bDisplay::getDisplayDri if (displayDriver == nullptr) { displayDriver = std::make_shared( panelHandle, - tt::lvgl::getSyncLock(), configuration->horizontalResolution, configuration->verticalResolution, tt::hal::display::ColorFormat::RGB565Swapped diff --git a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h index 397d03880..18a3040d9 100644 --- a/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h +++ b/Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h @@ -25,7 +25,7 @@ class Axs15231bDisplay final : public tt::hal::display::DisplayDevice { gpio_num_t csPin, gpio_num_t dcPin, gpio_num_t resetPin, - + gpio_num_t tePin, unsigned int horizontalResolution, unsigned int verticalResolution, std::shared_ptr touch, diff --git a/Devices/guition-jc3248w535c/Source/Configuration.cpp b/Devices/guition-jc3248w535c/Source/Configuration.cpp index 29c1d7131..0ceef45ae 100644 --- a/Devices/guition-jc3248w535c/Source/Configuration.cpp +++ b/Devices/guition-jc3248w535c/Source/Configuration.cpp @@ -3,13 +3,10 @@ #include #include -#include #include using namespace tt::hal; -static constexpr int SPI_TRANSFER_SIZE_LIMIT = 320 * 10; - static DeviceVector createDevices() { return { createDisplay(), @@ -23,57 +20,5 @@ static bool initBoot() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - //I2C Internal - Touch - //I2C External - P3 (JST SH 1.0)/ P4 (JST SH 1.25) headers - GND 3.3V IO17 IO18 - .spi { - //Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .data0_io_num = GPIO_NUM_21, - .data1_io_num = GPIO_NUM_48, - .sclk_io_num = GPIO_NUM_47, - .data2_io_num = GPIO_NUM_40, - .data3_io_num = GPIO_NUM_39, - .data4_io_num = -1, - .data5_io_num = -1, - .data6_io_num = -1, - .data7_io_num = -1, - .data_io_default_level = false, - .max_transfer_sz = SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - //SD Card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_13, - .sclk_io_num = GPIO_NUM_12, - .quadwp_io_num = -1, - .quadhd_io_num = -1, - .data4_io_num = -1, - .data5_io_num = -1, - .data6_io_num = -1, - .data7_io_num = -1, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp b/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp index 8648798b0..e4b2e2345 100644 --- a/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp +++ b/Devices/guition-jc3248w535c/Source/devices/SdCard.cpp @@ -1,7 +1,7 @@ #include "SdCard.h" +#include #include -#include constexpr auto SDCARD_SPI_HOST = SPI3_HOST; constexpr auto SDCARD_PIN_CS = GPIO_NUM_10; @@ -15,12 +15,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index 326df34c2..16d548f04 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -34,6 +35,28 @@ pin-scl-pullup; }; + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <21>; + pin-miso = <48>; + pin-sclk = <47>; + pin-wp = <40>; + pin-hd = <39>; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = <13>; + pin-sclk = <12>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + // P1 header uart0 { compatible = "espressif,esp32-uart"; diff --git a/Devices/guition-jc8048w550c/Source/Configuration.cpp b/Devices/guition-jc8048w550c/Source/Configuration.cpp index a6e82c6a4..174ca14fa 100644 --- a/Devices/guition-jc8048w550c/Source/Configuration.cpp +++ b/Devices/guition-jc8048w550c/Source/Configuration.cpp @@ -20,31 +20,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - //SD Card - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_13, - .sclk_io_num = GPIO_NUM_12, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp b/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp index 153440cf4..876fca400 100644 --- a/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp +++ b/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include #include @@ -13,14 +14,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + nullptr, std::vector(), SPI2_HOST ); - auto sdcard = std::make_shared( - std::move(config) - ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); - return std::static_pointer_cast(sdcard); + return std::make_shared( + std::move(config), + spi_controller + ); } diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index b0514a676..1c71247db 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -34,6 +35,17 @@ pin-scl-pullup; }; + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = <13>; + pin-sclk = <12>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp b/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp index 48eca3ddb..c6d3b1f06 100644 --- a/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp +++ b/Devices/heltec-wifi-lora-32-v3/Source/Configuration.cpp @@ -2,15 +2,13 @@ #include "devices/Power.h" #include "devices/Constants.h" +#include +#include + #include -#include -#include #include -#include "driver/gpio.h" -#include "driver/i2c.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" +#include static void enableOledPower() { gpio_config_t io_conf = { @@ -24,7 +22,7 @@ static void enableOledPower() { gpio_set_level(DISPLAY_PIN_POWER, 0); // Active low vTaskDelay(pdMS_TO_TICKS(500)); // Add a small delay for power to stabilize - tt::Logger("HeltecV3").info("OLED power enabled"); + LOG_I("HeltecV3", "OLED power enabled"); } static bool initBoot() { @@ -47,6 +45,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi {}, + .createDevices = createDevices }; diff --git a/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp b/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp index 61287a607..bc5b80549 100644 --- a/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp +++ b/Devices/lilygo-tdisplay-s3/Source/Configuration.cpp @@ -1,9 +1,7 @@ #include "devices/Display.h" #include "devices/Power.h" -#include #include -#include #include bool initBoot(); @@ -20,21 +18,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_7, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_6, - .max_transfer_sz = DISPLAY_HORIZONTAL_RESOLUTION * DISPLAY_VERTICAL_RESOLUTION * 2, - .flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - } - } + .createDevices = createDevices }; diff --git a/Devices/lilygo-tdisplay-s3/Source/Init.cpp b/Devices/lilygo-tdisplay-s3/Source/Init.cpp index 754b72f50..1ce00d086 100644 --- a/Devices/lilygo-tdisplay-s3/Source/Init.cpp +++ b/Devices/lilygo-tdisplay-s3/Source/Init.cpp @@ -7,9 +7,6 @@ #define TAG "tdisplay-s3" -// Power on - - static bool powerOn() { gpio_config_t power_signal_config = { .pin_bit_mask = BIT64(TDISPLAY_S3_POWERON_GPIO), @@ -27,7 +24,7 @@ static bool powerOn() { return false; } - + return true; } bool initBoot() { diff --git a/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts b/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts index d626d6b3d..723d6dcd5 100644 --- a/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts +++ b/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -12,4 +13,15 @@ compatible = "espressif,esp32-gpio"; gpio-count = <49>; }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <7>; + pin-miso = ; + pin-sclk = <6>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/lilygo-tdisplay/Source/Configuration.cpp b/Devices/lilygo-tdisplay/Source/Configuration.cpp index 9c049e35e..cb68ebfce 100644 --- a/Devices/lilygo-tdisplay/Source/Configuration.cpp +++ b/Devices/lilygo-tdisplay/Source/Configuration.cpp @@ -1,9 +1,7 @@ #include "devices/Display.h" -#include #include #include -#include #include using namespace tt::hal; @@ -22,29 +20,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_19, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - } - } + .createDevices = createDevices }; diff --git a/Devices/lilygo-tdisplay/Source/devices/Display.h b/Devices/lilygo-tdisplay/Source/devices/Display.h index a11933b31..7a8c13b55 100644 --- a/Devices/lilygo-tdisplay/Source/devices/Display.h +++ b/Devices/lilygo-tdisplay/Source/devices/Display.h @@ -14,6 +14,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 135; constexpr auto LCD_VERTICAL_RESOLUTION = 240; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 3; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); diff --git a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts index b7002491a..994b065c4 100644 --- a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts +++ b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -12,4 +13,15 @@ compatible = "espressif,esp32-gpio"; gpio-count = <49>; }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <19>; + pin-miso = ; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/lilygo-tdongle-s3/Source/Configuration.cpp b/Devices/lilygo-tdongle-s3/Source/Configuration.cpp index 1e1adb264..acec5b451 100644 --- a/Devices/lilygo-tdongle-s3/Source/Configuration.cpp +++ b/Devices/lilygo-tdongle-s3/Source/Configuration.cpp @@ -1,11 +1,7 @@ #include "devices/Display.h" #include "devices/Sdcard.h" -#include #include -#include - -#define TDECK_SPI_TRANSFER_SIZE_LIMIT (80 * 160 * (LV_COLOR_DEPTH / 8)) bool initBoot(); @@ -21,29 +17,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_3, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_5, - .quadwp_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = TDECK_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - } + .createDevices = createDevices }; diff --git a/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp b/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp index 35597a8d4..3285ba7c7 100644 --- a/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp +++ b/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp @@ -3,7 +3,7 @@ #include #include -#define LCD_SPI_HOST SPI3_HOST +#define LCD_SPI_HOST SPI2_HOST #define LCD_PIN_CS GPIO_NUM_4 #define LCD_PIN_DC GPIO_NUM_2 #define LCD_PIN_RESET GPIO_NUM_1 diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index bc5b5b341..bcfc2c997 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -24,6 +25,17 @@ pin-scl-pullup; }; + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <3>; + pin-miso = ; + pin-sclk = <5>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + stemma_qt: uart1 { compatible = "espressif,esp32-uart"; port = ; diff --git a/Devices/unphone/Source/Configuration.cpp b/Devices/unphone/Source/Configuration.cpp index c8d71b5a4..5322cf2f4 100644 --- a/Devices/unphone/Source/Configuration.cpp +++ b/Devices/unphone/Source/Configuration.cpp @@ -5,7 +5,6 @@ #include #include -#include #define UNPHONE_SPI_TRANSFER_SIZE_LIMIT (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_SPI_TRANSFER_HEIGHT * LV_COLOR_DEPTH / 8) @@ -13,7 +12,6 @@ bool initBoot(); static tt::hal::DeviceVector createDevices() { return { - std::make_shared(), createDisplay(), createSdCard() }; diff --git a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp index 5dd262d97..70c85db01 100644 --- a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp +++ b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp @@ -1,6 +1,6 @@ #include "devices/Display.h" #include "devices/SdCard.h" -#include +#include #include #include diff --git a/Documentation/ideas.md b/Documentation/ideas.md index 9b39c30d8..7a3600ea1 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -11,6 +11,9 @@ ## Higher Priority +- Make a root device type so it can be discovered more easily. +- DTS/yaml: Consider support for default values. +- DTS: throw custom exceptions and catch them to show cleaner error messages. - Add font design tokens such as "regular", "title" and "smaller". Perhaps via the LVGL kernel module. - Add kernel listening mechanism so that the root device init can be notified when a device becomes available: Callback for device/start stop with filtering on device type: diff --git a/Drivers/ILI9488/Source/Ili9488Display.h b/Drivers/ILI9488/Source/Ili9488Display.h index 81ba0c0da..8e2fb3f8f 100644 --- a/Drivers/ILI9488/Source/Ili9488Display.h +++ b/Drivers/ILI9488/Source/Ili9488Display.h @@ -75,7 +75,6 @@ class Ili9488Display final : public EspLcdDisplay { public: explicit Ili9488Display(std::unique_ptr inConfiguration) : - EspLcdDisplay(tt::hal::spi::getLock(inConfiguration->spiHostDevice)), configuration(std::move(inConfiguration) ) { assert(configuration != nullptr); diff --git a/Drivers/RgbDisplay/Source/RgbDisplay.h b/Drivers/RgbDisplay/Source/RgbDisplay.h index bbfb0a66a..46635cd03 100644 --- a/Drivers/RgbDisplay/Source/RgbDisplay.h +++ b/Drivers/RgbDisplay/Source/RgbDisplay.h @@ -1,15 +1,12 @@ #pragma once #include -#include #include #include #include class RgbDisplay final : public tt::hal::display::DisplayDevice { - std::shared_ptr lock = std::make_shared(); - public: struct BufferConfiguration final { @@ -75,7 +72,7 @@ class RgbDisplay final : public tt::hal::display::DisplayDevice { assert(configuration != nullptr); } - ~RgbDisplay(); + ~RgbDisplay() override; std::string getName() const override { return "RGB Display"; } std::string getDescription() const override { return "RGB Display"; } @@ -108,7 +105,7 @@ class RgbDisplay final : public tt::hal::display::DisplayDevice { std::shared_ptr _Nullable getDisplayDriver() override { if (displayDriver == nullptr) { auto config = getLvglPortDisplayConfig(); - displayDriver = std::make_shared(panelHandle, lock, config.hres, config.vres, tt::hal::display::ColorFormat::RGB888); + displayDriver = std::make_shared(panelHandle, config.hres, config.vres, tt::hal::display::ColorFormat::RGB888); } return displayDriver; } diff --git a/Drivers/SSD1306/Source/Ssd1306Display.h b/Drivers/SSD1306/Source/Ssd1306Display.h index aa09dc6d4..115982beb 100644 --- a/Drivers/SSD1306/Source/Ssd1306Display.h +++ b/Drivers/SSD1306/Source/Ssd1306Display.h @@ -57,7 +57,6 @@ class Ssd1306Display final : public EspLcdDisplay { public: explicit Ssd1306Display(std::unique_ptr inConfiguration) : - EspLcdDisplay(nullptr), configuration(std::move(inConfiguration)) { assert(configuration != nullptr); diff --git a/Drivers/ST7735/Source/St7735Display.h b/Drivers/ST7735/Source/St7735Display.h index ba90864f9..0c2083d8d 100644 --- a/Drivers/ST7735/Source/St7735Display.h +++ b/Drivers/ST7735/Source/St7735Display.h @@ -87,12 +87,8 @@ class St7735Display final : public EspLcdDisplay { public: explicit St7735Display(std::unique_ptr inConfiguration) : - EspLcdDisplay(tt::hal::spi::getLock(inConfiguration->spiHostDevice)), configuration(std::move(inConfiguration) - ) { - assert(configuration != nullptr); - assert(getLock() != nullptr); - } + ) {} std::string getName() const override { return "ST7735"; } diff --git a/Drivers/XPT2046/Source/Xpt2046Power.cpp b/Drivers/XPT2046/Source/Xpt2046Power.cpp deleted file mode 100644 index a68668aa3..000000000 --- a/Drivers/XPT2046/Source/Xpt2046Power.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "Xpt2046Power.h" -#include "Xpt2046Touch.h" - -#include -#include - -static const auto LOGGER = tt::Logger("Xpt2046Power"); - -constexpr auto BATTERY_VOLTAGE_MIN = 3.2f; -constexpr auto BATTERY_VOLTAGE_MAX = 4.2f; -constexpr auto MAX_VOLTAGE_SAMPLES = 15; - -static std::shared_ptr findXp2046TouchDevice() { - // Make a safe copy - auto touch = tt::hal::findFirstDevice(tt::hal::Device::Type::Touch); - if (touch == nullptr) { - LOGGER.error("Touch device not found"); - return nullptr; - } - - if (touch->getName() != "XPT2046") { - LOGGER.error("Touch device name mismatch"); - return nullptr; - } - - return std::reinterpret_pointer_cast(touch); -} - -static uint8_t estimateChargeLevelFromVoltage(uint32_t milliVolt) { - float volts = std::min((float)milliVolt / 1000.f, BATTERY_VOLTAGE_MAX); - float voltage_percentage = (volts - BATTERY_VOLTAGE_MIN) / (BATTERY_VOLTAGE_MAX - BATTERY_VOLTAGE_MIN); - float voltage_factor = std::min(1.0f, voltage_percentage); - auto charge_level = (uint8_t) (voltage_factor * 100.f); - LOGGER.verbose("mV = {}, scaled = {}, factor = {}, result = {}", milliVolt, volts, voltage_factor, charge_level); - return charge_level; -} - -bool Xpt2046Power::supportsMetric(MetricType type) const { - switch (type) { - using enum MetricType; - case BatteryVoltage: - case ChargeLevel: - return true; - default: - return false; - } -} - -bool Xpt2046Power::getMetric(MetricType type, MetricData& data) { - switch (type) { - using enum MetricType; - case BatteryVoltage: - return readBatteryVoltageSampled(data.valueAsUint32); - case ChargeLevel: { - uint32_t milli_volt; - if (readBatteryVoltageSampled(milli_volt)) { - data.valueAsUint8 = estimateChargeLevelFromVoltage(milli_volt); - return true; - } else { - return false; - } - } - default: - return false; - } -} - -bool Xpt2046Power::readBatteryVoltageOnce(uint32_t& output) { - if (xptTouch == nullptr) { - xptTouch = findXp2046TouchDevice(); - if (xptTouch == nullptr) { - LOGGER.error("XPT2046 touch device not found"); - return false; - } - } - - float vbat; - if (!xptTouch->getVBat(vbat)) { - return false; - } - - // Convert to mV - output = (uint32_t)(vbat * 1000.f); - return true; -} - -bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) { - size_t samples_read = 0; - uint32_t sample_accumulator = 0; - uint32_t sample_read_buffer; - - for (size_t i = 0; i < MAX_VOLTAGE_SAMPLES; ++i) { - if (readBatteryVoltageOnce(sample_read_buffer)) { - sample_accumulator += sample_read_buffer; - samples_read++; - } - } - - if (samples_read > 0) { - output = sample_accumulator / samples_read; - return true; - } else { - return false; - } -} diff --git a/Drivers/XPT2046/Source/Xpt2046Power.h b/Drivers/XPT2046/Source/Xpt2046Power.h deleted file mode 100644 index f14036ee7..000000000 --- a/Drivers/XPT2046/Source/Xpt2046Power.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -class Xpt2046Touch; -using tt::hal::power::PowerDevice; - -/** - * Power management based on the voltage measurement at the LCD panel. - * This estimates the battery power left. - */ -class Xpt2046Power : public PowerDevice { - - std::shared_ptr xptTouch; - - bool readBatteryVoltageOnce(uint32_t& output); - bool readBatteryVoltageSampled(uint32_t& output); - -public: - - ~Xpt2046Power() override = default; - - std::string getName() const final { return "XPT2046 Power Measurement"; } - std::string getDescription() const final { return "Power interface via XPT2046 voltage measurement"; } - - bool supportsMetric(MetricType type) const override; - bool getMetric(MetricType type, MetricData& data) override; -}; diff --git a/Drivers/XPT2046/Source/Xpt2046Touch.cpp b/Drivers/XPT2046/Source/Xpt2046Touch.cpp index 50c5ca150..1695777ab 100644 --- a/Drivers/XPT2046/Source/Xpt2046Touch.cpp +++ b/Drivers/XPT2046/Source/Xpt2046Touch.cpp @@ -35,19 +35,3 @@ esp_lcd_touch_config_t Xpt2046Touch::createEspLcdTouchConfig() { .driver_data = nullptr }; } - -bool Xpt2046Touch::getVBat(float& outputVbat) { - auto touch_handle = getTouchHandle(); - if (touch_handle == nullptr) { - return false; - } - - // Shares the SPI bus with the display, so we have to sync/lock as this method might be called from anywhere - if (!tt::lvgl::lock(50 / portTICK_PERIOD_MS)) { - return false; - } - - esp_lcd_touch_xpt2046_read_battery_level(touch_handle, &outputVbat); - tt::lvgl::unlock(); - return true; -} diff --git a/Drivers/XPT2046/Source/Xpt2046Touch.h b/Drivers/XPT2046/Source/Xpt2046Touch.h index fb813b244..91404e4fb 100644 --- a/Drivers/XPT2046/Source/Xpt2046Touch.h +++ b/Drivers/XPT2046/Source/Xpt2046Touch.h @@ -56,6 +56,4 @@ class Xpt2046Touch : public EspLcdTouch { std::string getName() const final { return "XPT2046"; } std::string getDescription() const final { return "XPT2046 I2C touch driver"; } - - bool getVBat(float& outputVbat); }; diff --git a/Firmware/idf_component.yml b/Firmware/idf_component.yml index 452569438..6d15beae6 100644 --- a/Firmware/idf_component.yml +++ b/Firmware/idf_component.yml @@ -21,7 +21,7 @@ dependencies: - if: "target in [esp32, esp32s3]" espressif/esp_lcd_touch: "1.2.1" atanisoft/esp_lcd_touch_xpt2046: - version: "1.0.5" + version: "1.0.6" rules: - if: "target in [esp32, esp32s3]" espressif/esp_lcd_touch_cst816s: "1.0.3" diff --git a/Modules/lvgl-module/Source/arch/lvgl_esp32.c b/Modules/lvgl-module/Source/arch/lvgl_esp32.c index 9c26a6f66..29370019c 100644 --- a/Modules/lvgl-module/Source/arch/lvgl_esp32.c +++ b/Modules/lvgl-module/Source/arch/lvgl_esp32.c @@ -12,12 +12,12 @@ extern struct LvglModuleConfig lvgl_module_config; static bool initialized = false; bool lvgl_lock(void) { - if (!initialized) return false; + if (!initialized) return true; // We allow (ake) locking because it's safe to do so as LVGL is not running yet return lvgl_port_lock(portMAX_DELAY); } bool lvgl_try_lock_timed(uint32_t timeout) { - if (!initialized) return false; + if (!initialized) return true; // We allow (ake) locking because it's safe to do so as LVGL is not running yet return lvgl_port_lock(millis_to_ticks(timeout)); } diff --git a/Tactility/Include/Tactility/hal/Configuration.h b/Tactility/Include/Tactility/hal/Configuration.h index 385bd322d..966c89f69 100644 --- a/Tactility/Include/Tactility/hal/Configuration.h +++ b/Tactility/Include/Tactility/hal/Configuration.h @@ -10,11 +10,6 @@ typedef std::vector> DeviceVector; typedef std::shared_ptr (*CreateDevice)(); -enum class LvglInit { - Default, - None -}; - /** Affects LVGL widget style */ enum class UiScale { /** Ideal for very small non-touch screen devices (e.g. Waveshare S3 LCD 1.3") */ @@ -30,13 +25,10 @@ struct Configuration { */ const InitBoot initBoot = nullptr; - /** Init behaviour: default (esp_lvgl_port for ESP32, nothing for PC) or None (nothing on any platform). Only used in Tactility, not in TactilityHeadless. */ - const LvglInit lvglInit = LvglInit::Default; - /** Modify LVGL widget size */ const UiScale uiScale = UiScale::Default; - std::function createDevices = [] { return std::vector>(); }; + std::function createDevices = [] { return DeviceVector(); }; }; } // namespace diff --git a/Tactility/Source/service/wifi/WifiEsp.cpp b/Tactility/Source/service/wifi/WifiEsp.cpp index b853b2eb2..a52211854 100644 --- a/Tactility/Source/service/wifi/WifiEsp.cpp +++ b/Tactility/Source/service/wifi/WifiEsp.cpp @@ -47,8 +47,8 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr wifi); class Wifi { std::atomic radio_state = RadioState::Off; - bool scan_active = false; - bool secure_connection = false; + std::atomic scan_active = false; + std::atomic secure_connection = false; public: @@ -81,54 +81,34 @@ class Wifi { kernel::SystemEventSubscription bootEventSubscription = kernel::NoSystemEventSubscription; RadioState getRadioState() const { - auto lock = dataMutex.asScopedLock(); - lock.lock(); - // TODO: Handle lock failure return radio_state; } void setRadioState(RadioState newState) { - auto lock = dataMutex.asScopedLock(); - lock.lock(); - // TODO: Handle lock failure radio_state = newState; } bool isScanning() const { - auto lock = dataMutex.asScopedLock(); - lock.lock(); - // TODO: Handle lock failure return scan_active; } void setScanning(bool newState) { - auto lock = dataMutex.asScopedLock(); - lock.lock(); - // TODO: Handle lock failure scan_active = newState; } bool isScanActive() const { - auto lock = dataMutex.asScopedLock(); - lock.lock(); return scan_active; } void setScanActive(bool newState) { - auto lock = dataMutex.asScopedLock(); - lock.lock(); scan_active = newState; } bool isSecureConnection() const { - auto lock = dataMutex.asScopedLock(); - lock.lock(); return secure_connection; } void setSecureConnection(bool newState) { - auto lock = dataMutex.asScopedLock(); - lock.lock(); secure_connection = newState; } }; @@ -913,7 +893,9 @@ std::string getIp() { auto wifi = std::static_pointer_cast(wifi_singleton); auto lock = wifi->dataMutex.asScopedLock(); - lock.lock(); + if (!lock.lock(100)) { + return "0.0.0.0"; + } return std::format("{}.{}.{}.{}", IP2STR(&wifi->ip_info.ip)); } diff --git a/TactilityC/Source/tt_init.cpp b/TactilityC/Source/tt_init.cpp index 0b862ef55..e89757de5 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -91,18 +91,28 @@ const esp_elfsym main_symbols[] { ESP_ELFSYM_EXPORT(sntp_get_sync_status), // math.h ESP_ELFSYM_EXPORT(atan), + ESP_ELFSYM_EXPORT(atanf), ESP_ELFSYM_EXPORT(cos), + ESP_ELFSYM_EXPORT(cosf), ESP_ELFSYM_EXPORT(sin), + ESP_ELFSYM_EXPORT(sinf), ESP_ELFSYM_EXPORT(tan), - ESP_ELFSYM_EXPORT(tanh), + ESP_ELFSYM_EXPORT(tanf), ESP_ELFSYM_EXPORT(frexp), + ESP_ELFSYM_EXPORT(frexpf), ESP_ELFSYM_EXPORT(modf), + ESP_ELFSYM_EXPORT(modff), + ESP_ELFSYM_EXPORT(fmodf), ESP_ELFSYM_EXPORT(ceil), + ESP_ELFSYM_EXPORT(ceilf), ESP_ELFSYM_EXPORT(fabs), - ESP_ELFSYM_EXPORT(floor), - ESP_ELFSYM_EXPORT(sinf), - ESP_ELFSYM_EXPORT(cosf), ESP_ELFSYM_EXPORT(fabsf), + ESP_ELFSYM_EXPORT(floor), + ESP_ELFSYM_EXPORT(floorf), + ESP_ELFSYM_EXPORT(fmax), + ESP_ELFSYM_EXPORT(fmaxf), + ESP_ELFSYM_EXPORT(fmin), + ESP_ELFSYM_EXPORT(fminf), #ifndef _REENT_ONLY ESP_ELFSYM_EXPORT(acos), ESP_ELFSYM_EXPORT(acosf), diff --git a/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h b/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h index a7b12299d..2c0cae834 100644 --- a/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h +++ b/TactilityKernel/Include/tactility/concurrent/recursive_mutex.h @@ -12,15 +12,14 @@ extern "C" { struct RecursiveMutex { QueueHandle_t handle; + // TODO: Debugging functionality }; inline static void recursive_mutex_construct(struct RecursiveMutex* mutex) { - check(mutex->handle == NULL); mutex->handle = xSemaphoreCreateRecursiveMutex(); } inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) { - check(mutex->handle != NULL); check(xPortInIsrContext() != pdTRUE); vSemaphoreDelete(mutex->handle); mutex->handle = NULL; From c73286d70bb9e20a722a1c073a97f444a837ffc0 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 21:00:19 +0100 Subject: [PATCH 3/9] WIP --- .../DevicetreeCompiler/source/generator.py | 2 + .../bigtreetech,panda-touch.dts | 2 - .../cyd-2432s028r/Source/devices/SdCard.cpp | 4 +- .../cyd-2432s028rv3/Source/devices/SdCard.cpp | 4 +- .../cyd-2432s032c/Source/Configuration.cpp | 2 +- .../Source/devices/St7701Display.h | 2 - Devices/cyd-4848s040c/cyd,4848s040c.dts | 2 - Devices/cyd-8048s043c/cyd,8048s043c.dts | 2 - .../Source/devices/SdCard.cpp | 3 +- .../elecrow,crowpanel-advance-28.dts | 2 - .../Source/devices/SdCard.cpp | 3 +- .../elecrow,crowpanel-advance-35.dts | 2 - .../elecrow,crowpanel-advance-50.dts | 2 - .../elecrow,crowpanel-basic-28.dts | 4 +- .../elecrow,crowpanel-basic-35.dts | 4 +- .../elecrow,crowpanel-basic-50.dts | 2 - .../guition,jc1060p470ciwy.dts | 2 - .../guition,jc3248w535c.dts | 4 -- .../Source/devices/SdCard.cpp | 7 +-- .../guition,jc8048w550c.dts | 4 -- .../heltec,wifi-lora-32-v3.dts | 2 - .../Source/devices/Display.cpp | 2 +- .../lilygo-tdongle-s3/lilygo,tdongle-s3.dts | 2 - .../Source/Configuration.cpp | 28 +-------- .../Source/devices/SdCard.cpp | 7 ++- .../lilygo-tlora-pager/lilygo,tlora-pager.dts | 12 ++++ .../Source/Configuration.cpp | 55 +---------------- .../Source/devices/SdCard.cpp | 9 ++- .../m5stack,cardputer-adv.dts | 27 +++++++-- .../Source/Configuration.cpp | 54 +---------------- .../Source/devices/SdCard.cpp | 9 ++- .../m5stack-cardputer/m5stack,cardputer.dts | 25 +++++++- .../m5stack-core2/Source/Configuration.cpp | 31 +--------- .../m5stack-core2/Source/devices/Display.h | 1 - .../m5stack-core2/Source/devices/SdCard.cpp | 7 ++- Devices/m5stack-core2/m5stack,core2.dts | 16 +++-- .../m5stack-cores3/Source/Configuration.cpp | 28 +-------- .../m5stack-cores3/Source/devices/Display.h | 2 +- .../m5stack-cores3/Source/devices/SdCard.cpp | 12 ++-- Devices/m5stack-cores3/m5stack,cores3.dts | 22 ++++--- .../m5stack-papers3/Source/Configuration.cpp | 29 +-------- .../m5stack-papers3/Source/devices/SdCard.cpp | 12 ++-- Devices/m5stack-papers3/device.properties | 2 +- Devices/m5stack-papers3/m5stack,papers3.dts | 14 ++++- .../Source/Configuration.cpp | 31 +--------- .../m5stack,stickc-plus.dts | 16 +++-- .../Source/Configuration.cpp | 28 +-------- .../m5stack,stickc-plus2.dts | 16 +++-- Devices/m5stack-tab5/Source/Configuration.cpp | 28 +-------- .../Source/devices/Ili9881cDisplay.h | 2 +- .../m5stack-tab5/Source/devices/SdCard.cpp | 12 ++-- Devices/m5stack-tab5/m5stack,tab5.dts | 16 +++-- Devices/unphone/Source/Configuration.cpp | 31 +--------- .../unphone/Source/devices/Hx8357Display.h | 2 - Devices/unphone/Source/devices/SdCard.cpp | 7 ++- Devices/unphone/unphone.dts | 14 ++++- .../Source/Configuration.cpp | 30 +--------- .../Source/devices/Display.h | 1 - .../waveshare,esp32-s3-geek.dts | 14 ++++- .../Source/Configuration.cpp | 53 +---------------- .../Source/devices/Display.h | 1 - .../Source/devices/SdCard.cpp | 9 ++- .../waveshare,s3-lcd-13.dts | 26 +++++++- .../Source/Configuration.cpp | 59 +------------------ .../Source/devices/SdCard.cpp | 10 +++- .../device.properties | 8 ++- .../waveshare,s3-touch-lcd-128.dts | 26 +++++++- .../Source/Configuration.cpp | 54 +---------------- .../Source/devices/Axs5106Touch.cpp | 2 - .../Source/devices/Display.cpp | 1 - .../Source/devices/Jd9853Display.h | 4 +- .../Source/devices/Sdcard.cpp | 12 ++-- .../waveshare,s3-touch-lcd-147.dts | 26 +++++++- .../Source/Configuration.cpp | 29 +-------- .../Source/devices/SdCard.cpp | 11 +++- .../waveshare,s3-touch-lcd-43.dts | 14 ++++- .../wireless-tag,wt32-sc01-plus.dts | 2 - Documentation/ideas.md | 1 + Drivers/EspLcdCompat/Source/EspLcdDisplay.h | 1 - Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h | 2 +- Drivers/GC9A01/Source/Gc9a01Display.h | 8 +-- Drivers/ILI9488/Source/Ili9488Display.h | 2 +- Drivers/ST7735/Source/St7735Display.h | 2 - Drivers/ST7796/Source/St7796Display.h | 1 - Modules/lvgl-module/Source/arch/lvgl_esp32.c | 4 +- .../Include/Tactility/hal/Configuration.h | 1 - Tactility/Source/service/wifi/WifiEsp.cpp | 4 +- TactilityC/Source/tt_init.cpp | 11 +++- .../Include/Tactility/kernel/SpiDeviceLock.h | 2 +- 89 files changed, 384 insertions(+), 717 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index 9d59a9526..bdcf7ce2a 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -63,6 +63,8 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: type = property.type if type == "value": return property.value + if type == "boolean": + return "true" elif type == "text": return f"\"{property.value}\"" elif type == "values": diff --git a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts index e19626de9..1b829a08c 100644 --- a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts +++ b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts @@ -20,8 +20,6 @@ clock-frequency = <400000>; pin-sda = <2>; pin-scl = <1>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_external: i2c1 { diff --git a/Devices/cyd-2432s028r/Source/devices/SdCard.cpp b/Devices/cyd-2432s028r/Source/devices/SdCard.cpp index fa96aa264..85960aacb 100644 --- a/Devices/cyd-2432s028r/Source/devices/SdCard.cpp +++ b/Devices/cyd-2432s028r/Source/devices/SdCard.cpp @@ -2,8 +2,6 @@ #include #include -#include -#include using tt::hal::sdcard::SpiSdCardDevice; @@ -14,7 +12,7 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + nullptr, std::vector(), SPI3_HOST ); diff --git a/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp b/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp index fa96aa264..85960aacb 100644 --- a/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp +++ b/Devices/cyd-2432s028rv3/Source/devices/SdCard.cpp @@ -2,8 +2,6 @@ #include #include -#include -#include using tt::hal::sdcard::SpiSdCardDevice; @@ -14,7 +12,7 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + nullptr, std::vector(), SPI3_HOST ); diff --git a/Devices/cyd-2432s032c/Source/Configuration.cpp b/Devices/cyd-2432s032c/Source/Configuration.cpp index 5308ea91f..af80ae199 100644 --- a/Devices/cyd-2432s032c/Source/Configuration.cpp +++ b/Devices/cyd-2432s032c/Source/Configuration.cpp @@ -8,7 +8,7 @@ #include -bool initBoot() { +static bool initBoot() { if (!driver::pwmbacklight::init(LCD_PIN_BACKLIGHT)) { return false; } diff --git a/Devices/cyd-4848s040c/Source/devices/St7701Display.h b/Devices/cyd-4848s040c/Source/devices/St7701Display.h index 104e725a5..593885f8d 100644 --- a/Devices/cyd-4848s040c/Source/devices/St7701Display.h +++ b/Devices/cyd-4848s040c/Source/devices/St7701Display.h @@ -1,7 +1,5 @@ #pragma once -#include - #include #include diff --git a/Devices/cyd-4848s040c/cyd,4848s040c.dts b/Devices/cyd-4848s040c/cyd,4848s040c.dts index 049c6072b..1ec85d2b7 100644 --- a/Devices/cyd-4848s040c/cyd,4848s040c.dts +++ b/Devices/cyd-4848s040c/cyd,4848s040c.dts @@ -20,8 +20,6 @@ clock-frequency = <400000>; pin-sda = <19>; pin-scl = <45>; - pin-sda-pullup; - pin-scl-pullup; }; spi0 { diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 446ab501b..d0c4c449d 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <19>; pin-scl = <20>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_external { diff --git a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp index aba0191cd..a7308c95f 100644 --- a/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-advance-28/Source/devices/SdCard.cpp @@ -1,7 +1,6 @@ #include "SdCard.h" #include -#include #include using tt::hal::sdcard::SpiSdCardDevice; @@ -15,7 +14,7 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), + nullptr, std::vector(), SPI3_HOST ); 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 b798d91a6..9e49dbdcd 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <15>; pin-scl = <16>; - pin-sda-pullup; - pin-scl-pullup; }; display_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp b/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp index aba0191cd..a7308c95f 100644 --- a/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp +++ b/Devices/elecrow-crowpanel-advance-35/Source/devices/SdCard.cpp @@ -1,7 +1,6 @@ #include "SdCard.h" #include -#include #include using tt::hal::sdcard::SpiSdCardDevice; @@ -15,7 +14,7 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), + nullptr, std::vector(), SPI3_HOST ); 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 ae6afc605..74abc8b0a 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <15>; pin-scl = <16>; - pin-sda-pullup; - pin-scl-pullup; }; display_spi: spi0 { 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 ef5d45543..828f36130 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <15>; pin-scl = <16>; - pin-sda-pullup; - pin-scl-pullup; }; sdcard_spi: spi0 { 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 e151ef588..50563f6d7 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <22>; pin-scl = <21>; - pin-sda-pullup; - pin-scl-pullup; }; display_spi: spi0 { @@ -33,7 +31,7 @@ pin-sclk = <14>; pin-wp = ; pin-hd = ; - max-transfer-size = <0>; + max-transfer-size = <65536>; }; sdcard_spi: spi1 { 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 aada9daa6..310036720 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <22>; pin-scl = <21>; - pin-sda-pullup; - pin-scl-pullup; }; display_spi: spi0 { @@ -33,7 +31,7 @@ pin-sclk = <14>; pin-wp = ; pin-hd = ; - max-transfer-size = <0>; + max-transfer-size = <65536>; }; sdcard_spi: spi1 { 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 02d145481..9e2cf2612 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <19>; pin-scl = <20>; - pin-sda-pullup; - pin-scl-pullup; }; sdcard_spi: spi0 { diff --git a/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts b/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts index 50b62152b..6df073fdc 100644 --- a/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts +++ b/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts @@ -28,8 +28,6 @@ clock-frequency = <400000>; pin-sda = <7>; pin-scl = <8>; - pin-sda-pullup; - pin-scl-pullup; }; i2s0 { diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index 16d548f04..c16e55000 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <4>; pin-scl = <8>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_external: i2c1 { @@ -31,8 +29,6 @@ clock-frequency = <400000>; pin-sda = <17>; pin-scl = <18>; - pin-sda-pullup; - pin-scl-pullup; }; display_spi: spi0 { diff --git a/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp b/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp index 876fca400..1b44c476c 100644 --- a/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp +++ b/Devices/guition-jc8048w550c/Source/devices/SdCard.cpp @@ -2,8 +2,6 @@ #include #include -#include -#include using tt::hal::sdcard::SpiSdCardDevice; @@ -13,10 +11,7 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - nullptr, - std::vector(), - SPI2_HOST + SdCardDevice::MountBehaviour::AtBoot ); auto* spi_controller = device_find_by_name("spi0"); diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index 1c71247db..2661aaae8 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <19>; pin-scl = <20>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_external: i2c1 { @@ -31,8 +29,6 @@ clock-frequency = <400000>; pin-sda = <17>; pin-scl = <18>; - pin-sda-pullup; - pin-scl-pullup; }; spi0 { diff --git a/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts b/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts index 0a54fd480..8a5cd8827 100644 --- a/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts +++ b/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts @@ -19,7 +19,5 @@ clock-frequency = <200000>; pin-sda = <17>; pin-scl = <18>; - pin-sda-pullup; - pin-scl-pullup; }; }; diff --git a/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp b/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp index 3285ba7c7..328d0ee48 100644 --- a/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp +++ b/Devices/lilygo-tdongle-s3/Source/devices/Display.cpp @@ -9,7 +9,7 @@ #define LCD_PIN_RESET GPIO_NUM_1 #define LCD_HORIZONTAL_RESOLUTION 80 #define LCD_VERTICAL_RESOLUTION 160 -#define LCD_SPI_TRANSFER_HEIGHT LCD_VERTICAL_RESOLUTION / 4 +#define LCD_SPI_TRANSFER_HEIGHT (LCD_VERTICAL_RESOLUTION / 4) std::shared_ptr createDisplay() { auto configuration = std::make_unique( diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index bcfc2c997..964c30e88 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -21,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <44>; pin-scl = <43>; - pin-sda-pullup; - pin-scl-pullup; }; spi0 { diff --git a/Devices/lilygo-tlora-pager/Source/Configuration.cpp b/Devices/lilygo-tlora-pager/Source/Configuration.cpp index 969a9b4fb..a6a5a8163 100644 --- a/Devices/lilygo-tlora-pager/Source/Configuration.cpp +++ b/Devices/lilygo-tlora-pager/Source/Configuration.cpp @@ -6,12 +6,9 @@ #include #include -#include #include #include -#define TPAGER_SPI_TRANSFER_SIZE_LIMIT (480 * 222 * (LV_COLOR_DEPTH / 8)) - bool tpagerInit(); using namespace tt::hal; @@ -38,28 +35,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = tpagerInit, - .createDevices = createDevices, - .spi {spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_34, - .miso_io_num = GPIO_NUM_33, - .sclk_io_num = GPIO_NUM_35, - .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = TPAGER_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }} + .createDevices = createDevices }; diff --git a/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp b/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp index 940dc7d49..7ce5e8857 100644 --- a/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp +++ b/Devices/lilygo-tlora-pager/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -23,7 +24,11 @@ std::shared_ptr createTpagerSdCard() { } ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index 69bcfcad6..ec60078b5 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -4,6 +4,7 @@ #include #include #include +#include #include // Reference: https://wiki.lilygo.cc/get_started/en/LoRa_GPS/T-LoraPager/T-LoraPager.html#Pin-Overview @@ -24,6 +25,17 @@ pin-scl = <2>; }; + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <34>; + pin-miso = <33>; + pin-sclk = <35>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + // ES8311 // TODO: init via I2C to enable audio playback i2s0 { diff --git a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp index 7dfce0d56..1d16e2010 100644 --- a/Devices/m5stack-cardputer-adv/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer-adv/Source/Configuration.cpp @@ -5,14 +5,13 @@ #include #include -#include #include #include using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT, 512); } @@ -30,55 +29,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_35, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_36, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - // SDCard - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_14, - .miso_io_num = GPIO_NUM_39, - .sclk_io_num = GPIO_NUM_40, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - }, - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp b/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp index 8715d72c8..abc1703e4 100644 --- a/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp +++ b/Devices/m5stack-cardputer-adv/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include constexpr auto SDCARD_PIN_CS = GPIO_NUM_12; @@ -14,12 +15,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - tt::hal::spi::getLock(SPI3_HOST), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index b616f418b..63ee256b7 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -4,6 +4,7 @@ #include #include #include +#include #include // Reference: https://docs.m5stack.com/en/core/Cardputer-Adv @@ -22,8 +23,6 @@ clock-frequency = <400000>; pin-sda = <8>; pin-scl = <9>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_port_a { @@ -32,8 +31,28 @@ clock-frequency = <400000>; pin-sda = <2>; pin-scl = <1>; - pin-sda-pullup; - pin-scl-pullup; + }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <35>; + pin-miso = ; + pin-sclk = <36>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <14>; + pin-miso = <39>; + pin-sclk = <40>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; // Speaker and microphone (ES8311) diff --git a/Devices/m5stack-cardputer/Source/Configuration.cpp b/Devices/m5stack-cardputer/Source/Configuration.cpp index 9c2757c2e..604ba926f 100644 --- a/Devices/m5stack-cardputer/Source/Configuration.cpp +++ b/Devices/m5stack-cardputer/Source/Configuration.cpp @@ -7,7 +7,6 @@ #include #include -#include using namespace tt::hal; @@ -28,56 +27,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_35, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_36, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - }, - // SDCard - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_14, - .miso_io_num = GPIO_NUM_39, - .sclk_io_num = GPIO_NUM_40, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - }, - - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-cardputer/Source/devices/SdCard.cpp b/Devices/m5stack-cardputer/Source/devices/SdCard.cpp index b7a130a90..7ab98cfa1 100644 --- a/Devices/m5stack-cardputer/Source/devices/SdCard.cpp +++ b/Devices/m5stack-cardputer/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include constexpr auto SDCARD_PIN_CS = GPIO_NUM_12; @@ -13,12 +14,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - tt::hal::spi::getLock(SPI3_HOST), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index 1eb50b041..8904f8988 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -4,6 +4,7 @@ #include #include #include +#include #include // Reference: https://docs.m5stack.com/en/core/Cardputer @@ -22,8 +23,28 @@ clock-frequency = <400000>; pin-sda = <2>; pin-scl = <1>; - pin-sda-pullup; - pin-scl-pullup; + }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <35>; + pin-miso = ; + pin-sclk = <36>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <14>; + pin-miso = <39>; + pin-sclk = <40>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; // Speaker and microphone diff --git a/Devices/m5stack-core2/Source/Configuration.cpp b/Devices/m5stack-core2/Source/Configuration.cpp index e71cc9560..7883adff4 100644 --- a/Devices/m5stack-core2/Source/Configuration.cpp +++ b/Devices/m5stack-core2/Source/Configuration.cpp @@ -1,14 +1,12 @@ #include "devices/Display.h" #include "devices/SdCard.h" #include "devices/Power.h" -#include #include -#include using namespace tt::hal; -bool initBoot() { +static bool initBoot() { return initAxp(); } @@ -22,30 +20,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_23, - .miso_io_num = GPIO_NUM_38, - .sclk_io_num = GPIO_NUM_18, - .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-core2/Source/devices/Display.h b/Devices/m5stack-core2/Source/devices/Display.h index e359e869f..bc66d3105 100644 --- a/Devices/m5stack-core2/Source/devices/Display.h +++ b/Devices/m5stack-core2/Source/devices/Display.h @@ -12,6 +12,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 320; constexpr auto LCD_VERTICAL_RESOLUTION = 240; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 10; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); diff --git a/Devices/m5stack-core2/Source/devices/SdCard.cpp b/Devices/m5stack-core2/Source/devices/SdCard.cpp index 9d0f12b96..3d0a8e306 100644 --- a/Devices/m5stack-core2/Source/devices/SdCard.cpp +++ b/Devices/m5stack-core2/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -21,7 +22,11 @@ std::shared_ptr createSdCard() { } ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index f8e1b6a6a..4346415e0 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -4,6 +4,7 @@ #include #include #include +#include #include // Reference: https://docs.m5stack.com/en/core/Core2 @@ -22,8 +23,6 @@ clock-frequency = <400000>; pin-sda = <21>; pin-scl = <22>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_port_a { @@ -32,8 +31,17 @@ clock-frequency = <400000>; pin-sda = <32>; pin-scl = <33>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <23>; + pin-miso = <38>; + pin-sclk = <18>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; // NS4168: Speaker and microphone diff --git a/Devices/m5stack-cores3/Source/Configuration.cpp b/Devices/m5stack-cores3/Source/Configuration.cpp index ffa11dd74..d00a16c34 100644 --- a/Devices/m5stack-cores3/Source/Configuration.cpp +++ b/Devices/m5stack-cores3/Source/Configuration.cpp @@ -4,7 +4,6 @@ #include #include -#include #include using namespace tt::hal; @@ -21,30 +20,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_37, - .miso_io_num = GPIO_NUM_35, - .sclk_io_num = GPIO_NUM_36, - .data2_io_num = GPIO_NUM_NC, - .data3_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-cores3/Source/devices/Display.h b/Devices/m5stack-cores3/Source/devices/Display.h index 04caf6464..bfb965229 100644 --- a/Devices/m5stack-cores3/Source/devices/Display.h +++ b/Devices/m5stack-cores3/Source/devices/Display.h @@ -5,7 +5,7 @@ #include // Display -constexpr auto LCD_SPI_HOST = SPI3_HOST; +constexpr auto LCD_SPI_HOST = SPI2_HOST; constexpr auto LCD_PIN_CS = GPIO_NUM_3; constexpr auto LCD_PIN_DC = GPIO_NUM_35; constexpr auto LCD_HORIZONTAL_RESOLUTION = 320; diff --git a/Devices/m5stack-cores3/Source/devices/SdCard.cpp b/Devices/m5stack-cores3/Source/devices/SdCard.cpp index f314b5f59..9083ef803 100644 --- a/Devices/m5stack-cores3/Source/devices/SdCard.cpp +++ b/Devices/m5stack-cores3/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -16,13 +17,14 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, tt::lvgl::getSyncLock(), - std::vector { - CORES3_LCD_PIN_CS - }, - SPI3_HOST + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index 5cc2d785b..a4e7b6793 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -4,6 +4,7 @@ #include #include #include +#include #include // Reference: https://docs.m5stack.com/en/core/CoreS3 @@ -22,8 +23,6 @@ clock-frequency = <400000>; pin-sda = <12>; pin-scl = <11>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_port_a { @@ -32,18 +31,14 @@ clock-frequency = <400000>; pin-sda = <2>; pin-scl = <1>; - pin-sda-pullup; - pin-scl-pullup; }; - +/* i2c_port_b { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; pin-sda = <9>; pin-scl = <8>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_port_c { @@ -52,8 +47,17 @@ clock-frequency = <400000>; pin-sda = <18>; pin-scl = <17>; - sda-pullup; - scl-pullup; + }; +*/ + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <37>; + pin-miso = <35>; + pin-sclk = <36>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; // 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 b97319637..f6c53e556 100644 --- a/Devices/m5stack-papers3/Source/Configuration.cpp +++ b/Devices/m5stack-papers3/Source/Configuration.cpp @@ -1,9 +1,7 @@ #include "devices/Display.h" #include "devices/SdCard.h" -#include #include -#include using namespace tt::hal; @@ -17,30 +15,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = nullptr, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_38, - .miso_io_num = GPIO_NUM_40, - .sclk_io_num = GPIO_NUM_39, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 4096, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() - } - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-papers3/Source/devices/SdCard.cpp b/Devices/m5stack-papers3/Source/devices/SdCard.cpp index 4c477dd07..cc51ba7da 100644 --- a/Devices/m5stack-papers3/Source/devices/SdCard.cpp +++ b/Devices/m5stack-papers3/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -13,13 +14,14 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::lvgl::getSyncLock(), - std::vector{}, - SPI2_HOST + SdCardDevice::MountBehaviour::AtBoot ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } diff --git a/Devices/m5stack-papers3/device.properties b/Devices/m5stack-papers3/device.properties index 83cdb996f..4b56d840c 100644 --- a/Devices/m5stack-papers3/device.properties +++ b/Devices/m5stack-papers3/device.properties @@ -1,6 +1,6 @@ [general] vendor=M5Stack -name=Paper S3 +name=PaperS3 incubating=true [hardware] diff --git a/Devices/m5stack-papers3/m5stack,papers3.dts b/Devices/m5stack-papers3/m5stack,papers3.dts index 9b0a43df4..29d30b4ec 100644 --- a/Devices/m5stack-papers3/m5stack,papers3.dts +++ b/Devices/m5stack-papers3/m5stack,papers3.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -19,7 +20,16 @@ clock-frequency = <400000>; pin-sda = <41>; pin-scl = <42>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <38>; + pin-miso = <40>; + pin-sclk = <39>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <4096>; }; }; diff --git a/Devices/m5stack-stickc-plus/Source/Configuration.cpp b/Devices/m5stack-stickc-plus/Source/Configuration.cpp index 8899fc0a1..8f395ec31 100644 --- a/Devices/m5stack-stickc-plus/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus/Source/Configuration.cpp @@ -1,14 +1,12 @@ #include "devices/Display.h" #include "devices/Power.h" -#include #include -#include #include using namespace tt::hal; -bool initBoot() { +static bool initBoot() { // CH552 applies 4 V to GPIO 0, which reduces Wi-Fi sensitivity // Setting output to high adds a bias of 3.3 V and suppresses over-voltage: gpio::configure(0, gpio::Mode::Output, false, false); @@ -28,30 +26,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_15, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_13, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts index 2b3c57887..4fab2a0cb 100644 --- a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts +++ b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -20,8 +21,6 @@ clock-frequency = <400000>; pin-sda = <21>; pin-scl = <22>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_grove { @@ -30,8 +29,17 @@ clock-frequency = <400000>; pin-sda = <32>; pin-scl = <33>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <15>; + pin-miso = ; + pin-sclk = <13>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; uart_grove: uart1 { diff --git a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp index 1600b9532..6c8f38548 100644 --- a/Devices/m5stack-stickc-plus2/Source/Configuration.cpp +++ b/Devices/m5stack-stickc-plus2/Source/Configuration.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -30,30 +29,5 @@ static DeviceVector createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_15, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_13, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index 83f936a11..76166f4ce 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -2,6 +2,7 @@ #include #include #include +#include #include / { @@ -19,8 +20,6 @@ clock-frequency = <400000>; pin-sda = <21>; pin-scl = <22>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_grove { @@ -29,8 +28,17 @@ clock-frequency = <400000>; pin-sda = <32>; pin-scl = <33>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <15>; + pin-miso = ; + pin-sclk = <13>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; uart_grove: uart1 { diff --git a/Devices/m5stack-tab5/Source/Configuration.cpp b/Devices/m5stack-tab5/Source/Configuration.cpp index eab607a8d..6de4c5187 100644 --- a/Devices/m5stack-tab5/Source/Configuration.cpp +++ b/Devices/m5stack-tab5/Source/Configuration.cpp @@ -88,31 +88,5 @@ static bool initBoot() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi = { - // SDCard - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_44, - .miso_io_num = GPIO_NUM_39, - .sclk_io_num = GPIO_NUM_43, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 0, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h b/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h index e2819f861..3ba945cce 100644 --- a/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h +++ b/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h @@ -34,7 +34,7 @@ class Ili9881cDisplay final : public EspLcdDisplayV2 { Ili9881cDisplay( const std::shared_ptr& configuration - ) : EspLcdDisplayV2(configuration, std::make_shared()) {} + ) : EspLcdDisplayV2(configuration) {} ~Ili9881cDisplay() override; diff --git a/Devices/m5stack-tab5/Source/devices/SdCard.cpp b/Devices/m5stack-tab5/Source/devices/SdCard.cpp index 5103a121f..639eed882 100644 --- a/Devices/m5stack-tab5/Source/devices/SdCard.cpp +++ b/Devices/m5stack-tab5/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include constexpr auto SDCARD_PIN_CS = GPIO_NUM_42; @@ -12,13 +13,14 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - tt::hal::spi::getLock(SPI3_HOST), - std::vector(), - SPI3_HOST + SdCardDevice::MountBehaviour::AtBoot ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } diff --git a/Devices/m5stack-tab5/m5stack,tab5.dts b/Devices/m5stack-tab5/m5stack,tab5.dts index d4576ad97..bb6c82fbd 100644 --- a/Devices/m5stack-tab5/m5stack,tab5.dts +++ b/Devices/m5stack-tab5/m5stack,tab5.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -19,8 +20,6 @@ clock-frequency = <400000>; pin-sda = <31>; pin-scl = <32>; - pin-sda-pullup; - pin-scl-pullup; }; i2c_port_a { @@ -29,7 +28,16 @@ clock-frequency = <400000>; pin-sda = <53>; pin-scl = <54>; - pin-sda-pullup; - pin-scl-pullup; + }; + + sdcard_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <44>; + pin-miso = <39>; + pin-sclk = <43>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; }; diff --git a/Devices/unphone/Source/Configuration.cpp b/Devices/unphone/Source/Configuration.cpp index 5322cf2f4..e51ecfd1d 100644 --- a/Devices/unphone/Source/Configuration.cpp +++ b/Devices/unphone/Source/Configuration.cpp @@ -1,12 +1,8 @@ #include "UnPhoneFeatures.h" #include "devices/Hx8357Display.h" #include "devices/SdCard.h" -#include #include -#include - -#define UNPHONE_SPI_TRANSFER_SIZE_LIMIT (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_SPI_TRANSFER_HEIGHT * LV_COLOR_DEPTH / 8) bool initBoot(); @@ -19,30 +15,5 @@ static tt::hal::DeviceVector createDevices() { extern const tt::hal::Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - tt::hal::spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_40, - .miso_io_num = GPIO_NUM_41, - .sclk_io_num = GPIO_NUM_39, - .quadwp_io_num = -1, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = -1, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = UNPHONE_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = tt::hal::spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; diff --git a/Devices/unphone/Source/devices/Hx8357Display.h b/Devices/unphone/Source/devices/Hx8357Display.h index 9dea80f1a..24b0076f6 100644 --- a/Devices/unphone/Source/devices/Hx8357Display.h +++ b/Devices/unphone/Source/devices/Hx8357Display.h @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -17,7 +16,6 @@ #define UNPHONE_LCD_HORIZONTAL_RESOLUTION 320 #define UNPHONE_LCD_VERTICAL_RESOLUTION 480 #define UNPHONE_LCD_DRAW_BUFFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15) -#define UNPHONE_LCD_SPI_TRANSFER_HEIGHT (UNPHONE_LCD_VERTICAL_RESOLUTION / 15) class Hx8357Display : public tt::hal::display::DisplayDevice { diff --git a/Devices/unphone/Source/devices/SdCard.cpp b/Devices/unphone/Source/devices/SdCard.cpp index 749470eef..c75ca5638 100644 --- a/Devices/unphone/Source/devices/SdCard.cpp +++ b/Devices/unphone/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -25,7 +26,11 @@ std::shared_ptr createSdCard() { } ); + auto* spi_controller = device_find_by_name("spi0"); + check(spi_controller, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spi_controller ); } diff --git a/Devices/unphone/unphone.dts b/Devices/unphone/unphone.dts index 0da8e2c21..354d759f8 100644 --- a/Devices/unphone/unphone.dts +++ b/Devices/unphone/unphone.dts @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -19,7 +20,16 @@ clock-frequency = <400000>; pin-sda = <3>; pin-scl = <4>; - pin-sda-pullup; - pin-scl-pullup; + }; + + sdcard_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <40>; + pin-miso = <41>; + pin-sclk = <39>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <65536>; }; }; diff --git a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp index 70c85db01..c93cd0028 100644 --- a/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp +++ b/Devices/waveshare-esp32-s3-geek/Source/Configuration.cpp @@ -1,9 +1,7 @@ #include "devices/Display.h" #include "devices/SdCard.h" -#include #include -#include #include #include @@ -24,31 +22,5 @@ static bool initBoot() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_12, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - } - } + .createDevices = createDevices }; \ No newline at end of file diff --git a/Devices/waveshare-esp32-s3-geek/Source/devices/Display.h b/Devices/waveshare-esp32-s3-geek/Source/devices/Display.h index d7cd4f1da..628270acf 100644 --- a/Devices/waveshare-esp32-s3-geek/Source/devices/Display.h +++ b/Devices/waveshare-esp32-s3-geek/Source/devices/Display.h @@ -14,6 +14,5 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 135; constexpr auto LCD_VERTICAL_RESOLUTION = 240; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 3; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; std::shared_ptr createDisplay(); \ No newline at end of file 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 963dba0f4..d38b3084f 100644 --- a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts +++ b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -20,8 +21,17 @@ clock-frequency = <400000>; pin-sda = <16>; pin-scl = <17>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = ; + pin-sclk = <12>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; uart0 { diff --git a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp index d211a1f3c..42cb0e138 100644 --- a/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp +++ b/Devices/waveshare-s3-lcd-13/Source/Configuration.cpp @@ -3,7 +3,6 @@ #include #include -#include #include using namespace tt::hal; @@ -22,55 +21,5 @@ static bool initBoot() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_41, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_40, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = LCD_SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_18, - .miso_io_num = GPIO_NUM_16, - .sclk_io_num = GPIO_NUM_21, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/waveshare-s3-lcd-13/Source/devices/Display.h b/Devices/waveshare-s3-lcd-13/Source/devices/Display.h index e08682b4e..a1cd4fe6c 100644 --- a/Devices/waveshare-s3-lcd-13/Source/devices/Display.h +++ b/Devices/waveshare-s3-lcd-13/Source/devices/Display.h @@ -8,4 +8,3 @@ constexpr auto LCD_HORIZONTAL_RESOLUTION = 240; constexpr auto LCD_VERTICAL_RESOLUTION = 240; constexpr auto LCD_BUFFER_HEIGHT = LCD_VERTICAL_RESOLUTION / 3; constexpr auto LCD_BUFFER_SIZE = LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT; -constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8; diff --git a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp b/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp index b2c81f671..ae706305d 100644 --- a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp +++ b/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using tt::hal::sdcard::SpiSdCardDevice; @@ -13,12 +14,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + 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) + std::move(configuration), + spi_controller ); } 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 3f8839e75..ba44bd3c3 100644 --- a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts +++ b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts @@ -3,7 +3,9 @@ #include #include #include +#include +// Reference: https://www.waveshare.com/wiki/ESP32-S3-LCD-1.3 / { compatible = "root"; model = "Waveshare S3 LCD 1.3"; @@ -19,7 +21,27 @@ clock-frequency = <400000>; pin-sda = <47>; pin-scl = <48>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <41>; + pin-miso = ; + pin-sclk = <40>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <18>; + pin-miso = <16>; + pin-sclk = <21>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp index d871491c2..fcfe9eacf 100644 --- a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp @@ -1,9 +1,7 @@ #include "devices/Display.h" -#include "devices/SdCard.h" #include #include -#include #include using namespace tt::hal; @@ -12,8 +10,7 @@ constexpr auto* TAG = "Waveshare"; static DeviceVector createDevices() { return { - createDisplay(), - createSdCard() + createDisplay() }; } @@ -24,57 +21,5 @@ static bool initBoot() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - // Display - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_DISABLED, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_12, - .sclk_io_num = GPIO_NUM_10, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = ((240 * (240 / 10)) * LV_COLOR_DEPTH / 8), - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - // SD card available via external sd card module and uses VSYS (5V) / GND / IO15 / IO16 / IO17 / IO18 pins. - // Common micro sd card module you'd find on aliexpress with voltage regulator onboard. Others may work. - // JST SH 1.0 Header, GND / VSYS (5V) / RESET / BOOT / GND / 3.3V / IO15 / IO16 / IO17 / IO18 / IO21 / IO33 - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_16, - .miso_io_num = GPIO_NUM_15, - .sclk_io_num = GPIO_NUM_17, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .createDevices = createDevices }; diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp index d9adcbdea..e56e5361f 100644 --- a/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp +++ b/Devices/waveshare-s3-touch-lcd-128/Source/devices/SdCard.cpp @@ -1,8 +1,8 @@ #include "SdCard.h" +#include #include #include -#include using tt::hal::sdcard::SpiSdCardDevice; @@ -13,12 +13,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), + 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) + std::move(configuration), + spi_controller ); } diff --git a/Devices/waveshare-s3-touch-lcd-128/device.properties b/Devices/waveshare-s3-touch-lcd-128/device.properties index 2940b09ae..4dae4cedb 100644 --- a/Devices/waveshare-s3-touch-lcd-128/device.properties +++ b/Devices/waveshare-s3-touch-lcd-128/device.properties @@ -18,4 +18,10 @@ shape=circle dpi=265 [lvgl] -colorDepth=16 \ No newline at end of file +colorDepth=16 + +[sdkconfig] +# Fix error "PSRAM space not enough for the Flash instructions" on boot: +CONFIG_SPIRAM_FETCH_INSTRUCTIONS=n +CONFIG_SPIRAM_RODATA=n +CONFIG_SPIRAM_XIP_FROM_PSRAM=n \ No newline at end of file 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 a6b953303..aaedb2f08 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 @@ -3,7 +3,9 @@ #include #include #include +#include +// Reference: https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.28 / { compatible = "root"; model = "Waveshare S3 Touch LCD 1.28"; @@ -13,11 +15,33 @@ gpio-count = <49>; }; - i2c_main { + i2c0 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; pin-sda = <6>; pin-scl = <7>; }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = <12>; + pin-sclk = <10>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <16>; + pin-miso = <15>; + pin-sclk = <17>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp index 7c1524fe8..acec5b451 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/Configuration.cpp @@ -1,11 +1,7 @@ #include "devices/Display.h" #include "devices/Sdcard.h" -#include #include -#include - -#define SPI_TRANSFER_SIZE_LIMIT (172 * 320 * (LV_COLOR_DEPTH / 8)) bool initBoot(); @@ -21,53 +17,5 @@ static std::vector> createDevices() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, .uiScale = UiScale::Smallest, - .createDevices = createDevices, - .spi { - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_39, - .miso_io_num = GPIO_NUM_NC, - .sclk_io_num = GPIO_NUM_38, - .quadwp_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .quadhd_io_num = GPIO_NUM_NC, // Quad SPI LCD driver is not yet supported - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display - }, - spi::Configuration { - .device = SPI3_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_15, - .miso_io_num = GPIO_NUM_17, - .sclk_io_num = GPIO_NUM_16, - .data2_io_num = GPIO_NUM_NC, - .data3_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = SPI_TRANSFER_SIZE_LIMIT, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Axs5106Touch.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Axs5106Touch.cpp index 6115c5d5f..a56aa279b 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Axs5106Touch.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Axs5106Touch.cpp @@ -3,8 +3,6 @@ #include #include -constexpr auto* TAG = "AXS5106"; - bool Axs5106Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_AXS5106_CONFIG(); return esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &outHandle) == ESP_OK; diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Display.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Display.cpp index b31c4d8b8..f23e7fdde 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Display.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Display.cpp @@ -8,7 +8,6 @@ constexpr auto LCD_PIN_DC = GPIO_NUM_45; constexpr auto LCD_PIN_RESET = GPIO_NUM_40; constexpr auto LCD_HORIZONTAL_RESOLUTION = 172; constexpr auto LCD_VERTICAL_RESOLUTION = 320; -constexpr auto LCD_SPI_TRANSFER_HEIGHT = (LCD_VERTICAL_RESOLUTION / 10); void setBacklightDuty(uint8_t level); diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h index aec2e5c2e..b1430e034 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h +++ b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Jd9853Display.h @@ -84,9 +84,7 @@ class Jd9853Display final : public EspLcdDisplay { explicit Jd9853Display(std::unique_ptr inConfiguration) : configuration(std::move(inConfiguration) - ) { - assert(configuration != nullptr); - } + ) {} std::string getName() const override { return "JD9853"; } diff --git a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp index 46ec87382..f419562c0 100644 --- a/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp +++ b/Devices/waveshare-s3-touch-lcd-147/Source/devices/Sdcard.cpp @@ -1,12 +1,12 @@ #include "Sdcard.h" +#include #include #include using tt::hal::sdcard::SpiSdCardDevice; constexpr auto SDCARD_PIN_CS = GPIO_NUM_14; -constexpr auto LCD_PIN_CS = GPIO_NUM_21; std::shared_ptr createSdCard() { auto configuration = std::make_unique( @@ -15,12 +15,16 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, SdCardDevice::MountBehaviour::AtBoot, - tt::hal::spi::getLock(SPI3_HOST), - std::vector { LCD_PIN_CS }, + 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) + std::move(configuration), + spi_controller ); } 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 463e34f05..544306b29 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 @@ -3,7 +3,9 @@ #include #include #include +#include +// Reference: https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-1.47 / { compatible = "root"; model = "Waveshare S3 Touch LCD 1.47"; @@ -19,7 +21,27 @@ clock-frequency = <400000>; pin-sda = <42>; pin-scl = <41>; - pin-sda-pullup; - pin-scl-pullup; + }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <39>; + pin-miso = ; + pin-sclk = <38>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <15>; + pin-miso = <17>; + pin-sclk = <16>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; }; diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp index 52063bf45..7ec8c4ce4 100644 --- a/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-43/Source/Configuration.cpp @@ -1,6 +1,5 @@ #include "devices/Display.h" #include "devices/SdCard.h" -#include #include @@ -14,31 +13,5 @@ static DeviceVector createDevices() { } extern const Configuration hardwareConfiguration = { - .createDevices = createDevices, - .spi { - // SD card - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_11, - .miso_io_num = GPIO_NUM_13, - .sclk_io_num = GPIO_NUM_12, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 8192, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr - } - } + .createDevices = createDevices }; diff --git a/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp b/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp index a27db36cb..891129943 100644 --- a/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp +++ b/Devices/waveshare-s3-touch-lcd-43/Source/devices/SdCard.cpp @@ -1,6 +1,8 @@ #include "SdCard.h" +#include #include +#include using tt::hal::sdcard::SpiSdCardDevice; @@ -10,10 +12,15 @@ std::shared_ptr createSdCard() { GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot + 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) + std::move(configuration), + spi_controller ); } 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 21757ad14..7400203c0 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 @@ -3,6 +3,7 @@ #include #include #include +#include #include / { @@ -20,8 +21,17 @@ clock-frequency = <400000>; pin-sda = <8>; pin-scl = <9>; - pin-sda-pullup; - pin-scl-pullup; + }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <11>; + pin-miso = <13>; + pin-sclk = <12>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; }; uart1 { 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 6c98b020c..d62f21a89 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 @@ -19,7 +19,5 @@ clock-frequency = <400000>; pin-sda = <6>; pin-scl = <5>; - pin-sda-pullup; - pin-scl-pullup; }; }; diff --git a/Documentation/ideas.md b/Documentation/ideas.md index 7a3600ea1..41c63a426 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -14,6 +14,7 @@ - Make a root device type so it can be discovered more easily. - DTS/yaml: Consider support for default values. - DTS: throw custom exceptions and catch them to show cleaner error messages. +- When device.py selects a new device, it should automatically delete the build dirs (build/, cmake-*/) when it detects that the platform has changed. - Add font design tokens such as "regular", "title" and "smaller". Perhaps via the LVGL kernel module. - Add kernel listening mechanism so that the root device init can be notified when a device becomes available: Callback for device/start stop with filtering on device type: diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplay.h b/Drivers/EspLcdCompat/Source/EspLcdDisplay.h index 0c26a2e7c..223395ea9 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplay.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplay.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h index 2f3ca2076..124c2356a 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h @@ -65,7 +65,7 @@ class EspLcdDisplayV2 : public tt::hal::display::DisplayDevice { public: - EspLcdDisplayV2(const std::shared_ptr& configuration) : + explicit EspLcdDisplayV2(const std::shared_ptr& configuration) : configuration(configuration) { assert(configuration != nullptr); diff --git a/Drivers/GC9A01/Source/Gc9a01Display.h b/Drivers/GC9A01/Source/Gc9a01Display.h index f62361233..d9a270ed2 100644 --- a/Drivers/GC9A01/Source/Gc9a01Display.h +++ b/Drivers/GC9A01/Source/Gc9a01Display.h @@ -12,8 +12,6 @@ class Gc9a01Display final : public EspLcdDisplay { - std::shared_ptr lock; - public: class Configuration { @@ -82,12 +80,8 @@ class Gc9a01Display final : public EspLcdDisplay { public: explicit Gc9a01Display(std::unique_ptr inConfiguration) : - EspLcdDisplay(tt::hal::spi::getLock(inConfiguration->spiHostDevice)), configuration(std::move(inConfiguration) - ) { - assert(configuration != nullptr); - assert(getLock() != nullptr); - } + ) {} std::string getName() const override { return "GC9A01"; } diff --git a/Drivers/ILI9488/Source/Ili9488Display.h b/Drivers/ILI9488/Source/Ili9488Display.h index 8e2fb3f8f..438170e44 100644 --- a/Drivers/ILI9488/Source/Ili9488Display.h +++ b/Drivers/ILI9488/Source/Ili9488Display.h @@ -28,7 +28,7 @@ class Ili9488Display final : public EspLcdDisplay { bool mirrorX = false, bool mirrorY = false, bool invertColor = false, - uint32_t bufferSize = 0 // Size in pixel count. 0 means default, which is 1/20 of the screen size + uint32_t bufferSize = 0 // Size in pixel count. 0 means default, which is 1/10 of the screen size ) : spiHostDevice(spiHostDevice), csPin(csPin), dcPin(dcPin), diff --git a/Drivers/ST7735/Source/St7735Display.h b/Drivers/ST7735/Source/St7735Display.h index 0c2083d8d..19420e677 100644 --- a/Drivers/ST7735/Source/St7735Display.h +++ b/Drivers/ST7735/Source/St7735Display.h @@ -12,8 +12,6 @@ class St7735Display final : public EspLcdDisplay { - std::shared_ptr lock; - public: class Configuration { diff --git a/Drivers/ST7796/Source/St7796Display.h b/Drivers/ST7796/Source/St7796Display.h index 195cbd0f3..2f1097d46 100644 --- a/Drivers/ST7796/Source/St7796Display.h +++ b/Drivers/ST7796/Source/St7796Display.h @@ -78,7 +78,6 @@ class St7796Display final : public EspLcdDisplay { public: explicit St7796Display(std::unique_ptr inConfiguration) : - EspLcdDisplay(tt::hal::spi::getLock(inConfiguration->spiHostDevice)), configuration(std::move(inConfiguration) ) { assert(configuration != nullptr); diff --git a/Modules/lvgl-module/Source/arch/lvgl_esp32.c b/Modules/lvgl-module/Source/arch/lvgl_esp32.c index 29370019c..231564b09 100644 --- a/Modules/lvgl-module/Source/arch/lvgl_esp32.c +++ b/Modules/lvgl-module/Source/arch/lvgl_esp32.c @@ -12,12 +12,12 @@ extern struct LvglModuleConfig lvgl_module_config; static bool initialized = false; bool lvgl_lock(void) { - if (!initialized) return true; // We allow (ake) locking because it's safe to do so as LVGL is not running yet + if (!initialized) return true; // We allow (fake) locking because it's safe to do so as LVGL is not running yet return lvgl_port_lock(portMAX_DELAY); } bool lvgl_try_lock_timed(uint32_t timeout) { - if (!initialized) return true; // We allow (ake) locking because it's safe to do so as LVGL is not running yet + if (!initialized) return true; // We allow (fake) locking because it's safe to do so as LVGL is not running yet return lvgl_port_lock(millis_to_ticks(timeout)); } diff --git a/Tactility/Include/Tactility/hal/Configuration.h b/Tactility/Include/Tactility/hal/Configuration.h index 966c89f69..6d4ece8f3 100644 --- a/Tactility/Include/Tactility/hal/Configuration.h +++ b/Tactility/Include/Tactility/hal/Configuration.h @@ -20,7 +20,6 @@ enum class UiScale { struct Configuration { /** - * Called before I2C/SPI/etc is initialized. * Used for powering on the peripherals manually. */ const InitBoot initBoot = nullptr; diff --git a/Tactility/Source/service/wifi/WifiEsp.cpp b/Tactility/Source/service/wifi/WifiEsp.cpp index a52211854..bb7b3926c 100644 --- a/Tactility/Source/service/wifi/WifiEsp.cpp +++ b/Tactility/Source/service/wifi/WifiEsp.cpp @@ -858,7 +858,7 @@ static void dispatchDisconnectButKeepActive(std::shared_ptr wifi) { static bool shouldScanForAutoConnect(std::shared_ptr wifi) { auto lock = wifi->dataMutex.asScopedLock(); - if (!lock.lock(100)) { + if (!lock.lock(100 / portTICK_PERIOD_MS)) { return false; } @@ -893,7 +893,7 @@ std::string getIp() { auto wifi = std::static_pointer_cast(wifi_singleton); auto lock = wifi->dataMutex.asScopedLock(); - if (!lock.lock(100)) { + if (!lock.lock(100 / portTICK_PERIOD_MS)) { return "0.0.0.0"; } diff --git a/TactilityC/Source/tt_init.cpp b/TactilityC/Source/tt_init.cpp index e89757de5..27e63a4d9 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -90,19 +90,28 @@ const esp_elfsym main_symbols[] { // esp_sntp.h ESP_ELFSYM_EXPORT(sntp_get_sync_status), // math.h + ESP_ELFSYM_EXPORT(acos), + ESP_ELFSYM_EXPORT(acoshf), + ESP_ELFSYM_EXPORT(acosf), + ESP_ELFSYM_EXPORT(asin), + ESP_ELFSYM_EXPORT(asinhf), + ESP_ELFSYM_EXPORT(asinf), ESP_ELFSYM_EXPORT(atan), + ESP_ELFSYM_EXPORT(atanhf), ESP_ELFSYM_EXPORT(atanf), ESP_ELFSYM_EXPORT(cos), + ESP_ELFSYM_EXPORT(coshf), ESP_ELFSYM_EXPORT(cosf), ESP_ELFSYM_EXPORT(sin), + ESP_ELFSYM_EXPORT(sinhf), ESP_ELFSYM_EXPORT(sinf), ESP_ELFSYM_EXPORT(tan), + ESP_ELFSYM_EXPORT(tanhf), ESP_ELFSYM_EXPORT(tanf), ESP_ELFSYM_EXPORT(frexp), ESP_ELFSYM_EXPORT(frexpf), ESP_ELFSYM_EXPORT(modf), ESP_ELFSYM_EXPORT(modff), - ESP_ELFSYM_EXPORT(fmodf), ESP_ELFSYM_EXPORT(ceil), ESP_ELFSYM_EXPORT(ceilf), ESP_ELFSYM_EXPORT(fabs), diff --git a/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h b/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h index 09e7b93d2..ad3acd172 100644 --- a/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h +++ b/TactilityCore/Include/Tactility/kernel/SpiDeviceLock.h @@ -10,7 +10,7 @@ namespace tt { class SpiDeviceLock : public Lock { ::Device* device; public: - SpiDeviceLock(::Device* device) : device(device) { } + explicit SpiDeviceLock(::Device* device) : device(device) { } bool lock(TickType_t timeout) const override { return spi_controller_try_lock(device, timeout) == ERROR_NONE; From 35ced445b37c5bb5060819ff7473829d6da0e07c Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 21:22:46 +0100 Subject: [PATCH 4/9] Fixes --- Buildscripts/DevicetreeCompiler/source/generator.py | 2 +- .../Source/devices/Jd9165Display.h | 7 +------ Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h | 6 ------ Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp | 1 - .../waveshare-s3-touch-lcd-128/Source/Configuration.cpp | 6 +++--- Drivers/EspLcdCompat/Source/EspLcdDisplay.h | 3 ++- Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h | 4 +--- Tactility/Include/Tactility/hal/Configuration.h | 2 +- Tactility/Source/service/wifi/WifiEsp.cpp | 9 +++------ 9 files changed, 12 insertions(+), 28 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index bdcf7ce2a..cf7f80f6c 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -63,7 +63,7 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: type = property.type if type == "value": return property.value - if type == "boolean": + elif type == "boolean": return "true" elif type == "text": return f"\"{property.value}\"" diff --git a/Devices/guition-jc1060p470ciwy/Source/devices/Jd9165Display.h b/Devices/guition-jc1060p470ciwy/Source/devices/Jd9165Display.h index 0dd66e07d..98d33c6a8 100644 --- a/Devices/guition-jc1060p470ciwy/Source/devices/Jd9165Display.h +++ b/Devices/guition-jc1060p470ciwy/Source/devices/Jd9165Display.h @@ -8,11 +8,6 @@ class Jd9165Display final : public EspLcdDisplayV2 { - class NoLock final : public tt::Lock { - bool lock(TickType_t timeout) const override { return true; } - void unlock() const override { /* NO-OP */ } - }; - esp_lcd_dsi_bus_handle_t mipiDsiBus = nullptr; esp_ldo_channel_handle_t ldoChannel = nullptr; @@ -34,7 +29,7 @@ class Jd9165Display final : public EspLcdDisplayV2 { Jd9165Display( const std::shared_ptr& configuration - ) : EspLcdDisplayV2(configuration, std::make_shared()) {} + ) : EspLcdDisplayV2(configuration) {} ~Jd9165Display() override; diff --git a/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h b/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h index 3ba945cce..3643df0dd 100644 --- a/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h +++ b/Devices/m5stack-tab5/Source/devices/Ili9881cDisplay.h @@ -1,18 +1,12 @@ #pragma once #include -#include #include #include class Ili9881cDisplay final : public EspLcdDisplayV2 { - class NoLock final : public tt::Lock { - bool lock(TickType_t timeout) const override { return true; } - void unlock() const override { /* NO-OP */ } - }; - esp_lcd_dsi_bus_handle_t mipiDsiBus = nullptr; esp_ldo_channel_handle_t ldoChannel = nullptr; diff --git a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp b/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp index ae706305d..b01a45b4d 100644 --- a/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp +++ b/Devices/waveshare-s3-lcd-13/Source/devices/SdCard.cpp @@ -2,7 +2,6 @@ #include #include -#include #include using tt::hal::sdcard::SpiSdCardDevice; diff --git a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp index fcfe9eacf..ce63c4185 100644 --- a/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp +++ b/Devices/waveshare-s3-touch-lcd-128/Source/Configuration.cpp @@ -1,4 +1,5 @@ #include "devices/Display.h" +#include "devices/SdCard.h" #include #include @@ -6,11 +7,10 @@ using namespace tt::hal; -constexpr auto* TAG = "Waveshare"; - static DeviceVector createDevices() { return { - createDisplay() + createDisplay(), + createSdCard() }; } diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplay.h b/Drivers/EspLcdCompat/Source/EspLcdDisplay.h index 223395ea9..b8144bd07 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplay.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplay.h @@ -13,7 +13,8 @@ class EspLcdDisplay : public tt::hal::display::DisplayDevice { esp_lcd_panel_handle_t panelHandle = nullptr; lv_display_t* lvglDisplay = nullptr; std::shared_ptr displayDriver; - lcd_rgb_element_order_t rgbElementOrder; + /** @warning This is never changed, so a driver that needs BGR is not supported */ + lcd_rgb_element_order_t rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB; protected: diff --git a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h index 124c2356a..5d843c4bd 100644 --- a/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h +++ b/Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h @@ -67,9 +67,7 @@ class EspLcdDisplayV2 : public tt::hal::display::DisplayDevice { explicit EspLcdDisplayV2(const std::shared_ptr& configuration) : configuration(configuration) - { - assert(configuration != nullptr); - } + {} ~EspLcdDisplayV2() override; diff --git a/Tactility/Include/Tactility/hal/Configuration.h b/Tactility/Include/Tactility/hal/Configuration.h index 6d4ece8f3..5117c1318 100644 --- a/Tactility/Include/Tactility/hal/Configuration.h +++ b/Tactility/Include/Tactility/hal/Configuration.h @@ -27,7 +27,7 @@ struct Configuration { /** Modify LVGL widget size */ const UiScale uiScale = UiScale::Default; - std::function createDevices = [] { return DeviceVector(); }; + const std::function createDevices = [] { return DeviceVector(); }; }; } // namespace diff --git a/Tactility/Source/service/wifi/WifiEsp.cpp b/Tactility/Source/service/wifi/WifiEsp.cpp index bb7b3926c..2840f9e05 100644 --- a/Tactility/Source/service/wifi/WifiEsp.cpp +++ b/Tactility/Source/service/wifi/WifiEsp.cpp @@ -304,11 +304,6 @@ bool isConnectionSecure() { return false; } - auto lock = wifi->dataMutex.asScopedLock(); - if (!lock.lock(10 / portTICK_PERIOD_MS)) { - return false; - } - return wifi->isSecureConnection(); } @@ -892,9 +887,11 @@ void onAutoConnectTimer() { std::string getIp() { auto wifi = std::static_pointer_cast(wifi_singleton); + if (wifi == nullptr) return "127.0.0.1"; + auto lock = wifi->dataMutex.asScopedLock(); if (!lock.lock(100 / portTICK_PERIOD_MS)) { - return "0.0.0.0"; + return "127.0.0.1"; } return std::format("{}.{}.{}.{}", IP2STR(&wifi->ip_info.ip)); From 886aa70c391518ad54e489a9a7ef636c9d1e1992 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 21:49:30 +0100 Subject: [PATCH 5/9] Migrate WT32-SC01-Plus device --- .../Source/Configuration.cpp | 31 ++----------------- .../Source/devices/SdCard.cpp | 7 ++++- .../wireless-tag,wt32-sc01-plus.dts | 12 +++++++ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp index e1ce2c8c6..b33fbb08a 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp +++ b/Devices/wireless-tag-wt32-sc01-plus/Source/Configuration.cpp @@ -1,9 +1,8 @@ #include "devices/Display.h" #include "devices/SdCard.h" -#include +#include #include -#include #include using namespace tt::hal; @@ -21,31 +20,5 @@ static bool initBoot() { extern const Configuration hardwareConfiguration = { .initBoot = initBoot, - .createDevices = createDevices, - .spi { - // SD card - spi::Configuration { - .device = SPI2_HOST, - .dma = SPI_DMA_CH_AUTO, - .config = { - .mosi_io_num = GPIO_NUM_40, - .miso_io_num = GPIO_NUM_38, - .sclk_io_num = GPIO_NUM_39, - .quadwp_io_num = GPIO_NUM_NC, - .quadhd_io_num = GPIO_NUM_NC, - .data4_io_num = GPIO_NUM_NC, - .data5_io_num = GPIO_NUM_NC, - .data6_io_num = GPIO_NUM_NC, - .data7_io_num = GPIO_NUM_NC, - .data_io_default_level = false, - .max_transfer_sz = 32768, - .flags = 0, - .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, - .intr_flags = 0 - }, - .initMode = spi::InitMode::ByTactility, - .isMutable = false, - .lock = nullptr // No custom lock needed - } - } + .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 index 425caf7cb..b2e4dc428 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.cpp +++ b/Devices/wireless-tag-wt32-sc01-plus/Source/devices/SdCard.cpp @@ -1,5 +1,6 @@ #include "SdCard.h" +#include #include #include @@ -17,7 +18,11 @@ std::shared_ptr createSdCard() { SPI2_HOST ); + ::Device* spiController = device_find_by_name("spi0"); + check(spiController != nullptr, "spi0 not found"); + return std::make_shared( - std::move(configuration) + std::move(configuration), + spiController ); } 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 d62f21a89..f96775ffe 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 @@ -3,6 +3,7 @@ #include #include #include +#include / { compatible = "root"; @@ -20,4 +21,15 @@ pin-sda = <6>; pin-scl = <5>; }; + + spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <40>; + pin-miso = <38>; + pin-sclk = <39>; + pin-wp = ; + pin-hd = ; + max-transfer-size = <0>; + }; }; From 24cce1bd2a1d629b8f44f6a2dc5ccf0603b09bea Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 22:26:30 +0100 Subject: [PATCH 6/9] Improve property parsing --- .../source/binding_parser.py | 1 + .../DevicetreeCompiler/source/generator.py | 23 +++++++++++++++++-- .../DevicetreeCompiler/source/models.py | 1 + Documentation/ideas.md | 2 -- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/binding_parser.py b/Buildscripts/DevicetreeCompiler/source/binding_parser.py index b6f7f116f..2b4889431 100644 --- a/Buildscripts/DevicetreeCompiler/source/binding_parser.py +++ b/Buildscripts/DevicetreeCompiler/source/binding_parser.py @@ -44,6 +44,7 @@ def parse_binding(file_path: str, binding_dirs: list[str]) -> Binding: type=details.get('type', 'unknown'), required=details.get('required', False), description=details.get('description', '').strip(), + default=details.get('default', 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 cf7f80f6c..3de7b5ff2 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -83,18 +83,37 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de raise Exception(f"Binding not found for {device.node_name} and compatible '{compatible_property.value}'") # Filter out system properties binding_properties = [] + binding_property_names = set() for property in device_binding.properties: if property.name != "compatible": binding_properties.append(property) + binding_property_names.add(property.name) + + # Check for invalid properties in device + for device_property in device.properties: + if device_property.name in ["compatible"]: + continue + if device_property.name not in binding_property_names: + raise Exception(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): device_property = find_device_property(device, binding_property.name) if device_property is None: - if binding_property.required: + if binding_property.type == "bool": + result[index] = "false" + elif binding_property.required: raise Exception(f"device {device.node_name} doesn't have property '{binding_property.name}'") + elif binding_property.default is not None: + temp_prop = DeviceProperty( + name=binding_property.name, + type=binding_property.type, + value=binding_property.default + ) + result[index] = property_to_string(temp_prop, devices) else: - result[index] = '0' + raise Exception(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 diff --git a/Buildscripts/DevicetreeCompiler/source/models.py b/Buildscripts/DevicetreeCompiler/source/models.py index a865c698f..3b5747535 100644 --- a/Buildscripts/DevicetreeCompiler/source/models.py +++ b/Buildscripts/DevicetreeCompiler/source/models.py @@ -36,6 +36,7 @@ class BindingProperty: type: str required: bool description: str + default: object = None @dataclass class Binding: diff --git a/Documentation/ideas.md b/Documentation/ideas.md index 41c63a426..b41ee4f74 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -69,8 +69,6 @@ ## Lower Priority -- Rename `Lock::lock()` and `Lock::unlock()` to `Lock::acquire()` and `Lock::release()`? -- Implement system suspend that turns off the screen - The boot button on some devices can be used as GPIO_NUM_0 at runtime - Localize all apps - Support hot-plugging SD card (note: this is not possible if they require the CS pin hack) From 20f358ebe5572249bd38281c1dad67c4f4204b8a Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 22:43:09 +0100 Subject: [PATCH 7/9] Fix for int defaults --- Buildscripts/DevicetreeCompiler/source/generator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index 3de7b5ff2..dd98c27c6 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -63,6 +63,8 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: type = property.type if type == "value": return property.value + elif type == "int": + return property.value elif type == "boolean": return "true" elif type == "text": From 2e7e5d36c09bd2743ed0cf8dc01e21345cf0c08a Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 22:43:19 +0100 Subject: [PATCH 8/9] Update binding yaml spec --- Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml | 4 ++++ Platforms/PlatformEsp32/Bindings/espressif,esp32-i2s.yaml | 6 +++--- Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml | 3 +++ Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml index 553fbf805..fff784b74 100644 --- a/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml @@ -7,16 +7,20 @@ compatible: "espressif,esp32-i2c" properties: port: type: int + required: true description: | The port number, defined by i2c_port_t. Depending on the hardware, these values are available: I2C_NUM_0, I2C_NUM_1, LP_I2C_NUM_0 clock-frequency: type: int + required: true description: Initial clock frequency in Hz pin-sda: type: int + required: true pin-scl: type: int + required: true pin-sda-pull-up: type: bool description: enable internal pull-up resistor for SDA pin diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2s.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2s.yaml index ee2712934..dec9e63fb 100644 --- a/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2s.yaml +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2s.yaml @@ -21,13 +21,13 @@ properties: description: WS pin pin-data-out: type: int - required: true description: DATA OUT pin pin-data-in: type: int - required: true + required: false description: DATA IN pin pin-mclk: type: int - required: true + required: false + default: GPIO_PIN_NONE description: MCLK pin diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml index d6555dbc1..4166042f4 100644 --- a/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-spi.yaml @@ -25,12 +25,15 @@ properties: description: Clock pin pin-wp: type: int + default: GPIO_PIN_NONE description: WP (Data 2) pin pin-hd: type: int + default: GPIO_PIN_NONE description: HD (Data 3) pin max-transfer-size: type: int + default: 0 description: | Data transfer size limit in bytes. 0 means the platform decides the limit. diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml index f39b11c64..c6a077e74 100644 --- a/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-uart.yaml @@ -21,7 +21,9 @@ properties: description: RX pin pin-cts: type: int + default: GPIO_PIN_NONE description: CTS pin pin-rts: type: int + default: GPIO_PIN_NONE description: RTS pin From 27cbec11510623e3e70ed13e607671a7e09c7123 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 8 Feb 2026 22:57:10 +0100 Subject: [PATCH 9/9] Implement cleaner error handling --- Buildscripts/DevicetreeCompiler/compile.py | 3 +- .../source/binding_files.py | 3 +- .../DevicetreeCompiler/source/exception.py | 3 + .../DevicetreeCompiler/source/generator.py | 26 ++++----- .../DevicetreeCompiler/source/main.py | 58 ++++++++++--------- .../DevicetreeCompiler/source/transformer.py | 7 ++- Documentation/ideas.md | 2 - 7 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 Buildscripts/DevicetreeCompiler/source/exception.py diff --git a/Buildscripts/DevicetreeCompiler/compile.py b/Buildscripts/DevicetreeCompiler/compile.py index b5db6034c..9f21731e7 100644 --- a/Buildscripts/DevicetreeCompiler/compile.py +++ b/Buildscripts/DevicetreeCompiler/compile.py @@ -24,5 +24,6 @@ def print_help(): is_verbose = "--verbose" in sys.argv devicetree_yaml_config = args[0] output_path = args[1] - main(devicetree_yaml_config, output_path, is_verbose) + result = main(devicetree_yaml_config, output_path, is_verbose) + sys.exit(result) diff --git a/Buildscripts/DevicetreeCompiler/source/binding_files.py b/Buildscripts/DevicetreeCompiler/source/binding_files.py index d69733109..504036dda 100644 --- a/Buildscripts/DevicetreeCompiler/source/binding_files.py +++ b/Buildscripts/DevicetreeCompiler/source/binding_files.py @@ -1,4 +1,5 @@ import os +from .exception import DevicetreeException def find_bindings(directory_path: str) -> list[str]: yaml_files = [] @@ -14,6 +15,6 @@ def find_all_bindings(directory_paths: list[str]) -> list[str]: for directory_path in directory_paths: new_paths = find_bindings(directory_path) if len(new_paths) == 0: - raise Exception(f"No bindings found in {directory_path}") + raise DevicetreeException(f"No bindings found in {directory_path}") yaml_files += new_paths return yaml_files \ No newline at end of file diff --git a/Buildscripts/DevicetreeCompiler/source/exception.py b/Buildscripts/DevicetreeCompiler/source/exception.py new file mode 100644 index 000000000..de70efd1f --- /dev/null +++ b/Buildscripts/DevicetreeCompiler/source/exception.py @@ -0,0 +1,3 @@ +class DevicetreeException(Exception): + def __init__(self, message): + super().__init__(message) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index dd98c27c6..c6d7685f2 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -1,7 +1,7 @@ import os.path from textwrap import dedent - from source.models import * +from .exception import DevicetreeException def write_include(file, include: IncludeC, verbose: bool): if verbose: @@ -26,9 +26,9 @@ def get_device_node_name_safe(device: Device): def get_device_type_name(device: Device, bindings: list[Binding]): device_binding = find_device_binding(device, bindings) if device_binding is None: - raise Exception(f"Binding not found for {device.node_name}") + raise DevicetreeException(f"Binding not found for {device.node_name}") if device_binding.compatible is None: - raise Exception(f"Couldn't find compatible binding for {device.node_name}") + raise DevicetreeException(f"Couldn't find compatible binding for {device.node_name}") compatible_safe = device_binding.compatible.split(",")[-1] return compatible_safe.replace("-", "_") @@ -41,7 +41,7 @@ def find_device_property(device: Device, name: str) -> DeviceProperty: def find_device_binding(device: Device, bindings: list[Binding]) -> Binding: compatible_property = find_device_property(device, "compatible") if compatible_property is None: - raise Exception(f"property 'compatible' not found in device {device.node_name}") + raise DevicetreeException(f"property 'compatible' not found in device {device.node_name}") for binding in bindings: if binding.compatible == compatible_property.value: return binding @@ -57,7 +57,7 @@ def find_phandle(devices: list[Device], phandle: str): for device in devices: if device.node_name == phandle or device.node_alias == phandle: return f"&{get_device_node_name_safe(device)}" - raise Exception(f"phandle '{phandle}' not found in device tree") + raise DevicetreeException(f"phandle '{phandle}' not found in device tree") def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: type = property.type @@ -74,15 +74,15 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: elif type == "phandle": return find_phandle(devices, property.value) else: - raise Exception(f"property_to_string() has an unsupported type: {type}") + raise DevicetreeException(f"property_to_string() has an unsupported type: {type}") 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: - raise Exception(f"Cannot find 'compatible' property for {device.node_name}") + raise DevicetreeException(f"Cannot find 'compatible' property for {device.node_name}") device_binding = find_binding(compatible_property.value, bindings) if device_binding is None: - raise Exception(f"Binding not found for {device.node_name} and compatible '{compatible_property.value}'") + raise DevicetreeException(f"Binding not found for {device.node_name} and compatible '{compatible_property.value}'") # Filter out system properties binding_properties = [] binding_property_names = set() @@ -96,7 +96,7 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de if device_property.name in ["compatible"]: continue if device_property.name not in binding_property_names: - raise Exception(f"Device '{device.node_name}' has invalid property '{device_property.name}'") + raise DevicetreeException(f"Device '{device.node_name}' has invalid property '{device_property.name}'") # Allocate total expected configuration arguments result = [0] * len(binding_properties) @@ -106,7 +106,7 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de if binding_property.type == "bool": result[index] = "false" elif binding_property.required: - raise Exception(f"device {device.node_name} doesn't have property '{binding_property.name}'") + raise DevicetreeException(f"device {device.node_name} doesn't have property '{binding_property.name}'") elif binding_property.default is not None: temp_prop = DeviceProperty( name=binding_property.name, @@ -115,7 +115,7 @@ def resolve_parameters_from_bindings(device: Device, bindings: list[Binding], de ) result[index] = property_to_string(temp_prop, devices) else: - raise Exception(f"Device {device.node_name} doesn't have property '{binding_property.name}' and no default value is set") + 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 @@ -142,7 +142,7 @@ def write_device_structs(file, device: Device, parent_device: Device, bindings: type_name = get_device_type_name(device, bindings) compatible_property = find_device_property(device, "compatible") if compatible_property is None: - raise Exception(f"Cannot find 'compatible' property for {device.node_name}") + raise DevicetreeException(f"Cannot find 'compatible' property for {device.node_name}") node_name = get_device_node_name_safe(device) config_variable_name = f"{node_name}_config" if parent_device is not None: @@ -169,7 +169,7 @@ def write_device_init(file, device: Device, bindings: list[Binding], verbose: bo # Assemble some pre-requisites compatible_property = find_device_property(device, "compatible") if compatible_property is None: - raise Exception(f"Cannot find 'compatible' property for {device.node_name}") + raise DevicetreeException(f"Cannot find 'compatible' property for {device.node_name}") # Type & instance names node_name = get_device_node_name_safe(device) device_variable = node_name diff --git a/Buildscripts/DevicetreeCompiler/source/main.py b/Buildscripts/DevicetreeCompiler/source/main.py index 97b7f0be1..cca885767 100644 --- a/Buildscripts/DevicetreeCompiler/source/main.py +++ b/Buildscripts/DevicetreeCompiler/source/main.py @@ -9,38 +9,44 @@ from source.binding_files import find_all_bindings from source.binding_parser import parse_binding from source.config import * +from source.exception import DevicetreeException -def main(config_path: str, output_path: str, verbose: bool): +def main(config_path: str, output_path: str, verbose: bool) -> int: print(f"Generating devicetree code\n config: {config_path}\n output: {output_path}") if not os.path.isdir(config_path): - raise Exception(f"Directory not found: {config_path}") + raise DevicetreeException(f"Directory not found: {config_path}") config = parse_config(config_path, os.getcwd()) if verbose: pprint(config) - project_dir = os.path.dirname(os.path.realpath(__file__)) - grammar_path = os.path.join(project_dir, "grammar.lark") - lark_data = read_file(grammar_path) - dts_data = read_file(config.dts) - lark = Lark(lark_data) - parsed = lark.parse(dts_data) - if verbose: - print(parsed.pretty()) - transformed = DtsTransformer().transform(parsed) - if verbose: - pprint(transformed) - binding_files = find_all_bindings(config.bindings) - if verbose: - print(f"Bindings found:") + try: + project_dir = os.path.dirname(os.path.realpath(__file__)) + grammar_path = os.path.join(project_dir, "grammar.lark") + lark_data = read_file(grammar_path) + dts_data = read_file(config.dts) + lark = Lark(lark_data) + parsed = lark.parse(dts_data) + if verbose: + print(parsed.pretty()) + transformed = DtsTransformer().transform(parsed) + if verbose: + pprint(transformed) + binding_files = find_all_bindings(config.bindings) + if verbose: + print(f"Bindings found:") + for binding_file in binding_files: + print(f" {binding_file}") + if verbose: + print(f"Parsing bindings") + bindings = [] for binding_file in binding_files: - print(f" {binding_file}") - if verbose: - print(f"Parsing bindings") - bindings = [] - for binding_file in binding_files: - bindings.append(parse_binding(binding_file, config.bindings)) - if verbose: - for binding in bindings: - pprint(binding) - generate(output_path, transformed, bindings, verbose) + bindings.append(parse_binding(binding_file, config.bindings)) + if verbose: + for binding in bindings: + pprint(binding) + generate(output_path, transformed, bindings, verbose) + return 0 + except DevicetreeException as caught: + print("\033[31mError: ", caught, "\033[0m") + return 1 diff --git a/Buildscripts/DevicetreeCompiler/source/transformer.py b/Buildscripts/DevicetreeCompiler/source/transformer.py index bb70e3cde..ffd6441cf 100644 --- a/Buildscripts/DevicetreeCompiler/source/transformer.py +++ b/Buildscripts/DevicetreeCompiler/source/transformer.py @@ -4,6 +4,7 @@ from lark import Token from source.models import * from dataclasses import dataclass +from .exception import DevicetreeException def flatten_token_array(tokens: List[Token], name: str): result_list = list() @@ -23,7 +24,7 @@ def start(self, tokens): def dts_version(self, tokens: List[Token]): version = tokens[0].value if version != "dts-v1": - raise Exception(f"Unsupported DTS version: {version}") + raise DevicetreeException(f"Unsupported DTS version: {version}") return DtsVersion(version) def device(self, tokens: list): node_name = None @@ -46,12 +47,12 @@ def device_property(self, objects: List[object]): if (len(objects) == 1) or (objects[1] is None): return DeviceProperty(name, "boolean", True) if type(objects[1]) is not PropertyValue: - raise Exception(f"Object was not converted to PropertyValue: {objects[1]}") + raise DevicetreeException(f"Object was not converted to PropertyValue: {objects[1]}") return DeviceProperty(name, objects[1].type, objects[1].value) def property_value(self, tokens: List): token = tokens[0] if type(token) is Token: - raise Exception(f"Failed to convert token to PropertyValue: {token}") + raise DevicetreeException(f"Failed to convert token to PropertyValue: {token}") return token def PHANDLE(self, token: Token): return PropertyValue(type="phandle", value=token.value[1:]) diff --git a/Documentation/ideas.md b/Documentation/ideas.md index b41ee4f74..ed7fed5bb 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -12,8 +12,6 @@ ## Higher Priority - Make a root device type so it can be discovered more easily. -- DTS/yaml: Consider support for default values. -- DTS: throw custom exceptions and catch them to show cleaner error messages. - When device.py selects a new device, it should automatically delete the build dirs (build/, cmake-*/) when it detects that the platform has changed. - Add font design tokens such as "regular", "title" and "smaller". Perhaps via the LVGL kernel module. - Add kernel listening mechanism so that the root device init can be notified when a device becomes available: