New kernel drivers and more (#560)
- Added kernel base drivers for: display, pointer (touch, mouse, etc.), keyboard, adc, power supply and backlight - Implement new kernel driver modules: `st7789-module` and `gt911-module` - Implement ESP32 ADC "oneshot" kernel driver - Implement ESP32 backlight kernel driver with ledc API - Implemented `battery-sense` driver that allows for voltage measurement and creates a power supply child device - Updated github actions - Updated flash scripts - Fix for esp32 legacy driver conflict with ADC - Created separate `lilygo-tdeck` and `lilygo-tdeck-plus` devices - Created `lilygo-module` with LilyGO kernel drivers - Fix for intermittent errors in build related to code generation of `devicetree.c` - `lvgl-module` can now map kernel drivers onto LVGL devices - Created `KernelDisplayApp` as a mirror of `HalDisplayApp` (formerly `DisplayApp`) - Removed `struct` and `enum` prefix in a lot of kernel driver cpp source files - `lilygo-tdeck` and `lilygo-tdeck-plus` are now fully relying on kernel drivers and don't use any of the old HAL
This commit is contained in:
committed by
GitHub
parent
c4406b24ba
commit
50c0a14a93
@@ -6,7 +6,7 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
|
||||
/ {
|
||||
@@ -37,7 +37,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -46,7 +46,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -46,7 +46,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -36,7 +36,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -45,7 +45,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -47,7 +47,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -47,7 +47,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES Tactility driver lilygo-module
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
general.vendor=LilyGO
|
||||
general.name=T-Deck Plus
|
||||
|
||||
apps.launcherAppId=Launcher
|
||||
|
||||
hardware.target=ESP32S3
|
||||
hardware.flashSize=16MB
|
||||
hardware.spiRam=true
|
||||
hardware.spiRamMode=OCT
|
||||
hardware.spiRamSpeed=120M
|
||||
hardware.tinyUsb=true
|
||||
hardware.esptoolFlashFreq=120M
|
||||
hardware.bluetooth=true
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
display.size=2.8"
|
||||
display.shape=rectangle
|
||||
display.dpi=143
|
||||
|
||||
cdn.infoMessage=To put the device into bootloader mode: <br/>1. Press the trackball and then the reset button at the same time,<br/>2. Let go of the reset button, then the trackball.<br/><br/>When this website reports that flashing is finished, you likely have to press the reset button.
|
||||
|
||||
lvgl.colorDepth=16
|
||||
@@ -0,0 +1,6 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/st7789-module
|
||||
- Drivers/gt911-module
|
||||
- Drivers/lilygo-module
|
||||
dts: lilygo,tdeck-plus.dts
|
||||
@@ -0,0 +1,150 @@
|
||||
/dts-v1/;
|
||||
|
||||
#include <tactility/bindings/battery_sense.h>
|
||||
#include <tactility/bindings/root.h>
|
||||
#include <tactility/bindings/esp32_adc_oneshot.h>
|
||||
#include <tactility/bindings/esp32_ble.h>
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_grove.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_i2s.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
|
||||
#include <bindings/gt911.h>
|
||||
#include <bindings/st7789.h>
|
||||
|
||||
#include <lilygo/bindings/tdeck_keyboard.h>
|
||||
#include <lilygo/bindings/tdeck_keyboard_backlight.h>
|
||||
#include <lilygo/bindings/tdeck_trackball.h>
|
||||
|
||||
// Reference: https://wiki.lilygo.cc/products/t-deck-series/t-deck-plus/
|
||||
/ {
|
||||
compatible = "root";
|
||||
model = "LilyGO T-Deck Plus";
|
||||
|
||||
adc0 {
|
||||
compatible = "espressif,esp32-adc-oneshot";
|
||||
unit-id = <ADC_UNIT_1>;
|
||||
clk-src = <ADC_RTC_CLK_SRC_DEFAULT>;
|
||||
channels = <ADC_CHANNEL_3 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
|
||||
};
|
||||
|
||||
battery-sense {
|
||||
compatible = "battery-sense";
|
||||
io-channel = <&adc0 0>;
|
||||
reference-voltage-mv = <3300>;
|
||||
multiplier = <2110>;
|
||||
};
|
||||
|
||||
wifi0 {
|
||||
compatible = "espressif,esp32-wifi-pinned";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
ble0 {
|
||||
compatible = "espressif,esp32-ble";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
gpio0 {
|
||||
compatible = "espressif,esp32-gpio";
|
||||
gpio-count = <49>;
|
||||
};
|
||||
|
||||
trackball {
|
||||
compatible = "lilygo,tdeck-trackball";
|
||||
pin-right = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
pin-up = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
pin-left = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
pin-down = <&gpio0 15 GPIO_FLAG_NONE>;
|
||||
pin-click = <&gpio0 0 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
i2c_internal: i2c0 {
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <100000>;
|
||||
pin-sda = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
|
||||
touch {
|
||||
compatible = "goodix,gt911";
|
||||
reg = <0x5D>;
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
swap-xy;
|
||||
mirror-x;
|
||||
pin-interrupt = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
keyboard {
|
||||
compatible = "lilygo,tdeck-keyboard";
|
||||
reg = <0x55>;
|
||||
};
|
||||
|
||||
keyboard_backlight {
|
||||
compatible = "lilygo,tdeck-keyboard-backlight";
|
||||
reg = <0x55>;
|
||||
};
|
||||
};
|
||||
|
||||
i2s0 {
|
||||
compatible = "espressif,esp32-i2s";
|
||||
port = <I2S_NUM_0>;
|
||||
pin-bclk = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-ws = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so dispaly power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
|
||||
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
|
||||
frequency-hz = <30000>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
cs-gpios = <&gpio0 12 GPIO_FLAG_NONE>, // Display
|
||||
<&gpio0 39 GPIO_FLAG_NONE>, // SD card
|
||||
<&gpio0 9 GPIO_FLAG_NONE>; // Radio
|
||||
pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>;
|
||||
pin-miso = <&gpio0 38 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
|
||||
display@0 {
|
||||
compatible = "sitronix,st7789";
|
||||
horizontal-resolution = <320>;
|
||||
vertical-resolution = <240>;
|
||||
swap-xy;
|
||||
mirror-x;
|
||||
invert-color;
|
||||
pixel-clock-hz = <62500000>;
|
||||
pin-dc = <&gpio0 11 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
// Must be started after display
|
||||
sdcard@1 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
status = "disabled";
|
||||
frequency-khz = <20000>;
|
||||
};
|
||||
};
|
||||
|
||||
uart0 {
|
||||
compatible = "espressif,esp32-uart";
|
||||
port = <UART_NUM_1>;
|
||||
pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
|
||||
pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/lvgl_module.h>
|
||||
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/hal/gps/GpsConfiguration.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
|
||||
#include <lilygo/drivers/trackball.h>
|
||||
#include <lilygo/drivers/tdeck_power_on.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
constexpr auto* TAG = "tdeck-plus";
|
||||
|
||||
// Legacy placeholder (required until legacy HAL is cleaned up everywhere)
|
||||
extern const tt::hal::Configuration hardwareConfiguration = {};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void subscribe_events() {
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto gps_service = tt::service::gps::findGpsService();
|
||||
if (gps_service != nullptr) {
|
||||
std::vector<tt::hal::gps::GpsConfiguration> gps_configurations;
|
||||
gps_service->getGpsConfigurations(gps_configurations);
|
||||
if (gps_configurations.empty()) {
|
||||
if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart0", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) {
|
||||
LOG_I(TAG, "Configured internal GPS");
|
||||
} else {
|
||||
LOG_E(TAG, "Failed to configure internal GPS");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// The kernel trackball device is already started by kernel_init(); this just registers it as an
|
||||
// LVGL input device and applies persisted settings, both of which require LVGL to be up first.
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto tbSettings = tt::settings::trackball::loadOrGetDefault();
|
||||
lvgl_lock();
|
||||
if (trackball::init() != nullptr) {
|
||||
trackball::setMode(tbSettings.trackballMode == tt::settings::trackball::TrackballMode::Pointer
|
||||
? trackball::Mode::Pointer
|
||||
: trackball::Mode::Encoder);
|
||||
trackball::setEncoderSensitivity(tbSettings.encoderSensitivity);
|
||||
trackball::setPointerSensitivity(tbSettings.pointerSensitivity);
|
||||
trackball::setEnabled(tbSettings.trackballEnabled);
|
||||
}
|
||||
lvgl_unlock();
|
||||
});
|
||||
}
|
||||
|
||||
static error_t start() {
|
||||
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
if (!tdeck_power_on()) {
|
||||
LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
// Avoids crash when no SD card is inserted. It's unknown why, but likely is related to power draw.
|
||||
tt::kernel::delayMillis(100);
|
||||
|
||||
subscribe_events();
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
Module lilygo_tdeck_plus_module = {
|
||||
.name = "lilygo-tdeck-plus",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility EspLcdCompat ST7789 GT911 PwmBacklight EstimatedPower driver
|
||||
REQUIRES Tactility driver lilygo-module
|
||||
)
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "devices/Display.h"
|
||||
#include "devices/KeyboardBacklight.h"
|
||||
#include "devices/Power.h"
|
||||
#include "devices/TdeckKeyboard.h"
|
||||
#include "devices/TrackballDevice.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
bool initBoot();
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
static std::vector<std::shared_ptr<tt::hal::Device>> createDevices() {
|
||||
auto* i2c_internal = device_find_by_name("i2c0");
|
||||
check(i2c_internal);
|
||||
return {
|
||||
createPower(),
|
||||
createDisplay(),
|
||||
std::make_shared<TdeckKeyboard>(i2c_internal),
|
||||
std::make_shared<KeyboardBacklightDevice>(),
|
||||
std::make_shared<TrackballDevice>(),
|
||||
};
|
||||
}
|
||||
|
||||
extern const Configuration hardwareConfiguration = {
|
||||
.initBoot = initBoot,
|
||||
.createDevices = createDevices
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
extern "C" {
|
||||
|
||||
extern void register_device_drivers() {
|
||||
/* NO-OP */
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
#include "PwmBacklight.h"
|
||||
#include "devices/KeyboardBacklight.h"
|
||||
#include "devices/TrackballDevice.h"
|
||||
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/hal/gps/GpsConfiguration.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "T-Deck";
|
||||
|
||||
constexpr auto TDECK_POWERON_GPIO = GPIO_NUM_10;
|
||||
|
||||
static bool powerOn() {
|
||||
gpio_config_t device_power_signal_config = {
|
||||
.pin_bit_mask = BIT64(TDECK_POWERON_GPIO),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (gpio_config(&device_power_signal_config) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gpio_set_level(TDECK_POWERON_GPIO, 1) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Avoids crash when no SD card is inserted. It's unknown why, but likely is related to power draw.
|
||||
tt::kernel::delayMillis(100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initBoot() {
|
||||
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
if (!powerOn()) {
|
||||
LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 32 Khz and higher gives an issue where the screen starts dimming again above 80% brightness
|
||||
* when moving the brightness slider rapidly from a lower setting to 100%.
|
||||
* This is not a slider bug (data was debug-traced) */
|
||||
if (!driver::pwmbacklight::init(GPIO_NUM_42, 30000)) {
|
||||
LOG_E(TAG, "Backlight init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto gps_service = tt::service::gps::findGpsService();
|
||||
if (gps_service != nullptr) {
|
||||
std::vector<tt::hal::gps::GpsConfiguration> gps_configurations;
|
||||
gps_service->getGpsConfigurations(gps_configurations);
|
||||
if (gps_configurations.empty()) {
|
||||
if (gps_service->addGpsConfiguration(tt::hal::gps::GpsConfiguration {.uartName = "uart0", .baudRate = 38400, .model = tt::hal::gps::GpsModel::UBLOX10})) {
|
||||
LOG_I(TAG, "Configured internal GPS");
|
||||
} else {
|
||||
LOG_E(TAG, "Failed to configure internal GPS");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto kbBacklight = tt::hal::findDevice("Keyboard Backlight");
|
||||
if (kbBacklight != nullptr) {
|
||||
LOG_I(TAG, "%s starting", kbBacklight->getName().c_str());
|
||||
auto kbDevice = std::static_pointer_cast<KeyboardBacklightDevice>(kbBacklight);
|
||||
if (kbDevice->start()) {
|
||||
LOG_I(TAG, "%s started", kbBacklight->getName().c_str());
|
||||
} else {
|
||||
LOG_E(TAG, "%s start failed", kbBacklight->getName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
auto trackball = tt::hal::findDevice("Trackball");
|
||||
if (trackball != nullptr) {
|
||||
LOG_I(TAG, "%s starting", trackball->getName().c_str());
|
||||
auto tbDevice = std::static_pointer_cast<TrackballDevice>(trackball);
|
||||
if (tbDevice->start()) {
|
||||
LOG_I(TAG, "%s started", trackball->getName().c_str());
|
||||
} else {
|
||||
LOG_E(TAG, "%s start failed", trackball->getName().c_str());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
#include "KeyboardBacklight.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <esp_log.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "KeyboardBacklight";
|
||||
|
||||
namespace keyboardbacklight {
|
||||
|
||||
static const uint8_t CMD_BRIGHTNESS = 0x01;
|
||||
static const uint8_t CMD_DEFAULT_BRIGHTNESS = 0x02;
|
||||
|
||||
static i2c_port_t g_i2cPort = I2C_NUM_MAX;
|
||||
static uint8_t g_slaveAddress = 0x55;
|
||||
static uint8_t g_currentBrightness = 127;
|
||||
|
||||
// TODO: Umm...something. Calls xxxBrightness, ignores return values.
|
||||
bool init(i2c_port_t i2cPort, uint8_t slaveAddress) {
|
||||
g_i2cPort = i2cPort;
|
||||
g_slaveAddress = slaveAddress;
|
||||
|
||||
LOG_I(TAG, "Initialized on I2C port %d, address 0x%02X", static_cast<int>(g_i2cPort), (unsigned)g_slaveAddress);
|
||||
|
||||
// Set a reasonable default brightness
|
||||
if (!setDefaultBrightness(127)) {
|
||||
LOG_E(TAG, "Failed to set default brightness");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!setBrightness(127)) {
|
||||
LOG_E(TAG, "Failed to set brightness");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setBrightness(uint8_t brightness) {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
LOG_E(TAG, "Not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip if brightness is already at target value (avoid I2C spam on every keypress)
|
||||
if (brightness == g_currentBrightness) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_I(TAG, "Setting brightness to %d on I2C port %d, address 0x%02X", brightness, static_cast<int>(g_i2cPort), (unsigned)g_slaveAddress);
|
||||
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (g_slaveAddress << 1) | I2C_MASTER_WRITE, true);
|
||||
i2c_master_write_byte(cmd, CMD_BRIGHTNESS, true);
|
||||
i2c_master_write_byte(cmd, brightness, true);
|
||||
i2c_master_stop(cmd);
|
||||
|
||||
esp_err_t ret = i2c_master_cmd_begin(g_i2cPort, cmd, pdMS_TO_TICKS(100));
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
g_currentBrightness = brightness;
|
||||
LOG_I(TAG, "Successfully set brightness to %d", brightness);
|
||||
return true;
|
||||
} else {
|
||||
LOG_E(TAG, "Failed to set brightness: %s (0x%02X)", esp_err_to_name(ret), (unsigned)ret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool setDefaultBrightness(uint8_t brightness) {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
LOG_E(TAG, "Not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clamp to valid range for default brightness
|
||||
if (brightness < 30) {
|
||||
brightness = 30;
|
||||
}
|
||||
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (g_slaveAddress << 1) | I2C_MASTER_WRITE, true);
|
||||
i2c_master_write_byte(cmd, CMD_DEFAULT_BRIGHTNESS, true);
|
||||
i2c_master_write_byte(cmd, brightness, true);
|
||||
i2c_master_stop(cmd);
|
||||
|
||||
esp_err_t ret = i2c_master_cmd_begin(g_i2cPort, cmd, pdMS_TO_TICKS(100));
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
if (ret == ESP_OK) {
|
||||
LOG_D(TAG, "Set default brightness to %d", brightness);
|
||||
return true;
|
||||
} else {
|
||||
LOG_E(TAG, "Failed to set default brightness: %s", esp_err_to_name(ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getBrightness() {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
LOG_E(TAG, "Not initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return g_currentBrightness;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/i2c.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace keyboardbacklight {
|
||||
|
||||
/**
|
||||
* @brief Initialize keyboard backlight control
|
||||
* @param i2cPort I2C port number (I2C_NUM_0 or I2C_NUM_1)
|
||||
* @param slaveAddress I2C slave address (default 0x55 for T-Deck keyboard)
|
||||
* @return true if initialization succeeded
|
||||
*/
|
||||
bool init(i2c_port_t i2cPort, uint8_t slaveAddress = 0x55);
|
||||
|
||||
/**
|
||||
* @brief Set keyboard backlight brightness
|
||||
* @param brightness Brightness level (0-255, 0=off, 255=max)
|
||||
* @return true if command succeeded
|
||||
*/
|
||||
bool setBrightness(uint8_t brightness);
|
||||
|
||||
/**
|
||||
* @brief Set default keyboard backlight brightness for ALT+B toggle
|
||||
* @param brightness Default brightness level (30-255)
|
||||
* @return true if command succeeded
|
||||
*/
|
||||
bool setDefaultBrightness(uint8_t brightness);
|
||||
|
||||
/**
|
||||
* @brief Get current keyboard backlight brightness
|
||||
* @return Current brightness level (0-255)
|
||||
*/
|
||||
uint8_t getBrightness();
|
||||
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
#include "Trackball.h"
|
||||
|
||||
#include <Tactility/Assets.h>
|
||||
#include <atomic>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "Trackball";
|
||||
|
||||
namespace trackball {
|
||||
|
||||
static TrackballConfig g_config;
|
||||
static lv_indev_t* g_indev = nullptr;
|
||||
static std::atomic<bool> g_initialized{false};
|
||||
static std::atomic<bool> g_enabled{true};
|
||||
static std::atomic<Mode> g_mode{Mode::Encoder};
|
||||
|
||||
// Interrupt-driven position tracking (atomic for ISR safety)
|
||||
static std::atomic<int32_t> g_cursorX{160};
|
||||
static std::atomic<int32_t> g_cursorY{120};
|
||||
static std::atomic<bool> g_buttonPressed{false};
|
||||
|
||||
// Encoder mode: accumulated diff since last read
|
||||
static std::atomic<int32_t> g_encoderDiff{0};
|
||||
|
||||
// Sensitivity cached for ISR access (atomic for thread safety)
|
||||
static std::atomic<int32_t> g_encoderSensitivity{1}; // Steps per tick for encoder
|
||||
static std::atomic<int32_t> g_pointerSensitivity{10}; // Pixels per tick for pointer
|
||||
|
||||
// Cursor object for pointer mode
|
||||
static lv_obj_t* g_cursor = nullptr;
|
||||
|
||||
// Screen dimensions (T-Deck: 320x240)
|
||||
static constexpr int32_t SCREEN_WIDTH = 320;
|
||||
static constexpr int32_t SCREEN_HEIGHT = 240;
|
||||
|
||||
static constexpr int32_t CURSOR_SIZE = 16;
|
||||
|
||||
// ISR handler for trackball directions
|
||||
static void IRAM_ATTR trackball_isr_handler(void* arg) {
|
||||
// Skip accumulating movement when disabled
|
||||
if (!g_enabled.load(std::memory_order_relaxed)) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_num_t pin = static_cast<gpio_num_t>(reinterpret_cast<intptr_t>(arg));
|
||||
|
||||
if (g_mode.load(std::memory_order_relaxed) == Mode::Pointer) {
|
||||
// Pointer mode: update absolute position using atomic fetch_add/sub
|
||||
// Clamping is done in read_cb to avoid race conditions
|
||||
int32_t step = g_pointerSensitivity.load(std::memory_order_relaxed);
|
||||
if (pin == g_config.pinRight) {
|
||||
g_cursorX.fetch_add(step, std::memory_order_relaxed);
|
||||
} else if (pin == g_config.pinLeft) {
|
||||
g_cursorX.fetch_sub(step, std::memory_order_relaxed);
|
||||
} else if (pin == g_config.pinUp) {
|
||||
g_cursorY.fetch_sub(step, std::memory_order_relaxed);
|
||||
} else if (pin == g_config.pinDown) {
|
||||
g_cursorY.fetch_add(step, std::memory_order_relaxed);
|
||||
}
|
||||
} else {
|
||||
// Encoder mode: accumulate diff
|
||||
int32_t step = g_encoderSensitivity.load(std::memory_order_relaxed);
|
||||
if (pin == g_config.pinRight || pin == g_config.pinDown) {
|
||||
g_encoderDiff.fetch_add(step, std::memory_order_relaxed);
|
||||
} else if (pin == g_config.pinLeft || pin == g_config.pinUp) {
|
||||
g_encoderDiff.fetch_sub(step, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ISR handler for button (any edge)
|
||||
static void IRAM_ATTR button_isr_handler(void* arg) {
|
||||
// Read current button state (active low)
|
||||
bool pressed = gpio_get_level(g_config.pinClick) == 0;
|
||||
g_buttonPressed.store(pressed, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// Helper to clamp value to range
|
||||
static inline int32_t clamp(int32_t val, int32_t minVal, int32_t maxVal) {
|
||||
if (val < minVal) return minVal;
|
||||
if (val > maxVal) return maxVal;
|
||||
return val;
|
||||
}
|
||||
|
||||
static void read_cb(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
Mode currentMode = g_mode.load(std::memory_order_relaxed);
|
||||
|
||||
if (!g_initialized.load(std::memory_order_relaxed) || !g_enabled.load(std::memory_order_relaxed)) {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
if (currentMode == Mode::Encoder) {
|
||||
data->enc_diff = 0;
|
||||
} else {
|
||||
// Clamp cursor position to screen bounds
|
||||
int32_t x = clamp(g_cursorX.load(std::memory_order_relaxed), 0, SCREEN_WIDTH - CURSOR_SIZE - 1);
|
||||
int32_t y = clamp(g_cursorY.load(std::memory_order_relaxed), 0, SCREEN_HEIGHT - CURSOR_SIZE - 1);
|
||||
g_cursorX.store(x, std::memory_order_relaxed);
|
||||
g_cursorY.store(y, std::memory_order_relaxed);
|
||||
data->point.x = static_cast<int16_t>(x);
|
||||
data->point.y = static_cast<int16_t>(y);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentMode == Mode::Encoder) {
|
||||
// Read and reset accumulated encoder diff
|
||||
int32_t diff = g_encoderDiff.exchange(0);
|
||||
data->enc_diff = static_cast<int16_t>(clamp(diff, INT16_MIN, INT16_MAX));
|
||||
|
||||
if (diff != 0) {
|
||||
lv_display_trigger_activity(nullptr);
|
||||
}
|
||||
} else {
|
||||
// Pointer mode: read and clamp cursor position
|
||||
int32_t x = clamp(g_cursorX.load(std::memory_order_relaxed), 0, SCREEN_WIDTH - CURSOR_SIZE - 1);
|
||||
int32_t y = clamp(g_cursorY.load(std::memory_order_relaxed), 0, SCREEN_HEIGHT - CURSOR_SIZE - 1);
|
||||
|
||||
// Store clamped values back to prevent unbounded growth
|
||||
g_cursorX.store(x, std::memory_order_relaxed);
|
||||
g_cursorY.store(y, std::memory_order_relaxed);
|
||||
|
||||
data->point.x = static_cast<int16_t>(x);
|
||||
data->point.y = static_cast<int16_t>(y);
|
||||
}
|
||||
|
||||
// Button state (same for both modes)
|
||||
bool pressed = g_buttonPressed.load(std::memory_order_relaxed);
|
||||
data->state = pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
|
||||
|
||||
if (pressed) {
|
||||
lv_display_trigger_activity(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
lv_indev_t* init(const TrackballConfig& config) {
|
||||
if (g_initialized.load(std::memory_order_relaxed)) {
|
||||
LOG_W(TAG, "Already initialized");
|
||||
return g_indev;
|
||||
}
|
||||
|
||||
g_config = config;
|
||||
|
||||
// Set default sensitivities if not specified
|
||||
if (g_config.encoderSensitivity == 0) {
|
||||
g_config.encoderSensitivity = 1;
|
||||
}
|
||||
if (g_config.pointerSensitivity == 0) {
|
||||
g_config.pointerSensitivity = 10;
|
||||
}
|
||||
g_encoderSensitivity.store(g_config.encoderSensitivity, std::memory_order_relaxed);
|
||||
g_pointerSensitivity.store(g_config.pointerSensitivity, std::memory_order_relaxed);
|
||||
|
||||
// Initialize cursor position to center
|
||||
g_cursorX.store(SCREEN_WIDTH / 2, std::memory_order_relaxed);
|
||||
g_cursorY.store(SCREEN_HEIGHT / 2, std::memory_order_relaxed);
|
||||
g_encoderDiff.store(0, std::memory_order_relaxed);
|
||||
g_buttonPressed.store(false, std::memory_order_relaxed);
|
||||
|
||||
// Configure direction pins as interrupt inputs (falling edge)
|
||||
const gpio_num_t dirPins[4] = {
|
||||
config.pinRight,
|
||||
config.pinUp,
|
||||
config.pinLeft,
|
||||
config.pinDown
|
||||
};
|
||||
|
||||
gpio_config_t io_conf = {};
|
||||
io_conf.intr_type = GPIO_INTR_NEGEDGE; // Falling edge (active low)
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
|
||||
// Install GPIO ISR service (if not already installed)
|
||||
static bool isr_service_installed = false;
|
||||
if (!isr_service_installed) {
|
||||
esp_err_t err = gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
|
||||
if (err == ESP_OK || err == ESP_ERR_INVALID_STATE) {
|
||||
// ESP_ERR_INVALID_STATE means already installed, which is fine
|
||||
isr_service_installed = true;
|
||||
} else {
|
||||
LOG_E(TAG, "Failed to install GPIO ISR service: %s", esp_err_to_name(err));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Track added handlers for cleanup on failure
|
||||
int handlersAdded = 0;
|
||||
|
||||
// Configure and attach ISR for direction pins
|
||||
for (int i = 0; i < 4; i++) {
|
||||
io_conf.pin_bit_mask = (1ULL << dirPins[i]);
|
||||
esp_err_t err = gpio_config(&io_conf);
|
||||
if (err != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to configure GPIO %d: %s", static_cast<int>(dirPins[i]), esp_err_to_name(err));
|
||||
// Cleanup previously added handlers
|
||||
for (int j = 0; j < handlersAdded; j++) {
|
||||
gpio_isr_handler_remove(dirPins[j]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
err = gpio_isr_handler_add(dirPins[i], trackball_isr_handler, reinterpret_cast<void*>(static_cast<intptr_t>(dirPins[i])));
|
||||
if (err != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to add ISR for GPIO %d: %s", static_cast<int>(dirPins[i]), esp_err_to_name(err));
|
||||
// Cleanup previously added handlers
|
||||
for (int j = 0; j < handlersAdded; j++) {
|
||||
gpio_isr_handler_remove(dirPins[j]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
handlersAdded++;
|
||||
}
|
||||
|
||||
// Configure button pin (any edge for press/release detection)
|
||||
io_conf.intr_type = GPIO_INTR_ANYEDGE;
|
||||
io_conf.pin_bit_mask = (1ULL << config.pinClick);
|
||||
esp_err_t err = gpio_config(&io_conf);
|
||||
if (err != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to configure button GPIO %d: %s", static_cast<int>(config.pinClick), esp_err_to_name(err));
|
||||
// Cleanup direction handlers
|
||||
for (int i = 0; i < 4; i++) {
|
||||
gpio_isr_handler_remove(dirPins[i]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
err = gpio_isr_handler_add(config.pinClick, button_isr_handler, nullptr);
|
||||
if (err != ESP_OK) {
|
||||
LOG_E(TAG, "Failed to add button ISR: %s", esp_err_to_name(err));
|
||||
// Cleanup direction handlers
|
||||
for (int i = 0; i < 4; i++) {
|
||||
gpio_isr_handler_remove(dirPins[i]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Read initial button state
|
||||
g_buttonPressed.store(gpio_get_level(config.pinClick) == 0);
|
||||
|
||||
// Register as LVGL encoder input device for group navigation (default mode)
|
||||
g_indev = lv_indev_create();
|
||||
if (g_indev == nullptr) {
|
||||
LOG_E(TAG, "Failed to register LVGL input device");
|
||||
// Cleanup ISR handlers on failure
|
||||
const gpio_num_t pins[5] = {
|
||||
config.pinRight, config.pinUp, config.pinLeft,
|
||||
config.pinDown, config.pinClick
|
||||
};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
gpio_intr_disable(pins[i]);
|
||||
gpio_isr_handler_remove(pins[i]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
lv_indev_set_type(g_indev, LV_INDEV_TYPE_ENCODER);
|
||||
lv_indev_set_read_cb(g_indev, read_cb);
|
||||
g_initialized.store(true, std::memory_order_relaxed);
|
||||
LOG_I(TAG, "Initialized with interrupts (R:%d U:%d L:%d D:%d Click:%d)",
|
||||
static_cast<int>(config.pinRight),
|
||||
static_cast<int>(config.pinUp),
|
||||
static_cast<int>(config.pinLeft),
|
||||
static_cast<int>(config.pinDown),
|
||||
static_cast<int>(config.pinClick));
|
||||
|
||||
return g_indev;
|
||||
}
|
||||
|
||||
// Create cursor for pointer mode
|
||||
static void createCursor() {
|
||||
if (g_cursor != nullptr || g_indev == nullptr) return;
|
||||
|
||||
g_cursor = lv_image_create(lv_layer_sys());
|
||||
if (g_cursor != nullptr) {
|
||||
lv_obj_remove_flag(g_cursor, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
// Set cursor image
|
||||
lv_image_set_src(g_cursor, TT_ASSETS_UI_CURSOR);
|
||||
lv_indev_set_cursor(g_indev, g_cursor);
|
||||
LOG_D(TAG, "Cursor created");
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy cursor when switching back to encoder mode
|
||||
static void destroyCursor() {
|
||||
if (g_cursor == nullptr) return;
|
||||
|
||||
// Delete the cursor object - this automatically detaches it from the indev
|
||||
lv_obj_delete(g_cursor);
|
||||
g_cursor = nullptr;
|
||||
LOG_D(TAG, "Cursor destroyed");
|
||||
}
|
||||
|
||||
void deinit() {
|
||||
if (!g_initialized.load(std::memory_order_relaxed)) return;
|
||||
|
||||
destroyCursor();
|
||||
|
||||
// Disable interrupts and remove ISR handlers
|
||||
const gpio_num_t pins[5] = {
|
||||
g_config.pinRight,
|
||||
g_config.pinUp,
|
||||
g_config.pinLeft,
|
||||
g_config.pinDown,
|
||||
g_config.pinClick
|
||||
};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
gpio_intr_disable(pins[i]);
|
||||
gpio_isr_handler_remove(pins[i]);
|
||||
}
|
||||
|
||||
if (g_indev) {
|
||||
lv_indev_delete(g_indev);
|
||||
g_indev = nullptr;
|
||||
}
|
||||
|
||||
g_initialized.store(false, std::memory_order_relaxed);
|
||||
g_mode.store(Mode::Encoder, std::memory_order_relaxed);
|
||||
g_enabled.store(true, std::memory_order_relaxed);
|
||||
LOG_I(TAG, "Deinitialized");
|
||||
}
|
||||
|
||||
void setEncoderSensitivity(uint8_t sensitivity) {
|
||||
if (sensitivity > 0) {
|
||||
// Only update the atomic - ISR reads from atomic, not g_config
|
||||
g_encoderSensitivity.store(sensitivity, std::memory_order_relaxed);
|
||||
LOG_D(TAG, "Encoder sensitivity set to %d", sensitivity);
|
||||
}
|
||||
}
|
||||
|
||||
void setPointerSensitivity(uint8_t sensitivity) {
|
||||
if (sensitivity > 0) {
|
||||
// Only update the atomic - ISR reads from atomic, not g_config
|
||||
g_pointerSensitivity.store(sensitivity, std::memory_order_relaxed);
|
||||
LOG_D(TAG, "Pointer sensitivity set to %d", sensitivity);
|
||||
}
|
||||
}
|
||||
|
||||
void setEnabled(bool enabled) {
|
||||
g_enabled.store(enabled, std::memory_order_relaxed);
|
||||
|
||||
if (!enabled) {
|
||||
// Clear accumulated state to prevent jumps on re-enable
|
||||
g_encoderDiff.store(0, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// Hide/show cursor based on enabled state when in pointer mode
|
||||
// Note: Must be called from LVGL thread (main thread) for thread safety
|
||||
lv_obj_t* cursor = g_cursor; // Local copy to avoid race with setMode
|
||||
if (cursor != nullptr) {
|
||||
if (enabled) {
|
||||
lv_obj_clear_flag(cursor, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_add_flag(cursor, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_I(TAG, "%s", enabled ? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
void setMode(Mode mode) {
|
||||
// Note: Must be called from LVGL thread (main thread) for thread safety
|
||||
if (!g_initialized.load(std::memory_order_relaxed) || g_indev == nullptr) {
|
||||
LOG_W(TAG, "Cannot set mode - not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_mode.load(std::memory_order_relaxed) == mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_mode.store(mode, std::memory_order_relaxed);
|
||||
|
||||
if (mode == Mode::Pointer) {
|
||||
// Switch to pointer mode
|
||||
lv_indev_set_type(g_indev, LV_INDEV_TYPE_POINTER);
|
||||
createCursor();
|
||||
if (!g_enabled.load(std::memory_order_relaxed) && g_cursor != nullptr) {
|
||||
lv_obj_add_flag(g_cursor, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
// Reset cursor to center when switching modes
|
||||
g_cursorX.store(SCREEN_WIDTH / 2, std::memory_order_relaxed);
|
||||
g_cursorY.store(SCREEN_HEIGHT / 2, std::memory_order_relaxed);
|
||||
LOG_I(TAG, "Switched to Pointer mode");
|
||||
} else {
|
||||
// Switch to encoder mode
|
||||
destroyCursor();
|
||||
lv_indev_set_type(g_indev, LV_INDEV_TYPE_ENCODER);
|
||||
g_encoderDiff.store(0, std::memory_order_relaxed); // Reset encoder diff
|
||||
LOG_I(TAG, "Switched to Encoder mode");
|
||||
}
|
||||
}
|
||||
|
||||
Mode getMode() {
|
||||
return g_mode.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace trackball {
|
||||
|
||||
/**
|
||||
* @brief Trackball operating mode
|
||||
*/
|
||||
enum class Mode {
|
||||
Encoder, // Navigation via enc_diff (scroll wheel behavior)
|
||||
Pointer // Mouse cursor via point.x/y
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Trackball configuration structure
|
||||
*/
|
||||
struct TrackballConfig {
|
||||
gpio_num_t pinRight; // Right direction GPIO
|
||||
gpio_num_t pinUp; // Up direction GPIO
|
||||
gpio_num_t pinLeft; // Left direction GPIO
|
||||
gpio_num_t pinDown; // Down direction GPIO
|
||||
gpio_num_t pinClick; // Click/select button GPIO
|
||||
uint8_t encoderSensitivity = 1; // Encoder mode: steps per tick
|
||||
uint8_t pointerSensitivity = 10; // Pointer mode: pixels per tick
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize trackball as LVGL input device
|
||||
* @param config Trackball GPIO configuration
|
||||
* @return LVGL input device pointer, or nullptr on failure
|
||||
*/
|
||||
lv_indev_t* init(const TrackballConfig& config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize trackball
|
||||
*/
|
||||
void deinit();
|
||||
|
||||
/**
|
||||
* @brief Set encoder mode sensitivity
|
||||
* @param sensitivity Steps per trackball tick (1-10, default: 1)
|
||||
*/
|
||||
void setEncoderSensitivity(uint8_t sensitivity);
|
||||
|
||||
/**
|
||||
* @brief Set pointer mode sensitivity
|
||||
* @param sensitivity Pixels per trackball tick (1-10, default: 10)
|
||||
*/
|
||||
void setPointerSensitivity(uint8_t sensitivity);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable trackball input processing
|
||||
* @param enabled Boolean value to enable or disable
|
||||
*/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* @brief Set trackball operating mode
|
||||
* @param mode Encoder or Pointer mode
|
||||
*/
|
||||
void setMode(Mode mode);
|
||||
|
||||
/**
|
||||
* @brief Get current trackball operating mode
|
||||
* @return Current mode
|
||||
*/
|
||||
Mode getMode();
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "Display.h"
|
||||
|
||||
#include <Gt911Touch.h>
|
||||
#include <PwmBacklight.h>
|
||||
#include <St7789Display.h>
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/device.h>
|
||||
|
||||
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
|
||||
auto* i2c = device_find_by_name("i2c0");
|
||||
check(i2c);
|
||||
auto configuration = std::make_unique<Gt911Touch::Configuration>(
|
||||
i2c,
|
||||
240,
|
||||
320,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
GPIO_NUM_NC,
|
||||
GPIO_NUM_16
|
||||
);
|
||||
|
||||
return std::make_shared<Gt911Touch>(std::move(configuration));
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
St7789Display::Configuration panel_configuration = {
|
||||
.horizontalResolution = 320,
|
||||
.verticalResolution = 240,
|
||||
.gapX = 0,
|
||||
.gapY = 0,
|
||||
.swapXY = true,
|
||||
.mirrorX = true,
|
||||
.mirrorY = false,
|
||||
.invertColor = true,
|
||||
.bufferSize = LCD_BUFFER_SIZE,
|
||||
.touch = createTouch(),
|
||||
.backlightDutyFunction = driver::pwmbacklight::setBacklightDuty,
|
||||
.resetPin = GPIO_NUM_NC,
|
||||
.lvglSwapBytes = false,
|
||||
.buffSpiram = false // Enabling leads to crashes when refreshing App Hub list
|
||||
};
|
||||
|
||||
auto spi_configuration = std::make_shared<St7789Display::SpiConfiguration>(St7789Display::SpiConfiguration {
|
||||
.spiHostDevice = LCD_SPI_HOST,
|
||||
.csPin = LCD_PIN_CS,
|
||||
.dcPin = LCD_PIN_DC,
|
||||
.pixelClockFrequency = 62'500'000,
|
||||
.transactionQueueDepth = 10
|
||||
});
|
||||
|
||||
return std::make_shared<St7789Display>(panel_configuration, spi_configuration);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
|
||||
constexpr auto LCD_SPI_HOST = SPI2_HOST;
|
||||
constexpr auto LCD_PIN_CS = GPIO_NUM_12;
|
||||
constexpr auto LCD_PIN_DC = GPIO_NUM_11; // RS
|
||||
constexpr auto LCD_HORIZONTAL_RESOLUTION = 320;
|
||||
constexpr auto LCD_VERTICAL_RESOLUTION = 240;
|
||||
constexpr auto LCD_BUFFER_HEIGHT = (LCD_VERTICAL_RESOLUTION / 10);
|
||||
constexpr auto LCD_BUFFER_SIZE = (LCD_HORIZONTAL_RESOLUTION * LCD_BUFFER_HEIGHT);
|
||||
constexpr auto LCD_SPI_TRANSFER_SIZE_LIMIT = LCD_BUFFER_SIZE * LV_COLOR_DEPTH / 8;
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
@@ -1,51 +0,0 @@
|
||||
#include "KeyboardBacklight.h"
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h> // Driver
|
||||
#include <Tactility/settings/KeyboardSettings.h>
|
||||
|
||||
// TODO: Add Mutex and consider refactoring into a class
|
||||
bool KeyboardBacklightDevice::start() {
|
||||
if (initialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// T-Deck uses I2C_NUM_0 for internal peripherals
|
||||
initialized = keyboardbacklight::init(I2C_NUM_0);
|
||||
if (!initialized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Backlight doesn't seem to turn on until toggled on and off from keyboard settings...
|
||||
// Or let the display and backlight sleep then wake it up.
|
||||
// Then it works fine...until reboot, then you need to toggle again.
|
||||
// The current keyboard firmware sets backlight duty to 0 on boot.
|
||||
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/firmware/T-Keyboard_Keyboard_ESP32C3_250620.bin
|
||||
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/Keyboard_ESP32C3/Keyboard_ESP32C3.ino#L25
|
||||
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/Keyboard_ESP32C3/Keyboard_ESP32C3.ino#L217
|
||||
auto kbSettings = tt::settings::keyboard::loadOrGetDefault();
|
||||
keyboardbacklight::setBrightness(kbSettings.backlightEnabled ? kbSettings.backlightBrightness : 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KeyboardBacklightDevice::stop() {
|
||||
if (initialized) {
|
||||
// Turn off backlight on shutdown
|
||||
keyboardbacklight::setBrightness(0);
|
||||
initialized = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KeyboardBacklightDevice::setBrightness(uint8_t brightness) {
|
||||
if (!initialized) {
|
||||
return false;
|
||||
}
|
||||
return keyboardbacklight::setBrightness(brightness);
|
||||
}
|
||||
|
||||
uint8_t KeyboardBacklightDevice::getBrightness() const {
|
||||
if (!initialized) {
|
||||
return 0;
|
||||
}
|
||||
return keyboardbacklight::getBrightness();
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/hal/Device.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
class KeyboardBacklightDevice final : public tt::hal::Device {
|
||||
|
||||
bool initialized = false;
|
||||
|
||||
public:
|
||||
|
||||
tt::hal::Device::Type getType() const override { return tt::hal::Device::Type::I2c; }
|
||||
std::string getName() const override { return "Keyboard Backlight"; }
|
||||
std::string getDescription() const override { return "T-Deck keyboard backlight control"; }
|
||||
|
||||
bool start();
|
||||
bool stop();
|
||||
bool isAttached() const { return initialized; }
|
||||
|
||||
/**
|
||||
* Set keyboard backlight brightness
|
||||
* @param brightness 0-255 (0=off, 255=max)
|
||||
*/
|
||||
bool setBrightness(uint8_t brightness);
|
||||
|
||||
/**
|
||||
* Get current brightness
|
||||
* @return 0-255
|
||||
*/
|
||||
uint8_t getBrightness() const;
|
||||
};
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <ChargeFromAdcVoltage.h>
|
||||
#include <EstimatedPower.h>
|
||||
|
||||
std::shared_ptr<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);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
|
||||
std::shared_ptr<tt::hal::power::PowerDevice> createPower();
|
||||
@@ -1,86 +0,0 @@
|
||||
#include "TdeckKeyboard.h"
|
||||
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
#include <Tactility/settings/KeyboardSettings.h>
|
||||
#include <lvgl.h>
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
using tt::hal::findFirstDevice;
|
||||
|
||||
constexpr auto* TAG = "TdeckKeyboard";
|
||||
|
||||
constexpr uint8_t TDECK_KEYBOARD_SLAVE_ADDRESS = 0x55;
|
||||
|
||||
/**
|
||||
* The callback simulates press and release events, because the T-Deck
|
||||
* keyboard only publishes press events on I2C.
|
||||
* LVGL currently works without those extra release events, but they
|
||||
* are implemented for correctness and future compatibility.
|
||||
*
|
||||
* @param indev_drv
|
||||
* @param data
|
||||
*/
|
||||
static void keyboard_read_callback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
static uint8_t last_buffer = 0x00;
|
||||
uint8_t read_buffer = 0x00;
|
||||
|
||||
// Defaults
|
||||
data->key = 0;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
auto* keyboard = static_cast<TdeckKeyboard*>(lv_indev_get_user_data(indev));
|
||||
if (i2c_controller_read(keyboard->getI2cController(), TDECK_KEYBOARD_SLAVE_ADDRESS, &read_buffer, 1, 100 / portTICK_PERIOD_MS) == ERROR_NONE) {
|
||||
if (read_buffer == 0 && read_buffer != last_buffer) {
|
||||
LOG_D(TAG, "Released %d", last_buffer);
|
||||
data->key = last_buffer;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
} else if (read_buffer != 0) {
|
||||
LOG_D(TAG, "Pressed %d", read_buffer);
|
||||
data->key = read_buffer;
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
// TODO: Avoid performance hit by calling loadOrGetDefault() on each key press
|
||||
// Ensure LVGL activity is triggered so idle services can wake the display
|
||||
lv_display_trigger_activity(nullptr);
|
||||
|
||||
// Actively wake display/backlights immediately on key press (independent of idle tick)
|
||||
// Restore display backlight if off (we assume duty 0 means dimmed)
|
||||
auto display = findFirstDevice<tt::hal::display::DisplayDevice>(tt::hal::Device::Type::Display);
|
||||
if (display && display->supportsBacklightDuty()) {
|
||||
// Load display settings for target duty
|
||||
auto dsettings = tt::settings::display::loadOrGetDefault();
|
||||
// Always set duty, harmless if already on
|
||||
display->setBacklightDuty(dsettings.backlightDuty);
|
||||
}
|
||||
|
||||
// Restore keyboard backlight if enabled in settings
|
||||
auto ksettings = tt::settings::keyboard::loadOrGetDefault();
|
||||
if (ksettings.backlightEnabled) {
|
||||
keyboardbacklight::setBrightness(ksettings.backlightBrightness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_buffer = read_buffer;
|
||||
}
|
||||
|
||||
bool TdeckKeyboard::startLvgl(lv_display_t* display) {
|
||||
deviceHandle = lv_indev_create();
|
||||
lv_indev_set_type(deviceHandle, LV_INDEV_TYPE_KEYPAD);
|
||||
lv_indev_set_read_cb(deviceHandle, &keyboard_read_callback);
|
||||
lv_indev_set_display(deviceHandle, display);
|
||||
lv_indev_set_user_data(deviceHandle, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TdeckKeyboard::stopLvgl() {
|
||||
lv_indev_delete(deviceHandle);
|
||||
deviceHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TdeckKeyboard::isAttached() const {
|
||||
return i2c_controller_has_device_at_address(i2cController, TDECK_KEYBOARD_SLAVE_ADDRESS, 100) == ERROR_NONE;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/keyboard/KeyboardDevice.h>
|
||||
|
||||
struct Device;
|
||||
|
||||
class TdeckKeyboard final : public tt::hal::keyboard::KeyboardDevice {
|
||||
|
||||
::Device* i2cController;
|
||||
lv_indev_t* deviceHandle = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
explicit TdeckKeyboard(::Device* i2cController) : i2cController(i2cController) {}
|
||||
|
||||
std::string getName() const override { return "T-Deck Keyboard"; }
|
||||
std::string getDescription() const override { return "I2C keyboard"; }
|
||||
|
||||
::Device* getI2cController() const { return i2cController; }
|
||||
|
||||
bool startLvgl(lv_display_t* display) override;
|
||||
bool stopLvgl() override;
|
||||
bool isAttached() const override;
|
||||
lv_indev_t* getLvglIndev() override { return deviceHandle; }
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
#include "TrackballDevice.h"
|
||||
#include <Trackball/Trackball.h> // Driver
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "TrackballDevice";
|
||||
|
||||
bool TrackballDevice::start() {
|
||||
if (initialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// T-Deck trackball GPIO configuration from LilyGo reference
|
||||
trackball::TrackballConfig config = {
|
||||
.pinRight = GPIO_NUM_2, // BOARD_TBOX_G02
|
||||
.pinUp = GPIO_NUM_3, // BOARD_TBOX_G01
|
||||
.pinLeft = GPIO_NUM_1, // BOARD_TBOX_G04
|
||||
.pinDown = GPIO_NUM_15, // BOARD_TBOX_G03
|
||||
.pinClick = GPIO_NUM_0, // BOARD_BOOT_PIN
|
||||
.encoderSensitivity = 1, // 1 step per tick for menu navigation
|
||||
.pointerSensitivity = 10 // 10 pixels per tick for cursor movement
|
||||
};
|
||||
|
||||
indev = trackball::init(config);
|
||||
if (indev == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
// Apply persisted trackball settings (requires LVGL lock for cursor manipulation)
|
||||
auto tbSettings = tt::settings::trackball::loadOrGetDefault();
|
||||
if (tt::lvgl::lock(100)) {
|
||||
trackball::setMode(tbSettings.trackballMode == tt::settings::trackball::TrackballMode::Pointer
|
||||
? trackball::Mode::Pointer
|
||||
: trackball::Mode::Encoder);
|
||||
trackball::setEncoderSensitivity(tbSettings.encoderSensitivity);
|
||||
trackball::setPointerSensitivity(tbSettings.pointerSensitivity);
|
||||
trackball::setEnabled(tbSettings.trackballEnabled);
|
||||
tt::lvgl::unlock();
|
||||
} else {
|
||||
LOG_W(TAG, "Failed to acquire LVGL lock for trackball settings");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TrackballDevice::stop() {
|
||||
if (initialized) {
|
||||
// LVGL will handle indev cleanup
|
||||
trackball::deinit();
|
||||
indev = nullptr;
|
||||
initialized = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/hal/Device.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
class TrackballDevice : public tt::hal::Device {
|
||||
public:
|
||||
tt::hal::Device::Type getType() const override { return tt::hal::Device::Type::Other; }
|
||||
std::string getName() const override { return "Trackball"; }
|
||||
std::string getDescription() const override { return "5-way GPIO trackball navigation"; }
|
||||
|
||||
bool start();
|
||||
bool stop();
|
||||
bool isAttached() const { return initialized; }
|
||||
|
||||
lv_indev_t* getLvglIndev() const { return indev; }
|
||||
|
||||
private:
|
||||
lv_indev_t* indev = nullptr;
|
||||
bool initialized = false;
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
#include <tactility/module.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static error_t start() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
// Empty for now
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module lilygo_tdeck_module = {
|
||||
.name = "lilygo-tdeck",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
general.vendor=LilyGO
|
||||
general.name=T-Deck,T-Deck Plus
|
||||
general.name=T-Deck
|
||||
|
||||
apps.launcherAppId=Launcher
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
dependencies:
|
||||
- Platforms/platform-esp32
|
||||
- Drivers/st7789-module
|
||||
- Drivers/gt911-module
|
||||
- Drivers/lilygo-module
|
||||
dts: lilygo,tdeck.dts
|
||||
|
||||
@@ -1,22 +1,45 @@
|
||||
/dts-v1/;
|
||||
|
||||
#include <tactility/bindings/battery_sense.h>
|
||||
#include <tactility/bindings/root.h>
|
||||
#include <tactility/bindings/esp32_adc_oneshot.h>
|
||||
#include <tactility/bindings/esp32_ble.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
#include <tactility/bindings/esp32_gpio.h>
|
||||
#include <tactility/bindings/esp32_grove.h>
|
||||
#include <tactility/bindings/esp32_i2c.h>
|
||||
#include <tactility/bindings/esp32_i2s.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
#include <tactility/bindings/esp32_ledc_backlight.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_wifi_pinned.h>
|
||||
#include <tactility/bindings/esp32_uart.h>
|
||||
|
||||
// Reference: https://wiki.lilygo.cc/get_started/en/Wearable/T-Deck-Plus/T-Deck-Plus.html#Pin-Overview
|
||||
#include <bindings/gt911.h>
|
||||
#include <bindings/st7789.h>
|
||||
|
||||
#include <lilygo/bindings/tdeck_keyboard.h>
|
||||
#include <lilygo/bindings/tdeck_keyboard_backlight.h>
|
||||
#include <lilygo/bindings/tdeck_trackball.h>
|
||||
|
||||
// Reference: https://wiki.lilygo.cc/products/t-deck-series/t-deck/
|
||||
/ {
|
||||
compatible = "root";
|
||||
model = "LilyGO T-Deck";
|
||||
|
||||
adc0 {
|
||||
compatible = "espressif,esp32-adc-oneshot";
|
||||
unit-id = <ADC_UNIT_1>;
|
||||
clk-src = <ADC_RTC_CLK_SRC_DEFAULT>;
|
||||
channels = <ADC_CHANNEL_3 ADC_ATTEN_DB_12 ADC_BITWIDTH_DEFAULT>;
|
||||
};
|
||||
|
||||
battery-sense {
|
||||
compatible = "battery-sense";
|
||||
io-channel = <&adc0 0>;
|
||||
reference-voltage-mv = <3300>;
|
||||
multiplier = <2110>;
|
||||
};
|
||||
|
||||
wifi0 {
|
||||
compatible = "espressif,esp32-wifi-pinned";
|
||||
status = "disabled";
|
||||
@@ -32,12 +55,41 @@
|
||||
gpio-count = <49>;
|
||||
};
|
||||
|
||||
trackball {
|
||||
compatible = "lilygo,tdeck-trackball";
|
||||
pin-right = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
pin-up = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
pin-left = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
pin-down = <&gpio0 15 GPIO_FLAG_NONE>;
|
||||
pin-click = <&gpio0 0 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
i2c_internal: i2c0 {
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <100000>;
|
||||
pin-sda = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
|
||||
touch {
|
||||
compatible = "goodix,gt911";
|
||||
reg = <0x5D>;
|
||||
x-max = <240>;
|
||||
y-max = <320>;
|
||||
swap-xy;
|
||||
mirror-x;
|
||||
pin-interrupt = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
keyboard {
|
||||
compatible = "lilygo,tdeck-keyboard";
|
||||
reg = <0x55>;
|
||||
};
|
||||
|
||||
keyboard_backlight {
|
||||
compatible = "lilygo,tdeck-keyboard-backlight";
|
||||
reg = <0x55>;
|
||||
};
|
||||
};
|
||||
|
||||
i2s0 {
|
||||
@@ -48,6 +100,17 @@
|
||||
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
display_backlight {
|
||||
compatible = "espressif,esp32-ledc-backlight";
|
||||
// Off by default so dispaly power-on won't show the screen from before the last power loss.
|
||||
// The display backlight is turned on during the boot process.
|
||||
status = "disabled";
|
||||
pin-backlight = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
// 32 KHz and higher causes the screen to start dimming again above 80% brightness
|
||||
// when moving the brightness slider rapidly from a lower setting to 100% (debug-traced, not a slider bug).
|
||||
frequency-hz = <30000>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
@@ -59,20 +122,32 @@
|
||||
pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
|
||||
|
||||
display@0 {
|
||||
compatible = "display-placeholder";
|
||||
compatible = "sitronix,st7789";
|
||||
horizontal-resolution = <320>;
|
||||
vertical-resolution = <240>;
|
||||
swap-xy;
|
||||
mirror-x;
|
||||
invert-color;
|
||||
pixel-clock-hz = <62500000>;
|
||||
pin-dc = <&gpio0 11 GPIO_FLAG_NONE>;
|
||||
backlight = <&display_backlight>;
|
||||
};
|
||||
|
||||
// Must be started after display
|
||||
sdcard@1 {
|
||||
compatible = "espressif,esp32-sdspi";
|
||||
status = "disabled"; // Must be started after display
|
||||
status = "disabled";
|
||||
frequency-khz = <20000>;
|
||||
};
|
||||
};
|
||||
|
||||
uart0 {
|
||||
compatible = "espressif,esp32-uart";
|
||||
port = <UART_NUM_1>;
|
||||
pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
|
||||
pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
|
||||
grove0 {
|
||||
compatible = "espressif,esp32-grove";
|
||||
defaultMode = <GROVE_MODE_I2C>;
|
||||
pinSdaTx = <&gpio0 43 GPIO_FLAG_NONE>;
|
||||
pinSclRx = <&gpio0 44 GPIO_FLAG_NONE>;
|
||||
uartPort = <UART_NUM_1>;
|
||||
i2cPort = <I2C_NUM_1>;
|
||||
i2cClockFrequency = <400000>;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include "lilygo/drivers/tdeck_power_on.h"
|
||||
#include "tactility/lvgl_module.h"
|
||||
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <Tactility/SystemEvents.h>
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
|
||||
#include <lilygo/drivers/trackball.h>
|
||||
|
||||
constexpr auto* TAG = "tdeck";
|
||||
|
||||
// Legacy placeholder (required until legacy HAL is cleaned up everywhere)
|
||||
extern const tt::hal::Configuration hardwareConfiguration = {};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void subscribe_events() {
|
||||
// The kernel trackball device is already started by kernel_init(); this just registers it as an
|
||||
// LVGL input device and applies persisted settings, both of which require LVGL to be up first.
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto tbSettings = tt::settings::trackball::loadOrGetDefault();
|
||||
lvgl_lock();
|
||||
if (trackball::init() != nullptr) {
|
||||
trackball::setMode(tbSettings.trackballMode == tt::settings::trackball::TrackballMode::Pointer
|
||||
? trackball::Mode::Pointer
|
||||
: trackball::Mode::Encoder);
|
||||
trackball::setEncoderSensitivity(tbSettings.encoderSensitivity);
|
||||
trackball::setPointerSensitivity(tbSettings.pointerSensitivity);
|
||||
trackball::setEnabled(tbSettings.trackballEnabled);
|
||||
}
|
||||
lvgl_unlock();
|
||||
});
|
||||
}
|
||||
|
||||
static error_t start() {
|
||||
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
if (!tdeck_power_on()) {
|
||||
LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
// Avoids crash when no SD card is inserted. It's unknown why, but likely is related to power draw.
|
||||
tt::kernel::delayMillis(100);
|
||||
|
||||
subscribe_events();
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
Module lilygo_tdeck_module = {
|
||||
.name = "lilygo-tdeck",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_sdmmc.h>
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -43,7 +43,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <tactility/bindings/esp32_spi.h>
|
||||
#include <tactility/bindings/esp32_sdspi.h>
|
||||
#include <tactility/bindings/display_placeholder.h>
|
||||
#include <tactility/bindings/touch_placeholder.h>
|
||||
#include <tactility/bindings/pointer_placeholder.h>
|
||||
|
||||
/ {
|
||||
compatible = "root";
|
||||
@@ -53,7 +53,7 @@
|
||||
};
|
||||
|
||||
touch@1 {
|
||||
compatible = "touch-placeholder";
|
||||
compatible = "pointer-placeholder";
|
||||
};
|
||||
|
||||
sdcard@2 {
|
||||
|
||||
Reference in New Issue
Block a user