Cleanup T-Deck driver

This commit is contained in:
Ken Van Hoeylandt 2025-09-01 00:24:22 +02:00
parent 601b7733d4
commit e87771ef5f
11 changed files with 28 additions and 52 deletions

View File

@ -30,7 +30,7 @@ static bool powerOn() {
return true;
}
bool tdeckInit() {
bool initBoot() {
ESP_LOGI(TAG, LOG_MESSAGE_POWER_ON_START);
if (!powerOn()) {
TT_LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);

View File

@ -9,16 +9,22 @@
#define TDECK_SPI_TRANSFER_SIZE_LIMIT (TDECK_LCD_HORIZONTAL_RESOLUTION * TDECK_LCD_SPI_TRANSFER_HEIGHT * (LV_COLOR_DEPTH / 8))
bool tdeckInit();
bool initBoot();
using namespace tt::hal;
static std::vector<std::shared_ptr<Device>> createDevices() {
return {
std::make_shared<TdeckPower>(),
createDisplay(),
std::make_shared<TdeckKeyboard>(),
createSdCard()
};
}
extern const Configuration lilygo_tdeck = {
.initBoot = tdeckInit,
.createDisplay = createDisplay,
.createKeyboard = createKeyboard,
.sdcard = createTdeckSdCard(),
.power = tdeck_get_power,
.initBoot = initBoot,
.createDevices = createDevices,
.i2c = {
i2c::Configuration {
.name = "Internal",

View File

@ -5,10 +5,6 @@
#include <PwmBacklight.h>
#include <St7789Display.h>
#include <driver/spi_master.h>
#define TAG "tdeck_display"
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
// Note for future changes: Reset pin is 48 and interrupt pin is 47
auto configuration = std::make_unique<Gt911Touch::Configuration>(

View File

@ -4,8 +4,8 @@
#define TAG "tdeck_keyboard"
#define TDECK_KEYBOARD_I2C_BUS_HANDLE I2C_NUM_0
#define TDECK_KEYBOARD_SLAVE_ADDRESS 0x55
constexpr auto TDECK_KEYBOARD_I2C_BUS_HANDLE = I2C_NUM_0;
constexpr auto TDECK_KEYBOARD_SLAVE_ADDRESS = 0x55;
static bool keyboard_i2c_read(uint8_t* output) {
return tt::hal::i2c::masterRead(TDECK_KEYBOARD_I2C_BUS_HANDLE, TDECK_KEYBOARD_SLAVE_ADDRESS, output, 1, 100 / portTICK_PERIOD_MS);
@ -61,7 +61,3 @@ bool TdeckKeyboard::stopLvgl() {
bool TdeckKeyboard::isAttached() const {
return tt::hal::i2c::masterHasDeviceAtAddress(TDECK_KEYBOARD_I2C_BUS_HANDLE, TDECK_KEYBOARD_SLAVE_ADDRESS, 100);
}
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard() {
return std::make_shared<TdeckKeyboard>();
}

View File

@ -2,8 +2,6 @@
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tactility/TactilityCore.h>
#include <esp_lcd_panel_io_interface.h>
#include <esp_lcd_touch.h>
class TdeckKeyboard final : public tt::hal::keyboard::KeyboardDevice {
@ -19,5 +17,3 @@ public:
bool isAttached() const override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
};
std::shared_ptr<tt::hal::keyboard::KeyboardDevice> createKeyboard();

View File

@ -2,16 +2,16 @@
#include <Tactility/Log.h>
#define TAG "power"
constexpr auto* TAG = "TdeckPower";
/**
* 2.0 ratio, but +.11 added as display voltage sag compensation.
*/
#define ADC_MULTIPLIER 2.11
constexpr auto ADC_MULTIPLIER = 2.11;
#define ADC_REF_VOLTAGE 3.3f
#define BATTERY_VOLTAGE_MIN 3.2f
#define BATTERY_VOLTAGE_MAX 4.2f
constexpr auto ADC_REF_VOLTAGE = 3.3f;
constexpr auto BATTERY_VOLTAGE_MIN = 3.2f;
constexpr auto BATTERY_VOLTAGE_MAX = 4.2f;
static adc_oneshot_unit_init_cfg_t adcConfig = {
.unit_id = ADC_UNIT_1,
@ -62,8 +62,6 @@ bool TdeckPower::supportsMetric(MetricType type) const {
default:
return false;
}
return false; // Safety guard for when new enum values are introduced
}
bool TdeckPower::getMetric(MetricType type, MetricData& data) {
@ -81,8 +79,6 @@ bool TdeckPower::getMetric(MetricType type, MetricData& data) {
default:
return false;
}
return false; // Safety guard for when new enum values are introduced
}
bool TdeckPower::readBatteryVoltageOnce(uint32_t& output) {
@ -118,13 +114,3 @@ bool TdeckPower::readBatteryVoltageSampled(uint32_t& output) {
return false;
}
}
static std::shared_ptr<PowerDevice> power;
std::shared_ptr<PowerDevice> tdeck_get_power() {
if (power == nullptr) {
power = std::make_shared<TdeckPower>();
}
return power;
}

View File

@ -1,12 +1,11 @@
#pragma once
#include "Tactility/hal/power/PowerDevice.h"
#include <Tactility/hal/power/PowerDevice.h>
#include <esp_adc/adc_oneshot.h>
#include <memory>
using tt::hal::power::PowerDevice;
class TdeckPower : public PowerDevice {
class TdeckPower final : public PowerDevice {
adc_oneshot_unit_handle_t adcHandle = nullptr;
@ -26,5 +25,3 @@ private:
bool readBatteryVoltageSampled(uint32_t& output);
bool readBatteryVoltageOnce(uint32_t& output);
};
std::shared_ptr<PowerDevice> tdeck_get_power();

View File

@ -3,15 +3,13 @@
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <esp_vfs_fat.h>
using tt::hal::sdcard::SpiSdCardDevice;
constexpr auto TDECK_SDCARD_PIN_CS = GPIO_NUM_39;
constexpr auto TDECK_LCD_PIN_CS = GPIO_NUM_12;
constexpr auto TDECK_RADIO_PIN_CS = GPIO_NUM_9;
std::shared_ptr<SdCardDevice> createTdeckSdCard() {
std::shared_ptr<SdCardDevice> createSdCard() {
auto configuration = std::make_unique<SpiSdCardDevice::Config>(
TDECK_SDCARD_PIN_CS,
GPIO_NUM_NC,

View File

@ -4,4 +4,4 @@
using tt::hal::sdcard::SdCardDevice;
std::shared_ptr<SdCardDevice> createTdeckSdCard();
std::shared_ptr<SdCardDevice> createSdCard();

View File

@ -9,6 +9,7 @@
- Fix Development service: when no SD card is present, the app fails to install. Consider installing to `/data`
- Refactor `PropertiesFile.cpp` to use `tt::file::readLines()` (see TODO in code)
- Localize all apps
- Fix: Statusbar time updates result in errors when `system.properties` is not present.
## Lower Priority

View File

@ -1,8 +1,8 @@
#pragma once
#include "Tactility/hal/sdcard/SdCardDevice.h"
#include "Tactility/hal/spi/Spi.h"
#include "Tactility/hal/uart/Uart.h"
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/hal/spi/Spi.h>
#include <Tactility/hal/uart/Uart.h>
#include "i2c/I2c.h"
namespace tt::hal {