Trackball Pointer Mode & driver rewrite (#453)
This commit is contained in:
@@ -1,16 +1,31 @@
|
||||
#include "KeyboardBacklight.h"
|
||||
#include <KeyboardBacklight/KeyboardBacklight.h> // Driver
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
#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);
|
||||
return initialized;
|
||||
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() {
|
||||
|
||||
@@ -1,28 +1,49 @@
|
||||
#include "TrackballDevice.h"
|
||||
#include <Trackball/Trackball.h> // Driver
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
|
||||
static const auto LOGGER = tt::Logger("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
|
||||
.movementStep = 1 // pixels per movement
|
||||
.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) {
|
||||
initialized = true;
|
||||
return true;
|
||||
if (indev == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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 {
|
||||
LOGGER.warn("Failed to acquire LVGL lock for trackball settings");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TrackballDevice::stop() {
|
||||
|
||||
Reference in New Issue
Block a user