qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

pmw3360.c (1301B)


      1 // Copyright 2022 Stefan Kerkmann (KarlK90)
      2 // Copyright 2022 Ulrich Spörlein (@uqs)
      3 // Copyright 2021 Alabastard (@Alabastard-64)
      4 // Copyright 2020 Christopher Courtney, aka Drashna Jael're  (@drashna) <drashna@live.com>
      5 // Copyright 2019 Sunjun Kim
      6 // Copyright 2020 Ploopy Corporation
      7 // SPDX-License-Identifier: GPL-2.0-or-later
      8 
      9 #include "pmw33xx_common.h"
     10 #include "progmem.h"
     11 
     12 uint16_t pmw33xx_get_cpi(uint8_t sensor) {
     13     if (sensor >= pmw33xx_number_of_sensors) {
     14         return 0;
     15     }
     16 
     17     uint8_t cpival = pmw33xx_read(sensor, REG_Config1);
     18     // In some cases (100, 900, 1700, 2500), reading the CPI corrupts the firmware and the sensor stops responding.
     19     // To avoid this, we write the value back to the sensor, which seems to prevent the corruption.
     20     pmw33xx_write(sensor, REG_Config1, cpival);
     21     return (uint16_t)((cpival + 1) & 0xFF) * PMW33XX_CPI_STEP;
     22 }
     23 
     24 void pmw33xx_set_cpi(uint8_t sensor, uint16_t cpi) {
     25     if (sensor >= pmw33xx_number_of_sensors) {
     26         return;
     27     }
     28 
     29     uint8_t cpival = CONSTRAIN((cpi / PMW33XX_CPI_STEP), (PMW33XX_CPI_MIN / PMW33XX_CPI_STEP), (PMW33XX_CPI_MAX / PMW33XX_CPI_STEP)) - 1U;
     30     pmw33xx_write(sensor, REG_Config1, cpival);
     31 }
     32 
     33 // PID, Inverse PID, SROM version
     34 const uint8_t pmw33xx_firmware_signature[2] PROGMEM = {0x42, 0xBD};