diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0c6cfe3f..2ca782ec2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - cyd-2.4 tags: - v* pull_request: @@ -34,6 +35,7 @@ jobs: board: [ { id: btt-panda-touch, arch: esp32s3 }, { id: cyd-2432s024c, arch: esp32 }, + { id: cyd-2432s024r, arch: esp32 }, { id: cyd-2432s028r, arch: esp32 }, { id: cyd-2432s028rv3, arch: esp32 }, { id: cyd-e32r28t, arch: esp32 }, diff --git a/Devices/cyd-2432s024r/CMakeLists.txt b/Devices/cyd-2432s024r/CMakeLists.txt new file mode 100644 index 000000000..1e6393dd4 --- /dev/null +++ b/Devices/cyd-2432s024r/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 ILI934x XPT2046 PwmBacklight driver vfs fatfs +) diff --git a/Devices/cyd-2432s024r/Source/Configuration.cpp b/Devices/cyd-2432s024r/Source/Configuration.cpp new file mode 100644 index 000000000..4fe462d3a --- /dev/null +++ b/Devices/cyd-2432s024r/Source/Configuration.cpp @@ -0,0 +1,35 @@ +#include "devices/Display.h" +#include "devices/SdCard.h" +#include + +#include +#include +#include + +using namespace tt::hal; + +static bool initBoot() { + // // Set the RGB LED Pins to output and turn them off + // ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_27, GPIO_MODE_OUTPUT)); // Red + // ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_12, GPIO_MODE_OUTPUT)); // Green + // ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_13, GPIO_MODE_OUTPUT)); // Blue + + // // 0 on, 1 off + // ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_27, 1)); // Red + // ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_12, 1)); // Green + // ESP_ERROR_CHECK(gpio_set_level(GPIO_NUM_13, 1)); // Blue + + return driver::pwmbacklight::init(LCD_PIN_BACKLIGHT); +} + +static DeviceVector createDevices() { + return { + createDisplay(), + createSdCard() + }; +} + +extern const Configuration hardwareConfiguration = { + .initBoot = initBoot, + .createDevices = createDevices +}; diff --git a/Devices/cyd-2432s024r/Source/devices/Display.cpp b/Devices/cyd-2432s024r/Source/devices/Display.cpp new file mode 100644 index 000000000..f8aef5e46 --- /dev/null +++ b/Devices/cyd-2432s024r/Source/devices/Display.cpp @@ -0,0 +1,46 @@ +#include "Display.h" +#include "Xpt2046Touch.h" +#include +#include + +static std::shared_ptr createTouch(esp_lcd_spi_bus_handle_t spiDevice) { + auto configuration = std::make_unique( + spiDevice, + TOUCH_CS_PIN, + LCD_HORIZONTAL_RESOLUTION, + LCD_VERTICAL_RESOLUTION, + true, // swapXY + false, // mirrorX + true // mirrorY + ); + return std::make_shared(std::move(configuration)); +} + +std::shared_ptr createDisplay() { + 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 + }); + + Ili934xDisplay::Configuration panel_configuration = { + .horizontalResolution = LCD_HORIZONTAL_RESOLUTION, + .verticalResolution = LCD_VERTICAL_RESOLUTION, + .gapX = 0, + .gapY = 0, + .swapXY = true, + .mirrorX = true, + .mirrorY = true, + .invertColor = false, + .swapBytes = true, + .bufferSize = LCD_BUFFER_SIZE, + .touch = createTouch(spi_configuration->spiHostDevice), + .backlightDutyFunction = driver::pwmbacklight::setBacklightDuty, + .resetPin = LCD_PIN_RST, + .rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB + }; + + return std::make_shared(panel_configuration, spi_configuration, true); +} diff --git a/Devices/cyd-2432s024r/Source/devices/Display.h b/Devices/cyd-2432s024r/Source/devices/Display.h new file mode 100644 index 000000000..d8a8ae6c4 --- /dev/null +++ b/Devices/cyd-2432s024r/Source/devices/Display.h @@ -0,0 +1,28 @@ +#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_RST = GPIO_NUM_NC; // tied to ESP32 RST +constexpr auto LCD_PIN_CLK = GPIO_NUM_14; +constexpr auto LCD_PIN_MOSI = GPIO_NUM_13; +constexpr auto LCD_PIN_MISO = GPIO_NUM_12; +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; + +// Backlight +constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_27; + +// Touch +constexpr auto TOUCH_CS_PIN = GPIO_NUM_33; +constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36; + +std::shared_ptr createDisplay(); diff --git a/Devices/cyd-2432s024r/Source/devices/SdCard.cpp b/Devices/cyd-2432s024r/Source/devices/SdCard.cpp new file mode 100644 index 000000000..cd8f648ab --- /dev/null +++ b/Devices/cyd-2432s024r/Source/devices/SdCard.cpp @@ -0,0 +1,23 @@ +#include "SdCard.h" +#include +#include + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto config = std::make_unique( + GPIO_NUM_5, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + nullptr, + std::vector(), + SPI3_HOST + ); + + auto* spi_controller = device_find_by_name("spi1"); + check(spi_controller, "spi1 not found"); + + return std::make_shared(std::move(config), spi_controller); +} diff --git a/Devices/cyd-2432s024r/Source/devices/SdCard.h b/Devices/cyd-2432s024r/Source/devices/SdCard.h new file mode 100644 index 000000000..4da9f5b97 --- /dev/null +++ b/Devices/cyd-2432s024r/Source/devices/SdCard.h @@ -0,0 +1,8 @@ +#pragma once + +#include "Tactility/hal/sdcard/SdCardDevice.h" + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); + diff --git a/Devices/cyd-2432s024r/Source/module.cpp b/Devices/cyd-2432s024r/Source/module.cpp new file mode 100644 index 000000000..2cd4c7385 --- /dev/null +++ b/Devices/cyd-2432s024r/Source/module.cpp @@ -0,0 +1,23 @@ +#include + +extern "C" { + +static error_t start() { + // Empty for now + return ERROR_NONE; +} + +static error_t stop() { + // Empty for now + return ERROR_NONE; +} + +struct Module cyd_2432s024r_module = { + .name = "cyd-2432s024r", + .start = start, + .stop = stop, + .symbols = nullptr, + .internal = nullptr +}; + +} diff --git a/Devices/cyd-2432s024r/cyd,2432s024r.dts b/Devices/cyd-2432s024r/cyd,2432s024r.dts new file mode 100644 index 000000000..0c151b587 --- /dev/null +++ b/Devices/cyd-2432s024r/cyd,2432s024r.dts @@ -0,0 +1,39 @@ +/dts-v1/; + +#include +#include +#include +#include + +/ { + compatible = "root"; + model = "CYD 2432S024R"; + + gpio0 { + compatible = "espressif,esp32-gpio"; + gpio-count = <40>; + }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; + pin-miso = <&gpio0 12 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; + }; + + sdcard_spi: spi1 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>; + pin-miso = <&gpio0 19 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; + }; + + uart1 { + compatible = "espressif,esp32-uart"; + port = ; + pin-tx = <&gpio0 1 GPIO_FLAG_NONE>; + pin-rx = <&gpio0 3 GPIO_FLAG_NONE>; + }; +}; \ No newline at end of file diff --git a/Devices/cyd-2432s024r/device.properties b/Devices/cyd-2432s024r/device.properties new file mode 100644 index 000000000..da517175a --- /dev/null +++ b/Devices/cyd-2432s024r/device.properties @@ -0,0 +1,19 @@ +[general] +vendor=CYD +name=2432S024R + +[apps] +launcherAppId=Launcher + +[hardware] +target=ESP32 +flashSize=4MB +spiRam=false + +[display] +size=2.4" +shape=rectangle +dpi=167 + +[lvgl] +colorDepth=16 diff --git a/Devices/cyd-2432s024r/devicetree.yaml b/Devices/cyd-2432s024r/devicetree.yaml new file mode 100644 index 000000000..ab75fd2c2 --- /dev/null +++ b/Devices/cyd-2432s024r/devicetree.yaml @@ -0,0 +1,3 @@ +dependencies: + - Platforms/platform-esp32 +dts: cyd,2432s024r.dts