Rename Boards/ to Devices/ (#414)

This commit is contained in:
Ken Van Hoeylandt
2025-11-13 23:50:43 +01:00
committed by GitHub
parent c7c9618f48
commit c1ff024657
314 changed files with 105 additions and 99 deletions
@@ -0,0 +1,96 @@
#include "devices/SdCard.h"
#include "devices/Display.h"
#include "devices/Power.h"
#include <Tactility/hal/Configuration.h>
#include <Tactility/lvgl/LvglSync.h>
#include <PwmBacklight.h>
using namespace tt::hal;
static bool initBoot() {
return driver::pwmbacklight::init(DISPLAY_BACKLIGHT_PIN);
}
static tt::hal::DeviceVector createDevices() {
return {
createPower(),
createDisplay(),
createSdCard()
};
}
extern const Configuration hardwareConfiguration = {
.initBoot = initBoot,
.createDevices = createDevices,
.i2c = {
tt::hal::i2c::Configuration {
.name = "External",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.isMutable = true,
.config = (i2c_config_t) {
.mode = I2C_MODE_MASTER,
.sda_io_num = GPIO_NUM_32,
.scl_io_num = GPIO_NUM_25,
.sda_pullup_en = false,
.scl_pullup_en = false,
.master = {
.clk_speed = 400000
},
.clk_flags = 0
}
},
},
// Display
.spi = {
tt::hal::spi::Configuration {
.device = SPI2_HOST,
.dma = SPI_DMA_CH_AUTO,
.config = {
.mosi_io_num = GPIO_NUM_13,
.miso_io_num = GPIO_NUM_12,
.sclk_io_num = GPIO_NUM_14,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC,
.data7_io_num = GPIO_NUM_NC,
.data_io_default_level = false,
.max_transfer_sz = DISPLAY_SPI_TRANSFER_SIZE_LIMIT,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
},
.initMode = tt::hal::spi::InitMode::ByTactility,
.isMutable = false,
.lock = tt::lvgl::getSyncLock()
},
// SD Card
tt::hal::spi::Configuration {
.device = SPI3_HOST,
.dma = SPI_DMA_CH_AUTO,
.config = {
.mosi_io_num = GPIO_NUM_23,
.miso_io_num = GPIO_NUM_19,
.sclk_io_num = GPIO_NUM_18,
.quadwp_io_num = GPIO_NUM_NC,
.quadhd_io_num = GPIO_NUM_NC,
.data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC,
.data7_io_num = GPIO_NUM_NC,
.data_io_default_level = false,
.max_transfer_sz = 8192,
.flags = 0,
.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO,
.intr_flags = 0
},
.initMode = tt::hal::spi::InitMode::ByTactility,
.isMutable = false,
.lock = nullptr
},
}
};
@@ -0,0 +1,52 @@
#include "Display.h"
#include <Xpt2046Touch.h>
#include <St7789Display.h>
#include <PwmBacklight.h>
#include <Tactility/hal/touch/TouchDevice.h>
// Create the XPT2046 touch device (hardware/esp_lcd driver)
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
auto config = std::make_unique<Xpt2046Touch::Configuration>(
DISPLAY_SPI_HOST, // spi device / bus (SPI2_HOST)
TOUCH_CS_PIN, // touch CS (IO33)
(uint16_t)DISPLAY_HORIZONTAL_RESOLUTION, // x max
(uint16_t)DISPLAY_VERTICAL_RESOLUTION, // y max
false, // swapXy
true, // mirrorX
true // mirrorY
);
return std::make_shared<Xpt2046Touch>(std::move(config));
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
// Create the ST7789 panel configuration
St7789Display::Configuration panel_configuration = {
.horizontalResolution = DISPLAY_HORIZONTAL_RESOLUTION,
.verticalResolution = DISPLAY_VERTICAL_RESOLUTION,
.gapX = 0,
.gapY = 0,
.swapXY = false,
.mirrorX = false,
.mirrorY = false,
.invertColor = false,
.bufferSize = DISPLAY_DRAW_BUFFER_SIZE, // 0 -> default 1/10 screen
.touch = createTouch(),
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
.resetPin = GPIO_NUM_NC,
.lvglSwapBytes = false,
.rgbElementOrder = LCD_RGB_ELEMENT_ORDER_BGR // BGR for this display
};
// Create the SPI configuration (from EspLcdSpiDisplay base class)
auto spi_configuration = std::make_shared<EspLcdSpiDisplay::SpiConfiguration>(EspLcdSpiDisplay::SpiConfiguration {
.spiHostDevice = DISPLAY_SPI_HOST,
.csPin = DISPLAY_PIN_CS,
.dcPin = DISPLAY_PIN_DC,
.pixelClockFrequency = 40'000'000,
.transactionQueueDepth = 10
});
return std::make_shared<St7789Display>(panel_configuration, spi_configuration);
}
@@ -0,0 +1,27 @@
#pragma once
#include <Tactility/hal/display/DisplayDevice.h>
#include "driver/gpio.h"
#include "driver/spi_common.h"
#include <memory>
// Display (ST7789P3 on this board)
constexpr auto DISPLAY_SPI_HOST = SPI2_HOST;
constexpr auto DISPLAY_PIN_CS = GPIO_NUM_15;
constexpr auto DISPLAY_PIN_DC = GPIO_NUM_2;
constexpr auto DISPLAY_HORIZONTAL_RESOLUTION = 240;
constexpr auto DISPLAY_VERTICAL_RESOLUTION = 320;
constexpr auto DISPLAY_DRAW_BUFFER_HEIGHT = (DISPLAY_VERTICAL_RESOLUTION / 10);
constexpr auto DISPLAY_DRAW_BUFFER_SIZE = (DISPLAY_HORIZONTAL_RESOLUTION * DISPLAY_DRAW_BUFFER_HEIGHT);
constexpr auto DISPLAY_BACKLIGHT_PIN = GPIO_NUM_27;
constexpr auto DISPLAY_SPI_TRANSFER_SIZE_LIMIT = DISPLAY_DRAW_BUFFER_SIZE * sizeof(lv_color_t);
// Touch (XPT2046, resistive, shared SPI with display)
constexpr auto TOUCH_MISO_PIN = GPIO_NUM_12;
constexpr auto TOUCH_MOSI_PIN = GPIO_NUM_13;
constexpr auto TOUCH_SCK_PIN = GPIO_NUM_14;
constexpr auto TOUCH_CS_PIN = GPIO_NUM_33;
constexpr auto TOUCH_IRQ_PIN = GPIO_NUM_36;
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
@@ -0,0 +1,12 @@
#include "Power.h"
#include <ChargeFromAdcVoltage.h>
#include <EstimatedPower.h>
std::shared_ptr<tt::hal::power::PowerDevice> createPower() {
ChargeFromAdcVoltage::Configuration configuration;
// 2.0 ratio, but +.11 added as display voltage sag compensation.
configuration.adcMultiplier = 2.11;
return std::make_shared<EstimatedPower>(configuration);
}
@@ -0,0 +1,6 @@
#pragma once
#include <memory>
#include <Tactility/hal/power/PowerDevice.h>
std::shared_ptr<tt::hal::power::PowerDevice> createPower();
@@ -0,0 +1,22 @@
#include "SdCard.h"
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
using tt::hal::sdcard::SpiSdCardDevice;
using SdCardDevice = tt::hal::sdcard::SdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
SD_CS_PIN, // CS pin (IO5 on the module)
GPIO_NUM_NC, // MOSI override: leave NC to use SPI host pins
GPIO_NUM_NC, // MISO override: leave NC
GPIO_NUM_NC, // SCLK override: leave NC
SdCardDevice::MountBehaviour::AtBoot,
std::make_shared<tt::Mutex>(tt::Mutex::Type::Recursive),
std::vector<gpio_num_t>(),
SD_SPI_HOST // SPI host for SD card (SPI3_HOST)
);
return std::make_shared<SpiSdCardDevice>(
std::move(configuration)
);
}
@@ -0,0 +1,13 @@
#pragma once
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include "driver/gpio.h"
#include "driver/spi_common.h"
using tt::hal::sdcard::SdCardDevice;
// SD card (microSD)
constexpr auto SD_CS_PIN = GPIO_NUM_5;
constexpr auto SD_SPI_HOST = SPI3_HOST;
std::shared_ptr<SdCardDevice> createSdCard();