touchpad5 2.0.0.0
touchpad5.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 TOUCHPAD5_H
29#define TOUCHPAD5_H
30
31#ifdef __cplusplus
32extern "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 TOUCHPAD5_CMD_VERSION_INFO 0x00
74#define TOUCHPAD5_CMD_XY_DATA 0x01
75#define TOUCHPAD5_CMD_PROXIMITY_STATUS 0x02
76#define TOUCHPAD5_CMD_TOUCH_STATUS 0x03
77#define TOUCHPAD5_CMD_COUNT_VALUES 0x04
78#define TOUCHPAD5_CMD_LONG_TERM_AVERAGES 0x05
79#define TOUCHPAD5_CMD_ATI_COMPENSATION 0x06
80#define TOUCHPAD5_CMD_PORT_CONTROL 0x07
81#define TOUCHPAD5_CMD_SNAP_STATUS 0x08
82#define TOUCHPAD5_CMD_CONTROL_SETTINGS 0x10
83#define TOUCHPAD5_CMD_THRESHOLD_SETTINGS 0x11
84#define TOUCHPAD5_CMD_ATI_SETTINGS 0x12
85#define TOUCHPAD5_CMD_FILTER_SETTINGS 0x13
86#define TOUCHPAD5_CMD_TIMING_SETTINGS 0x14
87#define TOUCHPAD5_CMD_CHANNEL_SETUP 0x15
88#define TOUCHPAD5_CMD_HARDWARE_CONFIG_SETTINGS 0x16
89#define TOUCHPAD5_CMD_ACTIVE_CHANNELS 0x17
90#define TOUCHPAD5_CMD_DEBOUNCE_SETTINGS 0x18
91#define TOUCHPAD5_CMD_PM_PROXIMITY_STATUS 0x20
92#define TOUCHPAD5_CMD_PM_COUNT_VALUES 0x21
93#define TOUCHPAD5_CMD_PM_LONG_TERM_AVERAGES 0x22
94#define TOUCHPAD5_CMD_PM_ATI_COMPENSATION 0x23
95#define TOUCHPAD5_CMD_PM_ATI_SETTINGS 0x24
96#define TOUCHPAD5_CMD_BOOTLOADER 0xFF
97
98 // touchpad5_cmd
99
115#define TOUCHPAD5_SET_DEV_ADDR 0x74
116
128#define TOUCHPAD5_SHOW_RESET 0x80
129#define TOUCHPAD5_MODE_INDICATOR 0x40
130#define TOUCHPAD5_NOISE_STATUS 0x20
131#define TOUCHPAD5_LP_STATUS 0x10
132#define TOUCHPAD5_SNAP_OUTPUT 0x08
133#define TOUCHPAD5_NO_OF_FINGERS 0x07
134
140#define TOUCHPAD5_ACK_RESET 0x80
141#define TOUCHPAD5_AUTO_MODES 0x40
142#define TOUCHPAD5_SINGLE_XY 0x20
143#define TOUCHPAD5_PM_RESEED 0x10
144#define TOUCHPAD5_MODE_SELECT 0x08
145#define TOUCHPAD5_AUTO_ATI 0x04
146#define TOUCHPAD5_TRACKPAD_RESEED 0x02
147#define TOUCHPAD5_EVENT_MODE 0x01
148#define TOUCHPAD5_DIS_PROX_EVENT 0x80
149#define TOUCHPAD5_DIS_TOUCH_EVENT 0x40
150#define TOUCHPAD5_DIS_SNAP_EVENT 0x20
151#define TOUCHPAD5_DIS_PMPROX_EVENT 0x10
152#define TOUCHPAD5_REVERSE_EN 0x08
153#define TOUCHPAD5_SLEEP_EN 0x04
154#define TOUCHPAD5_LOW_POWER 0x02
155#define TOUCHPAD5_SNAP_EN 0x01
156
162#define TOUCHPAD5_DIS_NM_FILTER 0x10
163#define TOUCHPAD5_DIS_PM_FILTER 0x08
164#define TOUCHPAD5_SELECT_TOUCH_FILTER 0x04
165#define TOUCHPAD5_DIS_HOVER_FILTER 0x02
166#define TOUCHPAD5_DIS_TOUCH_FILTER 0x01
167
173#define TOUCHPAD5_CHARGE_TYPE_SELF_CHARG 0x80
174#define TOUCHPAD5_CHARGE_MUTUAL_SELF_CHARG 0x00
175#define TOUCHPAD5_RX_GROUP_RXB 0x40
176#define TOUCHPAD5_RX_GROUP_RXA 0x00
177#define TOUCHPAD5_SUM_OF_TP_RX 0x10
178#define TOUCHPAD5_SUM_OF_TP_TX 0x00
179#define TOUCHPAD5_RX_SELECT 0x0F
180#define TOUCHPAD5_TX_HIGH_DFLT 0x1F
181#define TOUCHPAD5_TX_LOW_DFLT 0xFF
182
188#define TOUCHPAD5_ND_ENABLE 0x20
189#define TOUCHPAD5_RX_FLOAT 0x04
190#define TOUCHPAD5_CK_FREQ_2 0x40
191#define TOUCHPAD5_CK_FREQ_1 0x20
192#define TOUCHPAD5_CK_FREQ_0 0x10
193#define TOUCHPAD5_ANA_DEAD_TIME 0x02
194#define TOUCHPAD5_INCR_PHASE 0x01
195#define TOUCHPAD5_STAB_TIME_1 0x80
196#define TOUCHPAD5_STAB_TIME_0 0x40
197#define TOUCHPAD5_OPAMP_BIAS_1 0x20
198#define TOUCHPAD5_OPAMP_BIAS_0 0x10
199#define TOUCHPAD5_VTRIP_3 0x08
200#define TOUCHPAD5_VTRIP_2 0x04
201#define TOUCHPAD5_VTRIP_1 0x02
202#define TOUCHPAD5_VTRIP_0 0x01
203#define TOUCHPAD5_UPLEN_2 0x40
204#define TOUCHPAD5_UPLEN_1 0x20
205#define TOUCHPAD5_UPLEN_0 0x10
206#define TOUCHPAD5_PASSLEN_2 0x04
207#define TOUCHPAD5_PASSLEN_1 0x02
208#define TOUCHPAD5_PASSLEN_0 0x01
209
215#define TOUCHPAD5_PALM_REJECT 0x08
216#define TOUCHPAD5_SWITCH_XY_AXIS 0x04
217#define TOUCHPAD5_FLIP_Y 0x02
218#define TOUCHPAD5_FLIP_X 0x01
219
225#define TOUCHPAD5_PROX_EVENT 0x80
226#define TOUCHPAD5_TOUCH_EVENT 0x40
227#define TOUCHPAD5_SNAP_EVENT 0x20
228#define TOUCHPAD5_ALP_PROX_EVENT 0x10
229#define TOUCHPAD5_REATI_EVENT 0x08
230#define TOUCHPAD5_TP_EVENT 0x04
231#define TOUCHPAD5_GESTURE_EVENT 0x02
232#define TOUCHPAD5_EVENT_MODE 0x01
233#define TOUCHPAD5_ALP_COUNT_FILTER 0x08
234#define TOUCHPAD5_IIR_SELECT 0x04
235#define TOUCHPAD5_MAV_FILTER 0x02
236#define TOUCHPAD5_IIR_FILTER 0x01
237
243#define TOUCHPAD5_CHARGE_TYPE 0x80
244#define TOUCHPAD5_RX_GROUP 0x40
245#define TOUCHPAD5_PROX_REV 0x20
246#define TOUCHPAD5_ALP_ENABLE 0x10
247
253#define TOUCHPAD5_RX7_TX2 0x80
254#define TOUCHPAD5_RX6_TX3 0x40
255#define TOUCHPAD5_RX5_TX4 0x20
256#define TOUCHPAD5_RX4_TX5 0x10
257#define TOUCHPAD5_RX3_TX6 0x08
258#define TOUCHPAD5_RX2_TX7 0x04
259#define TOUCHPAD5_RX1_TX8 0x02
260#define TOUCHPAD5_RX0_TX9 0x01
261
262
263 // touchpad5_set
264
279#define TOUCHPAD5_PROXIMITY_STATUS 0x02
280#define TOUCHPAD5_TOUCH_STATUS 0x01
281#define TOUCHPAD5_SNAP_STATUS 0x05
282
283
284 // sel_status
285
295#define TOUCHPAD5_ID_TAG_TOUCH_1 0x01
296#define TOUCHPAD5_ID_TAG_TOUCH_2 0x02
297#define TOUCHPAD5_ID_TAG_TOUCH_3 0x03
298#define TOUCHPAD5_ID_TAG_TOUCH_4 0x04
299#define TOUCHPAD5_ID_TAG_TOUCH_5 0x05
300#define TOUCHPAD5_ID_TAG_HOVER_1 0x81
301#define TOUCHPAD5_ID_TAG_HOVER_2 0x82
302#define TOUCHPAD5_ID_TAG_HOVER_3 0x83
303#define TOUCHPAD5_ID_TAG_HOVER_4 0x84
304#define TOUCHPAD5_ID_TAG_HOVER_5 0x85
305
306 // id_tag
307
308
323#define TOUCHPAD5_MAP_MIKROBUS( cfg, mikrobus ) \
324 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
325 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
326 cfg.nrst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
327 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
328
329 // touchpad5_map
330
340#define TOUCHPAD5_IQS550_PRODUCT_NUMBER 40
341
342
343 // product_num
344 // touchpad5
345
350typedef struct
351{
352 // Output pins
353 digital_out_t nrst;
355 // Input pins
356 digital_in_t int_pin;
358 // Modules
359 i2c_master_t i2c;
361 // I2C slave address
365
370typedef struct
371{
372 pin_name_t scl;
373 pin_name_t sda;
375 pin_name_t nrst;
376 pin_name_t int_pin;
378 uint32_t i2c_speed;
379 uint8_t i2c_address;
382
387typedef struct
388{
389 uint16_t product_num;
390 uint16_t project_num;
391 float version;
392 uint16_t hw_id;
393 uint16_t hw_revision;
395
400typedef struct
401{
402 uint8_t xy_info;
404 uint8_t id_tag;
405 uint16_t x_pos;
406 uint16_t y_pos;
407 uint16_t touch_strength;
410
415typedef struct
416{
417 uint8_t total_rx;
418 uint8_t total_tx;
419 uint8_t track_pad_rx;
420 uint8_t track_pad_tx;
421 uint8_t pm_setup;
422 uint16_t tx_config;
425
443
448typedef struct
449{
454
465
482
493
509
524
540err_t touchpad5_generic_write( touchpad5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
541
557err_t touchpad5_generic_read( touchpad5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
558
559
575
588err_t touchpad5_check_bl_status( touchpad5_t *ctx, uint8_t* rx_buf );
589
603
616
633
649
650
666
667
684
703err_t touchpad5_get_all_data( touchpad5_t *ctx, uint8_t *rx_data );
704
724err_t touchpad5_get_status( touchpad5_t *ctx, uint8_t sel_status, uint16_t *rx_data, uint8_t num_of_samples );
725
726#ifdef __cplusplus
727}
728#endif
729#endif // TOUCHPAD5_H
730
731 // touchpad5
732
733// ------------------------------------------------------------------------ END
err_t touchpad5_check_bl_status(touchpad5_t *ctx, uint8_t *rx_buf)
TouchPad 5 Check Bootloader Status.
err_t touchpad5_get_all_data(touchpad5_t *ctx, uint8_t *rx_data)
TouchPad 5 get all data function.
err_t touchpad5_get_status(touchpad5_t *ctx, uint8_t sel_status, uint16_t *rx_data, uint8_t num_of_samples)
TouchPad 5 get status function.
uint8_t touchpad5_check_interrupt(touchpad5_t *ctx)
TouchPad 5 check interrupt function.
void touchpad5_cfg_setup(touchpad5_cfg_t *cfg)
Touchpad 5 configuration object setup function.
err_t touchpad5_init(touchpad5_t *ctx, touchpad5_cfg_t *cfg)
Touchpad 5 initialization function.
err_t touchpad5_generic_read(touchpad5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Touchpad 5 I2C reading function.
void touchpad5_wait_ready(touchpad5_t *ctx)
TouchPad 5 wait ready function.
err_t touchpad5_default_cfg(touchpad5_t *ctx)
Touchpad 5 default configuration function.
err_t touchpad5_threshold_setup(touchpad5_t *ctx, touchpad5_threshold_settings_t thresh_setup)
TouchPad 5 threshold setup function.
err_t touchpad5_channel_setup(touchpad5_t *ctx, touchpad5_channel_setup_t ch_setup)
TouchPad 5 channel setup function.
err_t touchpad5_control_setup(touchpad5_t *ctx, touchpad5_control_settings_t ctrl_setup)
TouchPad 5 control setup function.
err_t touchpad5_generic_write(touchpad5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Touchpad 5 I2C writing function.
err_t touchpad5_get_touch(touchpad5_t *ctx, touchpad5_touch_t *touch_data)
TouchPad 5 get touch function.
err_t touchpad5_check_version(touchpad5_t *ctx, touchpad5_ver_info_t *ver_info)
TouchPad 5 Check Version function.
void touchpad5_reset(touchpad5_t *ctx)
Touchpad 5 reset function.
Touchpad 5 Click configuration object.
Definition touchpad5.h:371
uint32_t i2c_speed
Definition touchpad5.h:378
pin_name_t nrst
Definition touchpad5.h:375
pin_name_t scl
Definition touchpad5.h:372
pin_name_t int_pin
Definition touchpad5.h:376
pin_name_t sda
Definition touchpad5.h:373
uint8_t i2c_address
Definition touchpad5.h:379
TouchPad 5 Channel Setup object.
Definition touchpad5.h:416
uint8_t pm_setup
Definition touchpad5.h:421
uint8_t track_pad_rx
Definition touchpad5.h:419
uint8_t total_rx
Definition touchpad5.h:417
uint16_t tx_config
Definition touchpad5.h:422
uint8_t track_pad_tx
Definition touchpad5.h:420
uint8_t total_tx
Definition touchpad5.h:418
TouchPad 5 Control Settings object.
Definition touchpad5.h:449
uint8_t ctrl_settings1
Definition touchpad5.h:451
uint8_t ctrl_settings0
Definition touchpad5.h:450
Touchpad 5 Click context object.
Definition touchpad5.h:351
digital_in_t int_pin
Definition touchpad5.h:356
i2c_master_t i2c
Definition touchpad5.h:359
uint8_t slave_address
Definition touchpad5.h:362
digital_out_t nrst
Definition touchpad5.h:353
TouchPad 5 Threshold Settings object.
Definition touchpad5.h:431
uint8_t snap_thresh_high
Definition touchpad5.h:436
uint8_t prox_thresh2
Definition touchpad5.h:438
uint8_t pm_prox_thresh
Definition touchpad5.h:435
uint8_t snap_thresh_low
Definition touchpad5.h:437
uint8_t touch_thresh_mult2
Definition touchpad5.h:439
uint8_t touch_thresh_shift2
Definition touchpad5.h:440
uint8_t prox_thresh
Definition touchpad5.h:432
uint8_t touch_thresh_mult
Definition touchpad5.h:433
uint8_t touch_thresh_shift
Definition touchpad5.h:434
TouchPad 5 XY data object.
Definition touchpad5.h:401
uint8_t xy_info
Definition touchpad5.h:402
uint16_t touch_strength
Definition touchpad5.h:407
uint16_t y_pos
Definition touchpad5.h:406
uint16_t x_pos
Definition touchpad5.h:405
uint8_t no_of_fingers
Definition touchpad5.h:403
uint8_t id_tag
Definition touchpad5.h:404
TouchPad 5 device version information object.
Definition touchpad5.h:388
uint16_t product_num
Definition touchpad5.h:389
uint16_t project_num
Definition touchpad5.h:390
uint16_t hw_revision
Definition touchpad5.h:393
float version
Definition touchpad5.h:391
uint16_t hw_id
Definition touchpad5.h:392
touchpad5_return_value_t
Touchpad 5 Click return value data.
Definition touchpad5.h:460
@ TOUCHPAD5_ERROR
Definition touchpad5.h:462
@ TOUCHPAD5_OK
Definition touchpad5.h:461