summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/sensors/pmw3360.c2
-rw-r--r--drivers/sensors/pmw33xx_common.c8
-rw-r--r--drivers/sensors/pmw33xx_common.h16
3 files changed, 21 insertions, 5 deletions
diff --git a/drivers/sensors/pmw3360.c b/drivers/sensors/pmw3360.c
index 2c6d91d588..81dca002e2 100644
--- a/drivers/sensors/pmw3360.c
+++ b/drivers/sensors/pmw3360.c
@@ -9,8 +9,6 @@
#include "pmw33xx_common.h"
#include "progmem.h"
-extern const size_t pmw33xx_number_of_sensors;
-
uint16_t pmw33xx_get_cpi(uint8_t sensor) {
if (sensor >= pmw33xx_number_of_sensors) {
return 0;
diff --git a/drivers/sensors/pmw33xx_common.c b/drivers/sensors/pmw33xx_common.c
index b8d4e532ca..82a7ec3297 100644
--- a/drivers/sensors/pmw33xx_common.c
+++ b/drivers/sensors/pmw33xx_common.c
@@ -1,3 +1,4 @@
+// Copyright 2022 Pablo Martinez (@elpekenin)
// Copyright 2022 Daniel Kao (dkao)
// Copyright 2022 Stefan Kerkmann (KarlK90)
// Copyright 2022 Ulrich Spörlein (@uqs)
@@ -17,10 +18,11 @@
extern const uint8_t pmw33xx_firmware_data[PMW33XX_FIRMWARE_LENGTH] PROGMEM;
extern const uint8_t pmw33xx_firmware_signature[3] PROGMEM;
-static const pin_t cs_pins[] = PMW33XX_CS_PINS;
-static bool in_burst[ARRAY_SIZE(cs_pins)] = {0};
+static const pin_t cs_pins_left[] = PMW33XX_CS_PINS;
+static const pin_t cs_pins_right[] = PMW33XX_CS_PINS_RIGHT;
-const size_t pmw33xx_number_of_sensors = ARRAY_SIZE(cs_pins);
+static bool in_burst_left[ARRAY_SIZE(cs_pins_left)] = {0};
+static bool in_burst_right[ARRAY_SIZE(cs_pins_right)] = {0};
bool __attribute__((cold)) pmw33xx_upload_firmware(uint8_t sensor);
bool __attribute__((cold)) pmw33xx_check_signature(uint8_t sensor);
diff --git a/drivers/sensors/pmw33xx_common.h b/drivers/sensors/pmw33xx_common.h
index c725e80f24..88523b8420 100644
--- a/drivers/sensors/pmw33xx_common.h
+++ b/drivers/sensors/pmw33xx_common.h
@@ -1,3 +1,4 @@
+// Copyright 2022 Pablo Martinez (@elpekenin)
// Copyright 2022 Daniel Kao (dkao)
// Copyright 2022 Stefan Kerkmann (KarlK90)
// Copyright 2022 Ulrich Spörlein (@uqs)
@@ -9,6 +10,7 @@
#pragma once
+#include "quantum.h" //to get is_keyboard_left
#include <stdint.h>
#include "spi_master.h"
#include "util.h"
@@ -79,6 +81,20 @@ _Static_assert(sizeof((pmw33xx_report_t){0}.motion) == 1, "pmw33xx_report_t.moti
# endif
#endif
+// Support single spelling and default to be the same as left side
+#if !defined(PMW33XX_CS_PINS_RIGHT)
+# if !defined(PMW33XX_CS_PIN_RIGHT)
+# define PMW33XX_CS_PIN_RIGHT PMW33XX_CS_PIN
+# endif
+# define PMW33XX_CS_PINS_RIGHT \
+ { PMW33XX_CS_PIN_RIGHT }
+#endif
+
+// Defines so the old variable names are swapped by the appropiate value on each half
+#define cs_pins (is_keyboard_left() ? cs_pins_left : cs_pins_right)
+#define in_burst (is_keyboard_left() ? in_burst_left : in_burst_right)
+#define pmw33xx_number_of_sensors (is_keyboard_left() ? ARRAY_SIZE((pin_t[])PMW33XX_CS_PINS) : ARRAY_SIZE((pin_t[])PMW33XX_CS_PINS_RIGHT))
+
#if PMW33XX_CPI > PMW33XX_CPI_MAX || PMW33XX_CPI < PMW33XX_CPI_MIN || (PMW33XX_CPI % PMW33XX_CPI_STEP) != 0U
# pragma message "PMW33XX_CPI has to be in the range of " STR(PMW33XX_CPI_MAX) "-" STR(PMW33XX_CPI_MIN) " in increments of " STR(PMW33XX_CPI_STEP) ". But it is " STR(PMW33XX_CPI) "."
# error Use correct PMW33XX_CPI value.