From 65335578a4f459ed7d13c4a9d9cc74205e1ac4f9 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 6 Sep 2025 15:12:40 +0200 Subject: [PATCH] Update CYD-E32R28T and fixed some minor issues (#319) --- Boards/CYD-E32R28T/Source/E32R28T.cpp | 19 +++--- Boards/CYD-E32R28T/Source/devices/Display.cpp | 41 +++++++++++++ .../Display.h} | 10 ++-- Boards/CYD-E32R28T/Source/devices/SdCard.cpp | 21 +++++++ Boards/CYD-E32R28T/Source/devices/SdCard.h | 7 +++ .../CYD-E32R28T/Source/hal/YellowDisplay.cpp | 58 ------------------- Boards/CYD-E32R28T/Source/hal/YellowDisplay.h | 6 -- .../CYD-E32R28T/Source/hal/YellowSdCard.cpp | 22 ------- Boards/CYD-E32R28T/Source/hal/YellowSdCard.h | 7 --- 9 files changed, 85 insertions(+), 106 deletions(-) create mode 100644 Boards/CYD-E32R28T/Source/devices/Display.cpp rename Boards/CYD-E32R28T/Source/{hal/YellowDisplayConstants.h => devices/Display.h} (83%) create mode 100644 Boards/CYD-E32R28T/Source/devices/SdCard.cpp create mode 100644 Boards/CYD-E32R28T/Source/devices/SdCard.h delete mode 100644 Boards/CYD-E32R28T/Source/hal/YellowDisplay.cpp delete mode 100644 Boards/CYD-E32R28T/Source/hal/YellowDisplay.h delete mode 100644 Boards/CYD-E32R28T/Source/hal/YellowSdCard.cpp delete mode 100644 Boards/CYD-E32R28T/Source/hal/YellowSdCard.h diff --git a/Boards/CYD-E32R28T/Source/E32R28T.cpp b/Boards/CYD-E32R28T/Source/E32R28T.cpp index b89b771b..7e2985d1 100644 --- a/Boards/CYD-E32R28T/Source/E32R28T.cpp +++ b/Boards/CYD-E32R28T/Source/E32R28T.cpp @@ -1,22 +1,25 @@ #include "E32R28T.h" -#include "hal/YellowSdCard.h" -#include "hal/YellowDisplay.h" -#include "hal/YellowDisplayConstants.h" +#include "devices/SdCard.h" +#include "devices/Display.h" #include -#include #include #define CYD_SPI_TRANSFER_SIZE_LIMIT (240 * 320 / 4 * 2) -bool initBoot() { +static bool initBoot() { return driver::pwmbacklight::init(CYD_BACKLIGHT_PIN); } +static tt::hal::DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + const tt::hal::Configuration cyd_e32r28t_config = { .initBoot = initBoot, - .createDisplay = createDisplay, - .sdcard = createYellowSdCard(), - .power = nullptr, + .createDevices = createDevices, .i2c = {}, .spi = { tt::hal::spi::Configuration { diff --git a/Boards/CYD-E32R28T/Source/devices/Display.cpp b/Boards/CYD-E32R28T/Source/devices/Display.cpp new file mode 100644 index 00000000..68b00820 --- /dev/null +++ b/Boards/CYD-E32R28T/Source/devices/Display.cpp @@ -0,0 +1,41 @@ +#include "Display.h" + +#include +#include +#include +#include + +static std::shared_ptr createTouch() { + auto config = std::make_unique( + CYD_TOUCH_MOSI_PIN, + CYD_TOUCH_MISO_PIN, + CYD_TOUCH_SCK_PIN, + CYD_TOUCH_CS_PIN, + CYD_DISPLAY_HORIZONTAL_RESOLUTION, + CYD_DISPLAY_VERTICAL_RESOLUTION, + false, + true, + false + ); + + return std::make_shared(std::move(config)); +} + +std::shared_ptr createDisplay() { + auto configuration = std::make_unique( + CYD_DISPLAY_SPI_HOST, + CYD_DISPLAY_PIN_CS, + CYD_DISPLAY_PIN_DC, + CYD_DISPLAY_HORIZONTAL_RESOLUTION, + CYD_DISPLAY_VERTICAL_RESOLUTION, + createTouch(), + false, + true, + false, + false, + 0, + LCD_RGB_ELEMENT_ORDER_BGR + ); + configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; + return std::make_shared(std::move(configuration)); +} diff --git a/Boards/CYD-E32R28T/Source/hal/YellowDisplayConstants.h b/Boards/CYD-E32R28T/Source/devices/Display.h similarity index 83% rename from Boards/CYD-E32R28T/Source/hal/YellowDisplayConstants.h rename to Boards/CYD-E32R28T/Source/devices/Display.h index 17638c47..31c73d55 100644 --- a/Boards/CYD-E32R28T/Source/hal/YellowDisplayConstants.h +++ b/Boards/CYD-E32R28T/Source/devices/Display.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + // Display #define CYD_DISPLAY_SPI_HOST SPI2_HOST #define CYD_DISPLAY_PIN_CS GPIO_NUM_15 @@ -16,10 +19,7 @@ #define CYD_TOUCH_CS_PIN GPIO_NUM_33 #define CYD_TOUCH_IRQ_PIN GPIO_NUM_36 -// SD Card -#define CYD_SDCARD_SPI_HOST SPI3_HOST -#define CYD_SDCARD_PIN_CS GPIO_NUM_5 - - // Backlight #define CYD_BACKLIGHT_PIN GPIO_NUM_21 + +std::shared_ptr createDisplay(); diff --git a/Boards/CYD-E32R28T/Source/devices/SdCard.cpp b/Boards/CYD-E32R28T/Source/devices/SdCard.cpp new file mode 100644 index 00000000..f9636e39 --- /dev/null +++ b/Boards/CYD-E32R28T/Source/devices/SdCard.cpp @@ -0,0 +1,21 @@ +#include "SdCard.h" +#include + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto configuration = std::make_unique( + GPIO_NUM_5, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + std::make_shared(), + std::vector(), + SPI3_HOST + ); + + return std::make_shared( + std::move(configuration) + ); +} diff --git a/Boards/CYD-E32R28T/Source/devices/SdCard.h b/Boards/CYD-E32R28T/Source/devices/SdCard.h new file mode 100644 index 00000000..6f5443c7 --- /dev/null +++ b/Boards/CYD-E32R28T/Source/devices/SdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Boards/CYD-E32R28T/Source/hal/YellowDisplay.cpp b/Boards/CYD-E32R28T/Source/hal/YellowDisplay.cpp deleted file mode 100644 index 5fa4c182..00000000 --- a/Boards/CYD-E32R28T/Source/hal/YellowDisplay.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "YellowDisplay.h" -#include "YellowDisplayConstants.h" -#include "Xpt2046SoftSpi.h" -#include -#include -#include -#include -#include - -static const char* TAG = "YellowDisplay"; - -// Global to hold reference (only needed if calling stop() later) -static std::unique_ptr touch; - -static std::shared_ptr createTouch() { - ESP_LOGI(TAG, "Creating bitbang SPI touch"); - - // Create bitbang config object - auto config = std::make_unique( - CYD_TOUCH_MOSI_PIN, - CYD_TOUCH_MISO_PIN, - CYD_TOUCH_SCK_PIN, - CYD_TOUCH_CS_PIN, - CYD_DISPLAY_HORIZONTAL_RESOLUTION, // 240 - CYD_DISPLAY_VERTICAL_RESOLUTION, // 320 - false, // swapXY - true, // mirrorX - false // mirrorY - ); - - // Allocate the driver - touch = std::make_unique(std::move(config)); - - // Start the driver - if (!touch->start()) { - ESP_LOGE(TAG, "Touch driver start failed"); - } - - return std::shared_ptr(touch.get(), [](tt::hal::touch::TouchDevice*) { - // No delete needed; `touch` is managed above - }); -} - -std::shared_ptr createDisplay() { - auto touch_device = createTouch(); - auto configuration = std::make_unique( - CYD_DISPLAY_SPI_HOST, - CYD_DISPLAY_PIN_CS, - CYD_DISPLAY_PIN_DC, - CYD_DISPLAY_HORIZONTAL_RESOLUTION, - CYD_DISPLAY_VERTICAL_RESOLUTION, - touch_device - ); - configuration->mirrorX = true; - configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; - configuration->rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR; - return std::make_shared(std::move(configuration)); -} diff --git a/Boards/CYD-E32R28T/Source/hal/YellowDisplay.h b/Boards/CYD-E32R28T/Source/hal/YellowDisplay.h deleted file mode 100644 index 036603c9..00000000 --- a/Boards/CYD-E32R28T/Source/hal/YellowDisplay.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" -#include - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-E32R28T/Source/hal/YellowSdCard.cpp b/Boards/CYD-E32R28T/Source/hal/YellowSdCard.cpp deleted file mode 100644 index 25d90617..00000000 --- a/Boards/CYD-E32R28T/Source/hal/YellowSdCard.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "YellowSdCard.h" -#include "YellowDisplayConstants.h" -#include - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createYellowSdCard() { - auto* configuration = new SpiSdCardDevice::Config( - CYD_SDCARD_PIN_CS, - GPIO_NUM_NC, // No card detect pin specified - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), - std::vector(), - CYD_SDCARD_SPI_HOST - ); - - return std::shared_ptr( - new SpiSdCardDevice(std::unique_ptr(configuration)) - ); -} diff --git a/Boards/CYD-E32R28T/Source/hal/YellowSdCard.h b/Boards/CYD-E32R28T/Source/hal/YellowSdCard.h deleted file mode 100644 index 0c862512..00000000 --- a/Boards/CYD-E32R28T/Source/hal/YellowSdCard.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "Tactility/hal/sdcard/SdCardDevice.h" - -using tt::hal::sdcard::SdCardDevice; - -std::shared_ptr createYellowSdCard();