qmk_firmware

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

azoteq_iqs5xx.h (7530B)


      1 // Copyright 2023 Dasky (@daskygit)
      2 // Copyright 2023 George Norton (@george-norton)
      3 // SPDX-License-Identifier: GPL-2.0-or-later
      4 
      5 #pragma once
      6 
      7 #include "compiler_support.h"
      8 #include "i2c_master.h"
      9 #include "pointing_device.h"
     10 #include "util.h"
     11 
     12 typedef enum {
     13     AZOTEQ_IQS5XX_UNKNOWN,
     14     AZOTEQ_IQS550 = 40,
     15     AZOTEQ_IQS525 = 52,
     16     AZOTEQ_IQS572 = 58,
     17 } azoteq_iqs5xx_product_numbers_t;
     18 typedef enum {
     19     AZOTEQ_IQS5XX_ACTIVE,
     20     AZOTEQ_IQS5XX_IDLE_TOUCH,
     21     AZOTEQ_IQS5XX_IDLE,
     22     AZOTEQ_IQS5XX_LP1,
     23     AZOTEQ_IQS5XX_LP2,
     24 } azoteq_iqs5xx_charging_modes_t;
     25 
     26 typedef struct {
     27     uint8_t h : 8;
     28     uint8_t l : 8;
     29 } azoteq_iqs5xx_report_rate_t;
     30 
     31 typedef struct PACKED {
     32     bool    single_tap : 1;     // Single tap gesture status
     33     bool    press_and_hold : 1; // Press and hold gesture status
     34     bool    swipe_x_neg : 1;    // Swipe in negative X direction status
     35     bool    swipe_x_pos : 1;    // Swipe in positive X direction status
     36     bool    swipe_y_pos : 1;    // Swipe in positive Y direction status
     37     bool    swipe_y_neg : 1;    // Swipe in negative Y direction status
     38     uint8_t _unused : 2;        // unused
     39 } azoteq_iqs5xx_gesture_events_0_t;
     40 
     41 typedef struct PACKED {
     42     bool    two_finger_tap : 1; // Two finger tap gesture status
     43     bool    scroll : 1;         // Scroll status
     44     bool    zoom : 1;           // Zoom gesture status
     45     uint8_t _unused : 5;        // unused
     46 } azoteq_iqs5xx_gesture_events_1_t;
     47 
     48 typedef struct PACKED {
     49     azoteq_iqs5xx_charging_modes_t charging_mode : 3;      // Indicates current mode
     50     bool                           ati_error : 1;          //
     51     bool                           reati_occurred : 1;     //
     52     bool                           alp_ati_error : 1;      //
     53     bool                           alp_reati_occurred : 1; //
     54     bool                           show_reset : 1;         //
     55 } azoteq_iqs5xx_system_info_0_t;
     56 
     57 typedef struct PACKED {
     58     bool    tp_movement : 1;      //
     59     bool    palm_detect : 1;      //  Palm detect status
     60     bool    too_many_fingers : 1; // Total finger status
     61     bool    rr_missed : 1;        // Report rate status
     62     bool    snap_toggle : 1;      // Change in any snap channel status
     63     bool    switch_state : 1;     // Status of input pin SW_IN
     64     uint8_t _unused : 2;          // unused
     65 } azoteq_iqs5xx_system_info_1_t;
     66 
     67 typedef struct {
     68     uint8_t h : 8;
     69     uint8_t l : 8;
     70 } azoteq_iqs5xx_relative_xy_t;
     71 
     72 typedef struct {
     73     uint8_t                          previous_cycle_time;
     74     azoteq_iqs5xx_gesture_events_0_t gesture_events_0;
     75     azoteq_iqs5xx_gesture_events_1_t gesture_events_1;
     76     azoteq_iqs5xx_system_info_0_t    system_info_0;
     77     azoteq_iqs5xx_system_info_1_t    system_info_1;
     78     uint8_t                          number_of_fingers;
     79     azoteq_iqs5xx_relative_xy_t      x;
     80     azoteq_iqs5xx_relative_xy_t      y;
     81 } azoteq_iqs5xx_base_data_t;
     82 
     83 STATIC_ASSERT(sizeof(azoteq_iqs5xx_base_data_t) == 10, "azoteq_iqs5xx_basic_report_t should be 10 bytes");
     84 
     85 typedef struct {
     86     uint8_t                     number_of_fingers;
     87     azoteq_iqs5xx_relative_xy_t x;
     88     azoteq_iqs5xx_relative_xy_t y;
     89 } azoteq_iqs5xx_report_data_t;
     90 
     91 STATIC_ASSERT(sizeof(azoteq_iqs5xx_report_data_t) == 5, "azoteq_iqs5xx_report_data_t should be 5 bytes");
     92 
     93 typedef struct PACKED {
     94     bool sw_input : 1;
     95     bool sw_input_select : 1;
     96     bool reati : 1;
     97     bool alp_reati : 1;
     98     bool sw_input_event : 1;
     99     bool wdt : 1;
    100     bool setup_complete : 1;
    101     bool manual_control : 1;
    102 } azoteq_iqs5xx_system_config_0_t;
    103 
    104 typedef struct PACKED {
    105     bool event_mode : 1;
    106     bool gesture_event : 1;
    107     bool tp_event : 1;
    108     bool reati_event : 1;
    109     bool alp_prox_event : 1;
    110     bool snap_event : 1;
    111     bool touch_event : 1;
    112     bool prox_event : 1;
    113 } azoteq_iqs5xx_system_config_1_t;
    114 
    115 typedef struct PACKED {
    116     bool    flip_x : 1;
    117     bool    flip_y : 1;
    118     bool    switch_xy_axis : 1;
    119     bool    palm_reject : 1;
    120     uint8_t _unused : 4;
    121 } azoteq_iqs5xx_xy_config_0_t;
    122 
    123 typedef struct PACKED {
    124     bool   suspend : 1;
    125     bool   reset : 1;
    126     int8_t _unused : 6;
    127 } azoteq_iqs5xx_system_control_1_t;
    128 
    129 typedef struct PACKED {
    130     bool   single_tap : 1;
    131     bool   press_and_hold : 1;
    132     bool   swipe_x_minus : 1;
    133     bool   swipe_x_plus : 1;
    134     bool   swipe_y_plus : 1;
    135     bool   swipe_y_minus : 1;
    136     int8_t _unused : 2;
    137 } azoteq_iqs5xx_single_finger_gesture_enable_t;
    138 
    139 typedef struct PACKED {
    140     bool   two_finger_tap : 1;
    141     bool   scroll : 1;
    142     bool   zoom : 1;
    143     int8_t _unused : 5;
    144 } azoteq_iqs5xx_multi_finger_gesture_enable_t;
    145 
    146 typedef struct PACKED {
    147     azoteq_iqs5xx_single_finger_gesture_enable_t single_finger_gestures;
    148     azoteq_iqs5xx_multi_finger_gesture_enable_t  multi_finger_gestures;
    149     uint16_t                                     tap_time;
    150     uint16_t                                     tap_distance;
    151     uint16_t                                     hold_time;
    152     uint16_t                                     swipe_initial_time;
    153     uint16_t                                     swipe_initial_distance;
    154     uint16_t                                     swipe_consecutive_time;
    155     uint16_t                                     swipe_consecutive_distance;
    156     int8_t                                       swipe_angle;
    157     uint16_t                                     scroll_initial_distance;
    158     int8_t                                       scroll_angle;
    159     uint16_t                                     zoom_initial_distance;
    160     uint16_t                                     zoom_consecutive_distance;
    161 } azoteq_iqs5xx_gesture_config_t;
    162 
    163 STATIC_ASSERT(sizeof(azoteq_iqs5xx_gesture_config_t) == 24, "azoteq_iqs5xx_gesture_config_t should be 24 bytes");
    164 
    165 typedef struct {
    166     uint16_t x_resolution;
    167     uint16_t y_resolution;
    168 } azoteq_iqs5xx_resolution_t;
    169 
    170 #define AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(h, l) ((int16_t)(h << 8) | l)
    171 #define AZOTEQ_IQS5XX_SWAP_H_L_BYTES(b) ((uint16_t)((b & 0xff) << 8) | (b >> 8))
    172 
    173 #ifndef AZOTEQ_IQS5XX_REPORT_RATE
    174 #    define AZOTEQ_IQS5XX_REPORT_RATE 10
    175 #endif
    176 #if !defined(POINTING_DEVICE_TASK_THROTTLE_MS) && !defined(POINTING_DEVICE_MOTION_PIN)
    177 // Polling the Azoteq isn't recommended, ensuring we only poll after the report is ready stops any unexpected NACKs
    178 #    define POINTING_DEVICE_TASK_THROTTLE_MS AZOTEQ_IQS5XX_REPORT_RATE + 1
    179 #endif
    180 
    181 extern const pointing_device_driver_t azoteq_iqs5xx_pointing_device_driver;
    182 
    183 bool           azoteq_iqs5xx_init(void);
    184 i2c_status_t   azoteq_iqs5xx_wake(void);
    185 report_mouse_t azoteq_iqs5xx_get_report(report_mouse_t mouse_report);
    186 i2c_status_t   azoteq_iqs5xx_get_report_rate(azoteq_iqs5xx_report_rate_t *report_rate, azoteq_iqs5xx_charging_modes_t mode, bool end_session);
    187 i2c_status_t   azoteq_iqs5xx_set_report_rate(uint16_t report_rate_ms, azoteq_iqs5xx_charging_modes_t mode, bool end_session);
    188 i2c_status_t   azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session);
    189 i2c_status_t   azoteq_iqs5xx_set_reati(bool enabled, bool end_session);
    190 i2c_status_t   azoteq_iqs5xx_set_gesture_config(bool end_session);
    191 i2c_status_t   azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_xy, bool palm_reject, bool end_session);
    192 i2c_status_t   azoteq_iqs5xx_reset_suspend(bool reset, bool suspend, bool end_session);
    193 i2c_status_t   azoteq_iqs5xx_get_base_data(azoteq_iqs5xx_base_data_t *base_data);
    194 void           azoteq_iqs5xx_set_cpi(uint16_t cpi);
    195 uint16_t       azoteq_iqs5xx_get_cpi(void);
    196 uint16_t       azoteq_iqs5xx_get_product(void);
    197 void           azoteq_iqs5xx_setup_resolution(void);