CoreS3 refactored & remove M5 libraries (#143)

Remove dependencies M5Unified and M5GFX because:
- Sometimes the release doesn't even compile
- The amount of functions is too close to the limit (I recently had to remove some code/dependency to be able to make a build at all)
- Graphics performance issue since last update
- Touch screen performance issues (not perfect yet, but better)
- Compatibility issues with Tactility SPI/I2C versus M5Unified/M5GFX variants.
This commit is contained in:
Ken Van Hoeylandt
2025-01-02 00:19:24 +01:00
committed by GitHub
parent 3214923425
commit 737c0f7447
37 changed files with 724 additions and 325 deletions
@@ -0,0 +1,74 @@
#include "Axp2101.h"
#include "Log.h"
bool Axp2101::readRegister12(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x0F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool Axp2101::readRegister14(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x3F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool Axp2101::readRegister16(uint8_t reg, uint16_t& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = data[0] << 8 | data[1];
return true;
} else {
return false;
}
}
bool Axp2101::readRegister8(uint8_t reg, uint8_t& result) const {
return tt::hal::i2c::masterWriteRead(port, DEFAULT_ADDRESS, &reg, 1, &result, 1, DEFAULT_TIMEOUT);
}
bool Axp2101::writeRegister8(uint8_t reg, uint8_t value) const {
return tt::hal::i2c::masterWrite(port, DEFAULT_ADDRESS, reg, &value, 1, DEFAULT_TIMEOUT);
}
bool Axp2101::getBatteryVoltage(float& vbatMillis) const {
return readRegister14(0x34, vbatMillis);
}
bool Axp2101::getChargeStatus(ChargeStatus& status) const {
uint8_t value;
if (readRegister8(0x01, value)) {
value = (value >> 5) & 0b11;
status = (value == 1) ? CHARGE_STATUS_CHARGING : ((value == 2) ? CHARGE_STATUS_DISCHARGING : CHARGE_STATUS_STANDBY);
return true;
} else {
return false;
}
}
bool Axp2101::isChargingEnabled(bool& enabled) const {
uint8_t value;
if (readRegister8(0x18, value)) {
enabled = value & 0b10;
return true;
} else {
return false;
}
}
bool Axp2101::setChargingEnabled(bool enabled) const {
uint8_t value;
if (readRegister8(0x18, value)) {
return writeRegister8(0x18, (value & 0xFD) | (enabled << 1));
} else {
return false;
}
}
@@ -0,0 +1,37 @@
#pragma once
#include "hal/i2c/I2c.h"
/**
* References:
* - https://github.com/m5stack/M5Unified/blob/master/src/utility/AXP2101_Class.cpp
* - http://file.whycan.com/files/members/6736/AXP2101_Datasheet_V1.0_en_3832.pdf
*/
class Axp2101 {
i2c_port_t port;
static constexpr uint8_t DEFAULT_ADDRESS = 0x34;
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
bool readRegister8(uint8_t reg, uint8_t& result) const;
bool writeRegister8(uint8_t reg, uint8_t value) const;
bool readRegister12(uint8_t reg, float& out) const;
bool readRegister14(uint8_t reg, float& out) const;
bool readRegister16(uint8_t reg, uint16_t& out) const;
public:
enum ChargeStatus {
CHARGE_STATUS_CHARGING = 0b01,
CHARGE_STATUS_DISCHARGING = 0b10,
CHARGE_STATUS_STANDBY = 0b00
};
Axp2101(i2c_port_t port) : port(port) {}
bool getBatteryVoltage(float& vbatMillis) const;
bool getChargeStatus(ChargeStatus& status) const;
bool isChargingEnabled(bool& enabled) const;
bool setChargingEnabled(bool enabled) const;
};
@@ -0,0 +1,4 @@
#pragma once
#define AXP2101_ADDRESS 0x34
#define AW9523_ADDRESS 0x58
+104
View File
@@ -0,0 +1,104 @@
#include <driver/i2c.h>
#include <driver/spi_master.h>
#include <intr_types.h>
#include "Log.h"
#include "hal/CoreS3DisplayConstants.h"
#include "hal/i2c/I2c.h"
#include "CoreS3Constants.h"
#define TAG "core2"
#define CORES3_SPI2_PIN_SCLK GPIO_NUM_36
#define CORES3_SPI2_PIN_MOSI GPIO_NUM_37
#define CORES3_SPI2_PIN_MISO GPIO_NUM_35
/**
* For details see https://github.com/espressif/esp-bsp/blob/master/bsp/m5stack_core_s3/m5stack_core_s3.c
*/
static bool initSpi3() {
TT_LOG_I(TAG, LOG_MESSAGE_SPI_INIT_START_FMT, SPI3_HOST);
const spi_bus_config_t bus_config = {
.mosi_io_num = CORES3_SPI2_PIN_MOSI,
.miso_io_num = CORES3_SPI2_PIN_MISO,
.sclk_io_num = CORES3_SPI2_PIN_SCLK,
.data2_io_num = GPIO_NUM_NC,
.data3_io_num = GPIO_NUM_NC,
.data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC,
.data7_io_num = GPIO_NUM_NC,
.max_transfer_sz = CORES3_LCD_DRAW_BUFFER_SIZE,
.flags = 0,
.isr_cpu_id = INTR_CPU_ID_AUTO,
.intr_flags = 0
};
if (spi_bus_initialize(SPI3_HOST, &bus_config, SPI_DMA_CH_AUTO) != ESP_OK) {
TT_LOG_E(TAG, LOG_MESSAGE_SPI_INIT_FAILED_FMT, SPI3_HOST);
return false;
}
return true;
}
/**
* For details see https://github.com/espressif/esp-bsp/blob/master/bsp/m5stack_core_s3/m5stack_core_s3.c
*/
bool initGpioExpander() {
TT_LOG_I(TAG, "Init AW9523 GPIO expander");
uint8_t aw9523_P0 = 0b10;
uint8_t aw9523_P1 = 0b10100000;
// Enable LCD
aw9523_P1 |= (1 << 1);
// Enable touch
aw9523_P0 |= (1);
// SD card
aw9523_P0 |= (1 << 4);
if (tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x02, &aw9523_P0, 1, 1000) != ESP_OK) {
TT_LOG_E(TAG, "Failed to enable LCD");
return false;
}
if (tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x03, &aw9523_P1, 1, 1000) != ESP_OK) {
TT_LOG_E(TAG, "Failed to enable touch");
return false;
}
return true;
}
bool initPowerControl() {
TT_LOG_I(TAG, "Init power control");
uint8_t sdcard_3v3 = 0b00011100;
// TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62
if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x95, &sdcard_3v3, 1, 1000) != ESP_OK) {
TT_LOG_E(TAG, "Failed to enable SD card");
return false;
}
// TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
uint8_t axp_dld01_enable = 0xBF; // For backlight
if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x90, &axp_dld01_enable, 1, 1000) != ESP_OK) {
TT_LOG_E(TAG, "Failed to enable display backlight");
return false;
}
// TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62
uint8_t axp_dld01_voltage = 0b00011000; // For backlight
if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &axp_dld01_voltage, 1, 1000) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set display backlight voltage");
return false;
}
return true;
}
bool initBoot() {
TT_LOG_I(TAG, "initBoot");
return initPowerControl() && initGpioExpander() && initSpi3();
}
+3
View File
@@ -0,0 +1,3 @@
#pragma once
bool initBoot();
+31
View File
@@ -0,0 +1,31 @@
#include "Log.h"
#include "Thread.h"
#include "lvgl/LvglSync.h"
#include "esp_lvgl_port.h"
#define TAG "core2"
// LVGL
// The minimum task stack seems to be about 3500, but that crashes the wifi app in some scenarios
// At 4000, it crashes when the fps renderer is available
#define CORE2_LVGL_TASK_STACK_DEPTH 8192
bool initLvgl() {
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = tt::THREAD_PRIORITY_RENDER,
.task_stack = CORE2_LVGL_TASK_STACK_DEPTH,
.task_affinity = -1, // core pinning
.task_max_sleep_ms = 500,
.timer_period_ms = 5
};
TT_LOG_D(TAG, "LVGL port init");
if (lvgl_port_init(&lvgl_cfg) != ESP_OK) {
TT_LOG_E(TAG, "LVGL port init failed");
return false;
}
tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock);
return true;
}
+3
View File
@@ -0,0 +1,3 @@
#pragma once
bool initLvgl();
+11 -7
View File
@@ -1,17 +1,21 @@
#include "M5stackCoreS3.h"
#include "M5stackShared.h"
#include "InitBoot.h"
#include "InitLvgl.h"
#include "hal/CoreS3Display.h"
#include "hal/CoreS3SdCard.h"
#include "hal/CoreS3Power.h"
const tt::hal::Configuration m5stack_cores3 = {
.initBoot = m5stack_bootstrap,
.initLvgl = m5stack_lvgl_init,
.initBoot = initBoot,
.initLvgl = initLvgl,
.createDisplay = createDisplay,
.sdcard = createM5SdCard(),
.power = m5stack_get_power,
.sdcard = createSdCard(),
.power = createPower,
.i2c = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByExternal,
.initMode = tt::hal::i2c::InitByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@@ -29,7 +33,7 @@ const tt::hal::Configuration m5stack_cores3 = {
tt::hal::i2c::Configuration {
.name = "External", // Grove
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByExternal,
.initMode = tt::hal::i2c::InitByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@@ -0,0 +1,189 @@
#include "CoreS3Display.h"
#include "CoreS3DisplayConstants.h"
#include "Log.h"
#include <TactilityCore.h>
#include <esp_lcd_panel_commands.h>
#include "driver/gpio.h"
#include "esp_err.h"
#include "esp_lcd_ili9341.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lvgl_port.h"
#include "hal/i2c/I2c.h"
#include "CoreS3Constants.h"
#include "CoreS3Touch.h"
#define TAG "cores3_display"
bool CoreS3Display::start() {
TT_LOG_I(TAG, "Starting");
const esp_lcd_panel_io_spi_config_t panel_io_config = {
.cs_gpio_num = CORES3_LCD_PIN_CS,
.dc_gpio_num = CORES3_LCD_PIN_DC,
.spi_mode = 0,
.pclk_hz = 40000000,
.trans_queue_depth = 10,
.on_color_trans_done = nullptr,
.user_ctx = nullptr,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.flags = {
.dc_high_on_cmd = 0,
.dc_low_on_data = 0,
.dc_low_on_param = 0,
.octal_mode = 0,
.quad_mode = 0,
.sio_mode = 0,
.lsb_first = 0,
.cs_high_active = 0
}
};
if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)CORES3_LCD_SPI_HOST, &panel_io_config, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
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_LITTLE,
.bits_per_pixel = CORES3_LCD_BITS_PER_PIXEL,
.flags = {
.reset_active_high = false
},
.vendor_config = nullptr
};
if (esp_lcd_new_panel_ili9341(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create ili9341");
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_mirror(panelHandle, false, false) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to mirror");
return false;
}
if (esp_lcd_panel_invert_color(panelHandle, true) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set panel to invert");
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 = CORES3_LCD_DRAW_BUFFER_SIZE,
.double_buffer = true,
.trans_size = 0,
.hres = CORES3_LCD_HORIZONTAL_RESOLUTION,
.vres = CORES3_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 = true,
.full_refresh = false,
.direct_mode = false
}
};
displayHandle = lvgl_port_add_disp(&disp_cfg);
TT_LOG_I(TAG, "Finished");
return displayHandle != nullptr;
}
bool CoreS3Display::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;
}
/**
* Note:
* The datasheet implies this should work, but it doesn't:
* https://www.digikey.com/htmldatasheets/production/1640716/0/0/1/ILI9341-Datasheet.pdf
*
* This repo claims it only has 1 curve:
* https://github.com/brucemack/hello-ili9341
*
* I'm leaving it in as I'm not sure if it's just my hardware that's problematic.
*/
void CoreS3Display::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");
}
}
void CoreS3Display::setBacklightDuty(uint8_t backlightDuty) {
const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark
// TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
if (tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set display backlight voltage");
}
}
tt::hal::Touch* _Nullable CoreS3Display::createTouch() {
return static_cast<tt::hal::Touch*>(new CoreS3Touch());
}
tt::hal::Display* createDisplay() {
return static_cast<tt::hal::Display*>(new CoreS3Display());
}
@@ -0,0 +1,35 @@
#pragma once
#include "lvgl.h"
#include "hal/Display.h"
#include <esp_lcd_types.h>
extern lv_disp_t* displayHandle;
class CoreS3Display : 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;
public:
bool start() override;
bool stop() override;
tt::hal::Touch* _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; }
};
tt::hal::Display* createDisplay();
@@ -0,0 +1,11 @@
#pragma once
// Display
#define CORES3_LCD_SPI_HOST SPI3_HOST
#define CORES3_LCD_PIN_CS GPIO_NUM_3
#define CORES3_LCD_PIN_DC GPIO_NUM_35
#define CORES3_LCD_HORIZONTAL_RESOLUTION 320
#define CORES3_LCD_VERTICAL_RESOLUTION 240
#define CORES3_LCD_BITS_PER_PIXEL 16
#define CORES3_LCD_DRAW_BUFFER_HEIGHT (CORES3_LCD_VERTICAL_RESOLUTION / 10)
#define CORES3_LCD_DRAW_BUFFER_SIZE (CORES3_LCD_HORIZONTAL_RESOLUTION * CORES3_LCD_DRAW_BUFFER_HEIGHT * (CORES3_LCD_BITS_PER_PIXEL / 8))
@@ -0,0 +1,83 @@
#include "CoreS3Power.h"
#include "TactilityCore.h"
#define TAG "core2_power"
bool CoreS3Power::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case IS_CHARGING:
case CHARGE_LEVEL:
return true;
case CURRENT:
return false;
}
return false; // Safety guard for when new enum values are introduced
}
bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE: {
float milliVolt;
if (axpDevice.getBatteryVoltage(milliVolt)) {
data.valueAsUint32 = (uint32_t)milliVolt;
return true;
} else {
return false;
}
}
case CHARGE_LEVEL: {
float vbatMillis;
if (axpDevice.getBatteryVoltage(vbatMillis)) {
float vbat = vbatMillis / 1000.f;
float max_voltage = 4.20f;
float min_voltage = 2.69f; // From M5Unified
if (vbat > 2.69f) {
float charge_factor = (vbat - min_voltage) / (max_voltage - min_voltage);
data.valueAsUint8 = (uint8_t)(charge_factor * 100.f);
} else {
data.valueAsUint8 = 0;
}
return true;
} else {
return false;
}
}
case IS_CHARGING: {
Axp2101::ChargeStatus status;
if (axpDevice.getChargeStatus(status)) {
data.valueAsBool = (status == Axp2101::CHARGE_STATUS_CHARGING);
return true;
} else {
return false;
}
}
case CURRENT:
return false;
}
return false; // Safety guard for when new enum values are introduced
}
bool CoreS3Power::isAllowedToCharge() const {
bool enabled;
if (axpDevice.isChargingEnabled(enabled)) {
return enabled;
} else {
return false;
}
}
void CoreS3Power::setAllowedToCharge(bool canCharge) {
axpDevice.setChargingEnabled(canCharge);
}
static std::shared_ptr<Power> power;
std::shared_ptr<Power> createPower() {
if (power == nullptr) {
power = std::make_shared<CoreS3Power>();
}
return power;
}
@@ -0,0 +1,26 @@
#pragma once
#include "hal/Power.h"
#include "Axp2101/Axp2101.h"
#include <memory>
using namespace tt::hal;
class CoreS3Power : public Power {
Axp2101 axpDevice = Axp2101(I2C_NUM_0);
public:
CoreS3Power() = default;
~CoreS3Power() override = default;
bool supportsMetric(MetricType type) const override;
bool getMetric(Power::MetricType type, Power::MetricData& data) override;
bool supportsChargeControl() const override { return true; }
bool isAllowedToCharge() const override;
void setAllowedToCharge(bool canCharge) override;
};
std::shared_ptr<Power> createPower();
@@ -0,0 +1,32 @@
#include "CoreS3SdCard.h"
#include "lvgl/LvglSync.h"
#include "hal/SpiSdCard.h"
#include <esp_vfs_fat.h>
#define CORES3_SDCARD_SPI_FREQUENCY 800000U
#define CORES3_SDCARD_PIN_CS GPIO_NUM_4
#define CORES3_LCD_PIN_CS GPIO_NUM_3
std::shared_ptr<SdCard> createSdCard() {
auto* configuration = new tt::hal::SpiSdCard::Config(
CORES3_SDCARD_SPI_FREQUENCY,
CORES3_SDCARD_PIN_CS,
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
tt::lvgl::getLvglSyncLockable(),
{
CORES3_LCD_PIN_CS
},
SPI3_HOST
);
auto* sdcard = (SdCard*) new SpiSdCard(
std::unique_ptr<SpiSdCard::Config>(configuration)
);
return std::shared_ptr<SdCard>(sdcard);
}
@@ -0,0 +1,7 @@
#pragma once
#include "hal/SdCard.h"
using namespace tt::hal;
std::shared_ptr<SdCard> createSdCard();
@@ -0,0 +1,73 @@
#include "CoreS3Touch.h"
#include "Log.h"
#include "driver/i2c.h"
#include "esp_err.h"
#include "esp_lcd_touch_ft5x06.h"
#include "esp_lcd_touch.h"
#include "esp_lvgl_port.h"
#define TAG "cores3_touch"
bool CoreS3Touch::start(lv_display_t* display) {
TT_LOG_I(TAG, "Starting");
esp_lcd_panel_io_handle_t ioHandle;
esp_lcd_touch_handle_t touchHandle;
esp_lcd_panel_io_i2c_config_t touch_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_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(I2C_NUM_0, &touch_io_config, &ioHandle);
/*
if (esp_lcd_new_panel_io_i2c(I2C_NUM_0, &touch_io_config, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Touch I2C IO init failed");
return false;
}
*/
esp_lcd_touch_config_t config = {
.x_max = 320,
.y_max = 240,
.rst_gpio_num = GPIO_NUM_NC,
.int_gpio_num = GPIO_NUM_NC,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.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, "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 CoreS3Touch::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 CoreS3Touch : 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; }
};