diff --git a/Boards/CYD-8048S043C/CMakeLists.txt b/Boards/CYD-8048S043C/CMakeLists.txt index 3ced6b9f..c6e98b90 100644 --- a/Boards/CYD-8048S043C/CMakeLists.txt +++ b/Boards/CYD-8048S043C/CMakeLists.txt @@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} INCLUDE_DIRS "Source" - REQUIRES Tactility esp_lvgl_port esp_lcd GT911 driver vfs fatfs + REQUIRES Tactility esp_lvgl_port esp_lcd RgbDisplay GT911 PwmBacklight driver vfs fatfs ) diff --git a/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp b/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp index 8a00c3b4..ae9bcf78 100644 --- a/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp +++ b/Boards/CYD-8048S043C/Source/CYD8048S043C.cpp @@ -1,16 +1,18 @@ -#include "CYD8048S043C.h" -#include "Tactility/lvgl/LvglSync.h" -#include "hal/YellowDisplay.h" -#include "hal/YellowDisplayConstants.h" -#include "hal/YellowSdCard.h" - -#include +#include "CYD8048S043C.h" // Don't remove, or we get a linker error ("undefined reference to `cyd_8048s043c_config'" - GCC bug?) +#include "PwmBacklight.h" +#include "hal/CydDisplay.h" +#include "hal/CydSdCard.h" using namespace tt::hal; +bool initBoot() { + return driver::pwmbacklight::init(GPIO_NUM_2); +} + const Configuration cyd_8048s043c_config = { + .initBoot = initBoot, .createDisplay = createDisplay, - .sdcard = createYellowSdCard(), + .sdcard = createSdCard(), .power = nullptr, .i2c = { //Touch diff --git a/Boards/CYD-8048S043C/Source/hal/CydDisplay.cpp b/Boards/CYD-8048S043C/Source/hal/CydDisplay.cpp new file mode 100644 index 00000000..b85e76ed --- /dev/null +++ b/Boards/CYD-8048S043C/Source/hal/CydDisplay.cpp @@ -0,0 +1,106 @@ +#include "RgbDisplay.h" + +#include "CydDisplay.h" + +#include +#include +#include + +std::shared_ptr _Nullable createTouch() { + // Note for future changes: Reset pin is 38 and interrupt pin is 18 + // or INT = NC, schematic and other info floating around is kinda conflicting... + auto configuration = std::make_unique( + I2C_NUM_0, + 800, + 480 + ); + + return std::make_shared(std::move(configuration)); +} + +std::shared_ptr createDisplay() { + auto touch = createTouch(); + + constexpr uint32_t bufferPixels = 800 * 10; + + esp_lcd_rgb_panel_config_t rgb_panel_config = { + .clk_src = LCD_CLK_SRC_DEFAULT, + .timings = { + .pclk_hz = 16000000, + .h_res = 800, + .v_res = 480, + .hsync_pulse_width = 4, + .hsync_back_porch = 8, + .hsync_front_porch = 8, + .vsync_pulse_width = 4, + .vsync_back_porch = 8, + .vsync_front_porch = 8, + .flags = { + .hsync_idle_low = false, + .vsync_idle_low = false, + .de_idle_high = false, + .pclk_active_neg = true, + .pclk_idle_high = false + } + }, + .data_width = 16, + .bits_per_pixel = 0, + .num_fbs = 2, + .bounce_buffer_size_px = bufferPixels, + .sram_trans_align = 8, + .psram_trans_align = 64, + .hsync_gpio_num = GPIO_NUM_39, + .vsync_gpio_num = GPIO_NUM_41, + .de_gpio_num = GPIO_NUM_40 , + .pclk_gpio_num = GPIO_NUM_42, + .disp_gpio_num = GPIO_NUM_NC, + .data_gpio_nums = { + GPIO_NUM_8, // B3 + GPIO_NUM_3, // B4 + GPIO_NUM_46, // B5 + GPIO_NUM_9, // B6 + GPIO_NUM_1, // B7 + GPIO_NUM_5, // G2 + GPIO_NUM_6, // G3 + GPIO_NUM_7, // G4 + GPIO_NUM_15, // G5 + GPIO_NUM_16, // G6 + GPIO_NUM_4, // G7 + GPIO_NUM_45, // R3 + GPIO_NUM_48, // R4 + GPIO_NUM_47, // R5 + GPIO_NUM_21, // R6 + GPIO_NUM_14, // R7 + }, + .flags = { + .disp_active_low = false, + .refresh_on_demand = false, + .fb_in_psram = true, + .double_fb = true, + .no_fb = false, + .bb_invalidate_cache = false + } + }; + + RgbDisplay::BufferConfiguration buffer_config = { + .size = (800 * 480), + .useSpi = true, + .doubleBuffer = true, + .bounceBufferMode = true, + .avoidTearing = false + }; + + auto configuration = std::make_unique( + rgb_panel_config, + buffer_config, + touch, + LV_COLOR_FORMAT_RGB565, + false, + false, + false, + false, + driver::pwmbacklight::setBacklightDuty + ); + + return std::make_shared(std::move(configuration)); +} diff --git a/Boards/CYD-8048S043C/Source/hal/CydDisplay.h b/Boards/CYD-8048S043C/Source/hal/CydDisplay.h new file mode 100644 index 00000000..5a0d81b3 --- /dev/null +++ b/Boards/CYD-8048S043C/Source/hal/CydDisplay.h @@ -0,0 +1,5 @@ +#pragma once + +#include "Tactility/hal/display/DisplayDevice.h" + +std::shared_ptr createDisplay(); diff --git a/Boards/CYD-8048S043C/Source/hal/CydSdCard.cpp b/Boards/CYD-8048S043C/Source/hal/CydSdCard.cpp new file mode 100644 index 00000000..0bb3c2bc --- /dev/null +++ b/Boards/CYD-8048S043C/Source/hal/CydSdCard.cpp @@ -0,0 +1,25 @@ +#include "CydSdCard.h" + +#include +#include + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto config = std::make_unique( + GPIO_NUM_10, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot, + std::make_shared(), + std::vector(), + SPI2_HOST + ); + + auto sdcard = std::make_shared( + std::move(config) + ); + + return std::static_pointer_cast(sdcard); +} diff --git a/Boards/CYD-8048S043C/Source/hal/YellowSdCard.h b/Boards/CYD-8048S043C/Source/hal/CydSdCard.h similarity index 65% rename from Boards/CYD-8048S043C/Source/hal/YellowSdCard.h rename to Boards/CYD-8048S043C/Source/hal/CydSdCard.h index 772f7119..5cb65a73 100644 --- a/Boards/CYD-8048S043C/Source/hal/YellowSdCard.h +++ b/Boards/CYD-8048S043C/Source/hal/CydSdCard.h @@ -4,5 +4,4 @@ using tt::hal::sdcard::SdCardDevice; -std::shared_ptr createYellowSdCard(); - +std::shared_ptr createSdCard(); diff --git a/Boards/CYD-8048S043C/Source/hal/YellowDisplay.cpp b/Boards/CYD-8048S043C/Source/hal/YellowDisplay.cpp deleted file mode 100644 index d8700732..00000000 --- a/Boards/CYD-8048S043C/Source/hal/YellowDisplay.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include "YellowDisplay.h" -#include "YellowDisplayConstants.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define TAG "yellow_display" - -static bool isBacklightInitialized = false; - -static bool initBacklight() { - ledc_timer_config_t ledc_timer = { - .speed_mode = CYD8048S043_LCD_BACKLIGHT_LEDC_MODE, - .duty_resolution = CYD8048S043_LCD_BACKLIGHT_LEDC_DUTY_RES, - .timer_num = CYD8048S043_LCD_BACKLIGHT_LEDC_TIMER, - .freq_hz = CYD8048S043_LCD_BACKLIGHT_LEDC_FREQUENCY, - .clk_cfg = LEDC_AUTO_CLK, - .deconfigure = false - }; - - if (ledc_timer_config(&ledc_timer) != ESP_OK) { - TT_LOG_E(TAG, "Backlight led timer config failed"); - return false; - } - - return true; -} - -static bool setBacklight(uint8_t duty) { - ledc_channel_config_t ledc_channel = { - .gpio_num = CYD8048S043_LCD_PIN_BACKLIGHT, - .speed_mode = CYD8048S043_LCD_BACKLIGHT_LEDC_MODE, - .channel = CYD8048S043_LCD_BACKLIGHT_LEDC_CHANNEL, - .intr_type = LEDC_INTR_DISABLE, - .timer_sel = CYD8048S043_LCD_BACKLIGHT_LEDC_TIMER, - .duty = duty, - .hpoint = 0, - .sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD, - .flags = { - .output_invert = false - } - }; - - if (ledc_channel_config(&ledc_channel) != ESP_OK) { - TT_LOG_E(TAG, "Backlight init failed"); - return false; - } - - return true; -} - -bool YellowDisplay::start() { - TT_LOG_I(TAG, "Starting"); - - const esp_lcd_rgb_panel_config_t panel_config = { - .clk_src = LCD_CLK_SRC_DEFAULT, - .timings = { - .pclk_hz = 16000000, - .h_res = CYD8048S043_LCD_HORIZONTAL_RESOLUTION, - .v_res = CYD8048S043_LCD_VERTICAL_RESOLUTION, - - .hsync_pulse_width = 4, - .hsync_back_porch = 8, - .hsync_front_porch = 8, - .vsync_pulse_width = 4, - .vsync_back_porch = 8, - .vsync_front_porch = 8, - .flags = { - .hsync_idle_low = false, - .vsync_idle_low = false, - .de_idle_high = false, - .pclk_active_neg = true, - .pclk_idle_high = false - } - }, - .data_width = 16, - .bits_per_pixel = 0, - .num_fbs = 2, - .bounce_buffer_size_px = CYD8048S043_LCD_HORIZONTAL_RESOLUTION * 10, - .sram_trans_align = 8, - .psram_trans_align = 64, - - .hsync_gpio_num = CYD8048S043_LCD_PIN_HSYNC, - .vsync_gpio_num = CYD8048S043_LCD_PIN_VSYNC, - .de_gpio_num = CYD8048S043_LCD_PIN_DE, - .pclk_gpio_num = CYD8048S043_LCD_PIN_PCLK, - .disp_gpio_num = CYD8048S043_LCD_PIN_DISP_EN, - .data_gpio_nums = { - CYD8048S043_LCD_PIN_DATA0, - CYD8048S043_LCD_PIN_DATA1, - CYD8048S043_LCD_PIN_DATA2, - CYD8048S043_LCD_PIN_DATA3, - CYD8048S043_LCD_PIN_DATA4, - CYD8048S043_LCD_PIN_DATA5, - CYD8048S043_LCD_PIN_DATA6, - CYD8048S043_LCD_PIN_DATA7, - CYD8048S043_LCD_PIN_DATA8, - CYD8048S043_LCD_PIN_DATA9, - CYD8048S043_LCD_PIN_DATA10, - CYD8048S043_LCD_PIN_DATA11, - CYD8048S043_LCD_PIN_DATA12, - CYD8048S043_LCD_PIN_DATA13, - CYD8048S043_LCD_PIN_DATA14, - CYD8048S043_LCD_PIN_DATA15 - }, - .flags = { - .disp_active_low = false, - .refresh_on_demand = false, - .fb_in_psram = true, - .double_fb = true, - .no_fb = false, - .bb_invalidate_cache = false - } - }; - - if (esp_lcd_new_rgb_panel(&panel_config, &panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); - return false; - } - - if (esp_lcd_panel_reset(panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to reset panel"); - return false; - } - - if (esp_lcd_panel_init(panelHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to init panel"); - return false; - } - - const lvgl_port_display_cfg_t disp_cfg = { - .io_handle = ioHandle, - .panel_handle = panelHandle, - .control_handle = nullptr, - .buffer_size = CYD8048S043_LCD_DRAW_BUFFER_SIZE, - .double_buffer = true, - .trans_size = 0, - .hres = CYD8048S043_LCD_HORIZONTAL_RESOLUTION, - .vres = CYD8048S043_LCD_VERTICAL_RESOLUTION, - .monochrome = false, - .rotation = { - .swap_xy = false, - .mirror_x = false, - .mirror_y = false, - }, - .color_format = LV_COLOR_FORMAT_RGB565, - .flags = { - .buff_dma = false, - .buff_spiram = true, - .sw_rotate = false, - .swap_bytes = false, - .full_refresh = false, - .direct_mode = false - } - }; - - const lvgl_port_display_rgb_cfg_t rgb_cfg = { - .flags = { - .bb_mode = true, - .avoid_tearing = false - } - }; - - displayHandle = lvgl_port_add_disp_rgb(&disp_cfg, &rgb_cfg); - TT_LOG_I(TAG, "Finished"); - return displayHandle != nullptr; -} - -bool YellowDisplay::stop() { - assert(displayHandle != nullptr); - - lvgl_port_remove_disp(displayHandle); - - if (esp_lcd_panel_del(panelHandle) != ESP_OK) { - return false; - } - - if (esp_lcd_panel_io_del(ioHandle) != ESP_OK) { - return false; - } - - displayHandle = nullptr; - return true; -} - -std::shared_ptr _Nullable YellowDisplay::createTouch() { - // Note for future changes: Reset pin is 38 and interrupt pin is 18 - // or INT = NC, schematic and other info floating around is kinda conflicting... - auto configuration = std::make_unique( - I2C_NUM_0, - 800, - 480 - ); - - return std::make_shared(std::move(configuration)); -} - -void YellowDisplay::setBacklightDuty(uint8_t backlightDuty) { - if (!isBacklightInitialized) { - tt_check(initBacklight()); - isBacklightInitialized = true; - } - - if (!setBacklight(backlightDuty)) { - TT_LOG_E(TAG, "Failed to configure display backlight"); - } -} - -std::shared_ptr createDisplay() { - return std::make_shared(); -} diff --git a/Boards/CYD-8048S043C/Source/hal/YellowDisplay.h b/Boards/CYD-8048S043C/Source/hal/YellowDisplay.h deleted file mode 100644 index 172ef92a..00000000 --- a/Boards/CYD-8048S043C/Source/hal/YellowDisplay.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "Tactility/hal/display/DisplayDevice.h" -#include -#include - -class YellowDisplay : public tt::hal::display::DisplayDevice { - -private: - - esp_lcd_panel_io_handle_t ioHandle = nullptr; - esp_lcd_panel_handle_t panelHandle = nullptr; - lv_display_t* displayHandle = nullptr; - -public: - - std::string getName() const final { return "ST7262"; } - std::string getDescription() const final { return "RGB Display"; } - - bool start() override; - - bool stop() override; - - std::shared_ptr _Nullable createTouch() override; - - void setBacklightDuty(uint8_t backlightDuty) override; - bool supportsBacklightDuty() const override { return true; } - - lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; } -}; - -std::shared_ptr createDisplay(); diff --git a/Boards/CYD-8048S043C/Source/hal/YellowDisplayConstants.h b/Boards/CYD-8048S043C/Source/hal/YellowDisplayConstants.h deleted file mode 100644 index 5ba96dcc..00000000 --- a/Boards/CYD-8048S043C/Source/hal/YellowDisplayConstants.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -// Display backlight (PWM) -#define CYD8048S043_LCD_BACKLIGHT_LEDC_TIMER LEDC_TIMER_0 -#define CYD8048S043_LCD_BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE -#define CYD8048S043_LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0 -#define CYD8048S043_LCD_BACKLIGHT_LEDC_DUTY_RES LEDC_TIMER_8_BIT -#define CYD8048S043_LCD_BACKLIGHT_LEDC_FREQUENCY (1000) - -#define CYD8048S043_LCD_PIN_BACKLIGHT GPIO_NUM_2 - -// Display pins -#define CYD8048S043_LCD_PIN_HSYNC GPIO_NUM_39 // HSYNC -#define CYD8048S043_LCD_PIN_VSYNC GPIO_NUM_41 // VSYNC -#define CYD8048S043_LCD_PIN_DE GPIO_NUM_40 // DE -#define CYD8048S043_LCD_PIN_PCLK GPIO_NUM_42 // DCLK - -#define CYD8048S043_LCD_PIN_DATA0 GPIO_NUM_8 // B3 -#define CYD8048S043_LCD_PIN_DATA1 GPIO_NUM_3 // B4 -#define CYD8048S043_LCD_PIN_DATA2 GPIO_NUM_46 // B5 -#define CYD8048S043_LCD_PIN_DATA3 GPIO_NUM_9 // B6 -#define CYD8048S043_LCD_PIN_DATA4 GPIO_NUM_1 // B7 - -#define CYD8048S043_LCD_PIN_DATA5 GPIO_NUM_5 // G2 -#define CYD8048S043_LCD_PIN_DATA6 GPIO_NUM_6 // G3 -#define CYD8048S043_LCD_PIN_DATA7 GPIO_NUM_7 // G4 -#define CYD8048S043_LCD_PIN_DATA8 GPIO_NUM_15 // G5 -#define CYD8048S043_LCD_PIN_DATA9 GPIO_NUM_16 // G6 -#define CYD8048S043_LCD_PIN_DATA10 GPIO_NUM_4 // G7 - -#define CYD8048S043_LCD_PIN_DATA11 GPIO_NUM_45 // R3 -#define CYD8048S043_LCD_PIN_DATA12 GPIO_NUM_48 // R4 -#define CYD8048S043_LCD_PIN_DATA13 GPIO_NUM_47 // R5 -#define CYD8048S043_LCD_PIN_DATA14 GPIO_NUM_21 // R6 -#define CYD8048S043_LCD_PIN_DATA15 GPIO_NUM_14 // R7 - -#define CYD8048S043_LCD_PIN_DISP_EN GPIO_NUM_NC // not connected - -// Display -#define CYD8048S043_LCD_HORIZONTAL_RESOLUTION 800 -#define CYD8048S043_LCD_VERTICAL_RESOLUTION 480 -#define CYD8048S043_LCD_DRAW_BUFFER_SIZE (CYD8048S043_LCD_HORIZONTAL_RESOLUTION * CYD8048S043_LCD_VERTICAL_RESOLUTION) diff --git a/Boards/CYD-8048S043C/Source/hal/YellowSdCard.cpp b/Boards/CYD-8048S043C/Source/hal/YellowSdCard.cpp deleted file mode 100644 index 12a46c52..00000000 --- a/Boards/CYD-8048S043C/Source/hal/YellowSdCard.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "YellowSdCard.h" - -#define TAG "cyd8048s043c_sdcard" - -#include -#include - -#define SDCARD_SPI_HOST SPI2_HOST -#define SDCARD_PIN_CS GPIO_NUM_10 - -using tt::hal::sdcard::SpiSdCardDevice; - -std::shared_ptr createYellowSdCard() { - auto* configuration = new SpiSdCardDevice::Config( - SDCARD_PIN_CS, - GPIO_NUM_NC, - GPIO_NUM_NC, - GPIO_NUM_NC, - SdCardDevice::MountBehaviour::AtBoot, - std::make_shared(), - std::vector(), - SDCARD_SPI_HOST - ); - - auto* sdcard = (SdCardDevice*) new SpiSdCardDevice( - std::unique_ptr(configuration) - ); - - return std::shared_ptr(sdcard); -} - diff --git a/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp b/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp index 0913dd2a..b85e76ed 100644 --- a/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp +++ b/Boards/CYD-JC8048W550C/Source/hal/CydDisplay.cpp @@ -83,7 +83,7 @@ std::shared_ptr createDisplay() { }; RgbDisplay::BufferConfiguration buffer_config = { - .size = bufferPixels, + .size = (800 * 480), .useSpi = true, .doubleBuffer = true, .bounceBufferMode = true,