diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0c6cfe3f..eca285271 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,6 +39,7 @@ jobs: { id: cyd-e32r28t, arch: esp32 }, { id: cyd-e32r32p, arch: esp32 }, { id: cyd-2432s032c, arch: esp32 }, + { id: cyd-3248s035c, arch: esp32 }, { id: cyd-8048s043c, arch: esp32s3 }, { id: cyd-4848s040c, arch: esp32s3 }, { id: elecrow-crowpanel-advance-28, arch: esp32s3 }, diff --git a/Devices/cyd-3248s035c/CMakeLists.txt b/Devices/cyd-3248s035c/CMakeLists.txt new file mode 100644 index 000000000..2d90a08fd --- /dev/null +++ b/Devices/cyd-3248s035c/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 ST7796 GT911 PwmBacklight driver vfs fatfs +) diff --git a/Devices/cyd-3248s035c/Source/Configuration.cpp b/Devices/cyd-3248s035c/Source/Configuration.cpp new file mode 100644 index 000000000..123cfab3b --- /dev/null +++ b/Devices/cyd-3248s035c/Source/Configuration.cpp @@ -0,0 +1,34 @@ +#include "devices/Display.h" +#include "devices/SdCard.h" +#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_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... yep it's backwards. + 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 + + 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-3248s035c/Source/devices/Display.cpp b/Devices/cyd-3248s035c/Source/devices/Display.cpp new file mode 100644 index 000000000..f96158248 --- /dev/null +++ b/Devices/cyd-3248s035c/Source/devices/Display.cpp @@ -0,0 +1,36 @@ +#include "Display.h" + +#include +#include +#include + +static std::shared_ptr createTouch() { + auto configuration = std::make_unique( + I2C_NUM_0, + LCD_HORIZONTAL_RESOLUTION, + LCD_VERTICAL_RESOLUTION + ); + + return std::make_shared(std::move(configuration)); +} + +std::shared_ptr createDisplay() { + auto touch = createTouch(); + auto configuration = std::make_unique( + LCD_SPI_HOST, + LCD_PIN_CS, + LCD_PIN_DC, + LCD_HORIZONTAL_RESOLUTION, + LCD_VERTICAL_RESOLUTION, + touch, + false, + true, + false, + false + ); + + configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; + + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); +} diff --git a/Devices/cyd-3248s035c/Source/devices/Display.h b/Devices/cyd-3248s035c/Source/devices/Display.h new file mode 100644 index 000000000..47cff95ae --- /dev/null +++ b/Devices/cyd-3248s035c/Source/devices/Display.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include + +// Display backlight (PWM) +constexpr auto LCD_PIN_BACKLIGHT = GPIO_NUM_27; + +// 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_HORIZONTAL_RESOLUTION = 320; +constexpr auto LCD_VERTICAL_RESOLUTION = 480; +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-3248s035c/Source/devices/SdCard.cpp b/Devices/cyd-3248s035c/Source/devices/SdCard.cpp new file mode 100644 index 000000000..fd4e1989f --- /dev/null +++ b/Devices/cyd-3248s035c/Source/devices/SdCard.cpp @@ -0,0 +1,31 @@ +#include "SdCard.h" + +#include +#include + +constexpr auto SDCARD_SPI_HOST = SPI3_HOST; +constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto configuration = std::make_unique( + SDCARD_PIN_CS, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + 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), + spi_controller + ); +} + diff --git a/Devices/cyd-3248s035c/Source/devices/SdCard.h b/Devices/cyd-3248s035c/Source/devices/SdCard.h new file mode 100644 index 000000000..051907e1b --- /dev/null +++ b/Devices/cyd-3248s035c/Source/devices/SdCard.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); + diff --git a/Devices/cyd-3248s035c/Source/module.cpp b/Devices/cyd-3248s035c/Source/module.cpp new file mode 100644 index 000000000..bf43c7b2c --- /dev/null +++ b/Devices/cyd-3248s035c/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_3248s035c_module = { + .name = "cyd-3248s035c", + .start = start, + .stop = stop, + .symbols = nullptr, + .internal = nullptr +}; + +} diff --git a/Devices/cyd-3248s035c/cyd,3248s035c.dts b/Devices/cyd-3248s035c/cyd,3248s035c.dts new file mode 100644 index 000000000..7463e6bb2 --- /dev/null +++ b/Devices/cyd-3248s035c/cyd,3248s035c.dts @@ -0,0 +1,58 @@ +/dts-v1/; + +#include +#include +#include +#include +#include + +/ { + compatible = "root"; + model = "CYD 3248S035C"; + + gpio0 { + compatible = "espressif,esp32-gpio"; + gpio-count = <40>; + }; + + i2c_internal: i2c0 { + compatible = "espressif,esp32-i2c"; + port = ; + clock-frequency = <400000>; + pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; + }; + + // CN1 header + i2c_external: i2c1 { + compatible = "espressif,esp32-i2c"; + port = ; + clock-frequency = <400000>; + pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; + }; + + display_spi: spi0 { + compatible = "espressif,esp32-spi"; + host = ; + pin-mosi = <&gpio0 13 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>; + }; + + // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V + uart1 { + compatible = "espressif,esp32-uart"; + status = "disabled"; + port = ; + pin-tx = <&gpio0 22 GPIO_FLAG_NONE>; + pin-rx = <&gpio0 21 GPIO_FLAG_NONE>; + }; +}; diff --git a/Devices/cyd-3248s035c/device.properties b/Devices/cyd-3248s035c/device.properties new file mode 100644 index 000000000..920c71edd --- /dev/null +++ b/Devices/cyd-3248s035c/device.properties @@ -0,0 +1,19 @@ +[general] +vendor=CYD +name=3248S035C + +[apps] +launcherAppId=Launcher + +[hardware] +target=ESP32 +flashSize=4MB +spiRam=false + +[display] +size=3.5" +shape=rectangle +dpi=165 + +[lvgl] +colorDepth=16 diff --git a/Devices/cyd-3248s035c/devicetree.yaml b/Devices/cyd-3248s035c/devicetree.yaml new file mode 100644 index 000000000..45ca5398e --- /dev/null +++ b/Devices/cyd-3248s035c/devicetree.yaml @@ -0,0 +1,3 @@ +dependencies: +- Platforms/platform-esp32 +dts: cyd,3248s035c.dts