touchpad3 2.0.0.0
touchpad3.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 TOUCHPAD3_H
29#define TOUCHPAD3_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 TOUCHPAD3_GENERAL_INDEX_LOCATION 0x00
74
79#define TOUCHPAD3_GENERAL_RX_CH_ADD 0x01
80#define TOUCHPAD3_GENERAL_TX_CH_ADD 0x02
81#define TOUCHPAD3_GENERAL_RX_SC_L_ADD 0x04
82#define TOUCHPAD3_GENERAL_RX_SC_H_ADD 0x05
83#define TOUCHPAD3_GENERAL_TX_SC_L_ADD 0x06
84#define TOUCHPAD3_GENERAL_TX_SC_H_ADD 0x07
85
91#define TOUCHPAD3_GENERAL_RX_CH 0x05
92#define TOUCHPAD3_GENERAL_TX_CH 0x04
93#define TOUCHPAD3_GENERAL_RX_SC_L 0x33
94#define TOUCHPAD3_GENERAL_RX_SC_H 0x33
95#define TOUCHPAD3_GENERAL_TX_SC_L 0x00
96#define TOUCHPAD3_GENERAL_TX_SC_H 0x40
97
102#define TOUCHPAD3_DECODING_INDEX_LOCATION 0x30
103
108#define TOUCHPAD3_DEC_FLIP_STATE_ADD 0x00
109#define TOUCHPAD3_DEC_NUM_AVG_ADD 0x01
110#define TOUCHPAD3_DEC_MIN_TOUCH_DISTANCE_ADD 0x04
111
116#define TOUCHPAD3_DEC_FLIP_STATE 0x04
117#define TOUCHPAD3_DEC_NUM_AVG 0x08
118#define TOUCHPAD3_DEC_MIN_TOUCH_DISTANCE 0x01
119
120 // touchpad3_reg
121
136#define TOUCHPAD3_REG_WRITE 0x55, 0x04, 0x15
137
138#define TOUCHPAD3_RX_MAP_INDEX_ADD 0x01
139#define TOUCHPAD3_RX_CH1_ADD 0x00
140#define TOUCHPAD3_RX_CH2_ADD 0x01
141#define TOUCHPAD3_RX_CH3_ADD 0x02
142#define TOUCHPAD3_RX_CH4_ADD 0x03
143#define TOUCHPAD3_RX_CH5_ADD 0x04
144
149#define TOUCHPAD3_RX_CH1 0x08
150#define TOUCHPAD3_RX_CH2 0x07
151#define TOUCHPAD3_RX_CH3 0x06
152#define TOUCHPAD3_RX_CH4 0x05
153#define TOUCHPAD3_RX_CH5 0x04
154
159#define TOUCHPAD3_TX_MAP_INDEX_ADD 0x02
160#define TOUCHPAD3_TX_CH1_ADD 0x00
161#define TOUCHPAD3_TX_CH2_ADD 0x01
162#define TOUCHPAD3_TX_CH3_ADD 0x02
163#define TOUCHPAD3_TX_CH4_ADD 0x03
164
169#define TOUCHPAD3_TX_CH1 0x0D
170#define TOUCHPAD3_TX_CH2 0x06
171#define TOUCHPAD3_TX_CH3 0x03
172#define TOUCHPAD3_TX_CH4 0x02
173
178#define TOUCHPAD3_SET_COMMAND 0x55
179#define TOUCHPAD3_CMD_ENABLE_TOUCH 0x00
180#define TOUCHPAD3_CMD_DISABLE_TOUCH 0x01
181#define TOUCHPAD3_CMD_SCAN_BASELINE 0x14
182#define TOUCHPAD3_CMD_WRITE_REGISTER 0x15
183#define TOUCHPAD3_CMD_READ_REGISTER 0x16
184#define TOUCHPAD3_CMD_WRITE_NVRAM 0x17
185#define TOUCHPAD3_CMD_SOFTWARE_SLEEP 0x18
186#define TOUCHPAD3_CMD_ERASE_NVRAM 0x19
187#define TOUCHPAD3_CMD_MANUFACTURING_TEST 0x1A
188#define TOUCHPAD3_CMD_DEVICE_ID 0x83
189
194#define TOUCHPAD3_GENERAL_INDEX_BYTE 0x00
195#define TOUCHPAD3_SENSOR_MAP_RX_INDEX_BYTE 0x01
196#define TOUCHPAD3_SENSOR_MAP_TX_INDEX_BYTE 0x02
197#define TOUCHPAD3_SELF_INDEX_BYTE 0x10
198#define TOUCHPAD3_MUTUAL_INDEX_BYTE 0x20
199#define TOUCHPAD3_DECODING_INDEX_BYTE 0x30
200#define TOUCHPAD3_GESTURES_INDEX_BYTE 0x50
201#define TOUCHPAD3_CONFIGURATION_INDEX_BYTE 0xF0
202#define TOUCHPAD3_I_O_STATUS_INDEX_BYTE 0xF1
203
208#define TOUCHPAD3_GENERAL_OFFSET_BYTE_RX_CHANNELS 0x01
209#define TOUCHPAD3_GENERAL_OFFSET_BYTE_TX_CHANNELS 0x02
210#define TOUCHPAD3_GENERAL_OFFSET_BYTE_RX_SCALING_LSB 0x04
211#define TOUCHPAD3_GENERAL_OFFSET_BYTE_RX_SCALING_MSB 0x05
212#define TOUCHPAD3_GENERAL_OFFSET_BYTE_TX_SCALING_LSB 0x06
213#define TOUCHPAD3_GENERAL_OFFSET_BYTE_TX_SCALING_MSB 0x07
214
215
220#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_0 0x00
221#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_1 0x01
222#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_2 0x02
223#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_3 0x03
224#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_4 0x04
225#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_5 0x05
226#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_6 0x06
227#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_7 0x07
228#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_8 0x08
229#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_9 0x09
230#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_10 0x0A
231#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_11 0x0B
232#define TOUCHPAD3_SENSOR_MAP_RX_OFFSET_BYTE_RX_PIN_MAP_12 0x0C
233
238#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_0 0x00
239#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_1 0x01
240#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_2 0x02
241#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_3 0x03
242#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_4 0x04
243#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_5 0x05
244#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_6 0x06
245#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_7 0x07
246#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_8 0x08
247#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_9 0x09
248#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_10 0x0A
249#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_11 0x0B
250#define TOUCHPAD3_SENSOR_MAP_TX_OFFSET_BYTE_RX_PIN_MAP_12 0x0C
251
256#define TOUCHPAD3_SELF_OFFSET_BYTE_SELF_SCAN_TIME 0x00
257#define TOUCHPAD3_SELF_OFFSET_BYTE_SELF_THRESHOLD 0x01
258
263#define TOUCHPAD3_MUTUAL_OFFSET_BYTE_MUTUAL_SCAN_TIME 0x00
264#define TOUCHPAD3_MUTUAL_OFFSET_BYTE_MUTUAL_THRESHOLD 0x01
265
270#define TOUCHPAD3_DECODING_OFFSET_BYTE_FLIP_STATE 0x00
271#define TOUCHPAD3_DECODING_OFFSET_BYTE_NUMBER_OF_AVG 0x01
272#define TOUCHPAD3_DECODING_OFFSET_BYTE_MIN_TOUCH_DIST 0x04
273#define TOUCHPAD3_DECODING_OFFSET_BYTE_PEN_DOWN_TIMER 0x05
274#define TOUCHPAD3_DECODING_OFFSET_BYTE_PEN_UP_TIMER 0x06
275#define TOUCHPAD3_DECODING_OFFSET_BYTE_TOUCH_SUPPR_VALUE 0x07
276
281#define TOUCHPAD3_GESTURES_OFFSET_BYTE_RX_SWIPE_LEN 0x00
282#define TOUCHPAD3_GESTURES_OFFSET_BYTE_TX_SWIPE_LEN 0x01
283#define TOUCHPAD3_GESTURES_OFFSET_BYTE_SWIPE_BOUNDARY 0x02
284#define TOUCHPAD3_GESTURES_OFFSET_BYTE_SWIPE_HOLD_THD 0x03
285#define TOUCHPAD3_GESTURES_OFFSET_BYTE_SWIPE_TIME_LSB 0x04
286#define TOUCHPAD3_GESTURES_OFFSET_BYTE_SWIPE_TIME_MSB 0x05
287#define TOUCHPAD3_GESTURES_OFFSET_BYTE_TAP_TIME_LSB 0x06
288#define TOUCHPAD3_GESTURES_OFFSET_BYTE_TAP_TIME_MSB 0x07
289#define TOUCHPAD3_GESTURES_OFFSET_BYTE_TAP_THD 0x08
290#define TOUCHPAD3_GESTURES_OFFSET_BYTE_MIN_SWIPE_VELOCITY 0x09
291#define TOUCHPAD3_GESTURES_OFFSET_BYTE_DOUBLE_TAP_TIME_LSB 0x0A
292#define TOUCHPAD3_GESTURES_OFFSET_BYTE_DOUBLE_TAP_TIME_MSB 0x0B
293#define TOUCHPAD3_GESTURES_OFFSET_BYTE_GESTURE_EDGE_KEEP_OUT 0x0C
294
299#define TOUCHPAD3_CONFIG_OFFSET_BYTE_SLP_LSW_LSB 0x00
300#define TOUCHPAD3_CONFIG_OFFSET_BYTE_SLP_LSW_MSB 0x01
301#define TOUCHPAD3_CONFIG_OFFSET_BYTE_SLP_MSW_LSB 0x02
302#define TOUCHPAD3_CONFIG_OFFSET_BYTE_SLP_MSW_MSB 0x03
303#define TOUCHPAD3_CONFIG_OFFSET_BYTE_TOUCH_PCK_CFG 0x07
304#define TOUCHPAD3_CONFIG_OFFSET_BYTE_GESTURE_PCK_CFG 0x09
305#define TOUCHPAD3_CONFIG_OFFSET_BYTE_STATUS_PCK_CFG 0x0A
306
311#define TOUCHPAD3_IOSTATUS_OFFSET_BYTE_TX_SHORT_STATUS_LSB 0x02
312#define TOUCHPAD3_IOSTATUS_OFFSET_BYTE_TX_SHORT_STATUS_MSB 0x03
313#define TOUCHPAD3_IOSTATUS_OFFSET_BYTE_RX_SHORT_STATUS_LSB 0x06
314#define TOUCHPAD3_IOSTATUS_OFFSET_BYTE_RX_SHORT_STATUS_MSB 0x07
315
320#define TOUCHPAD3_CONFIG_TOUCH_GESTURE_PCK_DISABLE 0x01
321#define TOUCHPAD3_CONFIG_TOUCH_GESTURE_PCK_ENABLE 0x81
322
327#define TOUCHPAD3_TOUCH_GESTURE_DISABLE 0x00
328#define TOUCHPAD3_TOUCH_GESTURE_ENABLE 0x01
329
334#define TOUCHPAD3_GESTURE_SINGLE_TAP 0x10
335#define TOUCHPAD3_GESTURE_SINGLE_TAP_HOLD 0x11
336#define TOUCHPAD3_GESTURE_DOUBLE_TAP 0x20
337#define TOUCHPAD3_GESTURE_UP_SWIPE 0x31
338#define TOUCHPAD3_GESTURE_UP_SWIPE_HOLD 0x32
339#define TOUCHPAD3_GESTURE_RIGHT_SWIPE 0x41
340#define TOUCHPAD3_GESTURE_RIGHT_SWIPE_HOLD 0x42
341#define TOUCHPAD3_GESTURE_DOWN_SWIPE 0x51
342#define TOUCHPAD3_GESTURE_DOWN_SWIPE_HOLD 0x52
343#define TOUCHPAD3_GESTURE_LEFT_SWIPE 0x61
344#define TOUCHPAD3_GESTURE_LEFT_SWIPE_HOLD 0x62
345
350#define TOUCHPAD3_CMD_STATUS_SUCCESS 0x00
351#define TOUCHPAD3_CMD_STATUS_PARAM_OUT_OF_RANGE 0x80
352#define TOUCHPAD3_CMD_STATUS_TIMEOUT 0xFE
353#define TOUCHPAD3_CMD_STATUS_UNRECOGNIZED 0xFF
354#define TOUCHPAD3_CMD_STATUS_INVALID_PARAM 0xFD
355#define TOUCHPAD3_CMD_STATUS_MISSING_OR_EXTRA_PARAM 0xFC
356
361#define TOUCHPAD3_T_AND_G_ID_BIT_MASK 0x0F
362#define TOUCHPAD3_TCH_STATE_BIT_MASK 0x01
363#define TOUCHPAD3_PEN_STATE_BIT_MASK 0x01
364#define TOUCHPAD3_5_BIT_MASK 0x1F
365
370#define TOUCHPAD3_INT_STATUS_LOW 0x00
371#define TOUCHPAD3_INT_STATUS_HIGH 0x01
372
377#define TOUCHPAD3_STATUS_ERROR 0x00
378#define TOUCHPAD3_STATUS_SUCCESS 0x01
379
384#define TOUCHPAD3_STATE_TCH 0x00
385#define TOUCHPAD3_STATE_GST 0x01
386#define TOUCHPAD3_LEN_TCH 0x05
387#define TOUCHPAD3_LEN_GST 0x02
388
394#define TOUCHPAD3_SET_DEV_ADDR 0x25
395
396 // touchpad3_set
397
412#define TOUCHPAD3_MAP_MIKROBUS( cfg, mikrobus ) \
413 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
414 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
415 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
416 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
417
418 // touchpad3_map
419 // touchpad3
420
425typedef struct
426{
427 // Output pins
428 digital_out_t rst;
430 // Input pins
431 digital_in_t int_pin;
433 // Modules
434 i2c_master_t i2c;
436 // I2C slave address
440
445typedef struct
446{
447 pin_name_t scl;
448 pin_name_t sda;
450 pin_name_t rst;
451 pin_name_t int_pin;
453 uint32_t i2c_speed;
454 uint8_t i2c_address;
457
458typedef struct
459{
460 uint8_t touch_id;
461 uint8_t tch_state;
462 uint8_t pen_state;
464
465typedef struct
466{
467 uint8_t cmd;
468 uint8_t n_tx_bytes;
469 uint8_t n_rx_bytes;
471
482
499
515
530
542
555
570void touchpad3_generic_write ( touchpad3_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
571
587err_t touchpad3_generic_read ( touchpad3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
588
601
614
627
643uint8_t touchpad3_get_touch ( touchpad3_t *ctx, touch_data_t *tch_data,uint16_t *x_axis, uint16_t *y_axis );
644
659uint8_t touchpad3_get_gesture ( touchpad3_t *ctx, touch_data_t *gst_data, uint8_t *gesture );
660
680uint8_t touchpad3_cmd_protocol ( touchpad3_t *ctx, cmd_protocol_t cmd_data, uint8_t *p_tx_data, uint8_t *p_rx_data );
681
702uint8_t touchpad3_write_reg ( touchpad3_t *ctx, uint8_t index_loc, uint8_t offset_loc, uint8_t tx_data, uint8_t
703*p_response );
704
725uint8_t touchpad3_read_reg ( touchpad3_t *ctx, uint8_t index_loc, uint8_t offset_loc, uint8_t *read_data, uint8_t *p_response );
726
740
751
763uint8_t touchpad3_config_touch ( touchpad3_t *ctx, uint8_t en_touch );
764
776uint8_t touchpad3_config_gesture ( touchpad3_t *ctx, uint8_t en_gesture );
777
778#ifdef __cplusplus
779}
780#endif
781#endif // TOUCHPAD3_H
782
783 // touchpad3
784
785// ------------------------------------------------------------------------ END
uint8_t touchpad3_get_touch(touchpad3_t *ctx, touch_data_t *tch_data, uint16_t *x_axis, uint16_t *y_axis)
Touchpad 3 get touch data function.
uint8_t touchpad3_write_reg(touchpad3_t *ctx, uint8_t index_loc, uint8_t offset_loc, uint8_t tx_data, uint8_t *p_response)
Touchpad 3 write register data function.
void touchpad3_sensor_mapping_configuration(touchpad3_t *ctx)
Touchpad 3 sensor mapping configuration function.
uint8_t touchpad3_read_reg(touchpad3_t *ctx, uint8_t index_loc, uint8_t offset_loc, uint8_t *read_data, uint8_t *p_response)
Touchpad 3 read register data function.
err_t touchpad3_init(touchpad3_t *ctx, touchpad3_cfg_t *cfg)
Touchpad 3 initialization function.
uint32_t touchpad3_get_device_id(touchpad3_t *ctx)
Touchpad 3 get device id function.
void touchpad3_decoding_configuration(touchpad3_t *ctx)
Touchpad 3 decoding configuration function.
void touchpad3_hw_reset(touchpad3_t *ctx)
Touchpad 3 hardware reset function.
uint8_t touchpad3_cmd_protocol(touchpad3_t *ctx, cmd_protocol_t cmd_data, uint8_t *p_tx_data, uint8_t *p_rx_data)
Touchpad 3 command protocol function.
uint8_t touchpad3_get_gesture(touchpad3_t *ctx, touch_data_t *gst_data, uint8_t *gesture)
Touchpad 3 get gesture data function.
void touchpad3_cfg_setup(touchpad3_cfg_t *cfg)
Touchpad 3 configuration object setup function.
err_t touchpad3_generic_read(touchpad3_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Touchpad 3 I2C reading function.
uint8_t touchpad3_config_touch(touchpad3_t *ctx, uint8_t en_touch)
Touchpad 3 configure touch function.
uint8_t touchpad3_manufacturing_test(touchpad3_t *ctx)
Touchpad 3 manufacturing test function.
void touchpad3_generic_write(touchpad3_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
Touchpad 3 I2C writing function.
err_t touchpad3_default_cfg(touchpad3_t *ctx)
Touchpad 3 default configuration function.
uint8_t touchpad3_config_gesture(touchpad3_t *ctx, uint8_t en_gesture)
Touchpad 3 configure gesture function.
uint8_t touchpad3_get_int(touchpad3_t *ctx)
Touchpad 3 get interrupt function..
void touchpad3_general_configuration(touchpad3_t *ctx)
Touchpad 3 general configuration function.
uint16_t x_axis
Definition main.c:31
uint16_t y_axis
Definition main.c:32
Definition touchpad3.h:466
uint8_t n_tx_bytes
Definition touchpad3.h:468
uint8_t cmd
Definition touchpad3.h:467
uint8_t n_rx_bytes
Definition touchpad3.h:469
Definition touchpad3.h:459
uint8_t tch_state
Definition touchpad3.h:461
uint8_t touch_id
Definition touchpad3.h:460
uint8_t pen_state
Definition touchpad3.h:462
Touchpad 3 Click configuration object.
Definition touchpad3.h:446
uint32_t i2c_speed
Definition touchpad3.h:453
pin_name_t scl
Definition touchpad3.h:447
pin_name_t int_pin
Definition touchpad3.h:451
pin_name_t sda
Definition touchpad3.h:448
pin_name_t rst
Definition touchpad3.h:450
uint8_t i2c_address
Definition touchpad3.h:454
Touchpad 3 Click context object.
Definition touchpad3.h:426
digital_in_t int_pin
Definition touchpad3.h:431
i2c_master_t i2c
Definition touchpad3.h:434
digital_out_t rst
Definition touchpad3.h:428
uint8_t slave_address
Definition touchpad3.h:437
touchpad3_return_value_t
Touchpad 3 Click return value data.
Definition touchpad3.h:477
@ TOUCHPAD3_OK
Definition touchpad3.h:478
@ TOUCHPAD3_ERROR
Definition touchpad3.h:479