Driver improvements (#226)

- Created driver subprojects: `FT5x06`, `FT6x36`, `CST816S`.
- Refactored existing projects to use new drivers.
- Improve `PwmBacklight` driver: expose frequency, channel id and timer id
- Update `build-and-release-all.sh` for recent board addition
This commit is contained in:
Ken Van Hoeylandt
2025-02-20 22:41:56 +01:00
committed by GitHub
parent 6e8fbae62b
commit 933bc5fb97
49 changed files with 429 additions and 413 deletions
@@ -1,25 +1,35 @@
#include "CoreS3Display.h"
#include "CoreS3Constants.h"
#include "CoreS3Touch.h"
#include <Ft5x06Touch.h>
#include <Ili934xDisplay.h>
#include <Tactility/Log.h>
#include <Tactility/hal/i2c/I2c.h>
#include <Ili934xDisplay.h>
#define TAG "cores3"
static void 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
// TODO: Refactor to use Axp2102 driver subproject. Reference: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
if (!tt::hal::i2c::masterWriteRegister(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) { // Sets DLD01
TT_LOG_E(TAG, "Failed to set display backlight voltage");
}
}
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
// Note for future changes: Reset pin is 48 and interrupt pin is 47
auto configuration = std::make_unique<Ft5x06Touch::Configuration>(
I2C_NUM_0,
320,
240
);
return std::make_shared<Ft5x06Touch>(std::move(configuration));
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
auto touch = std::make_shared<CoreS3Touch>();
auto touch = createTouch();
auto configuration = std::make_unique<Ili934xDisplay::Configuration>(
SPI3_HOST,
@@ -27,7 +37,11 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
GPIO_NUM_35,
320,
240,
touch
touch,
false,
false,
false,
true
);
configuration->backlightDutyFunction = ::setBacklightDuty;
@@ -6,6 +6,5 @@
#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)
@@ -1,83 +0,0 @@
#include "CoreS3Touch.h"
#include <Tactility/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"
bool CoreS3Touch::start(lv_display_t* display) {
TT_LOG_I(TAG, "Touch start");
esp_lcd_panel_io_i2c_config_t touch_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
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, "Touch driver init failed");
cleanup();
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, "Touch lvgl port failure");
cleanup();
return false;
}
TT_LOG_I(TAG, "Finished");
return true;
}
bool CoreS3Touch::stop() {
cleanup();
return true;
}
void CoreS3Touch::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;
}
}
@@ -1,25 +0,0 @@
#pragma once
#include "Tactility/hal/touch/TouchDevice.h"
#include <Tactility/TactilityCore.h>
#include <esp_lcd_touch.h>
class CoreS3Touch : public tt::hal::touch::TouchDevice {
private:
esp_lcd_panel_io_handle_t ioHandle = nullptr;
esp_lcd_touch_handle_t touchHandle = nullptr;
lv_indev_t* _Nullable deviceHandle = nullptr;
void cleanup();
public:
std::string getName() const final { return "FT6336U"; }
std::string getDescription() const final { return "I2C touch driver"; }
bool start(lv_display_t* display) override;
bool stop() override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
};