From f99970a562fb31b11357c8554cb69e2619b34aee Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Wed, 15 Jul 2026 23:06:57 +0200 Subject: [PATCH] Migrate cyd-2432s032c drivers --- Devices/cyd-2432s032c/CMakeLists.txt | 5 +- .../cyd-2432s032c/Source/Configuration.cpp | 47 ------------------ .../cyd-2432s032c/Source/devices/Display.cpp | 48 ------------------- .../cyd-2432s032c/Source/devices/Display.h | 18 ------- Devices/cyd-2432s032c/cyd,2432s032c.dts | 36 ++++++++++++-- Devices/cyd-2432s032c/device.properties | 2 + Devices/cyd-2432s032c/devicetree.yaml | 2 + .../{Source => source}/module.cpp | 0 8 files changed, 38 insertions(+), 120 deletions(-) delete mode 100644 Devices/cyd-2432s032c/Source/Configuration.cpp delete mode 100644 Devices/cyd-2432s032c/Source/devices/Display.cpp delete mode 100644 Devices/cyd-2432s032c/Source/devices/Display.h rename Devices/cyd-2432s032c/{Source => source}/module.cpp (100%) diff --git a/Devices/cyd-2432s032c/CMakeLists.txt b/Devices/cyd-2432s032c/CMakeLists.txt index 3b5cbbbe8..a832a83a2 100644 --- a/Devices/cyd-2432s032c/CMakeLists.txt +++ b/Devices/cyd-2432s032c/CMakeLists.txt @@ -1,7 +1,6 @@ -file(GLOB_RECURSE SOURCE_FILES Source/*.c*) +file(GLOB_RECURSE SOURCE_FILES source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} - INCLUDE_DIRS "Source" - REQUIRES Tactility esp_lvgl_port ILI934x GT911 PwmBacklight driver vfs fatfs + REQUIRES TactilityKernel driver ) diff --git a/Devices/cyd-2432s032c/Source/Configuration.cpp b/Devices/cyd-2432s032c/Source/Configuration.cpp deleted file mode 100644 index 9e5abd20c..000000000 --- a/Devices/cyd-2432s032c/Source/Configuration.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "devices/Display.h" -#include - -#include -#include -#include - -#include - -static bool init_boot() { - if (!driver::pwmbacklight::init(LCD_PIN_BACKLIGHT)) { - return false; - } - - // Set the RGB LED Pins to output and turn them off - ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); // Red - ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); // Green - ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT)); // Blue - - // 0 on, 1 off - ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_4, 1)); // Red - ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_16, 1)); // Green - ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_17, 1)); // Blue - - // This display has a weird glitch with gamma during boot, which results in uneven dark gray colours. - // Setting gamma curve index to 0 doesn't work at boot for an unknown reason, so we set the curve index to 1: - tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](auto) { - auto display = tt::hal::findFirstDevice(tt::hal::Device::Type::Display); - assert(display != nullptr); - tt::lvgl::lock(portMAX_DELAY); - display->setGammaCurve(1U); - tt::lvgl::unlock(); - }); - - return true; -} - -static tt::hal::DeviceVector createDevices() { - return { - createDisplay(), - }; -} - -extern const tt::hal::Configuration hardwareConfiguration = { - .initBoot = init_boot, - .createDevices = createDevices -}; diff --git a/Devices/cyd-2432s032c/Source/devices/Display.cpp b/Devices/cyd-2432s032c/Source/devices/Display.cpp deleted file mode 100644 index d0bb5ddd2..000000000 --- a/Devices/cyd-2432s032c/Source/devices/Display.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "Display.h" - -#include -#include -#include -#include -#include - -static std::shared_ptr createTouch() { - auto* i2c = device_find_by_name("i2c0"); - check(i2c); - auto configuration = std::make_unique( - i2c, - LCD_HORIZONTAL_RESOLUTION, - LCD_VERTICAL_RESOLUTION - ); - - return std::make_shared(std::move(configuration)); -} - -std::shared_ptr createDisplay() { - Ili934xDisplay::Configuration panel_configuration = { - .horizontalResolution = LCD_HORIZONTAL_RESOLUTION, - .verticalResolution = LCD_VERTICAL_RESOLUTION, - .gapX = 0, - .gapY = 0, - .swapXY = true, - .mirrorX = true, - .mirrorY = true, - .invertColor = true, - .swapBytes = true, - .bufferSize = LCD_BUFFER_SIZE, - .touch = createTouch(), - .backlightDutyFunction = driver::pwmbacklight::setBacklightDuty, - .resetPin = GPIO_NUM_NC, - .rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB - }; - - auto spi_configuration = std::make_shared(Ili934xDisplay::SpiConfiguration { - .spiHostDevice = LCD_SPI_HOST, - .csPin = LCD_PIN_CS, - .dcPin = LCD_PIN_DC, - .pixelClockFrequency = 40'000'000, - .transactionQueueDepth = 10 - }); - - return std::make_shared(panel_configuration, spi_configuration, true); -} diff --git a/Devices/cyd-2432s032c/Source/devices/Display.h b/Devices/cyd-2432s032c/Source/devices/Display.h deleted file mode 100644 index 8a54f1e1a..000000000 --- a/Devices/cyd-2432s032c/Source/devices/Display.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -// Display -constexpr auto LCD_SPI_HOST = SPI2_HOST; -constexpr auto LCD_PIN_CS = GPIO_NUM_15; -constexpr auto LCD_PIN_DC = GPIO_NUM_2; -constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_27; -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; - -std::shared_ptr createDisplay(); diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 4dbc0c74d..c04a13fe0 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -6,7 +6,9 @@ #include #include #include -#include +#include +#include +#include / { compatible = "root"; @@ -28,6 +30,21 @@ clock-frequency = <400000>; pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; + + touch { + compatible = "goodix,gt911"; + reg = <0x5D>; + x-max = <240>; + y-max = <320>; + }; + }; + + display_backlight { + compatible = "espressif,esp32-ledc-backlight"; + // Off by default so display power-on won't show the screen from before the last power loss. + // The display backlight is turned on during the boot process. + status = "disabled"; + pin-backlight = <&gpio0 27 GPIO_FLAG_NONE>; }; spi0 { @@ -36,9 +53,20 @@ cs-gpios = <&gpio0 15 GPIO_FLAG_NONE>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; - - display { - compatible = "display-placeholder"; + + display@0 { + compatible = "ilitek,ili9341"; + horizontal-resolution = <240>; + vertical-resolution = <320>; + swap-xy; + mirror-x; + mirror-y; + invert-color; + // Curve 0 doesn't apply cleanly at boot on this panel (uneven dark-gray gamma glitch); 1 does. + gamma-curve = <1>; + pixel-clock-hz = <40000000>; + pin-dc = <&gpio0 2 GPIO_FLAG_NONE>; + backlight = <&display_backlight>; }; }; diff --git a/Devices/cyd-2432s032c/device.properties b/Devices/cyd-2432s032c/device.properties index e483bd8c2..dc563dae6 100644 --- a/Devices/cyd-2432s032c/device.properties +++ b/Devices/cyd-2432s032c/device.properties @@ -7,6 +7,8 @@ hardware.target=ESP32 hardware.flashSize=4MB hardware.spiRam=false +dependencies.useDeprecatedHal=false + storage.userDataLocation=SD display.size=3.2" diff --git a/Devices/cyd-2432s032c/devicetree.yaml b/Devices/cyd-2432s032c/devicetree.yaml index 98ce41688..b7f4d0173 100644 --- a/Devices/cyd-2432s032c/devicetree.yaml +++ b/Devices/cyd-2432s032c/devicetree.yaml @@ -1,3 +1,5 @@ dependencies: - Platforms/platform-esp32 + - Drivers/ili9341-module + - Drivers/gt911-module dts: cyd,2432s032c.dts diff --git a/Devices/cyd-2432s032c/Source/module.cpp b/Devices/cyd-2432s032c/source/module.cpp similarity index 100% rename from Devices/cyd-2432s032c/Source/module.cpp rename to Devices/cyd-2432s032c/source/module.cpp