Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
{ id: elecrow-crowpanel-basic-50, arch: esp32s3 },
{ id: guition-jc1060p470ciwy, arch: esp32p4 },
{ id: guition-jc2432w328c, arch: esp32 },
{ id: guition-jc3248w535c, arch: esp32s3 },
{ id: guition-jc8048w550c, arch: esp32s3 },
{ id: heltec-wifi-lora-32-v3, arch: esp32s3 },
{ id: lilygo-tdeck, arch: esp32s3 },
Expand Down
7 changes: 7 additions & 0 deletions Devices/guition-jc3248w535c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)

idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility EspLcdCompat esp_lcd_axs15231b PwmBacklight driver vfs fatfs
)
495 changes: 495 additions & 0 deletions Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.cpp

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bDisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#pragma once

#include <Tactility/hal/spi/Spi.h>

#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/display/DisplayDriver.h>

#include <driver/gpio.h>
#include <esp_lcd_panel_io.h>
#include <esp_lcd_types.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <functional>
#include <lvgl.h>

class Axs15231bDisplay final : public tt::hal::display::DisplayDevice {

public:

class Configuration {

public:

Configuration(
spi_host_device_t spiHostDevice,
gpio_num_t csPin,
gpio_num_t dcPin,
gpio_num_t resetPin,
gpio_num_t tePin,
unsigned int horizontalResolution,
unsigned int verticalResolution,
std::shared_ptr<tt::hal::touch::TouchDevice> touch,
bool swapXY = false,
bool mirrorX = false,
bool mirrorY = false,
bool invertColor = false,
uint32_t bufferSize = 0, // Size in pixel count. 0 means default, which is 1/10 of the screen size,
lcd_rgb_element_order_t rgbElementOrder = LCD_RGB_ELEMENT_ORDER_RGB
) : spiHostDevice(spiHostDevice),
csPin(csPin),
dcPin(dcPin),
resetPin(resetPin),
tePin(tePin),
horizontalResolution(horizontalResolution),
verticalResolution(verticalResolution),
swapXY(swapXY),
mirrorX(mirrorX),
mirrorY(mirrorY),
invertColor(invertColor),
bufferSize(bufferSize),
rgbElementOrder(rgbElementOrder),
touch(std::move(touch))
{
if (this->bufferSize == 0) {
this->bufferSize = horizontalResolution * verticalResolution / 10;
}
}

spi_host_device_t spiHostDevice;
gpio_num_t csPin;
gpio_num_t dcPin;
gpio_num_t resetPin;
gpio_num_t tePin;
unsigned int pixelClockFrequency = 40'000'000; // Hertz
size_t transactionQueueDepth = 10;
unsigned int horizontalResolution;
unsigned int verticalResolution;
bool swapXY;
bool mirrorX;
bool mirrorY;
bool invertColor;
uint32_t bufferSize; // Size in pixel count. 0 means default, which is 1/10 of the screen size
lcd_rgb_element_order_t rgbElementOrder;
std::shared_ptr<tt::hal::touch::TouchDevice> touch;
std::function<void(uint8_t)> _Nullable backlightDutyFunction = nullptr;
};

private:

esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
esp_lcd_panel_handle_t _Nullable panelHandle = nullptr;
lv_display_t* _Nullable lvglDisplay = nullptr;
uint16_t* _Nullable buffer1 = nullptr;
uint16_t* _Nullable buffer2 = nullptr;
uint16_t* _Nullable tempBuf = nullptr;
SemaphoreHandle_t _Nullable teSyncSemaphore = nullptr;
bool teIsrInstalled = false;
bool isrServiceInstalledByUs = false;

std::unique_ptr<Configuration> configuration;
std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable displayDriver;

bool createIoHandle();

bool createPanelHandle();

bool setupTeSync();

void teardownTeSync();

static void IRAM_ATTR teIsrHandler(void* arg);

public:

explicit Axs15231bDisplay(std::unique_ptr<Configuration> inConfiguration);

std::string getName() const override { return "AXS15231B Display"; }

std::string getDescription() const override { return "AXS15231B display"; }

bool start() override;

bool stop() override;

bool supportsLvgl() const override { return true; }

bool startLvgl() override;

bool stopLvgl() override;

lv_display_t* _Nullable getLvglDisplay() const override { return lvglDisplay; }

std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }

void setBacklightDuty(uint8_t backlightDuty) override {
if (configuration->backlightDutyFunction != nullptr) {
configuration->backlightDutyFunction(backlightDuty);
}
}

bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; }

bool supportsDisplayDriver() const override { return true; }

std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable getDisplayDriver() override;

static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, uint8_t *color_map);

static bool onColorTransDone(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx);
};
38 changes: 38 additions & 0 deletions Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bTouch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "Axs15231bTouch.h"

#include <esp_lcd_axs15231b.h>
#include <esp_err.h>

bool Axs15231bTouch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
if (configuration == nullptr) {
return false;
}
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG();
return esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &outHandle) == ESP_OK;
}

bool Axs15231bTouch::createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& configuration, esp_lcd_touch_handle_t& panelHandle) {
return esp_lcd_touch_new_i2c_axs15231b(ioHandle, &configuration, &panelHandle) == ESP_OK;
}

esp_lcd_touch_config_t Axs15231bTouch::createEspLcdTouchConfig() {
return {
.x_max = configuration->xMax,
.y_max = configuration->yMax,
.rst_gpio_num = configuration->pinReset,
.int_gpio_num = configuration->pinInterrupt,
.levels = {
.reset = configuration->pinResetLevel,
.interrupt = configuration->pinInterruptLevel,
},
.flags = {
.swap_xy = configuration->swapXy,
.mirror_x = configuration->mirrorX,
.mirror_y = configuration->mirrorY,
},
.process_coordinates = nullptr,
.interrupt_callback = nullptr,
.user_data = nullptr,
.driver_data = nullptr
};
}
72 changes: 72 additions & 0 deletions Devices/guition-jc3248w535c/Source/Axs15231b/Axs15231bTouch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once

#include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/TactilityCore.h>
#include <driver/i2c.h>
#include <memory>
#include <string>

#include <EspLcdTouch.h>

class Axs15231bTouch final : public EspLcdTouch {

public:

class Configuration {
public:

Configuration(
i2c_port_t port,
uint16_t xMax,
uint16_t yMax,
bool swapXy = false,
bool mirrorX = false,
bool mirrorY = false,
gpio_num_t pinReset = GPIO_NUM_NC,
gpio_num_t pinInterrupt = GPIO_NUM_NC,
unsigned int pinResetLevel = 0,
unsigned int pinInterruptLevel = 0
) : port(port),
xMax(xMax),
yMax(yMax),
swapXy(swapXy),
mirrorX(mirrorX),
mirrorY(mirrorY),
pinReset(pinReset),
pinInterrupt(pinInterrupt),
pinResetLevel(pinResetLevel),
pinInterruptLevel(pinInterruptLevel)
{}

i2c_port_t port;
uint16_t xMax;
uint16_t yMax;
bool swapXy;
bool mirrorX;
bool mirrorY;
gpio_num_t pinReset;
gpio_num_t pinInterrupt;
unsigned int pinResetLevel;
unsigned int pinInterruptLevel;
};

private:

std::unique_ptr<Configuration> configuration;

bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle) override;

bool createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& configuration, esp_lcd_touch_handle_t& panelHandle) override;

esp_lcd_touch_config_t createEspLcdTouchConfig() override;

public:

explicit Axs15231bTouch(std::unique_ptr<Configuration> inConfiguration) : configuration(std::move(inConfiguration)) {
assert(configuration != nullptr);
}

std::string getName() const override { return "AXS15231B Touch"; }

std::string getDescription() const override { return "AXS15231B I2C touch driver"; }
};
104 changes: 104 additions & 0 deletions Devices/guition-jc3248w535c/Source/Configuration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "devices/Display.h"
#include "devices/SdCard.h"

#include <Tactility/hal/Configuration.h>
#include <Tactility/lvgl/LvglSync.h>
#include <PwmBacklight.h>

using namespace tt::hal;

static constexpr int SPI_TRANSFER_SIZE_LIMIT = 320 * 10;

static DeviceVector createDevices() {
return {
createDisplay(),
createSdCard()
};
}

static bool initBoot() {
return driver::pwmbacklight::init(GPIO_NUM_1);
}

extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.createDevices = createDevices,
//I2C Internal - Touch
//I2C External - P3 (JST SH 1.0)/ P4 (JST SH 1.25) headers - GND 3.3V IO17 IO18
.spi {
//Display
spi::Configuration {
.device = SPI2_HOST,
.dma = SPI_DMA_CH_AUTO,
.config = {
.data0_io_num = GPIO_NUM_21,
.data1_io_num = GPIO_NUM_48,
.sclk_io_num = GPIO_NUM_47,
.data2_io_num = GPIO_NUM_40,
.data3_io_num = GPIO_NUM_39,
.data4_io_num = -1,
.data5_io_num = -1,
.data6_io_num = -1,
.data7_io_num = -1,
.data_io_default_level = false,
.max_transfer_sz = SPI_TRANSFER_SIZE_LIMIT,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
},
.initMode = spi::InitMode::ByTactility,
.isMutable = false,
.lock = tt::lvgl::getSyncLock()
},
//SD Card
spi::Configuration {
.device = SPI3_HOST,
.dma = SPI_DMA_CH_AUTO,
.config = {
.mosi_io_num = GPIO_NUM_11,
.miso_io_num = GPIO_NUM_13,
.sclk_io_num = GPIO_NUM_12,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.data4_io_num = -1,
.data5_io_num = -1,
.data6_io_num = -1,
.data7_io_num = -1,
.data_io_default_level = false,
.max_transfer_sz = 8192,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
},
.initMode = spi::InitMode::ByTactility,
.isMutable = false,
.lock = nullptr
}
},
.uart {
//P1 header, JST SH 1.25, 5V / TXD (43) / RXD (44) / GND
uart::Configuration {
.name = "UART0",
.port = UART_NUM_0,
.rxPin = GPIO_NUM_44,
.txPin = GPIO_NUM_43,
.rtsPin = GPIO_NUM_NC,
.ctsPin = GPIO_NUM_NC,
.rxBufferSize = 1024,
.txBufferSize = 1024,
.config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 0,
.source_clk = UART_SCLK_DEFAULT,
.flags = {
.allow_pd = 0,
.backup_before_sleep = 0,
}
}
}
}
};
7 changes: 7 additions & 0 deletions Devices/guition-jc3248w535c/Source/Drivers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern "C" {

extern void register_device_drivers() {
/* NO-OP */
}

}
Loading