-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] PMW33XX drivers overhaul #17613
Conversation
141c59d
to
52693d6
Compare
52693d6
to
bef09d1
Compare
CC: @Alabastard-64 @uqs I refactored the PMW3360 and PMW3389 drivers into a common code base. Could you verify that it still works as intended for you? I only have a PMW3360 sensor on a ARM platform and missing AVR and PMW3389 sensors. |
741ebf0
to
d27f9a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pmw3360 changes work on AVR, ploopy mouse.
Nice, just need the PMW3389 confirmation and I'll merge 🎉 |
9111eb1
to
2d20bf6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I was gonna attempt this over the summer, now that I'm building a keeb with 2x 3389 sensors.
I can try to test this over the weekend, but no need to wait for me, I can complain after the fact should it not work properly for both sensor types :)
drivers/sensors/pmw33xx_common.c
Outdated
extern const uint8_t pmw33xx_firmware_data[PMW33XX_FIRMWARE_LENGTH] PROGMEM; | ||
extern const uint8_t pmw33xx_firmware_signature[3] PROGMEM; | ||
|
||
static const pin_t pmw33xx_cs_pins[] = PMW33XX_CS_PINS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming it pmw33xx_cs_pins is a bit verbose in this pmw33xx file, consider calling it just pins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 It was a global for a short time, renamed to cs_pins
as this is a bit more descriptive.
drivers/sensors/pmw33xx_common.c
Outdated
|
||
static const pin_t pmw33xx_cs_pins[] = PMW33XX_CS_PINS; | ||
static bool in_burst[(sizeof(pmw33xx_cs_pins) / sizeof(pin_t))] = {0}; | ||
const size_t pmw33xx_number_of_sensors = (sizeof(pmw33xx_cs_pins) / sizeof(pin_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be static
? Also excessive parenthesis on the RHS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed parenthesis, this variable is used in extern files therefore can't be static.
drivers/sensors/pmw33xx_common.c
Outdated
static bool in_burst[(sizeof(pmw33xx_cs_pins) / sizeof(pin_t))] = {0}; | ||
const size_t pmw33xx_number_of_sensors = (sizeof(pmw33xx_cs_pins) / sizeof(pin_t)); | ||
|
||
bool pmw33xx_spi_start(uint8_t sensor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded declaration as it's defined just a couple lines later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
drivers/sensors/pmw33xx_common.c
Outdated
} | ||
|
||
bool pmw33xx_spi_start(uint8_t sensor) { | ||
if (!spi_start(pmw33xx_cs_pins[sensor], false, 3, PMW33XX_SPI_DIVISOR)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you drop using the defines like PMW3360_SPI_LSBFIRST, PMW3360_SPI_MODE here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be sure that the sensor are always not LSB first, so this can be a fixed value. I'm not 100% sure about the SPI mode but it should also always be mode 3.
drivers/sensors/pmw33xx_common.c
Outdated
pmw33xx_write(sensor, REG_SROM_Enable, 0x18); | ||
|
||
if (!pmw33xx_spi_start(sensor)) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/sensors/pmw33xx_common.c
Outdated
|
||
void pmw33xx_write(uint8_t sensor, uint8_t reg_addr, uint8_t data) { | ||
if (!pmw33xx_spi_start(sensor)) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/sensors/pmw33xx_common.c
Outdated
pmw33xx_read(sensor, REG_Delta_Y_L); | ||
pmw33xx_read(sensor, REG_Delta_Y_H); | ||
|
||
pmw33xx_upload_firmware(sensor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should return a bool, as it can fail and then we'd just blindly would continue. I guess it'll be harmless, it depends a bit on how "correct" you want this to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About correctness: The functions now abort if the first SPI interaction fails, but subsequent ones are assumed to always succeed.
drivers/sensors/pmw33xx_common.c
Outdated
|
||
bool ok = pmw33xx_check_signature(sensor); | ||
|
||
if (ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how much flash space could be saved if you wrap this under
#ifdef CONSOLE_ENABLE
(assuming that the pd_dprintf() are no-ops in that case, does the compiler/optimizer throw all extra code away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified the statement to only one branch, dprintf
is already a no-op if console is not enabled. So this is eliminated by the compiler.
drivers/sensors/pmw33xx_common.c
Outdated
if (sensor >= pmw33xx_number_of_sensors) { | ||
return report; | ||
} | ||
u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u wat mate?
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe VIM in insert mode. Removed.
2d20bf6
to
3d8161f
Compare
Great, let me know what you think about the changes and I'll merge this evening. |
I know it's only a fairly minor change but feel this should be a separate PR. |
No problem, I can pull this out of this PR. |
3d8161f
to
21e14da
Compare
Pointing device specific debug messages are now in #17663 |
@uqs I tested the recent changes and it works well with PMW3360. Let me know if you are happy with them and I'll merge right away 😉 |
Lints not happy because some jerk didn't properly format a json file (me, it was me. and for the 4x6 tractyl manuform) |
21e14da
to
b201496
Compare
I just adjusted the json to use the correct 4x6 layout name, but it still complains. Could you open a PR with the corrected json (Or post it here)? |
Failing lint will be handled in #17681 |
This combines the PMW3389 and PM3360 drivers as they only differ in the firmware blobs and CPI get and set functions. The following changes have been made: * PMW3389 now gets the same multi-sensor feature that is already available on the PMW3360. * Introduced a shared pmw33xx_report_t struct is now directly readable via SPI transactions instead of individual byte-sized reads, saving multiple copies and bitshift operations. * pmw33(89/60)_get_report functions had unreachable branches in their motion detection logic these have been simplied as much as possible. * The fast firmware upload option has been removed as this becomes obsolete by the newly introduced polled waiting functions for ChibiOS * PMW33(60/89)_SPI_LSBFIRST and PMW33(60/89)_SPI_MODE config options have been removed as they don't need to be configurable. * All PMW3389 and PMW3360 defines have been unified to a PMW33XX prefix to reduce code duplication and make the defines interchangeable polled waiting
b201496
to
4aa2c5a
Compare
wait_ms(1); | ||
|
||
pmw33xx_write(sensor, REG_Config2, 0x00); | ||
pmw33xx_write(sensor, REG_Angle_Tune, CONSTRAIN(ROTATIONAL_TRANSFORM_ANGLE, -127, 127)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit late here, shouldn't this be:
pmw33xx_write(sensor, REG_Angle_Tune, CONSTRAIN(ROTATIONAL_TRANSFORM_ANGLE, -127, 127)); | |
pmw33xx_write(sensor, REG_Angle_Tune, CONSTRAIN(ROTATIONAL_TRANSFORM_ANGLE, -30, 30)); |
Register description for both PMW3360 and PMW3389 only suggest up to +/-30 degrees, so that's the constraint I originally added in the Ploopy sketch. Has this been empirically determined to go up to +/-127 degrees?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, this is not according to the specs. I'll open an PR to rectify this error.
| `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_ | | ||
| `PMW33XX_LIFTOFF_DISTANCE` | (Optional) Sets the lift off distance at run time | `0x02` | | ||
| `ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 127 degrees directly in the sensor. | `0` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 127 degrees directly in the sensor. | `0` | | |
| `ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 30 degrees directly in the sensor. | `0` | |
This is a follow-up of qmk#17613.
* bastardkb: restructure folder hierarchy ahead of supporting other adapters/mcus Upcoming support for the following (adapter, mcu) pairs will be submitted in follow-up PRs: - `v2/elitec` - `v2/stemcell` - `blackpill` This PR contains the following changes: - Move previous implementation to an inner `v1/elitec` folder - Move keyboard USB IDs and strings to data driven - Update headers to update maintainers list - Run `qmk format-c` * bastardkb/charybdis: remove broken acceleration implementation * bastardkb/charybdis: fix debug output * bastardkb: add support for BastardKb the `v2/elitec` (adapter, mcu) pair * bastardkb: add Blackpill support * bastardkb/charybdis/3x5: add `bstiq` keymap * bastardkb/charybdis: add fake LEDs to the configuration For the Charybdis 3x5 (respectively 4x6), the LED config now simulates 36 (respectively 58) LEDs instead of the actual 35 (respectively 56) to prevent confusion when testing LEDs during assembly when handedness is not set correctly. Those fake LEDs are bound to the physical bottom-left corner. * bastardkbk/charybdis/readme.md: update build commands Merge pull request #5 from Nathancooke7/update_charybdis_readme_v2_shield. * bastardkb/charybdis: fix Via keymap with blackpill * bastardkb/charybdis: add 3x6 configuration * bastardkb/charybdis: remove unnecessary files * bastardkb/charybdis: remove obsolete code * bastardkb/charybdis/3x6: add Via keymap * bastardkb: add support for Splinky (RP2040) board * bastardkb: initial configuration for the Splinky (SPI not working yet) * bastardkb/charybdis/3x5/v2/splinky: tentative change to enable trackball * bastardkb/charybdis/3x5/v2/splinky: fix SCK, MISO, MOSI pins * bastardkb/charybdis/3x5/v2/splinky: fix SCK, MISO, MOSI pins * bastardkb/charybdis/4x6/v2/splinky: add SPI configuration and enable trackball * bastardkb/charybdis/3x6: add splinky config * bastardkb/*/v2/splinky: update drivers to `vendor` * bastardkb/dilemma: add new board * bastardkb/charybdis: fix infinite loop in `layer_state_set_user(…)` in the `via` keymaps * bastardkb/dilemma: add `bstiq` keymap * bastardkb: specify blackpill boards * bastardkb/charybdis: fix blackpill-specific define syntax * bastardkb: remove `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION` which are no longer valid options * bastardkb: fix `QK_BOOT` keycodes * bastardkb/dilemma: fix mouse direction on X axis * bastardkb/charybdis/3x6: adjust CS * bastardkb/dilemma: adjust trackpad configuration * charybdis: fix `PWM33XX_CS_PIN` defines This is a follow-up of #17613. * bastardkb: remove Vial mentions from `bstiq` keymaps * Cleanup unnecessary comments Co-authored-by: Nathan <[email protected]> Co-authored-by: Charly Delay <[email protected]>
This is a follow-up of qmk#17613.
* PMW33XX drivers overhaul This combines the PMW3389 and PM3360 drivers as they only differ in the firmware blobs and CPI get and set functions. The following changes have been made: * PMW3389 now gets the same multi-sensor feature that is already available on the PMW3360. * Introduced a shared pmw33xx_report_t struct is now directly readable via SPI transactions instead of individual byte-sized reads, saving multiple copies and bitshift operations. * pmw33(89/60)_get_report functions had unreachable branches in their motion detection logic these have been simplied as much as possible. * The fast firmware upload option has been removed as this becomes obsolete by the newly introduced polled waiting functions for ChibiOS polled waiting * PMW33(60/89)_SPI_LSBFIRST and PMW33(60/89)_SPI_MODE config options have been removed as they don't need to be configurable. * All PMW3389 and PMW3360 defines have been unified to a PMW33XX prefix to reduce code duplication and make the defines interchangeable * Adjust keyboards to PMW33XX naming scheme
* bastardkb: restructure folder hierarchy ahead of supporting other adapters/mcus Upcoming support for the following (adapter, mcu) pairs will be submitted in follow-up PRs: - `v2/elitec` - `v2/stemcell` - `blackpill` This PR contains the following changes: - Move previous implementation to an inner `v1/elitec` folder - Move keyboard USB IDs and strings to data driven - Update headers to update maintainers list - Run `qmk format-c` * bastardkb/charybdis: remove broken acceleration implementation * bastardkb/charybdis: fix debug output * bastardkb: add support for BastardKb the `v2/elitec` (adapter, mcu) pair * bastardkb: add Blackpill support * bastardkb/charybdis/3x5: add `bstiq` keymap * bastardkb/charybdis: add fake LEDs to the configuration For the Charybdis 3x5 (respectively 4x6), the LED config now simulates 36 (respectively 58) LEDs instead of the actual 35 (respectively 56) to prevent confusion when testing LEDs during assembly when handedness is not set correctly. Those fake LEDs are bound to the physical bottom-left corner. * bastardkbk/charybdis/readme.md: update build commands Merge pull request qmk#5 from Nathancooke7/update_charybdis_readme_v2_shield. * bastardkb/charybdis: fix Via keymap with blackpill * bastardkb/charybdis: add 3x6 configuration * bastardkb/charybdis: remove unnecessary files * bastardkb/charybdis: remove obsolete code * bastardkb/charybdis/3x6: add Via keymap * bastardkb: add support for Splinky (RP2040) board * bastardkb: initial configuration for the Splinky (SPI not working yet) * bastardkb/charybdis/3x5/v2/splinky: tentative change to enable trackball * bastardkb/charybdis/3x5/v2/splinky: fix SCK, MISO, MOSI pins * bastardkb/charybdis/3x5/v2/splinky: fix SCK, MISO, MOSI pins * bastardkb/charybdis/4x6/v2/splinky: add SPI configuration and enable trackball * bastardkb/charybdis/3x6: add splinky config * bastardkb/*/v2/splinky: update drivers to `vendor` * bastardkb/dilemma: add new board * bastardkb/charybdis: fix infinite loop in `layer_state_set_user(…)` in the `via` keymaps * bastardkb/dilemma: add `bstiq` keymap * bastardkb: specify blackpill boards * bastardkb/charybdis: fix blackpill-specific define syntax * bastardkb: remove `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION` which are no longer valid options * bastardkb: fix `QK_BOOT` keycodes * bastardkb/dilemma: fix mouse direction on X axis * bastardkb/charybdis/3x6: adjust CS * bastardkb/dilemma: adjust trackpad configuration * charybdis: fix `PWM33XX_CS_PIN` defines This is a follow-up of qmk#17613. * bastardkb: remove Vial mentions from `bstiq` keymaps * Cleanup unnecessary comments Co-authored-by: Nathan <[email protected]> Co-authored-by: Charly Delay <[email protected]>
Description
This combines the PMW3389 and PM3360 drivers as they only differ in the firmware blobs and CPI get and set functions. The following changes have been made:
Common shared code base between PMW3389 and PMW3360 drivers
PMW3389 now gets the same multi-sensor feature that is already available on the PMW3360.
Introduced a shared
pmw33xx_report_t
struct which is now directly readable via SPI transactions instead of individual byte-sized reads, saving multiple copies and bitshift operations.pmw33(89/60)_get_report
functions had unreachable branches in their motion detection logic these have been simplified as much as possible.The fast firmware upload option has been removed as this becomes obsolete by the newly introduced polled waiting functions for ChibiOS ([Core] Use polled waiting on ChibiOS platforms that support it #17607)
PMW33(60/89)_SPI_LSBFIRST
andPMW33(60/89)_SPI_MODE
config options have been removed as they don't need to be configurable.All
PMW3389_
andPMW3360_
defines have been unified to aPMW33XX_
prefix to reduce code duplication and make the defines interchangeablePointing devices now have their own
pd_dprintf
macro that allows opt-in debug messagesTypes of Changes
Issues Fixed or Closed by This PR
Checklist