summaryrefslogtreecommitdiffstats
path: root/drivers/sensors/pimoroni_trackball.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sensors/pimoroni_trackball.c')
-rw-r--r--drivers/sensors/pimoroni_trackball.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/drivers/sensors/pimoroni_trackball.c b/drivers/sensors/pimoroni_trackball.c
index 7d390056ea..333e017a06 100644
--- a/drivers/sensors/pimoroni_trackball.c
+++ b/drivers/sensors/pimoroni_trackball.c
@@ -33,8 +33,26 @@
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 +78,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);
}