You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
7.1 KiB

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