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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define TOUCHPAD2_CMD_VERSION_INFO 0x00
70 #define TOUCHPAD2_CMD_XY_DATA 0x01
71 #define TOUCHPAD2_CMD_PROXIMITY_STATUS 0x02
72 #define TOUCHPAD2_CMD_TOUCH_STATUS 0x03
73 #define TOUCHPAD2_CMD_COUNT_VALUES 0x04
74 #define TOUCHPAD2_CMD_LONG_TERM_AVERAGES 0x05
75 #define TOUCHPAD2_CMD_ATI_COMPENSATION 0x06
76 #define TOUCHPAD2_CMD_PORT_CONTROL 0x07
77 #define TOUCHPAD2_CMD_SNAP_STATUS 0x08
78 #define TOUCHPAD2_CMD_CONTROL_SETTINGS 0x10
79 #define TOUCHPAD2_CMD_THRESHOLD_SETTINGS 0x11
80 #define TOUCHPAD2_CMD_ATI_SETTINGS 0x12
81 #define TOUCHPAD2_CMD_FILTER_SETTINGS 0x13
82 #define TOUCHPAD2_CMD_TIMING_SETTINGS 0x14
83 #define TOUCHPAD2_CMD_CHANNEL_SETUP 0x15
84 #define TOUCHPAD2_CMD_HARDWARE_CONFIG_SETTINGS 0x16
85 #define TOUCHPAD2_CMD_ACTIVE_CHANNELS 0x17
86 #define TOUCHPAD2_CMD_DEBOUNCE_SETTINGS 0x18
87 #define TOUCHPAD2_CMD_PM_PROXIMITY_STATUS 0x20
88 #define TOUCHPAD2_CMD_PM_COUNT_VALUES 0x21
89 #define TOUCHPAD2_CMD_PM_LONG_TERM_AVERAGES 0x22
90 #define TOUCHPAD2_CMD_PM_ATI_COMPENSATION 0x23
91 #define TOUCHPAD2_CMD_PM_ATI_SETTINGS 0x24
92 #define TOUCHPAD2_CMD_BOOTLOADER 0xFF
93  // touchpad2_cmd
95 
116 #define TOUCHPAD2_SET_DEV_ADDR 0x74
117 
123 #define TOUCHPAD2_SHOW_RESET 0x80
124 #define TOUCHPAD2_MODE_INDICATOR 0x40
125 #define TOUCHPAD2_NOISE_STATUS 0x20
126 #define TOUCHPAD2_LP_STATUS 0x10
127 #define TOUCHPAD2_SNAP_OUTPUT 0x08
128 #define TOUCHPAD2_NO_OF_FINGERS 0x07
129 
135 #define TOUCHPAD2_ACK_RESET 0x80
136 #define TOUCHPAD2_AUTO_MODES 0x40
137 #define TOUCHPAD2_SINGLE_XY 0x20
138 #define TOUCHPAD2_PM_RESEED 0x10
139 #define TOUCHPAD2_MODE_SELECT 0x08
140 #define TOUCHPAD2_AUTO_ATI 0x04
141 #define TOUCHPAD2_TRACKPAD_RESEED 0x02
142 #define TOUCHPAD2_EVENT_MODE 0x01
143 #define TOUCHPAD2_DIS_PROX_EVENT 0x80
144 #define TOUCHPAD2_DIS_TOUCH_EVENT 0x40
145 #define TOUCHPAD2_DIS_SNAP_EVENT 0x20
146 #define TOUCHPAD2_DIS_PMPROX_EVENT 0x10
147 #define TOUCHPAD2_REVERSE_EN 0x08
148 #define TOUCHPAD2_SLEEP_EN 0x04
149 #define TOUCHPAD2_LOW_POWER 0x02
150 #define TOUCHPAD2_SNAP_EN 0x01
151 
157 #define TOUCHPAD2_DIS_NM_FILTER 0x10
158 #define TOUCHPAD2_DIS_PM_FILTER 0x08
159 #define TOUCHPAD2_SELECT_TOUCH_FILTER 0x04
160 #define TOUCHPAD2_DIS_HOVER_FILTER 0x02
161 #define TOUCHPAD2_DIS_TOUCH_FILTER 0x01
162 
168 #define TOUCHPAD2_CHARGE_TYPE_SELF_CHARG 0x80
169 #define TOUCHPAD2_CHARGE_MUTUAL_SELF_CHARG 0x00
170 #define TOUCHPAD2_RX_GROUP_RXB 0x40
171 #define TOUCHPAD2_RX_GROUP_RXA 0x00
172 #define TOUCHPAD2_SUM_OF_TP_RX 0x10
173 #define TOUCHPAD2_SUM_OF_TP_TX 0x00
174 #define TOUCHPAD2_RX_SELECT 0x0F
175 #define TOUCHPAD2_TX_CFG_DEFAULT 0x001F
176 
182 #define TOUCHPAD2_ND_ENABLE 0x20
183 #define TOUCHPAD2_RX_FLOAT 0x04
184 #define TOUCHPAD2_CK_FREQ_2 0x40
185 #define TOUCHPAD2_CK_FREQ_1 0x20
186 #define TOUCHPAD2_CK_FREQ_0 0x10
187 #define TOUCHPAD2_ANA_DEAD_TIME 0x02
188 #define TOUCHPAD2_INCR_PHASE 0x01
189 #define TOUCHPAD2_STAB_TIME_1 0x80
190 #define TOUCHPAD2_STAB_TIME_0 0x40
191 #define TOUCHPAD2_OPAMP_BIAS_1 0x20
192 #define TOUCHPAD2_OPAMP_BIAS_0 0x10
193 #define TOUCHPAD2_VTRIP_3 0x08
194 #define TOUCHPAD2_VTRIP_2 0x04
195 #define TOUCHPAD2_VTRIP_1 0x02
196 #define TOUCHPAD2_VTRIP_0 0x01
197 #define TOUCHPAD2_UPLEN_2 0x40
198 #define TOUCHPAD2_UPLEN_1 0x20
199 #define TOUCHPAD2_UPLEN_0 0x10
200 #define TOUCHPAD2_PASSLEN_2 0x04
201 #define TOUCHPAD2_PASSLEN_1 0x02
202 #define TOUCHPAD2_PASSLEN_0 0x01
203 
209 #define TOUCHPAD2_PALM_REJECT 0x08
210 #define TOUCHPAD2_SWITCH_XY_AXIS 0x04
211 #define TOUCHPAD2_FLIP_Y 0x02
212 #define TOUCHPAD2_FLIP_X 0x01
213 
219 #define TOUCHPAD2_PROX_EVENT 0x80
220 #define TOUCHPAD2_TOUCH_EVENT 0x40
221 #define TOUCHPAD2_SNAP_EVENT 0x20
222 #define TOUCHPAD2_ALP_PROX_EVENT 0x10
223 #define TOUCHPAD2_REATI_EVENT 0x08
224 #define TOUCHPAD2_TP_EVENT 0x04
225 #define TOUCHPAD2_GESTURE_EVENT 0x02
226 #define TOUCHPAD2_EVENT_MODE 0x01
227 #define TOUCHPAD2_ALP_COUNT_FILTER 0x08
228 #define TOUCHPAD2_IIR_SELECT 0x04
229 #define TOUCHPAD2_MAV_FILTER 0x02
230 #define TOUCHPAD2_IIR_FILTER 0x01
231 
237 #define TOUCHPAD2_CHARGE_TYPE 0x80
238 #define TOUCHPAD2_RX_GROUP 0x40
239 #define TOUCHPAD2_PROX_REV 0x20
240 #define TOUCHPAD2_ALP_ENABLE 0x10
241 
247 #define TOUCHPAD2_RX7_TX2 0x80
248 #define TOUCHPAD2_RX6_TX3 0x40
249 #define TOUCHPAD2_RX5_TX4 0x20
250 #define TOUCHPAD2_RX4_TX5 0x10
251 #define TOUCHPAD2_RX3_TX6 0x08
252 #define TOUCHPAD2_RX2_TX7 0x04
253 #define TOUCHPAD2_RX1_TX8 0x02
254 #define TOUCHPAD2_RX0_TX9 0x01
255  // touchpad2_set
263 
278 #define TOUCHPAD2_PROXIMITY_STATUS 0x00
279 #define TOUCHPAD2_TOUCH_STATUS 0x01
280 #define TOUCHPAD2_SNAP_STATUS 0x02
281 
282  // sel_status
284 
294 #define TOUCHPAD2_ID_TAG_TOUCH_1 0x01
295 #define TOUCHPAD2_ID_TAG_TOUCH_2 0x02
296 #define TOUCHPAD2_ID_TAG_TOUCH_3 0x03
297 #define TOUCHPAD2_ID_TAG_TOUCH_4 0x04
298 #define TOUCHPAD2_ID_TAG_TOUCH_5 0x05
299 #define TOUCHPAD2_ID_TAG_HOVER_1 0x81
300 #define TOUCHPAD2_ID_TAG_HOVER_2 0x82
301 #define TOUCHPAD2_ID_TAG_HOVER_3 0x83
302 #define TOUCHPAD2_ID_TAG_HOVER_4 0x84
303 #define TOUCHPAD2_ID_TAG_HOVER_5 0x85
304 
305  // id_tag
307 
317 #define TOUCHPAD2_IQS525_PRODUCT_NUMBER 0x34
318 
319  // product_num
321 
336 #define TOUCHPAD2_MAP_MIKROBUS( cfg, mikrobus ) \
337  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
338  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
339  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
340  // touchpad2_map // touchpad2
343 
348 typedef struct
349 {
350  // Input pins
351 
352  digital_in_t int_pin;
354  // Modules
355 
356  i2c_master_t i2c;
358  // I2C slave address
359 
360  uint8_t slave_address;
362 } touchpad2_t;
363 
368 typedef struct
369 {
370  pin_name_t scl;
371  pin_name_t sda;
373  pin_name_t int_pin;
375  uint32_t i2c_speed;
376  uint8_t i2c_address;
379 
384 typedef struct
385 {
386  uint16_t product_num;
387  uint16_t projec_num;
388  float version;
389  uint16_t hw_id;
390  uint16_t hw_revision;
393 
398 typedef struct
399 {
400  uint8_t xy_info;
401  uint8_t no_of_fingers;
402  uint8_t id_tag;
403  uint16_t x_pos;
404  uint16_t y_pos;
405  uint16_t touch_str;
408 
413 typedef struct
414 {
415  uint8_t total_rx;
416  uint8_t total_tx;
417  uint8_t track_pad_rx;
418  uint8_t track_pad_tx;
419  uint8_t pm_setup;
420  uint16_t tx_config;
423 
428 typedef enum
429 {
431  TOUCHPAD2_ERROR = -1
432 
434 
453 
471 
488 
506 err_t touchpad2_generic_write ( touchpad2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
507 
525 err_t touchpad2_generic_read ( touchpad2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
526 
542 
557 
576 
594 
613 
634 err_t touchpad2_get_all_data ( touchpad2_t *ctx, uint8_t *rx_data );
635 
656 err_t touchpad2_get_status ( touchpad2_t *ctx, uint8_t sel_status, uint16_t *rx_data );
657 
658 #ifdef __cplusplus
659 }
660 #endif
661 #endif // TOUCHPAD2_H
662  // touchpad2
664 
665 // ------------------------------------------------------------------------ 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:360
ver_info
touchpad2_ver_info_t ver_info
Definition: main.c:31
TOUCHPAD2_OK
@ TOUCHPAD2_OK
Definition: touchpad2.h:430
touchpad2_touch_t::id_tag
uint8_t id_tag
Definition: touchpad2.h:402
touchpad2_touch_t::touch_str
uint16_t touch_str
Definition: touchpad2.h:405
touchpad2_cfg_t::int_pin
pin_name_t int_pin
Definition: touchpad2.h:373
touchpad2_ver_info_t::hw_revision
uint16_t hw_revision
Definition: touchpad2.h:390
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:376
touchpad2_channel_setup_t::tx_config
uint16_t tx_config
Definition: touchpad2.h:420
touchpad2_ver_info_t
TouchPad 2 device version information object.
Definition: touchpad2.h:385
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:356
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:399
touchpad2_channel_setup_t::total_tx
uint8_t total_tx
Definition: touchpad2.h:416
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:389
touchpad2_ver_info_t::version
float version
Definition: touchpad2.h:388
touchpad2_cfg_t
TouchPad 2 Click configuration object.
Definition: touchpad2.h:369
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:403
touchpad2_t::int_pin
digital_in_t int_pin
Definition: touchpad2.h:352
touchpad2_channel_setup_t
TouchPad Channel Setup object.
Definition: touchpad2.h:414
touchpad2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: touchpad2.h:375
touch_data
touchpad2_touch_t touch_data
Definition: main.c:32
touchpad2_channel_setup_t::pm_setup
uint8_t pm_setup
Definition: touchpad2.h:419
TOUCHPAD2_ERROR
@ TOUCHPAD2_ERROR
Definition: touchpad2.h:431
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:415
touchpad2_cfg_t::scl
pin_name_t scl
Definition: touchpad2.h:370
touchpad2_touch_t::y_pos
uint16_t y_pos
Definition: touchpad2.h:404
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:401
touchpad2_ver_info_t::projec_num
uint16_t projec_num
Definition: touchpad2.h:387
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:400
touchpad2_ver_info_t::product_num
uint16_t product_num
Definition: touchpad2.h:386
touchpad2_cfg_t::sda
pin_name_t sda
Definition: touchpad2.h:371
touchpad2_channel_setup_t::track_pad_tx
uint8_t track_pad_tx
Definition: touchpad2.h:418
touchpad2_return_value_t
touchpad2_return_value_t
TouchPad 2 Click return value data.
Definition: touchpad2.h:429
touchpad2_channel_setup_t::track_pad_rx
uint8_t track_pad_rx
Definition: touchpad2.h:417
touchpad2_t
TouchPad 2 Click context object.
Definition: touchpad2.h:349
touchpad2_wait_ready
void touchpad2_wait_ready(touchpad2_t *ctx)
TouchPad 2 wait ready function.