touchpad2  2.0.0.0
touchpad2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef TOUCHPAD2_H
29 #define TOUCHPAD2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define TOUCHPAD2_CMD_VERSION_INFO 0x00
60 #define TOUCHPAD2_CMD_XY_DATA 0x01
61 #define TOUCHPAD2_CMD_PROXIMITY_STATUS 0x02
62 #define TOUCHPAD2_CMD_TOUCH_STATUS 0x03
63 #define TOUCHPAD2_CMD_COUNT_VALUES 0x04
64 #define TOUCHPAD2_CMD_LONG_TERM_AVERAGES 0x05
65 #define TOUCHPAD2_CMD_ATI_COMPENSATION 0x06
66 #define TOUCHPAD2_CMD_PORT_CONTROL 0x07
67 #define TOUCHPAD2_CMD_SNAP_STATUS 0x08
68 #define TOUCHPAD2_CMD_CONTROL_SETTINGS 0x10
69 #define TOUCHPAD2_CMD_THRESHOLD_SETTINGS 0x11
70 #define TOUCHPAD2_CMD_ATI_SETTINGS 0x12
71 #define TOUCHPAD2_CMD_FILTER_SETTINGS 0x13
72 #define TOUCHPAD2_CMD_TIMING_SETTINGS 0x14
73 #define TOUCHPAD2_CMD_CHANNEL_SETUP 0x15
74 #define TOUCHPAD2_CMD_HARDWARE_CONFIG_SETTINGS 0x16
75 #define TOUCHPAD2_CMD_ACTIVE_CHANNELS 0x17
76 #define TOUCHPAD2_CMD_DEBOUNCE_SETTINGS 0x18
77 #define TOUCHPAD2_CMD_PM_PROXIMITY_STATUS 0x20
78 #define TOUCHPAD2_CMD_PM_COUNT_VALUES 0x21
79 #define TOUCHPAD2_CMD_PM_LONG_TERM_AVERAGES 0x22
80 #define TOUCHPAD2_CMD_PM_ATI_COMPENSATION 0x23
81 #define TOUCHPAD2_CMD_PM_ATI_SETTINGS 0x24
82 #define TOUCHPAD2_CMD_BOOTLOADER 0xFF
83  // touchpad2_cmd
85 
106 #define TOUCHPAD2_SET_DEV_ADDR 0x74
107 
113 #define TOUCHPAD2_SHOW_RESET 0x80
114 #define TOUCHPAD2_MODE_INDICATOR 0x40
115 #define TOUCHPAD2_NOISE_STATUS 0x20
116 #define TOUCHPAD2_LP_STATUS 0x10
117 #define TOUCHPAD2_SNAP_OUTPUT 0x08
118 #define TOUCHPAD2_NO_OF_FINGERS 0x07
119 
125 #define TOUCHPAD2_ACK_RESET 0x80
126 #define TOUCHPAD2_AUTO_MODES 0x40
127 #define TOUCHPAD2_SINGLE_XY 0x20
128 #define TOUCHPAD2_PM_RESEED 0x10
129 #define TOUCHPAD2_MODE_SELECT 0x08
130 #define TOUCHPAD2_AUTO_ATI 0x04
131 #define TOUCHPAD2_TRACKPAD_RESEED 0x02
132 #define TOUCHPAD2_EVENT_MODE 0x01
133 #define TOUCHPAD2_DIS_PROX_EVENT 0x80
134 #define TOUCHPAD2_DIS_TOUCH_EVENT 0x40
135 #define TOUCHPAD2_DIS_SNAP_EVENT 0x20
136 #define TOUCHPAD2_DIS_PMPROX_EVENT 0x10
137 #define TOUCHPAD2_REVERSE_EN 0x08
138 #define TOUCHPAD2_SLEEP_EN 0x04
139 #define TOUCHPAD2_LOW_POWER 0x02
140 #define TOUCHPAD2_SNAP_EN 0x01
141 
147 #define TOUCHPAD2_DIS_NM_FILTER 0x10
148 #define TOUCHPAD2_DIS_PM_FILTER 0x08
149 #define TOUCHPAD2_SELECT_TOUCH_FILTER 0x04
150 #define TOUCHPAD2_DIS_HOVER_FILTER 0x02
151 #define TOUCHPAD2_DIS_TOUCH_FILTER 0x01
152 
158 #define TOUCHPAD2_CHARGE_TYPE_SELF_CHARG 0x80
159 #define TOUCHPAD2_CHARGE_MUTUAL_SELF_CHARG 0x00
160 #define TOUCHPAD2_RX_GROUP_RXB 0x40
161 #define TOUCHPAD2_RX_GROUP_RXA 0x00
162 #define TOUCHPAD2_SUM_OF_TP_RX 0x10
163 #define TOUCHPAD2_SUM_OF_TP_TX 0x00
164 #define TOUCHPAD2_RX_SELECT 0x0F
165 #define TOUCHPAD2_TX_CFG_DEFAULT 0x001F
166 
172 #define TOUCHPAD2_ND_ENABLE 0x20
173 #define TOUCHPAD2_RX_FLOAT 0x04
174 #define TOUCHPAD2_CK_FREQ_2 0x40
175 #define TOUCHPAD2_CK_FREQ_1 0x20
176 #define TOUCHPAD2_CK_FREQ_0 0x10
177 #define TOUCHPAD2_ANA_DEAD_TIME 0x02
178 #define TOUCHPAD2_INCR_PHASE 0x01
179 #define TOUCHPAD2_STAB_TIME_1 0x80
180 #define TOUCHPAD2_STAB_TIME_0 0x40
181 #define TOUCHPAD2_OPAMP_BIAS_1 0x20
182 #define TOUCHPAD2_OPAMP_BIAS_0 0x10
183 #define TOUCHPAD2_VTRIP_3 0x08
184 #define TOUCHPAD2_VTRIP_2 0x04
185 #define TOUCHPAD2_VTRIP_1 0x02
186 #define TOUCHPAD2_VTRIP_0 0x01
187 #define TOUCHPAD2_UPLEN_2 0x40
188 #define TOUCHPAD2_UPLEN_1 0x20
189 #define TOUCHPAD2_UPLEN_0 0x10
190 #define TOUCHPAD2_PASSLEN_2 0x04
191 #define TOUCHPAD2_PASSLEN_1 0x02
192 #define TOUCHPAD2_PASSLEN_0 0x01
193 
199 #define TOUCHPAD2_PALM_REJECT 0x08
200 #define TOUCHPAD2_SWITCH_XY_AXIS 0x04
201 #define TOUCHPAD2_FLIP_Y 0x02
202 #define TOUCHPAD2_FLIP_X 0x01
203 
209 #define TOUCHPAD2_PROX_EVENT 0x80
210 #define TOUCHPAD2_TOUCH_EVENT 0x40
211 #define TOUCHPAD2_SNAP_EVENT 0x20
212 #define TOUCHPAD2_ALP_PROX_EVENT 0x10
213 #define TOUCHPAD2_REATI_EVENT 0x08
214 #define TOUCHPAD2_TP_EVENT 0x04
215 #define TOUCHPAD2_GESTURE_EVENT 0x02
216 #define TOUCHPAD2_EVENT_MODE 0x01
217 #define TOUCHPAD2_ALP_COUNT_FILTER 0x08
218 #define TOUCHPAD2_IIR_SELECT 0x04
219 #define TOUCHPAD2_MAV_FILTER 0x02
220 #define TOUCHPAD2_IIR_FILTER 0x01
221 
227 #define TOUCHPAD2_CHARGE_TYPE 0x80
228 #define TOUCHPAD2_RX_GROUP 0x40
229 #define TOUCHPAD2_PROX_REV 0x20
230 #define TOUCHPAD2_ALP_ENABLE 0x10
231 
237 #define TOUCHPAD2_RX7_TX2 0x80
238 #define TOUCHPAD2_RX6_TX3 0x40
239 #define TOUCHPAD2_RX5_TX4 0x20
240 #define TOUCHPAD2_RX4_TX5 0x10
241 #define TOUCHPAD2_RX3_TX6 0x08
242 #define TOUCHPAD2_RX2_TX7 0x04
243 #define TOUCHPAD2_RX1_TX8 0x02
244 #define TOUCHPAD2_RX0_TX9 0x01
245  // touchpad2_set
253 
268 #define TOUCHPAD2_PROXIMITY_STATUS 0x00
269 #define TOUCHPAD2_TOUCH_STATUS 0x01
270 #define TOUCHPAD2_SNAP_STATUS 0x02
271 
272  // sel_status
274 
284 #define TOUCHPAD2_ID_TAG_TOUCH_1 0x01
285 #define TOUCHPAD2_ID_TAG_TOUCH_2 0x02
286 #define TOUCHPAD2_ID_TAG_TOUCH_3 0x03
287 #define TOUCHPAD2_ID_TAG_TOUCH_4 0x04
288 #define TOUCHPAD2_ID_TAG_TOUCH_5 0x05
289 #define TOUCHPAD2_ID_TAG_HOVER_1 0x81
290 #define TOUCHPAD2_ID_TAG_HOVER_2 0x82
291 #define TOUCHPAD2_ID_TAG_HOVER_3 0x83
292 #define TOUCHPAD2_ID_TAG_HOVER_4 0x84
293 #define TOUCHPAD2_ID_TAG_HOVER_5 0x85
294 
295  // id_tag
297 
307 #define TOUCHPAD2_IQS525_PRODUCT_NUMBER 0x34
308 
309  // product_num
311 
326 #define TOUCHPAD2_MAP_MIKROBUS( cfg, mikrobus ) \
327  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
328  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
329  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
330  // touchpad2_map // touchpad2
333 
338 typedef struct
339 {
340  // Input pins
341 
342  digital_in_t int_pin;
344  // Modules
345 
346  i2c_master_t i2c;
348  // I2C slave address
349 
350  uint8_t slave_address;
352 } touchpad2_t;
353 
358 typedef struct
359 {
360  pin_name_t scl;
361  pin_name_t sda;
363  pin_name_t int_pin;
365  uint32_t i2c_speed;
366  uint8_t i2c_address;
369 
374 typedef struct
375 {
376  uint16_t product_num;
377  uint16_t projec_num;
378  float version;
379  uint16_t hw_id;
380  uint16_t hw_revision;
383 
388 typedef struct
389 {
390  uint8_t xy_info;
391  uint8_t no_of_fingers;
392  uint8_t id_tag;
393  uint16_t x_pos;
394  uint16_t y_pos;
395  uint16_t touch_str;
398 
403 typedef struct
404 {
405  uint8_t total_rx;
406  uint8_t total_tx;
407  uint8_t track_pad_rx;
408  uint8_t track_pad_tx;
409  uint8_t pm_setup;
410  uint16_t tx_config;
413 
418 typedef enum
419 {
421  TOUCHPAD2_ERROR = -1
422 
424 
443 
460 err_t touchpad2_init ( touchpad2_t *ctx, touchpad2_cfg_t *cfg );
461 
477 err_t touchpad2_default_cfg ( touchpad2_t *ctx );
478 
496 err_t touchpad2_generic_write ( touchpad2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
497 
515 err_t touchpad2_generic_read ( touchpad2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
516 
531 uint8_t touchpad2_check_interrupt ( touchpad2_t *ctx );
532 
546 void touchpad2_wait_ready ( touchpad2_t *ctx );
547 
566 
584 
603 
624 err_t touchpad2_get_all_data ( touchpad2_t *ctx, uint8_t *rx_data );
625 
646 err_t touchpad2_get_status ( touchpad2_t *ctx, uint8_t sel_status, uint16_t *rx_data );
647 
648 #ifdef __cplusplus
649 }
650 #endif
651 #endif // TOUCHPAD2_H
652  // touchpad2
654 
655 // ------------------------------------------------------------------------ END
touchpad2_cfg_setup
void touchpad2_cfg_setup(touchpad2_cfg_t *cfg)
TouchPad 2 configuration object setup function.
ver_info
touchpad2_ver_info_t ver_info
Definition: main.c:31
TOUCHPAD2_OK
Definition: touchpad2.h:419
touchpad2_generic_write
err_t touchpad2_generic_write(touchpad2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
TouchPad 2 I2C writing function.
touchpad2_ver_info_t
TouchPad 2 device version information object.
Definition: touchpad2.h:373
touchpad2_get_all_data
err_t touchpad2_get_all_data(touchpad2_t *ctx, uint8_t *rx_data)
TouchPad 2 get all data function.
touchpad2_check_interrupt
uint8_t touchpad2_check_interrupt(touchpad2_t *ctx)
TouchPad 2 check interrupt function.
touchpad2_generic_read
err_t touchpad2_generic_read(touchpad2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
TouchPad 2 I2C reading function.
touchpad2_touch_t
TouchPad 2 XY data object.
Definition: touchpad2.h:387
touchpad2_get_status
err_t touchpad2_get_status(touchpad2_t *ctx, uint8_t sel_status, uint16_t *rx_data)
TouchPad 2 get status function.
touchpad2_cfg_t
TouchPad 2 Click configuration object.
Definition: touchpad2.h:357
touchpad2_init
err_t touchpad2_init(touchpad2_t *ctx, touchpad2_cfg_t *cfg)
TouchPad 2 initialization function.
touchpad2_channel_setup_t
TouchPad Channel Setup object.
Definition: touchpad2.h:402
touch_data
touchpad2_touch_t touch_data
Definition: main.c:32
TOUCHPAD2_ERROR
Definition: touchpad2.h:420
touchpad2_get_touch
err_t touchpad2_get_touch(touchpad2_t *ctx, touchpad2_touch_t *touch_data)
TouchPad 2 get touch function.
touchpad2_check_version
err_t touchpad2_check_version(touchpad2_t *ctx, touchpad2_ver_info_t *ver_info)
TouchPad 2 check version function.
touchpad2_default_cfg
err_t touchpad2_default_cfg(touchpad2_t *ctx)
TouchPad 2 default configuration function.
touchpad2_channel_setup
err_t touchpad2_channel_setup(touchpad2_t *ctx, touchpad2_channel_setup_t ch_setup)
TouchPad 2 channel setup function.
touchpad2_return_value_t
touchpad2_return_value_t
TouchPad 2 Click return value data.
Definition: touchpad2.h:417
touchpad2_t
TouchPad 2 Click context object.
Definition: touchpad2.h:337
touchpad2_wait_ready
void touchpad2_wait_ready(touchpad2_t *ctx)
TouchPad 2 wait ready function.