qmk_firmware

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

adns5050.h (3086B)


      1 /* Copyright 2021 Colin Lam (Ploopy Corporation)
      2  * Copyright 2020 Christopher Courtney, aka Drashna Jael're  (@drashna) <drashna@live.com>
      3  * Copyright 2019 Sunjun Kim
      4  * Copyright 2019 Hiroyuki Okada
      5  *
      6  * This program is free software: you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation, either version 2 of the License, or
      9  * (at your option) any later version.
     10  *
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  * GNU General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     18  */
     19 
     20 #pragma once
     21 
     22 #include <stdbool.h>
     23 #include <stdint.h>
     24 #include "pointing_device.h"
     25 
     26 // CPI values
     27 // clang-format off
     28 #define CPI125  0x11
     29 #define CPI250  0x12
     30 #define CPI375  0x13
     31 #define CPI500  0x14
     32 #define CPI625  0x15
     33 #define CPI750  0x16
     34 #define CPI875  0x17
     35 #define CPI1000 0x18
     36 #define CPI1125 0x19
     37 #define CPI1250 0x1a
     38 #define CPI1375 0x1b
     39 // clang-format on
     40 
     41 #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
     42 
     43 // Definitions for the ADNS serial line.
     44 #ifndef ADNS5050_SCLK_PIN
     45 #    ifdef POINTING_DEVICE_SCLK_PIN
     46 #        define ADNS5050_SCLK_PIN POINTING_DEVICE_SCLK_PIN
     47 #    else
     48 #        error "No clock pin defined -- missing POINTING_DEVICE_SCLK_PIN or ADNS5050_SCLK_PIN"
     49 #    endif
     50 #endif
     51 
     52 #ifndef ADNS5050_SDIO_PIN
     53 #    ifdef POINTING_DEVICE_SDIO_PIN
     54 #        define ADNS5050_SDIO_PIN POINTING_DEVICE_SDIO_PIN
     55 #    else
     56 #        error "No data pin defined -- missing POINTING_DEVICE_SDIO_PIN or ADNS5050_SDIO_PIN"
     57 #    endif
     58 #endif
     59 
     60 #ifndef ADNS5050_CS_PIN
     61 #    ifdef POINTING_DEVICE_CS_PIN
     62 #        define ADNS5050_CS_PIN POINTING_DEVICE_CS_PIN
     63 #    else
     64 #        error "No chip select pin defined -- missing POINTING_DEVICE_CS_PIN or ADNS5050_CS_PIN define"
     65 #    endif
     66 #endif
     67 
     68 typedef struct {
     69     int8_t dx;
     70     int8_t dy;
     71 } report_adns5050_t;
     72 
     73 extern const pointing_device_driver_t adns5050_pointing_device_driver;
     74 
     75 // A bunch of functions to implement the ADNS5050-specific serial protocol.
     76 // Note that the "serial.h" driver is insufficient, because it does not
     77 // manually manipulate a serial clock signal.
     78 bool              adns5050_init(void);
     79 void              adns5050_sync(void);
     80 uint8_t           adns5050_serial_read(void);
     81 void              adns5050_serial_write(uint8_t data);
     82 uint8_t           adns5050_read_reg(uint8_t reg_addr);
     83 void              adns5050_write_reg(uint8_t reg_addr, uint8_t data);
     84 report_adns5050_t adns5050_read_burst(void);
     85 void              adns5050_set_cpi(uint16_t cpi);
     86 uint16_t          adns5050_get_cpi(void);
     87 int8_t            convert_twoscomp(uint8_t data);
     88 bool              adns5050_check_signature(void);
     89 void              adns5050_power_down(void);
     90 report_mouse_t    adns5050_get_report(report_mouse_t mouse_report);