mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-19 01:45: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 = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices,
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
#include "CYD2432S028R.h"
|
||||
#include "hal/YellowDisplay.h"
|
||||
#include "hal/YellowConstants.h"
|
||||
#include "hal/YellowSdCard.h"
|
||||
#include "devices/Display.h"
|
||||
#include "devices/SdCard.h"
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <PwmBacklight.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;
|
||||
|
||||
bool initBoot() {
|
||||
static bool initBoot() {
|
||||
//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_16, GPIO_MODE_OUTPUT)); //Green
|
||||
@ -22,16 +26,21 @@ bool initBoot() {
|
||||
return driver::pwmbacklight::init(CYD2432S028R_LCD_PIN_BACKLIGHT);
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createDisplay(),
|
||||
createSdCard()
|
||||
};
|
||||
}
|
||||
|
||||
const Configuration cyd_2432s028r_config = {
|
||||
.initBoot = initBoot,
|
||||
.createDisplay = createDisplay,
|
||||
.sdcard = createYellowSdCard(),
|
||||
.power = nullptr,
|
||||
.createDevices = createDevices,
|
||||
.i2c = {},
|
||||
.spi {
|
||||
//Display
|
||||
spi::Configuration {
|
||||
.device = CYD2432S028R_LCD_SPI_HOST,
|
||||
.device = SPI2_HOST,
|
||||
.dma = SPI_DMA_CH_AUTO,
|
||||
.config = {
|
||||
.mosi_io_num = GPIO_NUM_13,
|
||||
@ -56,7 +65,7 @@ const Configuration cyd_2432s028r_config = {
|
||||
|
||||
// SDCard
|
||||
spi::Configuration {
|
||||
.device = CYD2432S028R_SDCARD_SPI_HOST,
|
||||
.device = SPI3_HOST,
|
||||
.dma = SPI_DMA_CH_AUTO,
|
||||
.config = {
|
||||
.mosi_io_num = GPIO_NUM_23,
|
||||
@ -74,7 +83,7 @@ const Configuration cyd_2432s028r_config = {
|
||||
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
.intr_flags = 0
|
||||
},
|
||||
.initMode = tt::hal::spi::InitMode::ByTactility,
|
||||
.initMode = spi::InitMode::ByTactility,
|
||||
.isMutable = false,
|
||||
.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 "YellowConstants.h"
|
||||
#include <Ili934xDisplay.h>
|
||||
#include <PwmBacklight.h>
|
||||
|
||||
static const char* TAG = "YellowDisplay";
|
||||
|
||||
// Global to hold reference (only needed if calling stop() later)
|
||||
static std::unique_ptr<Xpt2046SoftSpi> touch;
|
||||
constexpr auto* TAG = "CYD";
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto configuration = std::make_unique<Xpt2046SoftSpi::Configuration>(
|
||||
@ -23,17 +19,15 @@ static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
);
|
||||
|
||||
// Allocate the driver
|
||||
touch = std::make_unique<Xpt2046SoftSpi>(std::move(configuration));
|
||||
auto touch = std::make_shared<Xpt2046SoftSpi>(std::move(configuration));
|
||||
|
||||
// Start the driver
|
||||
if (!touch->start()) {
|
||||
ESP_LOGE(TAG, "Touch driver start failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::shared_ptr<tt::hal::touch::TouchDevice>(touch.get(), [](tt::hal::touch::TouchDevice*) {
|
||||
// No delete needed; `touch` is managed above
|
||||
});
|
||||
|
||||
return touch;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// Display backlight (PWM)
|
||||
#define CYD2432S028R_LCD_PIN_BACKLIGHT GPIO_NUM_21
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
#include <memory>
|
||||
|
||||
// Display
|
||||
#define CYD2432S028R_LCD_SPI_HOST SPI2_HOST
|
||||
@ -12,10 +12,6 @@
|
||||
#define CYD2432S028R_LCD_PIN_CS GPIO_NUM_15
|
||||
#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)
|
||||
#define CYD_TOUCH_MISO_PIN GPIO_NUM_39
|
||||
#define CYD_TOUCH_MOSI_PIN GPIO_NUM_32
|
||||
@ -23,9 +19,4 @@
|
||||
#define CYD_TOUCH_CS_PIN GPIO_NUM_33
|
||||
#define CYD_TOUCH_IRQ_PIN GPIO_NUM_36
|
||||
|
||||
// SDCard
|
||||
#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)
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
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;
|
||||
|
||||
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