Trackball rewrite (#600)
- Implement generic trackball settings - Refactor T-Deck trackball driver into generic driver at `Drivers/gpio-trackball-module` - Automatically bind/unbind trackball devices with LVGL - Automatically load settings for trackball devices on boot
This commit is contained in:
committed by
GitHub
parent
de6fc3b346
commit
c729e8340f
@@ -2,5 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES Tactility driver lilygo-module
|
||||
REQUIRES TactilityKernel lilygo-module
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ dependencies:
|
||||
- Drivers/st7789-module
|
||||
- Drivers/gt911-module
|
||||
- Drivers/lilygo-module
|
||||
- Drivers/gpio-trackball-module
|
||||
- Drivers/es7210-module
|
||||
- Drivers/dummy-i2s-amp-module
|
||||
- Drivers/audio-stream-module
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#include <bindings/st7789.h>
|
||||
#include <bindings/es7210.h>
|
||||
#include <bindings/dummy_i2s_amp.h>
|
||||
#include <bindings/gpio_trackball.h>
|
||||
|
||||
#include <gps_generic/bindings.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/
|
||||
/ {
|
||||
@@ -61,7 +61,7 @@
|
||||
};
|
||||
|
||||
trackball {
|
||||
compatible = "lilygo,tdeck-trackball";
|
||||
compatible = "tactility,gpio-trackball";
|
||||
pin-right = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
pin-up = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
pin-left = <&gpio0 1 GPIO_FLAG_NONE>;
|
||||
|
||||
@@ -1,57 +1,25 @@
|
||||
#include <tactility/delay.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/system_event.h>
|
||||
|
||||
#include <Tactility/LogMessages.h>
|
||||
#include <Tactility/settings/TrackballSettings.h>
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
#include <lilygo/drivers/trackball.h>
|
||||
#include <lilygo/drivers/tdeck_power_on.h>
|
||||
|
||||
constexpr auto* TAG = "tdeck-plus";
|
||||
|
||||
extern "C" {
|
||||
|
||||
void init_trackball() {
|
||||
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 void on_boot_completed(struct SystemEvent* /*event*/, void* /*context*/) {
|
||||
init_trackball();
|
||||
}
|
||||
|
||||
static error_t start() {
|
||||
LOG_I(TAG, LOG_MESSAGE_POWER_ON_START);
|
||||
LOG_I(TAG, "Power on start");
|
||||
|
||||
if (!tdeck_power_on()) {
|
||||
LOG_E(TAG, LOG_MESSAGE_POWER_ON_FAILED);
|
||||
LOG_E(TAG, "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.
|
||||
delay_millis(100);
|
||||
|
||||
system_event_subscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed, nullptr);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static error_t stop() {
|
||||
system_event_unsubscribe(KERNEL_EVENT_BOOT_COMPLETED, on_boot_completed);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user