From 647678ff8210a19a97fe668f1aeb0267607a7b34 Mon Sep 17 00:00:00 2001 From: NellowTCS Date: Mon, 27 Oct 2025 12:59:53 -0600 Subject: [PATCH] New board: CYD-E32R32P (#393) --- .github/workflows/build-firmware.yml | 1 + Boards/CYD-E32R32P/CMakeLists.txt | 7 ++ Boards/CYD-E32R32P/Source/Configuration.cpp | 96 +++++++++++++++++++ Boards/CYD-E32R32P/Source/devices/Display.cpp | 51 ++++++++++ Boards/CYD-E32R32P/Source/devices/Display.h | 27 ++++++ Boards/CYD-E32R32P/Source/devices/Power.cpp | 12 +++ Boards/CYD-E32R32P/Source/devices/Power.h | 6 ++ Boards/CYD-E32R32P/Source/devices/SdCard.cpp | 22 +++++ Boards/CYD-E32R32P/Source/devices/SdCard.h | 13 +++ Buildscripts/board.cmake | 2 + Drivers/ST7789/Source/St7789Display.cpp | 2 +- Drivers/ST7789/Source/St7789Display.h | 1 + Firmware/Kconfig | 4 +- sdkconfig.board.cyd-e32r32p | 55 +++++++++++ 14 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 Boards/CYD-E32R32P/CMakeLists.txt create mode 100644 Boards/CYD-E32R32P/Source/Configuration.cpp create mode 100644 Boards/CYD-E32R32P/Source/devices/Display.cpp create mode 100644 Boards/CYD-E32R32P/Source/devices/Display.h create mode 100644 Boards/CYD-E32R32P/Source/devices/Power.cpp create mode 100644 Boards/CYD-E32R32P/Source/devices/Power.h create mode 100644 Boards/CYD-E32R32P/Source/devices/SdCard.cpp create mode 100644 Boards/CYD-E32R32P/Source/devices/SdCard.h create mode 100644 sdkconfig.board.cyd-e32r32p diff --git a/.github/workflows/build-firmware.yml b/.github/workflows/build-firmware.yml index ffc86d95..e8ba0e48 100644 --- a/.github/workflows/build-firmware.yml +++ b/.github/workflows/build-firmware.yml @@ -17,6 +17,7 @@ jobs: { id: cyd-2432s028r, arch: esp32 }, { id: cyd-2432s028rv3, arch: esp32 }, { id: cyd-e32r28t, arch: esp32 }, + { id: cyd-e32r32p, arch: esp32 }, { id: cyd-2432s032c, arch: esp32 }, { id: cyd-jc2432w328c, arch: esp32 }, { id: cyd-8048s043c, arch: esp32s3 }, diff --git a/Boards/CYD-E32R32P/CMakeLists.txt b/Boards/CYD-E32R32P/CMakeLists.txt new file mode 100644 index 00000000..ce394afb --- /dev/null +++ b/Boards/CYD-E32R32P/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE SOURCE_FILES Source/*.c*) + +idf_component_register( + SRCS ${SOURCE_FILES} + INCLUDE_DIRS "Source" + REQUIRES Tactility esp_lvgl_port ST7789 XPT2046 PwmBacklight EstimatedPower driver vfs fatfs +) diff --git a/Boards/CYD-E32R32P/Source/Configuration.cpp b/Boards/CYD-E32R32P/Source/Configuration.cpp new file mode 100644 index 00000000..370d8211 --- /dev/null +++ b/Boards/CYD-E32R32P/Source/Configuration.cpp @@ -0,0 +1,96 @@ +#include "devices/SdCard.h" +#include "devices/Display.h" +#include "devices/Power.h" + +#include +#include +#include + +using namespace tt::hal; + +static bool initBoot() { + return driver::pwmbacklight::init(DISPLAY_BACKLIGHT_PIN); +} + +static tt::hal::DeviceVector createDevices() { + return { + createPower(), + createDisplay(), + createSdCard() + }; +} + +extern const Configuration hardwareConfiguration = { + .initBoot = initBoot, + .createDevices = createDevices, + .i2c = { + tt::hal::i2c::Configuration { + .name = "External", + .port = I2C_NUM_0, + .initMode = tt::hal::i2c::InitMode::ByTactility, + .isMutable = true, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_32, + .scl_io_num = GPIO_NUM_25, + .sda_pullup_en = false, + .scl_pullup_en = false, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + }, + }, + // 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 + }, + + } +}; \ No newline at end of file diff --git a/Boards/CYD-E32R32P/Source/devices/Display.cpp b/Boards/CYD-E32R32P/Source/devices/Display.cpp new file mode 100644 index 00000000..506133d5 --- /dev/null +++ b/Boards/CYD-E32R32P/Source/devices/Display.cpp @@ -0,0 +1,51 @@ +#include "Display.h" + +#include +#include +#include +#include + +// Create the XPT2046 touch device (hardware/esp_lcd driver) +static std::shared_ptr createTouch() { + auto config = std::make_unique( + DISPLAY_SPI_HOST, // spi device / bus (SPI2_HOST) + TOUCH_CS_PIN, // touch CS (IO33) + (uint16_t)DISPLAY_HORIZONTAL_RESOLUTION, // x max + (uint16_t)DISPLAY_VERTICAL_RESOLUTION, // y max + false, // swapXy + true, // mirrorX + true // mirrorY + ); + + return std::make_shared(std::move(config)); +} + +std::shared_ptr createDisplay() { + // Create the ST7789 panel configuration + St7789Display::Configuration panel_configuration = { + .horizontalResolution = DISPLAY_HORIZONTAL_RESOLUTION, + .verticalResolution = DISPLAY_VERTICAL_RESOLUTION, + .gapX = 0, + .gapY = 0, + .swapXY = false, + .mirrorX = false, + .mirrorY = false, + .invertColor = false, + .bufferSize = DISPLAY_DRAW_BUFFER_SIZE, // 0 -> default 1/10 screen + .touch = createTouch(), + .backlightDutyFunction = driver::pwmbacklight::setBacklightDuty, + .resetPin = GPIO_NUM_NC, + .rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR // BGR for this display + }; + + // Create the SPI configuration (from EspLcdSpiDisplay base class) + auto spi_configuration = std::make_shared(EspLcdSpiDisplay::SpiConfiguration { + .spiHostDevice = DISPLAY_SPI_HOST, + .csPin = DISPLAY_PIN_CS, + .dcPin = DISPLAY_PIN_DC, + .pixelClockFrequency = 40'000'000, + .transactionQueueDepth = 10 + }); + + return std::make_shared(panel_configuration, spi_configuration); +} \ No newline at end of file diff --git a/Boards/CYD-E32R32P/Source/devices/Display.h b/Boards/CYD-E32R32P/Source/devices/Display.h new file mode 100644 index 00000000..90eae75a --- /dev/null +++ b/Boards/CYD-E32R32P/Source/devices/Display.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include "driver/gpio.h" +#include "driver/spi_common.h" +#include + +// Display (ST7789P3 on this board) +constexpr auto DISPLAY_SPI_HOST = SPI2_HOST; +constexpr auto DISPLAY_PIN_CS = GPIO_NUM_15; +constexpr auto DISPLAY_PIN_DC = GPIO_NUM_2; +constexpr auto DISPLAY_HORIZONTAL_RESOLUTION = 240; +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; +constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_13; +constexpr auto TOUCH_SCK_PIN = GPIO_NUM_14; +constexpr auto TOUCH_CS_PIN = GPIO_NUM_33; +constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36; + + +std::shared_ptr createDisplay(); \ No newline at end of file diff --git a/Boards/CYD-E32R32P/Source/devices/Power.cpp b/Boards/CYD-E32R32P/Source/devices/Power.cpp new file mode 100644 index 00000000..febacad1 --- /dev/null +++ b/Boards/CYD-E32R32P/Source/devices/Power.cpp @@ -0,0 +1,12 @@ +#include "Power.h" + +#include +#include + +std::shared_ptr createPower() { + ChargeFromAdcVoltage::Configuration configuration; + // 2.0 ratio, but +.11 added as display voltage sag compensation. + configuration.adcMultiplier = 2.11; + + return std::make_shared(configuration); +} \ No newline at end of file diff --git a/Boards/CYD-E32R32P/Source/devices/Power.h b/Boards/CYD-E32R32P/Source/devices/Power.h new file mode 100644 index 00000000..7598ded6 --- /dev/null +++ b/Boards/CYD-E32R32P/Source/devices/Power.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +std::shared_ptr createPower(); diff --git a/Boards/CYD-E32R32P/Source/devices/SdCard.cpp b/Boards/CYD-E32R32P/Source/devices/SdCard.cpp new file mode 100644 index 00000000..d73563c6 --- /dev/null +++ b/Boards/CYD-E32R32P/Source/devices/SdCard.cpp @@ -0,0 +1,22 @@ +#include "SdCard.h" +#include + +using tt::hal::sdcard::SpiSdCardDevice; +using SdCardDevice = tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard() { + auto configuration = std::make_unique( + SD_CS_PIN, // CS pin (IO5 on the module) + GPIO_NUM_NC, // MOSI override: leave NC to use SPI host pins + GPIO_NUM_NC, // MISO override: leave NC + GPIO_NUM_NC, // SCLK override: leave NC + SdCardDevice::MountBehaviour::AtBoot, + std::make_shared(tt::Mutex::Type::Recursive), + std::vector(), + SD_SPI_HOST // SPI host for SD card (SPI3_HOST) + ); + + return std::make_shared( + std::move(configuration) + ); +} \ No newline at end of file diff --git a/Boards/CYD-E32R32P/Source/devices/SdCard.h b/Boards/CYD-E32R32P/Source/devices/SdCard.h new file mode 100644 index 00000000..dc381d79 --- /dev/null +++ b/Boards/CYD-E32R32P/Source/devices/SdCard.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include "driver/gpio.h" +#include "driver/spi_common.h" + +using tt::hal::sdcard::SdCardDevice; + +// SD card (microSD) +constexpr auto SD_CS_PIN = GPIO_NUM_5; +constexpr auto SD_SPI_HOST = SPI3_HOST; + +std::shared_ptr createSdCard(); diff --git a/Buildscripts/board.cmake b/Buildscripts/board.cmake index 36cff483..b878ec2c 100644 --- a/Buildscripts/board.cmake +++ b/Buildscripts/board.cmake @@ -29,6 +29,8 @@ function(INIT_TACTILITY_GLOBALS SDKCONFIG_FILE) set(TACTILITY_BOARD_PROJECT CYD-2432S028RV3) elseif (board_id STREQUAL "cyd-e32r28t") set(TACTILITY_BOARD_PROJECT CYD-E32R28T) + elseif (board_id STREQUAL "cyd-e32r32p") + set(TACTILITY_BOARD_PROJECT CYD-E32R32P) elseif (board_id STREQUAL "cyd-2432s032c") set(TACTILITY_BOARD_PROJECT CYD-2432S032C) elseif (board_id STREQUAL "cyd-4848s040c") diff --git a/Drivers/ST7789/Source/St7789Display.cpp b/Drivers/ST7789/Source/St7789Display.cpp index 4b851d28..260073a1 100644 --- a/Drivers/ST7789/Source/St7789Display.cpp +++ b/Drivers/ST7789/Source/St7789Display.cpp @@ -19,7 +19,7 @@ std::shared_ptr St7789Display::createEspLcdConfiguration(co .resetPin = configuration.resetPin, .lvglColorFormat = LV_COLOR_FORMAT_RGB565, .lvglSwapBytes = false, - .rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB, + .rgbElementOrder = configuration.rgbElementOrder, .bitsPerPixel = 16, }); } diff --git a/Drivers/ST7789/Source/St7789Display.h b/Drivers/ST7789/Source/St7789Display.h index 7af184f1..32a14240 100644 --- a/Drivers/ST7789/Source/St7789Display.h +++ b/Drivers/ST7789/Source/St7789Display.h @@ -26,6 +26,7 @@ public: std::shared_ptr touch; std::function _Nullable backlightDutyFunction; gpio_num_t resetPin; + lcd_rgb_element_order_t rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB; }; private: diff --git a/Firmware/Kconfig b/Firmware/Kconfig index 669d1f6b..9c4c3a2f 100644 --- a/Firmware/Kconfig +++ b/Firmware/Kconfig @@ -18,7 +18,9 @@ menu "Tactility App" config TT_BOARD_CYD_2432S028RV3 bool "CYD 2432S028RV3" config TT_BOARD_CYD_E32R28T - bool "CYD E32R28T" + bool "CYD E32R28T" + config TT_BOARD_CYD_E32R32P + bool "CYD E32R32P" config TT_BOARD_CYD_2432S032C bool "CYD 2432S032C" config TT_BOARD_CYD_8048S043C diff --git a/sdkconfig.board.cyd-e32r32p b/sdkconfig.board.cyd-e32r32p new file mode 100644 index 00000000..99fb4220 --- /dev/null +++ b/sdkconfig.board.cyd-e32r32p @@ -0,0 +1,55 @@ +# Software defaults +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=3072 +CONFIG_LV_FONT_MONTSERRAT_14=y +CONFIG_LV_FONT_MONTSERRAT_18=y +CONFIG_LV_USE_USER_DATA=y +CONFIG_LV_USE_FS_STDIO=y +CONFIG_LV_FS_STDIO_LETTER=65 +CONFIG_LV_FS_STDIO_PATH="" +CONFIG_LV_FS_STDIO_CACHE_SIZE=4096 +CONFIG_LV_USE_LODEPNG=y +CONFIG_LV_USE_BUILTIN_MALLOC=n +CONFIG_LV_USE_CLIB_MALLOC=y +CONFIG_LV_USE_MSGBOX=n +CONFIG_LV_USE_SPINNER=n +CONFIG_LV_USE_WIN=n +CONFIG_LV_USE_SNAPSHOT=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 +CONFIG_FREERTOS_SMP=n +CONFIG_FREERTOS_UNICORE=n +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FATFS_LFN_HEAP=y +CONFIG_FATFS_VOLUME_COUNT=3 + +# Hardware: Main +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4mb.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions-4mb.csv" +CONFIG_TT_BOARD_CYD_E32R32P=y +CONFIG_TT_BOARD_NAME="CYD E32R32P" +CONFIG_TT_BOARD_ID="cyd-e32r32p" +CONFIG_IDF_TARGET="esp32" +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_FLASHMODE_QIO=y + +# LVGL +CONFIG_LV_DISP_DEF_REFR_PERIOD=10 +CONFIG_LV_DPI_DEF=130 # Adjusted for 2.8" 240x320 (~130 DPI) +CONFIG_LVGL_BUFFER_WIDTH=240 +CONFIG_LVGL_BUFFER_HEIGHT=40 +CONFIG_LVGL_COLOR_DEPTH=16 + +# Drivers +CONFIG_TOUCH_DRIVER_XPT2046=y +CONFIG_TOUCH_CALIBRATION=y +CONFIG_SD_CARD_ENABLE=y + +# Fix for IRAM +CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y +CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y +CONFIG_HEAP_PLACE_FUNCTION_INTO_FLASH=y +CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y