Hal refactored (#99)
This commit is contained in:
committed by
GitHub
parent
0188ce721c
commit
33bb742dfb
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "."
|
||||
INCLUDE_DIRS "."
|
||||
SRC_DIRS "Source" "Source/hal"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd_touch_cst816s esp_lcd_ili9341 driver vfs fatfs
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "config.h"
|
||||
#include "Config.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "display_i.h"
|
||||
#include "hal/YellowTouchConstants.h"
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
#define TAG "twodotfour_bootstrap"
|
||||
@@ -66,7 +66,7 @@ static bool init_spi3() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool twodotfour_bootstrap() {
|
||||
bool twodotfour_boot() {
|
||||
TT_LOG_I(TAG, "Init I2C");
|
||||
if (!init_i2c()) {
|
||||
TT_LOG_E(TAG, "Init I2C failed");
|
||||
@@ -85,12 +85,5 @@ bool twodotfour_bootstrap() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't turn the backlight on yet - Tactility init will take care of it
|
||||
TT_LOG_I(TAG, "Init backlight");
|
||||
if (!twodotfour_backlight_init()) {
|
||||
TT_LOG_E(TAG, "Init backlight failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "driver/spi_common.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "hal/YellowDisplayConstants.h"
|
||||
|
||||
// SPI 2 - display
|
||||
#define TWODOTFOUR_SPI2_PIN_SCLK GPIO_NUM_14
|
||||
@@ -15,20 +16,6 @@
|
||||
#define TWODOTFOUR_SPI3_PIN_MISO GPIO_NUM_19
|
||||
#define TWODOTFOUR_SPI3_TRANSACTION_LIMIT 8192 // TODO: Determine proper limit
|
||||
|
||||
// Display
|
||||
#define TWODOTFOUR_LCD_SPI_HOST SPI2_HOST
|
||||
#define TWODOTFOUR_LCD_HORIZONTAL_RESOLUTION 240
|
||||
#define TWODOTFOUR_LCD_VERTICAL_RESOLUTION 320
|
||||
#define TWODOTFOUR_LCD_BITS_PER_PIXEL 16
|
||||
#define TWODOTFOUR_LCD_DRAW_BUFFER_HEIGHT (TWODOTFOUR_LCD_VERTICAL_RESOLUTION / 10)
|
||||
#define TWODOTFOUR_LCD_DRAW_BUFFER_SIZE (TWODOTFOUR_LCD_HORIZONTAL_RESOLUTION * TWODOTFOUR_LCD_DRAW_BUFFER_HEIGHT * (TWODOTFOUR_LCD_BITS_PER_PIXEL / 8))
|
||||
#define TWODOTFOUR_LCD_PIN_CS GPIO_NUM_15
|
||||
#define TWODOTFOUR_LCD_PIN_DC GPIO_NUM_2
|
||||
#define TWODOTFOUR_LCD_PIN_BACKLIGHT GPIO_NUM_27
|
||||
|
||||
// Touch
|
||||
#define TWODOTFOUR_TOUCH_I2C_PORT I2C_NUM_0
|
||||
|
||||
// SD Card
|
||||
#define TWODOTFOUR_SDCARD_SPI_HOST SPI3_HOST
|
||||
#define TWODOTFOUR_SDCARD_PIN_CS GPIO_NUM_5
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "esp_lvgl_port.h"
|
||||
#include "Log.h"
|
||||
#include "lvgl/LvglSync.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#define TAG "twodotfour_lvgl"
|
||||
|
||||
bool twodotfour_lvgl_init() {
|
||||
const lvgl_port_cfg_t lvgl_cfg = {
|
||||
.task_priority = tt::Thread::PriorityHigh,
|
||||
.task_stack = 8096,
|
||||
.task_affinity = -1, // core pinning
|
||||
.task_max_sleep_ms = 500,
|
||||
.timer_period_ms = 5
|
||||
};
|
||||
|
||||
if (lvgl_port_init(&lvgl_cfg) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "lvgl port init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set syncing functions
|
||||
tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "hal/sdcard/Sdcard.h"
|
||||
#include "Check.h"
|
||||
#include "Log.h"
|
||||
#include "config.h"
|
||||
#include "Config.h"
|
||||
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
@@ -1,17 +1,15 @@
|
||||
#include "yellow_board.h"
|
||||
#include "display_i.h"
|
||||
#include "YellowBoard.h"
|
||||
#include "hal/YellowDisplay.h"
|
||||
|
||||
bool twodotfour_lvgl_init();
|
||||
bool twodotfour_bootstrap();
|
||||
bool twodotfour_boot();
|
||||
|
||||
extern const tt::hal::sdcard::SdCard twodotfour_sdcard;
|
||||
|
||||
const tt::hal::Configuration yellow_board_24inch_cap = {
|
||||
.initPower = &twodotfour_bootstrap,
|
||||
.initBoot = &twodotfour_boot,
|
||||
.initLvgl = &twodotfour_lvgl_init,
|
||||
.display = {
|
||||
.setBacklightDuty = &twodotfour_backlight_set
|
||||
},
|
||||
.createDisplay = createDisplay,
|
||||
.sdcard = &twodotfour_sdcard,
|
||||
.power = nullptr,
|
||||
.i2c = {
|
||||
@@ -1,24 +1,22 @@
|
||||
#include "config.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "YellowDisplay.h"
|
||||
#include "YellowDisplayConstants.h"
|
||||
#include "YellowTouch.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include <TactilityCore.h>
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_lcd_ili9341.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
|
||||
#define TAG "twodotfour_ili9341"
|
||||
#define TAG "yellow_display"
|
||||
|
||||
// Dipslay backlight (PWM)
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_TIMER LEDC_TIMER_0
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_DUTY_RES LEDC_TIMER_8_BIT
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_FREQUENCY (1000)
|
||||
static bool isBacklightInitialized = false;
|
||||
|
||||
bool twodotfour_backlight_init() {
|
||||
static bool initBacklight() {
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE,
|
||||
.duty_resolution = TWODOTFOUR_LCD_BACKLIGHT_LEDC_DUTY_RES,
|
||||
@@ -35,7 +33,7 @@ bool twodotfour_backlight_init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void twodotfour_backlight_set(uint8_t duty) {
|
||||
static bool setBacklight(uint8_t duty) {
|
||||
ledc_channel_config_t ledc_channel = {
|
||||
.gpio_num = TWODOTFOUR_LCD_PIN_BACKLIGHT,
|
||||
.speed_mode = TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE,
|
||||
@@ -43,18 +41,22 @@ void twodotfour_backlight_set(uint8_t duty) {
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = TWODOTFOUR_LCD_BACKLIGHT_LEDC_TIMER,
|
||||
.duty = duty,
|
||||
.hpoint = 0
|
||||
.hpoint = 0,
|
||||
.flags = {
|
||||
.output_invert = false
|
||||
}
|
||||
};
|
||||
|
||||
// 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:
|
||||
if (ledc_channel_config(&ledc_channel) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to configure display backlight");
|
||||
TT_LOG_E(TAG, "Backlight init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
lv_disp_t* twodotfour_display_init() {
|
||||
TT_LOG_I(TAG, "Display init");
|
||||
bool YellowDisplay::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
|
||||
const esp_lcd_panel_io_spi_config_t panel_io_config = ILI9341_PANEL_IO_SPI_CONFIG(
|
||||
TWODOTFOUR_LCD_PIN_CS,
|
||||
@@ -63,47 +65,50 @@ lv_disp_t* twodotfour_display_init() {
|
||||
nullptr
|
||||
);
|
||||
|
||||
esp_lcd_panel_io_handle_t io_handle;
|
||||
if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)TWODOTFOUR_LCD_SPI_HOST, &panel_io_config, &io_handle) != ESP_OK) {
|
||||
if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)TWODOTFOUR_LCD_SPI_HOST, &panel_io_config, &ioHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to create panel");
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = GPIO_NUM_NC,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
|
||||
.data_endian = LCD_RGB_DATA_ENDIAN_BIG,
|
||||
.bits_per_pixel = TWODOTFOUR_LCD_BITS_PER_PIXEL,
|
||||
.flags = {
|
||||
.reset_active_high = false
|
||||
},
|
||||
.vendor_config = nullptr
|
||||
};
|
||||
|
||||
esp_lcd_panel_handle_t panel_handle;
|
||||
if (esp_lcd_new_panel_ili9341(io_handle, &panel_config, &panel_handle) != ESP_OK) {
|
||||
if (esp_lcd_new_panel_ili9341(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to create ili9341");
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_reset(panel_handle) != ESP_OK) {
|
||||
if (esp_lcd_panel_reset(panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to reset panel");
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_init(panel_handle) != ESP_OK) {
|
||||
if (esp_lcd_panel_init(panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to init panel");
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_mirror(panel_handle, true, false) != ESP_OK) {
|
||||
if (esp_lcd_panel_mirror(panelHandle, true, false) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set panel to mirror");
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_disp_on_off(panel_handle, true) != ESP_OK) {
|
||||
if (esp_lcd_panel_disp_on_off(panelHandle, true) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to turn display on");
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
const lvgl_port_display_cfg_t disp_cfg = {
|
||||
.io_handle = io_handle,
|
||||
.panel_handle = panel_handle,
|
||||
.io_handle = ioHandle,
|
||||
.panel_handle = panelHandle,
|
||||
.buffer_size = TWODOTFOUR_LCD_DRAW_BUFFER_SIZE,
|
||||
.double_buffer = false,
|
||||
.hres = TWODOTFOUR_LCD_HORIZONTAL_RESOLUTION,
|
||||
@@ -122,5 +127,45 @@ lv_disp_t* twodotfour_display_init() {
|
||||
}
|
||||
};
|
||||
|
||||
return lvgl_port_add_disp(&disp_cfg);
|
||||
displayHandle = lvgl_port_add_disp(&disp_cfg);
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool YellowDisplay::stop() {
|
||||
tt_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 YellowDisplay::setBacklightDuty(uint8_t backlightDuty) {
|
||||
if (!isBacklightInitialized) {
|
||||
tt_check(initBacklight());
|
||||
isBacklightInitialized = true;
|
||||
}
|
||||
|
||||
if (setBacklight(backlightDuty)) {
|
||||
TT_LOG_I(TAG, "Backlight set: %d", backlightDuty);
|
||||
lastBacklightDuty = backlightDuty;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to configure display backlight");
|
||||
}
|
||||
}
|
||||
tt::hal::Touch* _Nullable YellowDisplay::createTouch() {
|
||||
return static_cast<tt::hal::Touch*>(new YellowTouch());
|
||||
}
|
||||
|
||||
tt::hal::Display* createDisplay() {
|
||||
return static_cast<tt::hal::Display*>(new YellowDisplay());
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "hal/Display.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
|
||||
extern lv_disp_t* displayHandle;
|
||||
|
||||
class YellowDisplay : public tt::hal::Display {
|
||||
|
||||
private:
|
||||
|
||||
esp_lcd_panel_io_handle_t ioHandle = nullptr;
|
||||
esp_lcd_panel_handle_t panelHandle = nullptr;
|
||||
lv_display_t* displayHandle = nullptr;
|
||||
uint8_t lastBacklightDuty = 255;
|
||||
|
||||
public:
|
||||
|
||||
bool start() override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
void setPowerOn(bool turnOn) override {}
|
||||
bool isPoweredOn() const override { return true; };
|
||||
bool supportsPowerControl() const override { return false; }
|
||||
|
||||
tt::hal::Touch* _Nullable createTouch() override;
|
||||
|
||||
void setBacklightDuty(uint8_t backlightDuty) override;
|
||||
uint8_t getBacklightDuty() const override { return lastBacklightDuty; }
|
||||
bool supportsBacklightDuty() const override { return true; }
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
};
|
||||
|
||||
tt::hal::Display* createDisplay();
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
// Dipslay backlight (PWM)
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_TIMER LEDC_TIMER_0
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_MODE LEDC_LOW_SPEED_MODE
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_0
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_DUTY_RES LEDC_TIMER_8_BIT
|
||||
#define TWODOTFOUR_LCD_BACKLIGHT_LEDC_FREQUENCY (1000)
|
||||
|
||||
#define TWODOTFOUR_LCD_PIN_BACKLIGHT GPIO_NUM_27
|
||||
|
||||
// Display
|
||||
#define TWODOTFOUR_LCD_SPI_HOST SPI2_HOST
|
||||
#define TWODOTFOUR_LCD_HORIZONTAL_RESOLUTION 240
|
||||
#define TWODOTFOUR_LCD_VERTICAL_RESOLUTION 320
|
||||
#define TWODOTFOUR_LCD_BITS_PER_PIXEL 16
|
||||
#define TWODOTFOUR_LCD_DRAW_BUFFER_HEIGHT (TWODOTFOUR_LCD_VERTICAL_RESOLUTION / 10)
|
||||
#define TWODOTFOUR_LCD_DRAW_BUFFER_SIZE (TWODOTFOUR_LCD_HORIZONTAL_RESOLUTION * TWODOTFOUR_LCD_DRAW_BUFFER_HEIGHT * (TWODOTFOUR_LCD_BITS_PER_PIXEL / 8))
|
||||
#define TWODOTFOUR_LCD_PIN_CS GPIO_NUM_15
|
||||
#define TWODOTFOUR_LCD_PIN_DC GPIO_NUM_2
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
#include "config.h"
|
||||
#include "YellowTouch.h"
|
||||
#include "YellowTouchConstants.h"
|
||||
#include "Log.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_lcd_touch_cst816s.h"
|
||||
#include "esp_lcd_touch.h"
|
||||
#include "Log.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
|
||||
#define TAG "twodotfour_cst816"
|
||||
#define TAG "m5stack_touch"
|
||||
|
||||
bool twodotfour_touch_init(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_handle_t* touch_handle) {
|
||||
TT_LOG_I(TAG, "Touch init");
|
||||
bool YellowTouch::start(lv_display_t* display) {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
esp_lcd_panel_io_handle_t ioHandle;
|
||||
esp_lcd_touch_handle_t touchHandle;
|
||||
|
||||
const esp_lcd_panel_io_i2c_config_t touch_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
|
||||
|
||||
// TODO: Check when ESP-IDF publishes fix (5.3.2 or 5.4.x)
|
||||
static_assert(ESP_IDF_VERSION == ESP_IDF_VERSION_VAL(5, 3, 1));
|
||||
esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TWODOTFOUR_TOUCH_I2C_PORT, &touch_io_config, io_handle);
|
||||
esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TWODOTFOUR_TOUCH_I2C_PORT, &touch_io_config, &ioHandle);
|
||||
/*
|
||||
if (esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TWODOTFOUR_TOUCH_I2C_PORT, &touch_io_config, io_handle) != ESP_OK) {
|
||||
if (esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)TWODOTFOUR_TOUCH_I2C_PORT, &touch_io_config, &ioHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Touch I2C IO init failed");
|
||||
return false;
|
||||
}
|
||||
@@ -41,10 +45,29 @@ bool twodotfour_touch_init(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_h
|
||||
.user_data = nullptr
|
||||
};
|
||||
|
||||
if (esp_lcd_touch_new_i2c_cst816s(*io_handle, &config, touch_handle) != ESP_OK) {
|
||||
if (esp_lcd_touch_new_i2c_cst816s(ioHandle, &config, &touchHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Driver init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||
.disp = display,
|
||||
.handle = touchHandle,
|
||||
};
|
||||
|
||||
deviceHandle = lvgl_port_add_touch(&touch_cfg);
|
||||
if (deviceHandle == nullptr) {
|
||||
TT_LOG_E(TAG, "Adding touch failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool YellowTouch::stop() {
|
||||
tt_assert(deviceHandle != nullptr);
|
||||
lv_indev_delete(deviceHandle);
|
||||
deviceHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Touch.h"
|
||||
#include "TactilityCore.h"
|
||||
|
||||
class YellowTouch : public tt::hal::Touch {
|
||||
private:
|
||||
lv_indev_t* _Nullable deviceHandle = nullptr;
|
||||
public:
|
||||
bool start(lv_display_t* display) override;
|
||||
bool stop() override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// Touch
|
||||
#define TWODOTFOUR_TOUCH_I2C_PORT I2C_NUM_0
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
bool twodotfour_backlight_init();
|
||||
void twodotfour_backlight_set(uint8_t duty);
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "esp_lvgl_port.h"
|
||||
#include "Log.h"
|
||||
#include "lvgl/LvglSync.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#define TAG "twodotfour_lvgl"
|
||||
|
||||
lv_display_t* twodotfour_display_init();
|
||||
bool twodotfour_touch_init(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_handle_t* touch_handle);
|
||||
|
||||
bool twodotfour_lvgl_init() {
|
||||
static lv_display_t* display = nullptr;
|
||||
static esp_lcd_panel_io_handle_t touch_io_handle;
|
||||
static esp_lcd_touch_handle_t touch_handle;
|
||||
|
||||
const lvgl_port_cfg_t lvgl_cfg = {
|
||||
.task_priority = tt::Thread::PriorityHigh,
|
||||
.task_stack = 8096,
|
||||
.task_affinity = -1, // core pinning
|
||||
.task_max_sleep_ms = 500,
|
||||
.timer_period_ms = 5
|
||||
};
|
||||
|
||||
if (lvgl_port_init(&lvgl_cfg) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "lvgl port init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add display
|
||||
display = twodotfour_display_init();
|
||||
if (display == nullptr) {
|
||||
TT_LOG_E(TAG, "failed to add display");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add touch
|
||||
if (!twodotfour_touch_init(&touch_io_handle, &touch_handle)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||
.disp = display,
|
||||
.handle = touch_handle,
|
||||
};
|
||||
|
||||
auto* touch_indev= lvgl_port_add_touch(&touch_cfg);
|
||||
if (touch_indev == nullptr) {
|
||||
TT_LOG_E(TAG, "failed to add touch to lvgl");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set syncing functions
|
||||
tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock);
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user