Created Drivers folder with ILI934x subproject (#209)

Refactored all existing boards to re-use the ILI934x driver code.
This commit is contained in:
Ken Van Hoeylandt
2025-02-08 18:54:09 +01:00
committed by GitHub
parent 8ccba15c25
commit c74006f8b6
27 changed files with 355 additions and 610 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source" "Source/hal" "Source/Axp2101" "Source/Aw9523"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 esp_lcd_touch_ft5x06 driver vfs fatfs
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 ILI934x esp_lcd_touch_ft5x06 driver vfs fatfs
)
-2
View File
@@ -2,8 +2,6 @@
Reference implementations:
- [ESP-BSP](https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_s3)
- [M5Unified](https://github.com/m5stack/M5Unified)
- [M5GFX](https://github.com/m5stack/M5GFX)
Docs:
- [M5Stack.com](https://docs.m5stack.com/en/core/CoreS3)
+1 -2
View File
@@ -1,4 +1,3 @@
#include "hal/CoreS3DisplayConstants.h"
#include "Axp2101/Axp2101.h"
#include "Aw9523/Aw9523.h"
@@ -6,7 +5,7 @@
#include <Tactility/kernel/Kernel.h>
#include <driver/i2c.h>
#define TAG "core2"
#define TAG "cores3"
std::shared_ptr<Axp2101> axp2101;
std::shared_ptr<Aw9523> aw9523;
+19 -173
View File
@@ -1,179 +1,16 @@
#include "CoreS3Display.h"
#include "CoreS3DisplayConstants.h"
#include <Tactility/Log.h>
#include <Tactility/hal/i2c/I2c.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 "CoreS3Constants.h"
#include "CoreS3Touch.h"
#define TAG "cores3_display"
#include <Tactility/Log.h>
#include <Tactility/hal/i2c/I2c.h>
bool CoreS3Display::start() {
TT_LOG_I(TAG, "Starting");
#include <Ili934xDisplay.h>
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,
.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 = 0,
.lsb_first = 0,
.cs_high_active = 0
}
};
#define TAG "cores3"
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 = false,
.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 = true,
.buff_spiram = false,
.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() {
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) {
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
if (!tt::hal::i2c::masterWriteRegister(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) { // Sets DLD01
@@ -181,10 +18,19 @@ void CoreS3Display::setBacklightDuty(uint8_t backlightDuty) {
}
}
std::shared_ptr<tt::hal::Touch> _Nullable CoreS3Display::createTouch() {
return std::make_shared<CoreS3Touch>();
}
std::shared_ptr<tt::hal::Display> createDisplay() {
return std::make_shared<CoreS3Display>();
auto touch = std::make_shared<CoreS3Touch>();
auto configuration = std::make_unique<Ili934xDisplay::Configuration>(
SPI3_HOST,
GPIO_NUM_3,
GPIO_NUM_35,
320,
240,
touch
);
configuration->backlightDutyFunction = ::setBacklightDuty;
return std::make_shared<Ili934xDisplay>(std::move(configuration));
}
@@ -1,37 +1,5 @@
#pragma once
#include <lvgl.h>
#include <Tactility/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:
std::string getName() const final { return "ILI9342C"; }
std::string getDescription() const final { return "Display (ILI9342C with an ILI9341 driver)"; }
bool start() override;
bool stop() override;
std::shared_ptr<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; }
};
std::shared_ptr<tt::hal::Display> createDisplay();
@@ -1,7 +1,5 @@
#include "CoreS3Power.h"
#define TAG "core2_power"
bool CoreS3Power::supportsMetric(MetricType type) const {
switch (type) {
using enum MetricType;
@@ -6,10 +6,10 @@
#include "esp_lcd_touch.h"
#include "esp_lvgl_port.h"
#define TAG "cores3_touch"
#define TAG "cores3"
bool CoreS3Touch::start(lv_display_t* display) {
TT_LOG_I(TAG, "Starting");
TT_LOG_I(TAG, "Touch start");
esp_lcd_panel_io_i2c_config_t touch_io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
@@ -39,7 +39,7 @@ bool CoreS3Touch::start(lv_display_t* display) {
};
if (esp_lcd_touch_new_i2c_ft5x06(ioHandle, &config, &touchHandle) != ESP_OK) {
TT_LOG_E(TAG, "Driver init failed");
TT_LOG_E(TAG, "Touch driver init failed");
cleanup();
return false;
}
@@ -51,7 +51,7 @@ bool CoreS3Touch::start(lv_display_t* display) {
deviceHandle = lvgl_port_add_touch(&touch_cfg);
if (deviceHandle == nullptr) {
TT_LOG_E(TAG, "Adding touch failed");
TT_LOG_E(TAG, "Touch lvgl port failure");
cleanup();
return false;
}