summaryrefslogtreecommitdiff
path: root/drivers/sensors/pimoroni_trackball.c
diff options
context:
space:
mode:
authorDasky <32983009+daskygit@users.noreply.github.com>2021-12-27 01:05:51 +0000
committerGitHub <noreply@github.com>2021-12-27 12:05:51 +1100
commit7f7364c55912879baaff8fafca550d02f17b4d44 (patch)
tree8afd414f6b202a126632a8c047dcf200312c78ff /drivers/sensors/pimoroni_trackball.c
parent76a673233c8cb3d97130a6dece364c24b29f5fd7 (diff)
[Core] Split support for pointing devices. (#15304)
* Draft implementation * formatting * fix combined buttons * remove pimoroni throttle * sync pointing on a throttle loop with checksum * no longer used * doh Co-authored-by: Drashna Jaelre <drashna@live.com> * switch pimoroni to a cpi equivalent * add cpi support * allow user modification of seperate mouse reports * a little tidy up * add *_RIGHT defines. * docs * doxygen comments * basic changelog * clean up pimoroni * small doc fixes * Update docs/feature_pointing_device.md Co-authored-by: Drashna Jaelre <drashna@live.com> * performance tweak if side has usb * Don't run init funtions on wrong side * renamed some variables for consistency * fix pimoroni typos * Clamp instead of OR * Promote combined values to uint16_t * Update pointing_device.c Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'drivers/sensors/pimoroni_trackball.c')
-rw-r--r--drivers/sensors/pimoroni_trackball.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c
index 7d390056ea..2867e763bc 100644
--- a/drivers/sensors/pimoroni_trackball.c
+++ b/drivers/sensors/pimoroni_trackball.c
@@ -33,8 +33,24 @@
static uint16_t precision = 128;
-float pimoroni_trackball_get_precision(void) { return ((float)precision / 128); }
-void pimoroni_trackball_set_precision(float floatprecision) { precision = (floatprecision * 128); }
+uint16_t pimoroni_trackball_get_cpi(void) { return (precision * 125); }
+/**
+ * @brief Sets the scaling value for pimoroni trackball
+ *
+ * Sets a scaling value for pimoroni trackball to allow runtime adjustment. This isn't used by the sensor and is an
+ * approximation so the functions are consistent across drivers.
+ *
+ * NOTE: This rounds down to the nearest number divisable by 125 that's a positive integer, values below 125 are clamped to 125.
+ *
+ * @param cpi uint16_t
+ */
+void pimoroni_trackball_set_cpi(uint16_t cpi) {
+ if (cpi < 249) {
+ precision = 1;
+ } else {
+ precision = (cpi - (cpi % 125)) / 125;
+ }
+}
void pimoroni_trackball_set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
uint8_t data[4] = {r, g, b, w};
@@ -60,7 +76,7 @@ i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data) {
return status;
}
-__attribute__((weak)) void pimironi_trackball_device_init(void) {
+__attribute__((weak)) void pimoroni_trackball_device_init(void) {
i2c_init();
pimoroni_trackball_set_rgbw(0x00, 0x00, 0x00, 0x00);
}