mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-21 19:05:06 +00:00
Board refactor and driver fix
This commit is contained in:
parent
3b0f2354a0
commit
1de78a6dc6
@ -18,7 +18,6 @@ static tt::hal::DeviceVector createDevices() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const tt::hal::Configuration cyd_2432s024c_config = {
|
const tt::hal::Configuration cyd_2432s024c_config = {
|
||||||
.initBoot = initBoot,
|
.initBoot = initBoot,
|
||||||
.createDevices = createDevices,
|
.createDevices = createDevices,
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
#include "CYD2432S028R.h"
|
#include "CYD2432S028R.h"
|
||||||
#include "hal/YellowDisplay.h"
|
#include "devices/Display.h"
|
||||||
#include "hal/YellowConstants.h"
|
#include "devices/SdCard.h"
|
||||||
#include "hal/YellowSdCard.h"
|
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
#include <PwmBacklight.h>
|
#include <PwmBacklight.h>
|
||||||
#include <Tactility/hal/Configuration.h>
|
#include <Tactility/hal/Configuration.h>
|
||||||
|
|
||||||
|
// SPI Transfer
|
||||||
|
#define CYD_SPI_TRANSFER_SIZE_LIMIT (CYD2432S028R_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8)
|
||||||
|
// Display backlight (PWM)
|
||||||
|
#define CYD2432S028R_LCD_PIN_BACKLIGHT GPIO_NUM_21
|
||||||
|
|
||||||
using namespace tt::hal;
|
using namespace tt::hal;
|
||||||
|
|
||||||
bool initBoot() {
|
static bool initBoot() {
|
||||||
//Set the RGB Led Pins to output and turn them off
|
//Set the RGB Led Pins to output and turn them off
|
||||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red
|
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT)); //Red
|
||||||
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green
|
ESP_ERROR_CHECK(gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT)); //Green
|
||||||
@ -22,16 +26,21 @@ bool initBoot() {
|
|||||||
return driver::pwmbacklight::init(CYD2432S028R_LCD_PIN_BACKLIGHT);
|
return driver::pwmbacklight::init(CYD2432S028R_LCD_PIN_BACKLIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DeviceVector createDevices() {
|
||||||
|
return {
|
||||||
|
createDisplay(),
|
||||||
|
createSdCard()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const Configuration cyd_2432s028r_config = {
|
const Configuration cyd_2432s028r_config = {
|
||||||
.initBoot = initBoot,
|
.initBoot = initBoot,
|
||||||
.createDisplay = createDisplay,
|
.createDevices = createDevices,
|
||||||
.sdcard = createYellowSdCard(),
|
|
||||||
.power = nullptr,
|
|
||||||
.i2c = {},
|
.i2c = {},
|
||||||
.spi {
|
.spi {
|
||||||
//Display
|
//Display
|
||||||
spi::Configuration {
|
spi::Configuration {
|
||||||
.device = CYD2432S028R_LCD_SPI_HOST,
|
.device = SPI2_HOST,
|
||||||
.dma = SPI_DMA_CH_AUTO,
|
.dma = SPI_DMA_CH_AUTO,
|
||||||
.config = {
|
.config = {
|
||||||
.mosi_io_num = GPIO_NUM_13,
|
.mosi_io_num = GPIO_NUM_13,
|
||||||
@ -56,7 +65,7 @@ const Configuration cyd_2432s028r_config = {
|
|||||||
|
|
||||||
// SDCard
|
// SDCard
|
||||||
spi::Configuration {
|
spi::Configuration {
|
||||||
.device = CYD2432S028R_SDCARD_SPI_HOST,
|
.device = SPI3_HOST,
|
||||||
.dma = SPI_DMA_CH_AUTO,
|
.dma = SPI_DMA_CH_AUTO,
|
||||||
.config = {
|
.config = {
|
||||||
.mosi_io_num = GPIO_NUM_23,
|
.mosi_io_num = GPIO_NUM_23,
|
||||||
@ -74,7 +83,7 @@ const Configuration cyd_2432s028r_config = {
|
|||||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||||
.intr_flags = 0
|
.intr_flags = 0
|
||||||
},
|
},
|
||||||
.initMode = tt::hal::spi::InitMode::ByTactility,
|
.initMode = spi::InitMode::ByTactility,
|
||||||
.isMutable = false,
|
.isMutable = false,
|
||||||
.lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display
|
.lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,13 +1,9 @@
|
|||||||
#include "YellowDisplay.h"
|
#include "Display.h"
|
||||||
#include "Xpt2046SoftSpi.h"
|
#include "Xpt2046SoftSpi.h"
|
||||||
#include "YellowConstants.h"
|
|
||||||
#include <Ili934xDisplay.h>
|
#include <Ili934xDisplay.h>
|
||||||
#include <PwmBacklight.h>
|
#include <PwmBacklight.h>
|
||||||
|
|
||||||
static const char* TAG = "YellowDisplay";
|
constexpr auto* TAG = "CYD";
|
||||||
|
|
||||||
// Global to hold reference (only needed if calling stop() later)
|
|
||||||
static std::unique_ptr<Xpt2046SoftSpi> touch;
|
|
||||||
|
|
||||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||||
auto configuration = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
auto configuration = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
||||||
@ -23,7 +19,7 @@ static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Allocate the driver
|
// Allocate the driver
|
||||||
touch = std::make_unique<Xpt2046SoftSpi>(std::move(configuration));
|
auto touch = std::make_shared<Xpt2046SoftSpi>(std::move(configuration));
|
||||||
|
|
||||||
// Start the driver
|
// Start the driver
|
||||||
if (!touch->start()) {
|
if (!touch->start()) {
|
||||||
@ -31,9 +27,7 @@ static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::shared_ptr<tt::hal::touch::TouchDevice>(touch.get(), [](tt::hal::touch::TouchDevice*) {
|
return touch;
|
||||||
// No delete needed; `touch` is managed above
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Display backlight (PWM)
|
#include "Tactility/hal/display/DisplayDevice.h"
|
||||||
#define CYD2432S028R_LCD_PIN_BACKLIGHT GPIO_NUM_21
|
#include <memory>
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
#define CYD2432S028R_LCD_SPI_HOST SPI2_HOST
|
#define CYD2432S028R_LCD_SPI_HOST SPI2_HOST
|
||||||
@ -12,10 +12,6 @@
|
|||||||
#define CYD2432S028R_LCD_PIN_CS GPIO_NUM_15
|
#define CYD2432S028R_LCD_PIN_CS GPIO_NUM_15
|
||||||
#define CYD2432S028R_LCD_PIN_DC GPIO_NUM_2
|
#define CYD2432S028R_LCD_PIN_DC GPIO_NUM_2
|
||||||
|
|
||||||
// Touch
|
|
||||||
#define CYD2432S028R_TOUCH_SPI_HOST SPI3_HOST
|
|
||||||
#define CYD2432S028R_TOUCH_PIN_CS GPIO_NUM_33
|
|
||||||
|
|
||||||
// Touch (Software SPI)
|
// Touch (Software SPI)
|
||||||
#define CYD_TOUCH_MISO_PIN GPIO_NUM_39
|
#define CYD_TOUCH_MISO_PIN GPIO_NUM_39
|
||||||
#define CYD_TOUCH_MOSI_PIN GPIO_NUM_32
|
#define CYD_TOUCH_MOSI_PIN GPIO_NUM_32
|
||||||
@ -23,9 +19,4 @@
|
|||||||
#define CYD_TOUCH_CS_PIN GPIO_NUM_33
|
#define CYD_TOUCH_CS_PIN GPIO_NUM_33
|
||||||
#define CYD_TOUCH_IRQ_PIN GPIO_NUM_36
|
#define CYD_TOUCH_IRQ_PIN GPIO_NUM_36
|
||||||
|
|
||||||
// SDCard
|
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||||
#define CYD2432S028R_SDCARD_SPI_HOST SPI3_HOST
|
|
||||||
#define CYD2432S028R_SDCARD_PIN_CS GPIO_NUM_5
|
|
||||||
|
|
||||||
// SPI Transfer
|
|
||||||
#define CYD_SPI_TRANSFER_SIZE_LIMIT (CYD2432S028R_LCD_DRAW_BUFFER_SIZE * LV_COLOR_DEPTH / 8)
|
|
||||||
21
Boards/CYD-2432S028R/Source/devices/SdCard.cpp
Normal file
21
Boards/CYD-2432S028R/Source/devices/SdCard.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "SdCard.h"
|
||||||
|
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
||||||
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
|
|
||||||
|
using tt::hal::sdcard::SpiSdCardDevice;
|
||||||
|
|
||||||
|
std::shared_ptr<SdCardDevice> createSdCard() {
|
||||||
|
auto config = std::make_unique<SpiSdCardDevice::Config>(
|
||||||
|
GPIO_NUM_5,
|
||||||
|
GPIO_NUM_NC,
|
||||||
|
GPIO_NUM_NC,
|
||||||
|
GPIO_NUM_NC,
|
||||||
|
SdCardDevice::MountBehaviour::AtBoot,
|
||||||
|
std::make_shared<tt::Mutex>(),
|
||||||
|
std::vector<gpio_num_t>(),
|
||||||
|
SPI3_HOST
|
||||||
|
);
|
||||||
|
|
||||||
|
return std::make_shared<SpiSdCardDevice>(std::move(config));
|
||||||
|
}
|
||||||
|
|
||||||
@ -4,5 +4,5 @@
|
|||||||
|
|
||||||
using tt::hal::sdcard::SdCardDevice;
|
using tt::hal::sdcard::SdCardDevice;
|
||||||
|
|
||||||
std::shared_ptr<SdCardDevice> createYellowSdCard();
|
std::shared_ptr<SdCardDevice> createSdCard();
|
||||||
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Tactility/hal/display/DisplayDevice.h"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
#include "YellowSdCard.h"
|
|
||||||
#include "YellowConstants.h"
|
|
||||||
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
|
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
|
||||||
|
|
||||||
using tt::hal::sdcard::SpiSdCardDevice;
|
|
||||||
|
|
||||||
std::shared_ptr<SdCardDevice> createYellowSdCard() {
|
|
||||||
auto* configuration = new SpiSdCardDevice::Config(
|
|
||||||
CYD2432S028R_SDCARD_PIN_CS,
|
|
||||||
GPIO_NUM_NC,
|
|
||||||
GPIO_NUM_NC,
|
|
||||||
GPIO_NUM_NC,
|
|
||||||
SdCardDevice::MountBehaviour::AtBoot,
|
|
||||||
std::make_shared<tt::Mutex>(),
|
|
||||||
std::vector<gpio_num_t>(),
|
|
||||||
CYD2432S028R_SDCARD_SPI_HOST
|
|
||||||
);
|
|
||||||
|
|
||||||
auto* sdcard = (SdCardDevice*) new SpiSdCardDevice(
|
|
||||||
std::unique_ptr<SpiSdCardDevice::Config>(configuration)
|
|
||||||
);
|
|
||||||
|
|
||||||
return std::shared_ptr<SdCardDevice>(sdcard);
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user