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
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
/**
|
||||
* @brief API for trackball drivers.
|
||||
* Reports raw, unscaled movement: sensitivity and mode (encoder vs. pointer) are UI concerns
|
||||
* layered on top by the consumer (see lvgl/devices/trackball.h), not something this driver knows about.
|
||||
*/
|
||||
struct TrackballApi {
|
||||
/**
|
||||
* @brief Reads the accumulated movement since the last read, then resets it to zero.
|
||||
* @param[in] device the trackball device
|
||||
* @param[out] out_dx horizontal movement (right positive), in raw pulses
|
||||
* @param[out] out_dy vertical movement (down positive), in raw pulses
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*read_delta)(struct Device* device, int32_t* out_dx, int32_t* out_dy);
|
||||
|
||||
/**
|
||||
* @brief Gets whether the click button is currently pressed.
|
||||
* @param[in] device the trackball device
|
||||
* @param[out] out_pressed true when pressed
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*get_button_pressed)(struct Device* device, bool* out_pressed);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Reads the accumulated movement using the specified trackball device.
|
||||
*/
|
||||
error_t trackball_read_delta(struct Device* device, int32_t* out_dx, int32_t* out_dy);
|
||||
|
||||
/**
|
||||
* @brief Gets whether the click button is currently pressed on the specified trackball device.
|
||||
*/
|
||||
error_t trackball_get_button_pressed(struct Device* device, bool* out_pressed);
|
||||
|
||||
extern const struct DeviceType TRACKBALL_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/trackball.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
#define TRACKBALL_DRIVER_API(driver) ((struct TrackballApi*)driver->api)
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t trackball_read_delta(Device* device, int32_t* out_dx, int32_t* out_dy) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return TRACKBALL_DRIVER_API(driver)->read_delta(device, out_dx, out_dy);
|
||||
}
|
||||
|
||||
error_t trackball_get_button_pressed(Device* device, bool* out_pressed) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
return TRACKBALL_DRIVER_API(driver)->get_button_pressed(device, out_pressed);
|
||||
}
|
||||
|
||||
const DeviceType TRACKBALL_TYPE {
|
||||
.name = "trackball"
|
||||
};
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <tactility/drivers/rtc.h>
|
||||
#include <tactility/drivers/sdcard.h>
|
||||
#include <tactility/drivers/spi_controller.h>
|
||||
#include <tactility/drivers/trackball.h>
|
||||
#include <tactility/drivers/uart_controller.h>
|
||||
#include <tactility/drivers/usb_host_hid.h>
|
||||
#include <tactility/drivers/usb_host_midi.h>
|
||||
@@ -294,6 +295,10 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
|
||||
DEFINE_MODULE_SYMBOL(spi_controller_try_lock),
|
||||
DEFINE_MODULE_SYMBOL(spi_controller_unlock),
|
||||
DEFINE_MODULE_SYMBOL(SPI_CONTROLLER_TYPE),
|
||||
// drivers/trackball
|
||||
DEFINE_MODULE_SYMBOL(trackball_read_delta),
|
||||
DEFINE_MODULE_SYMBOL(trackball_get_button_pressed),
|
||||
DEFINE_MODULE_SYMBOL(TRACKBALL_TYPE),
|
||||
// drivers/uart_controller
|
||||
DEFINE_MODULE_SYMBOL(uart_controller_open),
|
||||
DEFINE_MODULE_SYMBOL(uart_controller_close),
|
||||
|
||||
Reference in New Issue
Block a user