-
-
Notifications
You must be signed in to change notification settings - Fork 85
Add CYD-3248S035C Support #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "devices/Display.h" | ||
| #include "devices/SdCard.h" | ||
| #include <driver/gpio.h> | ||
|
|
||
| #include <PwmBacklight.h> | ||
| #include <Tactility/hal/Configuration.h> | ||
|
|
||
| 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 | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "Display.h" | ||
|
|
||
| #include <Gt911Touch.h> | ||
| #include <PwmBacklight.h> | ||
| #include <St7796Display.h> | ||
|
|
||
| static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() { | ||
| auto configuration = std::make_unique<Gt911Touch::Configuration>( | ||
| I2C_NUM_0, | ||
| LCD_HORIZONTAL_RESOLUTION, | ||
| LCD_VERTICAL_RESOLUTION | ||
| ); | ||
|
|
||
| return std::make_shared<Gt911Touch>(std::move(configuration)); | ||
| } | ||
|
|
||
| std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() { | ||
| auto touch = createTouch(); | ||
| auto configuration = std::make_unique<St7796Display::Configuration>( | ||
| 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<St7796Display>(std::move(configuration)); | ||
| return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #pragma once | ||
|
|
||
| #include "Display.h" | ||
|
|
||
| #include <Tactility/hal/display/DisplayDevice.h> | ||
| #include <memory> | ||
|
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify where DisplayDevice is declared and whether this include path exists.
fd -i 'DisplayDevice.h'
rg -n -C2 --iglob '*.{h,cpp}' 'Tactility/hal/display/DisplayDevice.h|class DisplayDevice|namespace tt::hal::display' Devices TactilityKernel Firmware DriversRepository: TactilityProject/Tactility Length of output: 22049 Remove the self-include of Line 3 includes itself ( 🧰 Tools🪛 Clang (14.0.6)[error] 5-5: 'Tactility/hal/display/DisplayDevice.h' file not found (clang-diagnostic-error) |
||
| #include <driver/gpio.h> | ||
| #include <driver/spi_common.h> | ||
|
|
||
| // 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<tt::hal::display::DisplayDevice> createDisplay(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include "SdCard.h" | ||
|
|
||
| #include <tactility/device.h> | ||
| #include <Tactility/hal/sdcard/SpiSdCardDevice.h> | ||
|
|
||
| constexpr auto SDCARD_SPI_HOST = SPI3_HOST; | ||
| constexpr auto SDCARD_PIN_CS = GPIO_NUM_5; | ||
|
|
||
| using tt::hal::sdcard::SpiSdCardDevice; | ||
|
|
||
| std::shared_ptr<SdCardDevice> createSdCard() { | ||
| auto configuration = std::make_unique<SpiSdCardDevice::Config>( | ||
| SDCARD_PIN_CS, | ||
| GPIO_NUM_NC, | ||
| GPIO_NUM_NC, | ||
| GPIO_NUM_NC, | ||
| SdCardDevice::MountBehaviour::AtBoot, | ||
| nullptr, | ||
| std::vector<gpio_num_t>(), | ||
| SDCARD_SPI_HOST | ||
| ); | ||
|
|
||
| auto* spi_controller = device_find_by_name("spi1"); | ||
| check(spi_controller, "spi1 not found"); | ||
|
|
||
| return std::make_shared<SpiSdCardDevice>( | ||
| std::move(configuration), | ||
| spi_controller | ||
| ); | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #pragma once | ||
|
|
||
| #include <Tactility/hal/sdcard/SdCardDevice.h> | ||
|
|
||
| using tt::hal::sdcard::SdCardDevice; | ||
|
|
||
| std::shared_ptr<SdCardDevice> createSdCard(); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include <tactility/module.h> | ||
|
|
||
| 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 | ||
| }; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /dts-v1/; | ||
|
|
||
| #include <tactility/bindings/root.h> | ||
| #include <tactility/bindings/esp32_gpio.h> | ||
| #include <tactility/bindings/esp32_i2c.h> | ||
| #include <tactility/bindings/esp32_spi.h> | ||
| #include <tactility/bindings/esp32_uart.h> | ||
|
|
||
| / { | ||
| compatible = "root"; | ||
| model = "CYD 3248S035C"; | ||
|
|
||
| gpio0 { | ||
| compatible = "espressif,esp32-gpio"; | ||
| gpio-count = <40>; | ||
| }; | ||
|
|
||
| i2c_internal: i2c0 { | ||
| compatible = "espressif,esp32-i2c"; | ||
| port = <I2C_NUM_0>; | ||
| 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 = <I2C_NUM_1>; | ||
| 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 = <SPI2_HOST>; | ||
| pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>; | ||
| pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>; | ||
| }; | ||
|
|
||
| sdcard_spi: spi1 { | ||
| compatible = "espressif,esp32-spi"; | ||
| host = <SPI3_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 = <UART_NUM_1>; | ||
| pin-tx = <&gpio0 22 GPIO_FLAG_NONE>; | ||
| pin-rx = <&gpio0 21 GPIO_FLAG_NONE>; | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| dependencies: | ||
| - Platforms/platform-esp32 | ||
| dts: cyd,3248s035c.dts | ||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize this YAML file to LF line endings.
🧰 Tools🪛 YAMLlint (1.38.0)[error] 1-1: wrong new line character: expected \n (new-lines) |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TactilityProject/Tactility
Length of output: 1887
🏁 Script executed:
Repository: TactilityProject/Tactility
Length of output: 160
🏁 Script executed:
Repository: TactilityProject/Tactility
Length of output: 166
🏁 Script executed:
Repository: TactilityProject/Tactility
Length of output: 240
🏁 Script executed:
Repository: TactilityProject/Tactility
Length of output: 414
🏁 Script executed:
Repository: TactilityProject/Tactility
Length of output: 1389
Use
static_pointer_castinstead ofreinterpret_pointer_castfor upcasting.Line 35 performs an unsafe cast for what should be a normal polymorphic upcast.
St7796Displayinherits fromEspLcdDisplay, which inherits fromtt::hal::display::DisplayDevice. Thereinterpret_pointer_casttreats the pointer bits directly without adjustment, which is unsafe and can cause undefined behavior. Usestatic_pointer_castfor compile-time known polymorphic upcasts.🛠️ Safe cast fix