cirque_pinnacle.h (4891B)
1 // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license 2 3 #pragma once 4 5 #include "cirque_pinnacle_regdefs.h" 6 #include <stdint.h> 7 #include <stdbool.h> 8 #include "pointing_device_internal.h" 9 #include "pointing_device.h" 10 11 #ifndef CIRQUE_PINNACLE_TIMEOUT 12 # define CIRQUE_PINNACLE_TIMEOUT 20 // I2C timeout in milliseconds 13 #endif 14 15 #define CIRQUE_PINNACLE_ABSOLUTE_MODE 1 16 #define CIRQUE_PINNACLE_RELATIVE_MODE 0 17 #ifndef CIRQUE_PINNACLE_POSITION_MODE 18 # define CIRQUE_PINNACLE_POSITION_MODE CIRQUE_PINNACLE_ABSOLUTE_MODE 19 #endif 20 21 #define CIRQUE_PINNACLE_DEFAULT_SCALE 1024 22 #ifndef CIRQUE_PINNACLE_DIAMETER_MM 23 # define CIRQUE_PINNACLE_DIAMETER_MM 40 24 #endif 25 26 #if CIRQUE_PINNACLE_POSITION_MODE 27 // Coordinate scaling values 28 # ifndef CIRQUE_PINNACLE_X_LOWER 29 # define CIRQUE_PINNACLE_X_LOWER 127 // min "reachable" X value 30 # endif 31 # ifndef CIRQUE_PINNACLE_X_UPPER 32 # define CIRQUE_PINNACLE_X_UPPER 1919 // max "reachable" X value 33 # endif 34 # ifndef CIRQUE_PINNACLE_Y_LOWER 35 # define CIRQUE_PINNACLE_Y_LOWER 63 // min "reachable" Y value 36 # endif 37 # ifndef CIRQUE_PINNACLE_Y_UPPER 38 # define CIRQUE_PINNACLE_Y_UPPER 1471 // max "reachable" Y value 39 # endif 40 # ifndef CIRQUE_PINNACLE_X_RANGE 41 # define CIRQUE_PINNACLE_X_RANGE (CIRQUE_PINNACLE_X_UPPER - CIRQUE_PINNACLE_X_LOWER) 42 # endif 43 # ifndef CIRQUE_PINNACLE_Y_RANGE 44 # define CIRQUE_PINNACLE_Y_RANGE (CIRQUE_PINNACLE_Y_UPPER - CIRQUE_PINNACLE_Y_LOWER) 45 # endif 46 # if defined(POINTING_DEVICE_GESTURES_SCROLL_ENABLE) 47 # define CIRQUE_PINNACLE_CIRCULAR_SCROLL_ENABLE 48 # endif 49 #else 50 # define CIRQUE_PINNACLE_X_RANGE 256 51 # define CIRQUE_PINNACLE_Y_RANGE 256 52 # if defined(POINTING_DEVICE_GESTURES_SCROLL_ENABLE) 53 # define CIRQUE_PINNACLE_SIDE_SCROLL_ENABLE 54 # endif 55 #endif 56 #if !defined(POINTING_DEVICE_TASK_THROTTLE_MS) 57 # define POINTING_DEVICE_TASK_THROTTLE_MS 10 // Cirque Pinnacle in normal operation produces data every 10ms. Advanced configuration for pen/stylus usage might require lower values. 58 #endif 59 #if defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) 60 # include "i2c_master.h" 61 // Cirque's 7-bit I2C Slave Address 62 # ifndef CIRQUE_PINNACLE_ADDR 63 # define CIRQUE_PINNACLE_ADDR I2C_ADDRESS_DEFAULT 64 # endif 65 #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi) 66 # include "spi_master.h" 67 # ifndef CIRQUE_PINNACLE_CLOCK_SPEED 68 # define CIRQUE_PINNACLE_CLOCK_SPEED 10000000 69 # endif 70 # ifndef CIRQUE_PINNACLE_SPI_LSBFIRST 71 # define CIRQUE_PINNACLE_SPI_LSBFIRST false 72 # endif 73 # ifndef CIRQUE_PINNACLE_SPI_MODE 74 # define CIRQUE_PINNACLE_SPI_MODE 1 75 # endif 76 # ifndef CIRQUE_PINNACLE_SPI_DIVISOR 77 # ifdef __AVR__ 78 # define CIRQUE_PINNACLE_SPI_DIVISOR (F_CPU / CIRQUE_PINNACLE_CLOCK_SPEED) 79 # else 80 # define CIRQUE_PINNACLE_SPI_DIVISOR 64 81 # endif 82 # ifndef CIRQUE_PINNACLE_SPI_CS_PIN 83 # ifdef POINTING_DEVICE_CS_PIN 84 # define CIRQUE_PINNACLE_SPI_CS_PIN POINTING_DEVICE_CS_PIN 85 # else 86 # error "No Chip Select pin has been defined -- missing POINTING_DEVICE_CS_PIN or CIRQUE_PINNACLE_SPI_CS_PIN define" 87 # endif 88 # endif 89 # endif 90 #endif 91 92 #define DIVIDE_UNSIGNED_ROUND(numerator, denominator) (((numerator) + ((denominator) / 2)) / (denominator)) 93 #define CIRQUE_PINNACLE_INCH_TO_PX(inch) (DIVIDE_UNSIGNED_ROUND((inch) * (uint32_t)CIRQUE_PINNACLE_DIAMETER_MM * 10, 254)) 94 #define CIRQUE_PINNACLE_PX_TO_INCH(px) (DIVIDE_UNSIGNED_ROUND((px) * (uint32_t)254, CIRQUE_PINNACLE_DIAMETER_MM * 10)) 95 96 // Convenient way to store and access measurements 97 typedef struct { 98 bool valid; // true if valid data was read, false if no data was ready 99 #if CIRQUE_PINNACLE_POSITION_MODE 100 uint16_t xValue; 101 uint16_t yValue; 102 uint16_t zValue; 103 uint8_t buttonFlags; 104 bool touchDown; 105 #else 106 int16_t xDelta; 107 int16_t yDelta; 108 int8_t wheelCount; 109 uint8_t buttons; 110 #endif 111 } pinnacle_data_t; 112 113 #define cirque_pinnacle_i2c_pointing_device_driver cirque_pinnacle_pointing_device_driver 114 #define cirque_pinnacle_spi_pointing_device_driver cirque_pinnacle_pointing_device_driver 115 extern const pointing_device_driver_t cirque_pinnacle_pointing_device_driver; 116 117 bool cirque_pinnacle_init(void); 118 void cirque_pinnacle_calibrate(void); 119 void cirque_pinnacle_cursor_smoothing(bool enable); 120 pinnacle_data_t cirque_pinnacle_read_data(void); 121 void cirque_pinnacle_scale_data(pinnacle_data_t* coordinates, uint16_t xResolution, uint16_t yResolution); 122 uint16_t cirque_pinnacle_get_scale(void); 123 void cirque_pinnacle_set_scale(uint16_t scale); 124 uint16_t cirque_pinnacle_get_cpi(void); 125 void cirque_pinnacle_set_cpi(uint16_t cpi); 126 report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report);