Created Drivers folder with ILI934x subproject (#209)
Refactored all existing boards to re-use the ILI934x driver code.
This commit is contained in:
committed by
GitHub
parent
8ccba15c25
commit
c74006f8b6
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source" "Source/hal" "Source/ft6x36" "Source/axp192"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 driver vfs fatfs
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd ILI934x driver vfs fatfs
|
||||
)
|
||||
|
||||
@@ -4,8 +4,6 @@ This board implementation concerns the original Core2 hardware and **not** the v
|
||||
|
||||
Reference implementations:
|
||||
- [ESP-BSP](https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core_2)
|
||||
- [M5Unified](https://github.com/m5stack/M5Unified)
|
||||
- [M5GFX](https://github.com/m5stack/M5GFX)
|
||||
|
||||
Docs:
|
||||
- [M5Stack.com](https://docs.m5stack.com/en/core/Core2)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "M5stackCore2.h"
|
||||
#include "InitBoot.h"
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
#include "hal/Core2Display.h"
|
||||
#include "hal/Core2DisplayConstants.h"
|
||||
#include "hal/Core2Power.h"
|
||||
#include "hal/Core2SdCard.h"
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
#define CORE2_SPI_TRANSFER_SIZE_LIMIT (CORE2_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8)
|
||||
|
||||
extern const tt::hal::Configuration m5stack_core2 = {
|
||||
|
||||
@@ -1,162 +1,19 @@
|
||||
#include "Core2Display.h"
|
||||
#include "Core2DisplayConstants.h"
|
||||
#include "Core2Touch.h"
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_lcd_panel_commands.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_lcd_ili9341.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#define TAG "core2_display"
|
||||
|
||||
bool Core2Display::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
|
||||
const esp_lcd_panel_io_spi_config_t panel_io_config = ILI9341_PANEL_IO_SPI_CONFIG(
|
||||
CORE2_LCD_PIN_CS,
|
||||
CORE2_LCD_PIN_DC,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)CORE2_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 = CORE2_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 = CORE2_LCD_DRAW_BUFFER_SIZE,
|
||||
.double_buffer = false,
|
||||
.trans_size = 0,
|
||||
.hres = CORE2_LCD_HORIZONTAL_RESOLUTION,
|
||||
.vres = CORE2_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 Core2Display::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 Core2Display::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::Touch> _Nullable Core2Display::createTouch() {
|
||||
return std::make_shared<Core2Touch>();
|
||||
}
|
||||
#include <Ili934xDisplay.h>
|
||||
|
||||
std::shared_ptr<tt::hal::Display> createDisplay() {
|
||||
return std::make_shared<Core2Display>();
|
||||
auto touch = std::make_shared<Core2Touch>();
|
||||
|
||||
auto configuration = std::make_unique<Ili934xDisplay::Configuration>(
|
||||
CORE2_LCD_SPI_HOST,
|
||||
CORE2_LCD_PIN_CS,
|
||||
CORE2_LCD_PIN_DC,
|
||||
CORE2_LCD_HORIZONTAL_RESOLUTION,
|
||||
CORE2_LCD_VERTICAL_RESOLUTION,
|
||||
touch
|
||||
);
|
||||
|
||||
return std::make_shared<Ili934xDisplay>(std::move(configuration));
|
||||
}
|
||||
|
||||
@@ -1,37 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "lvgl.h"
|
||||
#include <Tactility/hal/Display.h>
|
||||
#include <memory>
|
||||
|
||||
#include <esp_lcd_types.h>
|
||||
|
||||
extern lv_disp_t* displayHandle;
|
||||
|
||||
class Core2Display : 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;
|
||||
|
||||
bool supportsBacklightDuty() const override { return false; }
|
||||
|
||||
void setGammaCurve(uint8_t index) override;
|
||||
uint8_t getGammaCurveCount() const override { return 4; };
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
};
|
||||
#define CORE2_LCD_SPI_HOST SPI2_HOST
|
||||
#define CORE2_LCD_PIN_CS GPIO_NUM_5
|
||||
#define CORE2_LCD_PIN_DC GPIO_NUM_15
|
||||
#define CORE2_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define CORE2_LCD_VERTICAL_RESOLUTION 240
|
||||
#define CORE2_LCD_DRAW_BUFFER_HEIGHT (CORE2_LCD_VERTICAL_RESOLUTION / 10)
|
||||
#define CORE2_LCD_DRAW_BUFFER_SIZE (CORE2_LCD_HORIZONTAL_RESOLUTION * CORE2_LCD_DRAW_BUFFER_HEIGHT)
|
||||
|
||||
std::shared_ptr<tt::hal::Display> createDisplay();
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Display
|
||||
#define CORE2_LCD_SPI_HOST SPI2_HOST
|
||||
#define CORE2_LCD_PIN_CS GPIO_NUM_5
|
||||
#define CORE2_LCD_PIN_DC GPIO_NUM_15
|
||||
#define CORE2_LCD_HORIZONTAL_RESOLUTION 320
|
||||
#define CORE2_LCD_VERTICAL_RESOLUTION 240
|
||||
#define CORE2_LCD_BITS_PER_PIXEL 16
|
||||
#define CORE2_LCD_DRAW_BUFFER_HEIGHT (CORE2_LCD_VERTICAL_RESOLUTION / 10)
|
||||
#define CORE2_LCD_DRAW_BUFFER_SIZE (CORE2_LCD_HORIZONTAL_RESOLUTION * CORE2_LCD_DRAW_BUFFER_HEIGHT)
|
||||
Reference in New Issue
Block a user