Feature additions (#434)
Lots of things "ported" over from the "enhanced" fork. With some adjustments here and there. KeyboardBacklight driver (for T-Deck only currently) Trackball driver (for T-Deck only currently) Keyboard backlight sleep/wake (for T-Deck only currently...also requires keyboard firmware update) Display sleep/wake Files - create file/folder Keyboard settings (for T-Deck only currently) Time & Date settings tweaks Locale settings tweaks Systeminfo additions Espnow wifi coexist initI2cDevices - moved to T-deck init.cpp / initBoot KeyboardInitService - removed, moved to T-deck init.cpp / initBoot Adjusted TIMER_UPDATE_INTERVAL to 2 seconds. Added lock to ActionCreateFolder Maybe missed some things in the list. Display wake could do with some kind of block on wake first touch to prevent UI elements being hit when waking device with touch. Same with encoder/trackball/keyboard press i guess. The original code was written by @cscott0108 at https://github.com/cscott0108/tactility-enhanced-t-deck
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "devices/Display.h"
|
||||
#include "devices/KeyboardBacklight.h"
|
||||
#include "devices/Power.h"
|
||||
#include "devices/Sdcard.h"
|
||||
#include "devices/TdeckKeyboard.h"
|
||||
#include "devices/TrackballDevice.h"
|
||||
|
||||
#include <Tactility/hal/Configuration.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
@@ -15,6 +17,8 @@ static std::vector<std::shared_ptr<Device>> createDevices() {
|
||||
createPower(),
|
||||
createDisplay(),
|
||||
std::make_shared<TdeckKeyboard>(),
|
||||
std::make_shared<KeyboardBacklightDevice>(),
|
||||
std::make_shared<TrackballDevice>(),
|
||||
createSdCard()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <Tactility/hal/gps/GpsConfiguration.h>
|
||||
#include <Tactility/settings/KeyboardSettings.h>
|
||||
|
||||
#include "devices/KeyboardBacklight.h"
|
||||
#include "devices/TrackballDevice.h"
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h>
|
||||
#include <Trackball/Trackball.h>
|
||||
|
||||
#define TAG "tdeck"
|
||||
|
||||
@@ -59,5 +65,45 @@ bool initBoot() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](tt::kernel::SystemEvent event) {
|
||||
auto kbBacklight = tt::hal::findDevice("Keyboard Backlight");
|
||||
if (kbBacklight != nullptr) {
|
||||
TT_LOG_I(TAG, "%s starting", kbBacklight->getName().c_str());
|
||||
auto kbDevice = std::static_pointer_cast<KeyboardBacklightDevice>(kbBacklight);
|
||||
if (kbDevice->start()) {
|
||||
TT_LOG_I(TAG, "%s started", kbBacklight->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "%s start failed", kbBacklight->getName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
auto trackball = tt::hal::findDevice("Trackball");
|
||||
if (trackball != nullptr) {
|
||||
TT_LOG_I(TAG, "%s starting", trackball->getName().c_str());
|
||||
auto tbDevice = std::static_pointer_cast<TrackballDevice>(trackball);
|
||||
if (tbDevice->start()) {
|
||||
TT_LOG_I(TAG, "%s started", trackball->getName().c_str());
|
||||
} else {
|
||||
TT_LOG_E(TAG, "%s start failed", trackball->getName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
bool result = keyboardbacklight::setBrightness(kbSettings.backlightEnabled ? kbSettings.backlightBrightness : 0);
|
||||
if (!result) {
|
||||
TT_LOG_W(TAG, "Failed to set keyboard backlight brightness");
|
||||
}
|
||||
|
||||
trackball::setEnabled(kbSettings.trackballEnabled);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
#include "KeyboardBacklight.h"
|
||||
#include <esp_log.h>
|
||||
#include <cstring>
|
||||
|
||||
static const char* 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;
|
||||
|
||||
ESP_LOGI(TAG, "Keyboard backlight initialized on I2C port %d, address 0x%02X", g_i2cPort, g_slaveAddress);
|
||||
|
||||
// Set a reasonable default brightness
|
||||
if (!setDefaultBrightness(127)) {
|
||||
ESP_LOGE(TAG, "Failed to set default brightness");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!setBrightness(127)) {
|
||||
ESP_LOGE(TAG, "Failed to set brightness");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setBrightness(uint8_t brightness) {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "Keyboard backlight not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip if brightness is already at target value (avoid I2C spam on every keypress)
|
||||
if (brightness == g_currentBrightness) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting brightness to %d on I2C port %d, address 0x%02X", brightness, g_i2cPort, 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;
|
||||
ESP_LOGI(TAG, "Successfully set brightness to %d", brightness);
|
||||
return true;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to set brightness: %s (0x%x)", esp_err_to_name(ret), ret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool setDefaultBrightness(uint8_t brightness) {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "Keyboard backlight 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) {
|
||||
ESP_LOGD(TAG, "Set default brightness to %d", brightness);
|
||||
return true;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to set default brightness: %s", esp_err_to_name(ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getBrightness() {
|
||||
if (g_i2cPort >= I2C_NUM_MAX) {
|
||||
ESP_LOGE(TAG, "Keyboard backlight not initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return g_currentBrightness;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#include "Trackball.h"
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "Trackball";
|
||||
|
||||
namespace trackball {
|
||||
|
||||
static TrackballConfig g_config;
|
||||
static lv_indev_t* g_indev = nullptr;
|
||||
static bool g_initialized = false;
|
||||
static bool g_enabled = true;
|
||||
|
||||
// Track last GPIO states for edge detection
|
||||
static bool g_lastState[5] = {false, false, false, false, false};
|
||||
|
||||
static void read_cb(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
if (!g_initialized || !g_enabled) {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
data->enc_diff = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const gpio_num_t pins[5] = {
|
||||
g_config.pinRight,
|
||||
g_config.pinUp,
|
||||
g_config.pinLeft,
|
||||
g_config.pinDown,
|
||||
g_config.pinClick
|
||||
};
|
||||
|
||||
// Read GPIO states and detect changes (active low with pull-up)
|
||||
bool currentStates[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
currentStates[i] = gpio_get_level(pins[i]) == 0;
|
||||
}
|
||||
|
||||
// Process directional inputs as encoder steps
|
||||
// Right/Down = positive diff (next item), Left/Up = negative diff (prev item)
|
||||
int16_t diff = 0;
|
||||
|
||||
// Right pressed (rising edge)
|
||||
if (currentStates[0] && !g_lastState[0]) {
|
||||
diff += g_config.movementStep;
|
||||
}
|
||||
// Up pressed (rising edge)
|
||||
if (currentStates[1] && !g_lastState[1]) {
|
||||
diff -= g_config.movementStep;
|
||||
}
|
||||
// Left pressed (rising edge)
|
||||
if (currentStates[2] && !g_lastState[2]) {
|
||||
diff -= g_config.movementStep;
|
||||
}
|
||||
// Down pressed (rising edge)
|
||||
if (currentStates[3] && !g_lastState[3]) {
|
||||
diff += g_config.movementStep;
|
||||
}
|
||||
|
||||
// Update last states
|
||||
for (int i = 0; i < 5; i++) {
|
||||
g_lastState[i] = currentStates[i];
|
||||
}
|
||||
|
||||
// Update encoder diff and button state
|
||||
data->enc_diff = diff;
|
||||
data->state = currentStates[4] ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
|
||||
|
||||
// Trigger activity for wake-on-trackball
|
||||
if (diff != 0 || currentStates[4]) {
|
||||
lv_disp_trig_activity(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
lv_indev_t* init(const TrackballConfig& config) {
|
||||
if (g_initialized) {
|
||||
ESP_LOGW(TAG, "Trackball already initialized");
|
||||
return g_indev;
|
||||
}
|
||||
|
||||
g_config = config;
|
||||
|
||||
// Set default movement step if not specified
|
||||
if (g_config.movementStep == 0) {
|
||||
g_config.movementStep = 10;
|
||||
}
|
||||
|
||||
// Configure all GPIO pins as inputs with pull-ups (active low)
|
||||
const gpio_num_t pins[5] = {
|
||||
config.pinRight,
|
||||
config.pinUp,
|
||||
config.pinLeft,
|
||||
config.pinDown,
|
||||
config.pinClick
|
||||
};
|
||||
|
||||
gpio_config_t io_conf = {};
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
io_conf.pin_bit_mask = (1ULL << pins[i]);
|
||||
gpio_config(&io_conf);
|
||||
g_lastState[i] = gpio_get_level(pins[i]) == 0;
|
||||
}
|
||||
|
||||
// Register as LVGL encoder input device for group navigation
|
||||
g_indev = lv_indev_create();
|
||||
lv_indev_set_type(g_indev, LV_INDEV_TYPE_ENCODER);
|
||||
lv_indev_set_read_cb(g_indev, read_cb);
|
||||
|
||||
if (g_indev) {
|
||||
g_initialized = true;
|
||||
ESP_LOGI(TAG, "Trackball initialized as encoder (R:%d U:%d L:%d D:%d Click:%d)",
|
||||
config.pinRight, config.pinUp, config.pinLeft, config.pinDown,
|
||||
config.pinClick);
|
||||
return g_indev;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to register LVGL input device");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void deinit() {
|
||||
if (g_indev) {
|
||||
lv_indev_delete(g_indev);
|
||||
g_indev = nullptr;
|
||||
}
|
||||
g_initialized = false;
|
||||
ESP_LOGI(TAG, "Trackball deinitialized");
|
||||
}
|
||||
|
||||
void setMovementStep(uint8_t step) {
|
||||
if (step > 0) {
|
||||
g_config.movementStep = step;
|
||||
ESP_LOGD(TAG, "Movement step set to %d", step);
|
||||
}
|
||||
}
|
||||
|
||||
void setEnabled(bool enabled) {
|
||||
g_enabled = enabled;
|
||||
ESP_LOGI(TAG, "Trackball %s", enabled ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace trackball {
|
||||
|
||||
/**
|
||||
* @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 movementStep; // Pixels to move per trackball event (default: 10)
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 movement step size
|
||||
* @param step Encoder steps per trackball event
|
||||
*/
|
||||
void setMovementStep(uint8_t step);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable trackball input processing
|
||||
* @param enabled Boolean value to enable or disable
|
||||
*/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "KeyboardBacklight.h"
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h> // Driver
|
||||
#include <Tactility/hal/i2c/I2c.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);
|
||||
return initialized;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#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,6 +1,14 @@
|
||||
#include "TdeckKeyboard.h"
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
#include <driver/i2c.h>
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/settings/KeyboardSettings.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/Device.h>
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h>
|
||||
|
||||
using tt::hal::findFirstDevice;
|
||||
|
||||
constexpr auto* TAG = "TdeckKeyboard";
|
||||
constexpr auto TDECK_KEYBOARD_I2C_BUS_HANDLE = I2C_NUM_0;
|
||||
@@ -36,6 +44,25 @@ static void keyboard_read_callback(TT_UNUSED lv_indev_t* indev, lv_indev_data_t*
|
||||
TT_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_disp_trig_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "TrackballDevice.h"
|
||||
#include <Trackball/Trackball.h> // Driver
|
||||
|
||||
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
|
||||
.movementStep = 1 // pixels per movement
|
||||
};
|
||||
|
||||
indev = trackball::init(config);
|
||||
if (indev != nullptr) {
|
||||
initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TrackballDevice::stop() {
|
||||
if (initialized) {
|
||||
// LVGL will handle indev cleanup
|
||||
trackball::deinit();
|
||||
indev = nullptr;
|
||||
initialized = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#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;
|
||||
};
|
||||
Reference in New Issue
Block a user