qmk_firmware

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

adns9800.h (2112B)


      1 /* Copyright 2020 Alexander Tulloh
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #pragma once
     18 
     19 #include <stdint.h>
     20 #include "pointing_device.h"
     21 
     22 #ifndef ADNS9800_CPI
     23 #    define ADNS9800_CPI 1600
     24 #endif
     25 
     26 #ifndef ADNS9800_CLOCK_SPEED
     27 #    define ADNS9800_CLOCK_SPEED 2000000
     28 #endif
     29 
     30 #ifndef ADNS9800_SPI_LSBFIRST
     31 #    define ADNS9800_SPI_LSBFIRST false
     32 #endif
     33 
     34 #ifndef ADNS9800_SPI_MODE
     35 #    define ADNS9800_SPI_MODE 3
     36 #endif
     37 
     38 #ifndef ADNS9800_SPI_DIVISOR
     39 #    ifdef __AVR__
     40 #        define ADNS9800_SPI_DIVISOR (F_CPU / ADNS9800_CLOCK_SPEED)
     41 #    else
     42 #        define ADNS9800_SPI_DIVISOR 64
     43 #    endif
     44 #endif
     45 
     46 #ifndef ADNS9800_CS_PIN
     47 #    ifdef POINTING_DEVICE_CS_PIN
     48 #        define ADNS9800_CS_PIN POINTING_DEVICE_CS_PIN
     49 #    else
     50 #        error "No chip select pin defined -- missing POINTING_DEVICE_CS_PIN or ADNS9800_CS_PIN"
     51 #    endif
     52 #endif
     53 
     54 typedef struct {
     55     /* 200 - 8200 CPI supported */
     56     uint16_t cpi;
     57 } config_adns9800_t;
     58 
     59 typedef struct {
     60     int16_t x;
     61     int16_t y;
     62 } report_adns9800_t;
     63 
     64 extern const pointing_device_driver_t adns9800_pointing_device_driver;
     65 
     66 bool              adns9800_init(void);
     67 config_adns9800_t adns9800_get_config(void);
     68 void              adns9800_set_config(config_adns9800_t);
     69 uint16_t          adns9800_get_cpi(void);
     70 void              adns9800_set_cpi(uint16_t cpi);
     71 /* Reads and clears the current delta values on the ADNS sensor */
     72 report_adns9800_t adns9800_get_report(void);
     73 report_mouse_t    adns9800_get_report_driver(report_mouse_t mouse_report);