logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

pmw3389.c (1181B)


  1. // Copyright 2022 Stefan Kerkmann (KarlK90)
  2. // Copyright 2021 Alabastard (@Alabastard-64)
  3. // Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  4. // Copyright 2019 Sunjun Kim
  5. // Copyright 2020 Ploopy Corporation
  6. // SPDX-License-Identifier: GPL-2.0-or-later
  7. #include "pmw33xx_common.h"
  8. #include "progmem.h"
  9. uint16_t pmw33xx_get_cpi(uint8_t sensor) {
  10. if (sensor >= pmw33xx_number_of_sensors) {
  11. return 0;
  12. }
  13. uint16_t cpival = (pmw33xx_read(sensor, REG_Resolution_H) << 8) | pmw33xx_read(sensor, REG_Resolution_L);
  14. return (uint16_t)((cpival + 1) & 0xFFFF) * PMW33XX_CPI_STEP;
  15. }
  16. void pmw33xx_set_cpi(uint8_t sensor, uint16_t cpi) {
  17. if (sensor >= pmw33xx_number_of_sensors) {
  18. return;
  19. }
  20. uint16_t cpival = CONSTRAIN((cpi / PMW33XX_CPI_STEP), (PMW33XX_CPI_MIN / PMW33XX_CPI_STEP), (PMW33XX_CPI_MAX / PMW33XX_CPI_STEP)) - 1U;
  21. // Sets upper byte first for more consistent setting of cpi
  22. pmw33xx_write(sensor, REG_Resolution_H, (cpival >> 8) & 0xFF);
  23. pmw33xx_write(sensor, REG_Resolution_L, cpival & 0xFF);
  24. }
  25. // PID, Inverse PID
  26. const uint8_t pmw33xx_firmware_signature[2] PROGMEM = {0x42, 0xBD};