Skip to content

Commit

Permalink
Add *_RIGHT configuration for PMW33XX driver (#19243)
Browse files Browse the repository at this point in the history
  • Loading branch information
elpekenin authored Dec 10, 2022
1 parent 8c12559 commit d9cba6e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
21 changes: 12 additions & 9 deletions docs/feature_pointing_device.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ POINTING_DEVICE_DRIVER = adns5050

The ADNS 5050 sensor uses a serial type protocol for communication, and requires an additional light source.

| Setting | Description | Default |
| ------------------- | ------------------------------------------------------------------- | -------------------------- |
| `ADNS5050_SCLK_PIN` | (Required) The pin connected to the clock pin of the sensor. | `POINTING_DEVICE_SCLK_PIN` |
| `ADNS5050_SDIO_PIN` | (Required) The pin connected to the data pin of the sensor. | `POINTING_DEVICE_SDIO_PIN` |
| `ADNS5050_CS_PIN` | (Required) The pin connected to the cable select pin of the sensor. | `POINTING_DEVICE_CS_PIN` |
| Setting | Description | Default |
| ------------------- | ------------------------------------------------------------------ | -------------------------- |
| `ADNS5050_SCLK_PIN` | (Required) The pin connected to the clock pin of the sensor. | `POINTING_DEVICE_SCLK_PIN` |
| `ADNS5050_SDIO_PIN` | (Required) The pin connected to the data pin of the sensor. | `POINTING_DEVICE_SDIO_PIN` |
| `ADNS5050_CS_PIN` | (Required) The pin connected to the Chip Select pin of the sensor. | `POINTING_DEVICE_CS_PIN` |



Expand All @@ -48,7 +48,7 @@ The ADNS 9800 is an SPI driven optical sensor, that uses laser output for surfac
| `ADNS9800_SPI_LSBFIRST` | (Optional) Sets the Least/Most Significant Byte First setting for SPI. | `false` |
| `ADNS9800_SPI_MODE` | (Optional) Sets the SPI Mode for the sensor. | `3` |
| `ADNS9800_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ |
| `ADNS9800_CS_PIN` | (Required) Sets the Cable Select pin connected to the sensor. | `POINTING_DEVICE_CS_PIN` |
| `ADNS9800_CS_PIN` | (Required) Sets the Chip Select pin connected to the sensor. | `POINTING_DEVICE_CS_PIN` |


The CPI range is 800-8200, in increments of 200. Defaults to 1800 CPI.
Expand Down Expand Up @@ -124,7 +124,7 @@ Default attenuation is set to 4X, although if you are using a thicker overlay (s
| `CIRQUE_PINNACLE_SPI_LSBFIRST` | (Optional) Sets the Least/Most Significant Byte First setting for SPI. | `false` |
| `CIRQUE_PINNACLE_SPI_MODE` | (Optional) Sets the SPI Mode for the sensor. | `1` |
| `CIRQUE_PINNACLE_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ |
| `CIRQUE_PINNACLE_SPI_CS_PIN` | (Required) Sets the Cable Select pin connected to the sensor. | `POINTING_DEVICE_CS_PIN` |
| `CIRQUE_PINNACLE_SPI_CS_PIN` | (Required) Sets the Chip Select pin connected to the sensor. | `POINTING_DEVICE_CS_PIN` |

Default Scaling is 1024. Actual CPI depends on trackpad diameter.

Expand Down Expand Up @@ -218,11 +218,14 @@ POINTING_DEVICE_DRIVER = pmw3389
The CPI range is 50-16000, in increments of 50. Defaults to 2000 CPI.

Both PMW 3360 and PMW 3389 are SPI driven optical sensors, that use a built in IR LED for surface tracking.
If you have different CS wiring on each half you can use `PMW33XX_CS_PIN_RIGHT` or `PMW33XX_CS_PINS_RIGHT` in combination with `PMW33XX_CS_PIN` or `PMW33XX_CS_PINS` to configure both sides independently. If `_RIGHT` values aren't provided, they default to be the same as the left ones.

| Setting | Description | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------- | ------------------------ |
| `PMW33XX_CS_PIN` | (Required) Sets the Cable Select pin connected to the sensor. | `POINTING_DEVICE_CS_PIN` |
| `PMW33XX_CS_PINS` | (Alternative) Sets the Cable Select pins connected to multiple sensors. | _not defined_ |
| `PMW33XX_CS_PIN` | (Required) Sets the Chip Select pin connected to the sensor. | `POINTING_DEVICE_CS_PIN` |
| `PMW33XX_CS_PINS` | (Alternative) Sets the Chip Select pins connected to multiple sensors. | `{PMW33XX_CS_PIN}` |
| `PMW33XX_CS_PIN_RIGHT` | (Optional) Sets the Chip Select pin connected to the sensor on the right half. | `PMW33XX_CS_PIN` |
| `PMW33XX_CS_PINS_RIGHT` | (Optional) Sets the Chip Select pins connected to multiple sensors on the right half. | `{PMW33XX_CS_PIN_RIGHT}` |
| `PMW33XX_CPI` | (Optional) Sets counts per inch sensitivity of the sensor. | _varies_ |
| `PMW33XX_CLOCK_SPEED` | (Optional) Sets the clock speed that the sensor runs at. | `2000000` |
| `PMW33XX_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ |
Expand Down
2 changes: 0 additions & 2 deletions drivers/sensors/pmw3360.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions drivers/sensors/pmw33xx_common.c
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions drivers/sensors/pmw33xx_common.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -9,6 +10,7 @@

#pragma once

#include "quantum.h" //to get is_keyboard_left
#include <stdint.h>
#include "spi_master.h"
#include "util.h"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d9cba6e

Please sign in to comment.