New board: Elecrow CrowPanel Avance 2.8" (#224)
- Added new board - Extracted ST7789 driver and backlight PWM driver into separate subprojects - Refactored T-Deck to use the shared driver modules - Fix bug in WiFi service: searching for APs was broken
This commit is contained in:
committed by
GitHub
parent
5055fa7822
commit
0563e42dc9
@@ -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 esp_lcd esp_lcd_touch_ft5x06 ST7789 PwmBacklight driver esp_adc
|
||||
)
|
||||
@@ -0,0 +1,150 @@
|
||||
#include "PwmBacklight.h"
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "hal/CrowPanelDisplay.h"
|
||||
#include "hal/CrowPanelDisplayConstants.h"
|
||||
#include "hal/CrowPanelSdCard.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
#define CROWPANEL_SPI_TRANSFER_SIZE_LIMIT (CROWPANEL_LCD_HORIZONTAL_RESOLUTION * CROWPANEL_LCD_SPI_TRANSFER_HEIGHT * (CROWPANEL_LCD_BITS_PER_PIXEL / 8))
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
bool initBoot() {
|
||||
return driver::pwmbacklight::init(GPIO_NUM_38);
|
||||
}
|
||||
|
||||
extern const Configuration crowpanel_advance_28 = {
|
||||
.initBoot = initBoot,
|
||||
.createDisplay = createDisplay,
|
||||
.sdcard = createSdCard(),
|
||||
.i2c = {
|
||||
// There is only 1 (internal for touch, and also serves as "I2C-OUT" port)
|
||||
// Note: You could repurpose 1 or more UART interfaces as I2C interfaces
|
||||
i2c::Configuration {
|
||||
.name = "Main",
|
||||
.port = I2C_NUM_0,
|
||||
.initMode = i2c::InitMode::ByTactility,
|
||||
.canReinit = false,
|
||||
.hasMutableConfiguration = false,
|
||||
.config = (i2c_config_t) {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = GPIO_NUM_15,
|
||||
.scl_io_num = GPIO_NUM_16,
|
||||
.sda_pullup_en = true,
|
||||
.scl_pullup_en = true,
|
||||
.master = {
|
||||
.clk_speed = 400000
|
||||
},
|
||||
.clk_flags = 0
|
||||
}
|
||||
}
|
||||
},
|
||||
.spi {
|
||||
// Display
|
||||
spi::Configuration {
|
||||
.device = SPI2_HOST,
|
||||
.dma = SPI_DMA_DISABLED,
|
||||
.config = {
|
||||
.mosi_io_num = GPIO_NUM_39,
|
||||
.miso_io_num = GPIO_NUM_NC,
|
||||
.sclk_io_num = GPIO_NUM_42,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.data4_io_num = 0,
|
||||
.data5_io_num = 0,
|
||||
.data6_io_num = 0,
|
||||
.data7_io_num = 0,
|
||||
.data_io_default_level = false,
|
||||
.max_transfer_sz = CROWPANEL_SPI_TRANSFER_SIZE_LIMIT,
|
||||
.flags = 0,
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
.intr_flags = 0
|
||||
},
|
||||
.initMode = spi::InitMode::ByTactility,
|
||||
.canReinit = false,
|
||||
.hasMutableConfiguration = false,
|
||||
.lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display
|
||||
},
|
||||
// SD card
|
||||
spi::Configuration {
|
||||
.device = SPI3_HOST,
|
||||
.dma = SPI_DMA_CH_AUTO,
|
||||
.config = {
|
||||
.mosi_io_num = GPIO_NUM_6,
|
||||
.miso_io_num = GPIO_NUM_4,
|
||||
.sclk_io_num = GPIO_NUM_5,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.data4_io_num = 0,
|
||||
.data5_io_num = 0,
|
||||
.data6_io_num = 0,
|
||||
.data7_io_num = 0,
|
||||
.data_io_default_level = false,
|
||||
.max_transfer_sz = 32768,
|
||||
.flags = 0,
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
.intr_flags = 0
|
||||
},
|
||||
.initMode = spi::InitMode::ByTactility,
|
||||
.canReinit = false,
|
||||
.hasMutableConfiguration = false,
|
||||
.lock = nullptr // No custom lock needed
|
||||
}
|
||||
},
|
||||
.uart {
|
||||
// "UART0-IN"
|
||||
uart::Configuration {
|
||||
.port = UART_NUM_1,
|
||||
.initMode = uart::InitMode::Disabled, // Manual init
|
||||
.canReinit = true,
|
||||
.hasMutableConfiguration = false,
|
||||
.rxPin = GPIO_NUM_44,
|
||||
.txPin = GPIO_NUM_43,
|
||||
.rtsPin = GPIO_NUM_NC,
|
||||
.ctsPin = GPIO_NUM_NC,
|
||||
.rxBufferSize = 1024,
|
||||
.txBufferSize = 1024,
|
||||
.config = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.rx_flow_ctrl_thresh = 0,
|
||||
.source_clk = UART_SCLK_DEFAULT,
|
||||
.flags = {
|
||||
.allow_pd = 0,
|
||||
.backup_before_sleep = 0,
|
||||
}
|
||||
}
|
||||
},
|
||||
// "UART1-OUT"
|
||||
uart::Configuration {
|
||||
.port = UART_NUM_1,
|
||||
.initMode = uart::InitMode::Disabled, // Manual init
|
||||
.canReinit = true,
|
||||
.hasMutableConfiguration = false,
|
||||
.rxPin = GPIO_NUM_18,
|
||||
.txPin = GPIO_NUM_17,
|
||||
.rtsPin = GPIO_NUM_NC,
|
||||
.ctsPin = GPIO_NUM_NC,
|
||||
.rxBufferSize = 1024,
|
||||
.txBufferSize = 1024,
|
||||
.config = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.rx_flow_ctrl_thresh = 0,
|
||||
.source_clk = UART_SCLK_DEFAULT,
|
||||
.flags = {
|
||||
.allow_pd = 0,
|
||||
.backup_before_sleep = 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
.gps = {}
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
|
||||
extern const tt::hal::Configuration crowpanel_advance_28;
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "CrowPanelDisplay.h"
|
||||
#include "CrowPanelDisplayConstants.h"
|
||||
#include "CrowPanelTouch.h"
|
||||
|
||||
#include <St7789Display.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#define TAG "crowpanel_display"
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
auto touch = std::make_shared<CrowPanelTouch>();
|
||||
|
||||
auto configuration = std::make_unique<St7789Display::Configuration>(
|
||||
CROWPANEL_LCD_SPI_HOST,
|
||||
CROWPANEL_LCD_PIN_CS,
|
||||
CROWPANEL_LCD_PIN_DC,
|
||||
320,
|
||||
240,
|
||||
touch
|
||||
);
|
||||
|
||||
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
|
||||
|
||||
return std::make_shared<St7789Display>(std::move(configuration));
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
#include <esp_lcd_types.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
class CrowPanelDisplay : 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;
|
||||
bool poweredOn = false;
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "ST7789"; }
|
||||
std::string getDescription() const final { return "SPI display"; }
|
||||
|
||||
bool start() override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
void setPowerOn(bool turnOn) override;
|
||||
bool isPoweredOn() const override { return poweredOn; };
|
||||
bool supportsPowerControl() const override { return true; }
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() override;
|
||||
|
||||
void setBacklightDuty(uint8_t backlightDuty) override;
|
||||
bool supportsBacklightDuty() const override { return true; }
|
||||
|
||||
void setGammaCurve(uint8_t index) override;
|
||||
uint8_t getGammaCurveCount() const override { return 4; };
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#define CROWPANEL_LCD_SPI_HOST SPI2_HOST
|
||||
#define CROWPANEL_LCD_PIN_CS GPIO_NUM_40
|
||||
#define CROWPANEL_LCD_PIN_DC GPIO_NUM_41 // RS
|
||||
#define CROWPANEL_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define CROWPANEL_LCD_VERTICAL_RESOLUTION 240
|
||||
#define CROWPANEL_LCD_BITS_PER_PIXEL 16
|
||||
#define CROWPANEL_LCD_SPI_TRANSFER_HEIGHT (CROWPANEL_LCD_VERTICAL_RESOLUTION / 10)
|
||||
|
||||
// Backlight (PWM)
|
||||
#define CROWPANEL_LCD_BACKLIGHT_LEDC_TIMER LEDC_TIMER_0
|
||||
#define CROWPANEL_LCD_BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE
|
||||
#define CROWPANEL_LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0
|
||||
#define CROWPANEL_LCD_BACKLIGHT_LEDC_DUTY_RES LEDC_TIMER_8_BIT
|
||||
#define CROWPANEL_LCD_BACKLIGHT_LEDC_FREQUENCY (4000)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "CrowPanelSdCard.h"
|
||||
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||
|
||||
#include <esp_vfs_fat.h>
|
||||
|
||||
using tt::hal::sdcard::SpiSdCardDevice;
|
||||
|
||||
#define CROWPANEL_SDCARD_PIN_CS GPIO_NUM_7
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||
auto* configuration = new SpiSdCardDevice::Config(
|
||||
CROWPANEL_SDCARD_PIN_CS,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_NC,
|
||||
SdCardDevice::MountBehaviour::AtBoot,
|
||||
tt::lvgl::getSyncLock(),
|
||||
{},
|
||||
SPI3_HOST
|
||||
);
|
||||
|
||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
||||
);
|
||||
|
||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
|
||||
using tt::hal::sdcard::SdCardDevice;
|
||||
|
||||
std::shared_ptr<SdCardDevice> createSdCard();
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "CrowPanelTouch.h"
|
||||
#include "esp_lcd_touch_ft5x06.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "crowpanel_touch"
|
||||
|
||||
// Touch (GT911)
|
||||
#define CROWPANEL_TOUCH_I2C_BUS_HANDLE I2C_NUM_0
|
||||
#define CROWPANEL_TOUCH_X_MAX 240
|
||||
#define CROWPANEL_TOUCH_Y_MAX 320
|
||||
|
||||
bool CrowPanelTouch::start(lv_display_t* display) {
|
||||
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
|
||||
|
||||
if (esp_lcd_new_panel_io_i2c(CROWPANEL_TOUCH_I2C_BUS_HANDLE, &io_config, &ioHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "touch io i2c creation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_lcd_touch_config_t config = {
|
||||
.x_max = CROWPANEL_TOUCH_X_MAX,
|
||||
.y_max = CROWPANEL_TOUCH_Y_MAX,
|
||||
.rst_gpio_num = GPIO_NUM_NC, // GPIO_NUM_48,
|
||||
.int_gpio_num = GPIO_NUM_NC, // GPIO_NUM_47,
|
||||
.levels = {
|
||||
.reset = 0,
|
||||
.interrupt = 0,
|
||||
},
|
||||
.flags = {
|
||||
.swap_xy = 1,
|
||||
.mirror_x = 1,
|
||||
.mirror_y = 0,
|
||||
},
|
||||
.process_coordinates = nullptr,
|
||||
.interrupt_callback = nullptr,
|
||||
.user_data = nullptr,
|
||||
.driver_data = nullptr
|
||||
};
|
||||
|
||||
if (esp_lcd_touch_new_i2c_ft5x06(ioHandle, &config, &touchHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "GT911 driver init failed");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||
.disp = display,
|
||||
.handle = touchHandle,
|
||||
};
|
||||
|
||||
TT_LOG_I(TAG, "Adding touch to LVGL");
|
||||
deviceHandle = lvgl_port_add_touch(&touch_cfg);
|
||||
if (deviceHandle == nullptr) {
|
||||
TT_LOG_E(TAG, "Adding touch failed");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CrowPanelTouch::stop() {
|
||||
cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CrowPanelTouch::cleanup() {
|
||||
if (deviceHandle != nullptr) {
|
||||
lv_indev_delete(deviceHandle);
|
||||
deviceHandle = nullptr;
|
||||
}
|
||||
|
||||
if (touchHandle != nullptr) {
|
||||
esp_lcd_touch_del(touchHandle);
|
||||
touchHandle = nullptr;
|
||||
}
|
||||
|
||||
if (ioHandle != nullptr) {
|
||||
esp_lcd_panel_io_del(ioHandle);
|
||||
ioHandle = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/touch/TouchDevice.h"
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <esp_lcd_panel_io_interface.h>
|
||||
#include <esp_lcd_touch.h>
|
||||
|
||||
class CrowPanelTouch : public tt::hal::touch::TouchDevice {
|
||||
|
||||
private:
|
||||
|
||||
std::string getName() const final { return "GT911"; }
|
||||
std::string getDescription() const final { return "I2C Touch Driver"; }
|
||||
|
||||
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
|
||||
esp_lcd_touch_handle_t _Nullable touchHandle = nullptr;
|
||||
lv_indev_t* _Nullable deviceHandle = nullptr;
|
||||
void cleanup();
|
||||
|
||||
public:
|
||||
|
||||
bool start(lv_display_t* display) override;
|
||||
bool stop() override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
};
|
||||
@@ -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 esp_lcd_touch_gt911 driver esp_adc
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_touch_gt911 ST7789 PwmBacklight driver esp_adc
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <driver/gpio.h>
|
||||
#include "PwmBacklight.h"
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
#define TAG "tdeck"
|
||||
@@ -33,5 +34,10 @@ bool tdeckInit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!driver::pwmbacklight::init(GPIO_NUM_42)) {
|
||||
TT_LOG_E(TAG, "Backlight init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,237 +2,26 @@
|
||||
#include "TdeckDisplayConstants.h"
|
||||
#include "TdeckTouch.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <PwmBacklight.h>
|
||||
#include <St7789Display.h>
|
||||
|
||||
#include <esp_lcd_panel_commands.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/spi_master.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "tdeck_display"
|
||||
|
||||
static bool isBacklightInitialized = false;
|
||||
|
||||
static bool initBacklight() {
|
||||
TT_LOG_I(TAG, "Init backlight");
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = TDECK_LCD_BACKLIGHT_LEDC_MODE,
|
||||
.duty_resolution = TDECK_LCD_BACKLIGHT_LEDC_DUTY_RES,
|
||||
.timer_num = TDECK_LCD_BACKLIGHT_LEDC_TIMER,
|
||||
.freq_hz = TDECK_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 = TDECK_LCD_PIN_BACKLIGHT,
|
||||
.speed_mode = TDECK_LCD_BACKLIGHT_LEDC_MODE,
|
||||
.channel = TDECK_LCD_BACKLIGHT_LEDC_CHANNEL,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = TDECK_LCD_BACKLIGHT_LEDC_TIMER,
|
||||
.duty = duty,
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
.flags = {
|
||||
.output_invert = 0
|
||||
}
|
||||
};
|
||||
|
||||
// Setting the config in the timer init and then calling ledc_set_duty() doesn't work when
|
||||
// the app is running. For an unknown reason we have to call this config method every time:
|
||||
return ledc_channel_config(&ledc_channel) == ESP_OK;
|
||||
}
|
||||
|
||||
bool TdeckDisplay::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
|
||||
const esp_lcd_panel_io_spi_config_t panel_io_config = {
|
||||
.cs_gpio_num = TDECK_LCD_PIN_CS,
|
||||
.dc_gpio_num = TDECK_LCD_PIN_DC,
|
||||
.spi_mode = 0,
|
||||
.pclk_hz = TDECK_LCD_SPI_FREQUENCY,
|
||||
.trans_queue_depth = 10,
|
||||
.on_color_trans_done = nullptr,
|
||||
.user_ctx = nullptr,
|
||||
.lcd_cmd_bits = 8,
|
||||
.lcd_param_bits = 8,
|
||||
.cs_ena_pretrans = 0,
|
||||
.cs_ena_posttrans = 0,
|
||||
.flags = {
|
||||
.dc_high_on_cmd = 0,
|
||||
.dc_low_on_data = 0,
|
||||
.dc_low_on_param = 0,
|
||||
.octal_mode = 0,
|
||||
.quad_mode = 0,
|
||||
.sio_mode = 1,
|
||||
.lsb_first = 0,
|
||||
.cs_high_active = 0,
|
||||
}
|
||||
};
|
||||
|
||||
if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)TDECK_LCD_SPI_HOST, &panel_io_config, &ioHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to create panel IO");
|
||||
return false;
|
||||
}
|
||||
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = GPIO_NUM_NC,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE,
|
||||
.bits_per_pixel = TDECK_LCD_BITS_PER_PIXEL,
|
||||
.flags = {
|
||||
.reset_active_high = 0
|
||||
},
|
||||
.vendor_config = nullptr
|
||||
};
|
||||
|
||||
if (esp_lcd_new_panel_st7789(ioHandle, &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;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_invert_color(panelHandle, true) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to init panel");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_swap_xy(panelHandle, true) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to swap XY ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_mirror(panelHandle, true, false) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to mirror panel");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to turn display on");
|
||||
return false;
|
||||
}
|
||||
|
||||
const lvgl_port_display_cfg_t disp_cfg = {
|
||||
.io_handle = ioHandle,
|
||||
.panel_handle = panelHandle,
|
||||
.control_handle = nullptr,
|
||||
.buffer_size = TDECK_LCD_HORIZONTAL_RESOLUTION * TDECK_LCD_DRAW_BUFFER_HEIGHT,
|
||||
.double_buffer = false, // Disable to free up memory
|
||||
.trans_size = 0,
|
||||
.hres = TDECK_LCD_HORIZONTAL_RESOLUTION,
|
||||
.vres = TDECK_LCD_VERTICAL_RESOLUTION,
|
||||
.monochrome = false,
|
||||
.rotation = {
|
||||
.swap_xy = true,
|
||||
.mirror_x = true,
|
||||
.mirror_y = false,
|
||||
},
|
||||
.color_format = LV_COLOR_FORMAT_RGB565,
|
||||
.flags = {
|
||||
.buff_dma = true,
|
||||
.buff_spiram = false,
|
||||
.sw_rotate = false,
|
||||
.swap_bytes = false,
|
||||
.full_refresh = false,
|
||||
.direct_mode = false
|
||||
}
|
||||
};
|
||||
|
||||
displayHandle = lvgl_port_add_disp(&disp_cfg);
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool TdeckDisplay::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;
|
||||
|
||||
}
|
||||
|
||||
void TdeckDisplay::setPowerOn(bool turnOn) {
|
||||
if (esp_lcd_panel_disp_on_off(panelHandle, turnOn) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to turn display on/off");
|
||||
} else {
|
||||
poweredOn = turnOn;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable TdeckDisplay::createTouch() {
|
||||
return std::make_shared<TdeckTouch>();
|
||||
}
|
||||
|
||||
void TdeckDisplay::setBacklightDuty(uint8_t backlightDuty) {
|
||||
if (!isBacklightInitialized) {
|
||||
tt_check(initBacklight());
|
||||
isBacklightInitialized = true;
|
||||
}
|
||||
|
||||
if (!setBacklight(backlightDuty)) {
|
||||
TT_LOG_E(TAG, "Failed to configure display backlight");
|
||||
}
|
||||
}
|
||||
|
||||
void TdeckDisplay::setGammaCurve(uint8_t index) {
|
||||
uint8_t gamma_curve;
|
||||
switch (index) {
|
||||
case 0:
|
||||
gamma_curve = 0x01;
|
||||
break;
|
||||
case 1:
|
||||
gamma_curve = 0x04;
|
||||
break;
|
||||
case 2:
|
||||
gamma_curve = 0x02;
|
||||
break;
|
||||
case 3:
|
||||
gamma_curve = 0x08;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
const uint8_t param[] = {
|
||||
gamma_curve
|
||||
};
|
||||
|
||||
if (esp_lcd_panel_io_tx_param(ioHandle , LCD_CMD_GAMSET, param, 1) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set gamma");
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
return std::make_shared<TdeckDisplay>();
|
||||
auto touch = std::make_shared<TdeckTouch>();
|
||||
|
||||
auto configuration = std::make_unique<St7789Display::Configuration>(
|
||||
TDECK_LCD_SPI_HOST,
|
||||
TDECK_LCD_PIN_CS,
|
||||
TDECK_LCD_PIN_DC,
|
||||
320,
|
||||
240,
|
||||
touch
|
||||
);
|
||||
|
||||
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
|
||||
|
||||
return std::make_shared<St7789Display>(std::move(configuration));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "ST7780"; }
|
||||
std::string getName() const final { return "ST7789"; }
|
||||
std::string getDescription() const final { return "SPI display"; }
|
||||
|
||||
bool start() override;
|
||||
|
||||
@@ -3,18 +3,7 @@
|
||||
#define TDECK_LCD_SPI_HOST SPI2_HOST
|
||||
#define TDECK_LCD_PIN_CS GPIO_NUM_12
|
||||
#define TDECK_LCD_PIN_DC GPIO_NUM_11 // RS
|
||||
#define TDECK_LCD_PIN_BACKLIGHT GPIO_NUM_42
|
||||
#define TDECK_LCD_SPI_FREQUENCY 80000000
|
||||
#define TDECK_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define TDECK_LCD_VERTICAL_RESOLUTION 240
|
||||
#define TDECK_LCD_BITS_PER_PIXEL 16
|
||||
#define TDECK_LCD_DRAW_BUFFER_HEIGHT (TDECK_LCD_VERTICAL_RESOLUTION / 10)
|
||||
#define TDECK_LCD_SPI_TRANSFER_HEIGHT (TDECK_LCD_VERTICAL_RESOLUTION / 10)
|
||||
|
||||
// Backlight (PWM)
|
||||
#define TDECK_LCD_BACKLIGHT_LEDC_TIMER LEDC_TIMER_0
|
||||
#define TDECK_LCD_BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE
|
||||
#define TDECK_LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0
|
||||
#define TDECK_LCD_BACKLIGHT_LEDC_DUTY_RES LEDC_TIMER_8_BIT
|
||||
#define TDECK_LCD_BACKLIGHT_LEDC_FREQUENCY (4000)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ bool TdeckTouch::start(lv_display_t* display) {
|
||||
};
|
||||
|
||||
if (esp_lcd_touch_new_i2c_gt911(ioHandle, &config, &touchHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "GT199 driver init failed");
|
||||
TT_LOG_E(TAG, "GT911 driver init failed");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user