qmk_firmware

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

pointing_device.h (6273B)


      1 /*
      2 Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com>
      3 
      4 This program is free software: you can redistribute it and/or modify
      5 it under the terms of the GNU General Public License as published by
      6 the Free Software Foundation, either version 2 of the License, or
      7 (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 GNU General Public License for more details.
     13 
     14 You should have received a copy of the GNU General Public License
     15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16 */
     17 
     18 #pragma once
     19 
     20 #include <stdbool.h>
     21 #include <stdint.h>
     22 #include "host.h"
     23 #include "report.h"
     24 
     25 typedef struct {
     26     bool (*init)(void);
     27     report_mouse_t (*get_report)(report_mouse_t mouse_report);
     28     void (*set_cpi)(uint16_t);
     29     uint16_t (*get_cpi)(void);
     30 } pointing_device_driver_t;
     31 
     32 #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
     33 #    include "pointing_device_auto_mouse.h"
     34 #endif
     35 
     36 #if defined(POINTING_DEVICE_DRIVER_adns5050)
     37 #    include "drivers/sensors/adns5050.h"
     38 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     39 #elif defined(POINTING_DEVICE_DRIVER_pmw3320)
     40 #    include "drivers/sensors/pmw3320.h"
     41 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     42 #elif defined(POINTING_DEVICE_DRIVER_paw3222)
     43 #    include "spi_master.h"
     44 #    include "drivers/sensors/paw3222.h"
     45 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     46 #elif defined(POINTING_DEVICE_DRIVER_adns9800)
     47 #    include "spi_master.h"
     48 #    include "drivers/sensors/adns9800.h"
     49 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     50 #elif defined(POINTING_DEVICE_DRIVER_analog_joystick)
     51 #    include "analog.h"
     52 #    include "drivers/sensors/analog_joystick.h"
     53 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     54 #elif defined(POINTING_DEVICE_DRIVER_azoteq_iqs5xx)
     55 #    include "i2c_master.h"
     56 #    include "drivers/sensors/azoteq_iqs5xx.h"
     57 #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
     58 #    include "drivers/sensors/cirque_pinnacle.h"
     59 #    include "pointing_device_gestures.h"
     60 #elif defined(POINTING_DEVICE_DRIVER_paw3204)
     61 #    include "drivers/sensors/paw3204.h"
     62 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     63 #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
     64 #    include "i2c_master.h"
     65 #    include "drivers/sensors/pimoroni_trackball.h"
     66 // support for legacy pimoroni defines
     67 #    ifdef PIMORONI_TRACKBALL_INVERT_X
     68 #        define POINTING_DEVICE_INVERT_X
     69 #    endif
     70 #    ifdef PIMORONI_TRACKBALL_INVERT_Y
     71 #        define POINTING_DEVICE_INVERT_Y
     72 #    endif
     73 #    ifdef PIMORONI_TRACKBALL_ROTATE
     74 #        define POINTING_DEVICE_ROTATION_90
     75 #    endif
     76 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     77 #elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
     78 #    include "spi_master.h"
     79 #    include "drivers/sensors/pmw33xx_common.h"
     80 #    define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
     81 #else
     82 bool           pointing_device_driver_init(void);
     83 report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report);
     84 uint16_t       pointing_device_driver_get_cpi(void);
     85 void           pointing_device_driver_set_cpi(uint16_t cpi);
     86 #endif
     87 
     88 typedef enum {
     89     POINTING_DEVICE_BUTTON1,
     90     POINTING_DEVICE_BUTTON2,
     91     POINTING_DEVICE_BUTTON3,
     92     POINTING_DEVICE_BUTTON4,
     93     POINTING_DEVICE_BUTTON5,
     94     POINTING_DEVICE_BUTTON6,
     95     POINTING_DEVICE_BUTTON7,
     96     POINTING_DEVICE_BUTTON8,
     97 } pointing_device_buttons_t;
     98 
     99 typedef enum {
    100     POINTING_DEVICE_STATUS_UNKNOWN,
    101     POINTING_DEVICE_STATUS_INIT_FAILED,
    102     POINTING_DEVICE_STATUS_FAILED,
    103     POINTING_DEVICE_STATUS_SUCCESS,
    104 } pointing_device_status_t;
    105 
    106 #ifdef MOUSE_EXTENDED_REPORT
    107 typedef int32_t xy_clamp_range_t;
    108 #else
    109 typedef int16_t xy_clamp_range_t;
    110 #endif
    111 
    112 #ifdef WHEEL_EXTENDED_REPORT
    113 typedef int32_t hv_clamp_range_t;
    114 #else
    115 typedef int16_t hv_clamp_range_t;
    116 #endif
    117 
    118 #define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
    119 #define CONSTRAIN_HID_XY(amt) ((amt) < MOUSE_REPORT_XY_MIN ? MOUSE_REPORT_XY_MIN : ((amt) > MOUSE_REPORT_XY_MAX ? MOUSE_REPORT_XY_MAX : (amt)))
    120 
    121 void                     pointing_device_init(void);
    122 bool                     pointing_device_task(void);
    123 bool                     pointing_device_send(void);
    124 report_mouse_t           pointing_device_get_report(void);
    125 void                     pointing_device_set_report(report_mouse_t mouse_report);
    126 uint16_t                 pointing_device_get_cpi(void);
    127 void                     pointing_device_set_cpi(uint16_t cpi);
    128 pointing_device_status_t pointing_device_get_status(void);
    129 void                     pointing_device_set_status(pointing_device_status_t status);
    130 
    131 void           pointing_device_init_kb(void);
    132 void           pointing_device_init_user(void);
    133 report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report);
    134 report_mouse_t pointing_device_task_user(report_mouse_t mouse_report);
    135 uint8_t        pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button);
    136 report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report);
    137 void           pointing_device_keycode_handler(uint16_t keycode, bool pressed);
    138 
    139 #ifdef POINTING_DEVICE_HIRES_SCROLL_ENABLE
    140 uint16_t pointing_device_get_hires_scroll_resolution(void);
    141 #endif
    142 
    143 #if defined(SPLIT_POINTING_ENABLE)
    144 void     pointing_device_set_shared_report(report_mouse_t report);
    145 uint16_t pointing_device_get_shared_cpi(void);
    146 #    if !defined(POINTING_DEVICE_TASK_THROTTLE_MS)
    147 #        define POINTING_DEVICE_TASK_THROTTLE_MS 1
    148 #    endif
    149 #    if defined(POINTING_DEVICE_COMBINED)
    150 void           pointing_device_set_cpi_on_side(bool left, uint16_t cpi);
    151 report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report);
    152 report_mouse_t pointing_device_task_combined_kb(report_mouse_t left_report, report_mouse_t right_report);
    153 report_mouse_t pointing_device_task_combined_user(report_mouse_t left_report, report_mouse_t right_report);
    154 report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report);
    155 #    endif // defined(POINTING_DEVICE_COMBINED)
    156 #endif     // defined(SPLIT_POINTING_ENABLE)