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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define TOUCHPAD2_CMD_VERSION_INFO 0x00
74 #define TOUCHPAD2_CMD_XY_DATA 0x01
75 #define TOUCHPAD2_CMD_PROXIMITY_STATUS 0x02
76 #define TOUCHPAD2_CMD_TOUCH_STATUS 0x03
77 #define TOUCHPAD2_CMD_COUNT_VALUES 0x04
78 #define TOUCHPAD2_CMD_LONG_TERM_AVERAGES 0x05
79 #define TOUCHPAD2_CMD_ATI_COMPENSATION 0x06
80 #define TOUCHPAD2_CMD_PORT_CONTROL 0x07
81 #define TOUCHPAD2_CMD_SNAP_STATUS 0x08
82 #define TOUCHPAD2_CMD_CONTROL_SETTINGS 0x10
83 #define TOUCHPAD2_CMD_THRESHOLD_SETTINGS 0x11
84 #define TOUCHPAD2_CMD_ATI_SETTINGS 0x12
85 #define TOUCHPAD2_CMD_FILTER_SETTINGS 0x13
86 #define TOUCHPAD2_CMD_TIMING_SETTINGS 0x14
87 #define TOUCHPAD2_CMD_CHANNEL_SETUP 0x15
88 #define TOUCHPAD2_CMD_HARDWARE_CONFIG_SETTINGS 0x16
89 #define TOUCHPAD2_CMD_ACTIVE_CHANNELS 0x17
90 #define TOUCHPAD2_CMD_DEBOUNCE_SETTINGS 0x18
91 #define TOUCHPAD2_CMD_PM_PROXIMITY_STATUS 0x20
92 #define TOUCHPAD2_CMD_PM_COUNT_VALUES 0x21
93 #define TOUCHPAD2_CMD_PM_LONG_TERM_AVERAGES 0x22
94 #define TOUCHPAD2_CMD_PM_ATI_COMPENSATION 0x23
95 #define TOUCHPAD2_CMD_PM_ATI_SETTINGS 0x24
96 #define TOUCHPAD2_CMD_BOOTLOADER 0xFF
97  // touchpad2_cmd
99 
120 #define TOUCHPAD2_SET_DEV_ADDR 0x74
121 
127 #define TOUCHPAD2_SHOW_RESET 0x80
128 #define TOUCHPAD2_MODE_INDICATOR 0x40
129 #define TOUCHPAD2_NOISE_STATUS 0x20
130 #define TOUCHPAD2_LP_STATUS 0x10
131 #define TOUCHPAD2_SNAP_OUTPUT 0x08
132 #define TOUCHPAD2_NO_OF_FINGERS 0x07
133 
139 #define TOUCHPAD2_ACK_RESET 0x80
140 #define TOUCHPAD2_AUTO_MODES 0x40
141 #define TOUCHPAD2_SINGLE_XY 0x20
142 #define TOUCHPAD2_PM_RESEED 0x10
143 #define TOUCHPAD2_MODE_SELECT 0x08
144 #define TOUCHPAD2_AUTO_ATI 0x04
145 #define TOUCHPAD2_TRACKPAD_RESEED 0x02
146 #define TOUCHPAD2_EVENT_MODE 0x01
147 #define TOUCHPAD2_DIS_PROX_EVENT 0x80
148 #define TOUCHPAD2_DIS_TOUCH_EVENT 0x40
149 #define TOUCHPAD2_DIS_SNAP_EVENT 0x20
150 #define TOUCHPAD2_DIS_PMPROX_EVENT 0x10
151 #define TOUCHPAD2_REVERSE_EN 0x08
152 #define TOUCHPAD2_SLEEP_EN 0x04
153 #define TOUCHPAD2_LOW_POWER 0x02
154 #define TOUCHPAD2_SNAP_EN 0x01
155 
161 #define TOUCHPAD2_DIS_NM_FILTER 0x10
162 #define TOUCHPAD2_DIS_PM_FILTER 0x08
163 #define TOUCHPAD2_SELECT_TOUCH_FILTER 0x04
164 #define TOUCHPAD2_DIS_HOVER_FILTER 0x02
165 #define TOUCHPAD2_DIS_TOUCH_FILTER 0x01
166 
172 #define TOUCHPAD2_CHARGE_TYPE_SELF_CHARG 0x80
173 #define TOUCHPAD2_CHARGE_MUTUAL_SELF_CHARG 0x00
174 #define TOUCHPAD2_RX_GROUP_RXB 0x40
175 #define TOUCHPAD2_RX_GROUP_RXA 0x00
176 #define TOUCHPAD2_SUM_OF_TP_RX 0x10
177 #define TOUCHPAD2_SUM_OF_TP_TX 0x00
178 #define TOUCHPAD2_RX_SELECT 0x0F
179 #define TOUCHPAD2_TX_CFG_DEFAULT 0x001F
180 
186 #define TOUCHPAD2_ND_ENABLE 0x20
187 #define TOUCHPAD2_RX_FLOAT 0x04
188 #define TOUCHPAD2_CK_FREQ_2 0x40
189 #define TOUCHPAD2_CK_FREQ_1 0x20
190 #define TOUCHPAD2_CK_FREQ_0 0x10
191 #define TOUCHPAD2_ANA_DEAD_TIME 0x02
192 #define TOUCHPAD2_INCR_PHASE 0x01
193 #define TOUCHPAD2_STAB_TIME_1 0x80
194 #define TOUCHPAD2_STAB_TIME_0 0x40
195 #define TOUCHPAD2_OPAMP_BIAS_1 0x20
196 #define TOUCHPAD2_OPAMP_BIAS_0 0x10
197 #define TOUCHPAD2_VTRIP_3 0x08
198 #define TOUCHPAD2_VTRIP_2 0x04
199 #define TOUCHPAD2_VTRIP_1 0x02
200 #define TOUCHPAD2_VTRIP_0 0x01
201 #define TOUCHPAD2_UPLEN_2 0x40
202 #define TOUCHPAD2_UPLEN_1 0x20
203 #define TOUCHPAD2_UPLEN_0 0x10
204 #define TOUCHPAD2_PASSLEN_2 0x04
205 #define TOUCHPAD2_PASSLEN_1 0x02
206 #define TOUCHPAD2_PASSLEN_0 0x01
207 
213 #define TOUCHPAD2_PALM_REJECT 0x08
214 #define TOUCHPAD2_SWITCH_XY_AXIS 0x04
215 #define TOUCHPAD2_FLIP_Y 0x02
216 #define TOUCHPAD2_FLIP_X 0x01
217 
223 #define TOUCHPAD2_PROX_EVENT 0x80
224 #define TOUCHPAD2_TOUCH_EVENT 0x40
225 #define TOUCHPAD2_SNAP_EVENT 0x20
226 #define TOUCHPAD2_ALP_PROX_EVENT 0x10
227 #define TOUCHPAD2_REATI_EVENT 0x08
228 #define TOUCHPAD2_TP_EVENT 0x04
229 #define TOUCHPAD2_GESTURE_EVENT 0x02
230 #define TOUCHPAD2_EVENT_MODE 0x01
231 #define TOUCHPAD2_ALP_COUNT_FILTER 0x08
232 #define TOUCHPAD2_IIR_SELECT 0x04
233 #define TOUCHPAD2_MAV_FILTER 0x02
234 #define TOUCHPAD2_IIR_FILTER 0x01
235 
241 #define TOUCHPAD2_CHARGE_TYPE 0x80
242 #define TOUCHPAD2_RX_GROUP 0x40
243 #define TOUCHPAD2_PROX_REV 0x20
244 #define TOUCHPAD2_ALP_ENABLE 0x10
245 
251 #define TOUCHPAD2_RX7_TX2 0x80
252 #define TOUCHPAD2_RX6_TX3 0x40
253 #define TOUCHPAD2_RX5_TX4 0x20
254 #define TOUCHPAD2_RX4_TX5 0x10
255 #define TOUCHPAD2_RX3_TX6 0x08
256 #define TOUCHPAD2_RX2_TX7 0x04
257 #define TOUCHPAD2_RX1_TX8 0x02
258 #define TOUCHPAD2_RX0_TX9 0x01
259  // touchpad2_set
267 
282 #define TOUCHPAD2_PROXIMITY_STATUS 0x00
283 #define TOUCHPAD2_TOUCH_STATUS 0x01
284 #define TOUCHPAD2_SNAP_STATUS 0x02
285 
286  // sel_status
288 
298 #define TOUCHPAD2_ID_TAG_TOUCH_1 0x01
299 #define TOUCHPAD2_ID_TAG_TOUCH_2 0x02
300 #define TOUCHPAD2_ID_TAG_TOUCH_3 0x03
301 #define TOUCHPAD2_ID_TAG_TOUCH_4 0x04
302 #define TOUCHPAD2_ID_TAG_TOUCH_5 0x05
303 #define TOUCHPAD2_ID_TAG_HOVER_1 0x81
304 #define TOUCHPAD2_ID_TAG_HOVER_2 0x82
305 #define TOUCHPAD2_ID_TAG_HOVER_3 0x83
306 #define TOUCHPAD2_ID_TAG_HOVER_4 0x84
307 #define TOUCHPAD2_ID_TAG_HOVER_5 0x85
308 
309  // id_tag
311 
321 #define TOUCHPAD2_IQS525_PRODUCT_NUMBER 0x34
322 
323  // product_num
325 
340 #define TOUCHPAD2_MAP_MIKROBUS( cfg, mikrobus ) \
341  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
342  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
343  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
344  // touchpad2_map // touchpad2
347 
352 typedef struct
353 {
354  // Input pins
355 
356  digital_in_t int_pin;
358  // Modules
359 
360  i2c_master_t i2c;
362  // I2C slave address
363 
364  uint8_t slave_address;
366 } touchpad2_t;
367 
372 typedef struct
373 {
374  pin_name_t scl;
375  pin_name_t sda;
377  pin_name_t int_pin;
379  uint32_t i2c_speed;
380  uint8_t i2c_address;
383 
388 typedef struct
389 {
390  uint16_t product_num;
391  uint16_t projec_num;
392  float version;
393  uint16_t hw_id;
394  uint16_t hw_revision;
397 
402 typedef struct
403 {
404  uint8_t xy_info;
405  uint8_t no_of_fingers;
406  uint8_t id_tag;
407  uint16_t x_pos;
408  uint16_t y_pos;
409  uint16_t touch_str;
412 
417 typedef struct
418 {
419  uint8_t total_rx;
420  uint8_t total_tx;
421  uint8_t track_pad_rx;
422  uint8_t track_pad_tx;
423  uint8_t pm_setup;
424  uint16_t tx_config;
427 
432 typedef enum
433 {
435  TOUCHPAD2_ERROR = -1
436 
438 
457 
475 
492 
510 err_t touchpad2_generic_write ( touchpad2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
511 
529 err_t touchpad2_generic_read ( touchpad2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
530 
546 
561 
580 
598 
617 
638 err_t touchpad2_get_all_data ( touchpad2_t *ctx, uint8_t *rx_data );
639 
660 err_t touchpad2_get_status ( touchpad2_t *ctx, uint8_t sel_status, uint16_t *rx_data );
661 
662 #ifdef __cplusplus
663 }
664 #endif
665 #endif // TOUCHPAD2_H
666  // touchpad2
668 
669 // ------------------------------------------------------------------------ END
touchpad2_cfg_setup
void touchpad2_cfg_setup(touchpad2_cfg_t *cfg)
TouchPad 2 configuration object setup function.
touchpad2_t::slave_address
uint8_t slave_address
Definition: touchpad2.h:364
ver_info
touchpad2_ver_info_t ver_info
Definition: main.c:31
TOUCHPAD2_OK
@ TOUCHPAD2_OK
Definition: touchpad2.h:434
touchpad2_touch_t::id_tag
uint8_t id_tag
Definition: touchpad2.h:406
touchpad2_touch_t::touch_str
uint16_t touch_str
Definition: touchpad2.h:409
touchpad2_cfg_t::int_pin
pin_name_t int_pin
Definition: touchpad2.h:377
touchpad2_ver_info_t::hw_revision
uint16_t hw_revision
Definition: touchpad2.h:394
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_cfg_t::i2c_address
uint8_t i2c_address
Definition: touchpad2.h:380
touchpad2_channel_setup_t::tx_config
uint16_t tx_config
Definition: touchpad2.h:424
touchpad2_ver_info_t
TouchPad 2 device version information object.
Definition: touchpad2.h:389
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_t::i2c
i2c_master_t i2c
Definition: touchpad2.h:360
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:403
touchpad2_channel_setup_t::total_tx
uint8_t total_tx
Definition: touchpad2.h:420
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_ver_info_t::hw_id
uint16_t hw_id
Definition: touchpad2.h:393
touchpad2_ver_info_t::version
float version
Definition: touchpad2.h:392
touchpad2_cfg_t
TouchPad 2 Click configuration object.
Definition: touchpad2.h:373
touchpad2_init
err_t touchpad2_init(touchpad2_t *ctx, touchpad2_cfg_t *cfg)
TouchPad 2 initialization function.
touchpad2_touch_t::x_pos
uint16_t x_pos
Definition: touchpad2.h:407
touchpad2_t::int_pin
digital_in_t int_pin
Definition: touchpad2.h:356
touchpad2_channel_setup_t
TouchPad Channel Setup object.
Definition: touchpad2.h:418
touchpad2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: touchpad2.h:379
touch_data
touchpad2_touch_t touch_data
Definition: main.c:32
touchpad2_channel_setup_t::pm_setup
uint8_t pm_setup
Definition: touchpad2.h:423
TOUCHPAD2_ERROR
@ TOUCHPAD2_ERROR
Definition: touchpad2.h:435
touchpad2_get_touch
err_t touchpad2_get_touch(touchpad2_t *ctx, touchpad2_touch_t *touch_data)
TouchPad 2 get touch function.
touchpad2_channel_setup_t::total_rx
uint8_t total_rx
Definition: touchpad2.h:419
touchpad2_cfg_t::scl
pin_name_t scl
Definition: touchpad2.h:374
touchpad2_touch_t::y_pos
uint16_t y_pos
Definition: touchpad2.h:408
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_touch_t::no_of_fingers
uint8_t no_of_fingers
Definition: touchpad2.h:405
touchpad2_ver_info_t::projec_num
uint16_t projec_num
Definition: touchpad2.h:391
touchpad2_channel_setup
err_t touchpad2_channel_setup(touchpad2_t *ctx, touchpad2_channel_setup_t ch_setup)
TouchPad 2 channel setup function.
touchpad2_touch_t::xy_info
uint8_t xy_info
Definition: touchpad2.h:404
touchpad2_ver_info_t::product_num
uint16_t product_num
Definition: touchpad2.h:390
touchpad2_cfg_t::sda
pin_name_t sda
Definition: touchpad2.h:375
touchpad2_channel_setup_t::track_pad_tx
uint8_t track_pad_tx
Definition: touchpad2.h:422
touchpad2_return_value_t
touchpad2_return_value_t
TouchPad 2 Click return value data.
Definition: touchpad2.h:433
touchpad2_channel_setup_t::track_pad_rx
uint8_t track_pad_rx
Definition: touchpad2.h:421
touchpad2_t
TouchPad 2 Click context object.
Definition: touchpad2.h:353
touchpad2_wait_ready
void touchpad2_wait_ready(touchpad2_t *ctx)
TouchPad 2 wait ready function.