captouch2  2.0.0.0
captouch2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef CAPTOUCH2_H
36 #define CAPTOUCH2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define CAPTOUCH2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
59  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT );
60 
66 #define CAPTOUCH2_RETVAL uint8_t
67 
68 #define CAPTOUCH2_OK 0x00
69 #define CAPTOUCH2_INIT_ERROR 0xFF
70 
76 #define CAPTOUCH2_MAIN_CONTROL_REG 0x00
77 #define CAPTOUCH2_GEN_STATUS_REG 0x02
78 #define CAPTOUCH2_SENS_IN_STATUS_REG 0x03
79 #define CAPTOUCH2_NOISE_FLAG_REG 0x0A
80 #define CAPTOUCH2_SENS_IN1_DELTA_CNT_REG 0x10
81 #define CAPTOUCH2_SENS_IN2_DELTA_CNT_REG 0x11
82 #define CAPTOUCH2_SENS_IN3_DELTA_CNT_REG 0x12
83 #define CAPTOUCH2_SENS_IN4_DELTA_CNT_REG 0x13
84 #define CAPTOUCH2_SENS_IN5_DELTA_CNT_REG 0x14
85 #define CAPTOUCH2_SENS_IN6_DELTA_CNT_REG 0x15
86 #define CAPTOUCH2_SENSITIVITY_CON_REG 0x1F
87 #define CAPTOUCH2_CONFIG_REG 0x20
88 #define CAPTOUCH2_SENS_IN_EN_REG 0x21
89 #define CAPTOUCH2_SENS_IN_CONFIG_REG 0x22
90 #define CAPTOUCH2_SENS_IN_CONFIG2_REG 0x23
91 #define CAPTOUCH2_AVRG_AND_SAMPL_CONFIG_REG 0x24
92 #define CAPTOUCH2_CALIB_ACTIVATE_REG 0x26
93 #define CAPTOUCH2_INTERR_EN_REG 0x27
94 #define CAPTOUCH2_REPEAT_RATE_EN_REG 0x28
95 #define CAPTOUCH2_MULTIPLE_TOUCH_CONFIG_REG 0x2A
96 #define CAPTOUCH2_MULTIPLE_TOUCH_PATTERN_CONFIG_REG 0x2B
97 #define CAPTOUCH2_MULTIPLE_TOUCH_PATTERN_REG 0x2D
98 #define CAPTOUCH2_RECALIB_CONFIG_REG 0x2F
99 #define CAPTOUCH2_SENS_IN1_THRESHOLD_REG 0x30
100 #define CAPTOUCH2_SENS_IN2_THRESHOLD_REG 0x31
101 #define CAPTOUCH2_SENS_IN3_THRESHOLD_REG 0x32
102 #define CAPTOUCH2_SENS_IN4_THRESHOLD_REG 0x33
103 #define CAPTOUCH2_SENS_IN5_THRESHOLD_REG 0x34
104 #define CAPTOUCH2_SENS_IN6_THRESHOLD_REG 0x35
105 #define CAPTOUCH2_SENS_IN_NOISE_THRESHOLD_REG 0x38
106 #define CAPTOUCH2_STANDBY_CHANN_REG 0x40
107 #define CAPTOUCH2_STANDBY_CONFIG_REG 0x41
108 #define CAPTOUCH2_STANDBY_SENSITIVITY_REG 0x42
109 #define CAPTOUCH2_STANDBY_THRESHOLD_REG 0x43
110 #define CAPTOUCH2_CONFIG2_REG 0x44
111 #define CAPTOUCH2_SENS_IN1_BASE_CNT_REG 0x50
112 #define CAPTOUCH2_SENS_IN2_BASE_CNT_REG 0x51
113 #define CAPTOUCH2_SENS_IN3_BASE_CNT_REG 0x52
114 #define CAPTOUCH2_SENS_IN4_BASE_CNT_REG 0x53
115 #define CAPTOUCH2_SENS_IN5_BASE_CNT_REG 0x54
116 #define CAPTOUCH2_SENS_IN6_BASE_CNT_REG 0x55
117 #define CAPTOUCH2_LED_OUTPUT_TYPE_REG 0x71
118 #define CAPTOUCH2_SENS_IN_LED_LINK_REG 0x72
119 #define CAPTOUCH2_LED_POLARITY_REG 0x73
120 #define CAPTOUCH2_LED_OUT_CON_REG 0x74
121 #define CAPTOUCH2_LED_LINK_TRANS_CON_REG 0x77
122 #define CAPTOUCH2_LED_MIRROR_CON_REG 0x79
123 #define CAPTOUCH2_LED_BEHAVIOR1_REG 0x81
124 #define CAPTOUCH2_LED_BEHAVIOR2_REG 0x82
125 #define CAPTOUCH2_LED_PULSE1_PERIOD_REG 0x84
126 #define CAPTOUCH2_LED_PULSE2_PERIOD_REG 0x85
127 #define CAPTOUCH2_LED_BREATHE_PERIOD_REG 0x86
128 #define CAPTOUCH2_LED_CONFIG_REG 0x88
129 #define CAPTOUCH2_LED_PULSE1_DUTY_REG 0x90
130 #define CAPTOUCH2_LED_PULSE2_DUTY_REG 0x91
131 #define CAPTOUCH2_LED_BREATHE_DUTY_REG 0x92
132 #define CAPTOUCH2_LED_DIRECT_DUTY_REG 0x93
133 #define CAPTOUCH2_LED_DIRECT_RAMP_RATES_REG 0x94
134 #define CAPTOUCH2_LED_OFF_DELAY_REG 0x95
135 #define CAPTOUCH2_SENS_IN1_CALIB_REG 0xB1
136 #define CAPTOUCH2_SENS_IN2_CALIB_REG 0xB2
137 #define CAPTOUCH2_SENS_IN3_CALIB_REG 0xB3
138 #define CAPTOUCH2_SENS_IN4_CALIB_REG 0xB4
139 #define CAPTOUCH2_SENS_IN5_CALIB_REG 0xB5
140 #define CAPTOUCH2_SENS_IN6_CALIB_REG 0xB6
141 #define CAPTOUCH2_SENS_IN_CALIB_LSB1_REG 0xB9
142 #define CAPTOUCH2_SENS_IN_CALIB_LSB2_REG 0xBA
143 #define CAPTOUCH2_PRODUCT_ID_REG 0xFD
144 #define CAPTOUCH2_MANUFACT_ID_REG 0xFE
145 #define CAPTOUCH2_REVISION_REG 0xFF
146 
152 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_128X 0x00
153 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_64X 0x10
154 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_32X 0x20
155 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_16X 0x30
156 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_8X 0x40
157 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_4X 0x50
158 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_2X 0x60
159 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_1X 0x70
160 #define CAPTOUCH2_DATA_SCALING_FACTOR_1X 0x00
161 #define CAPTOUCH2_DATA_SCALING_FACTOR_2X 0x01
162 #define CAPTOUCH2_DATA_SCALING_FACTOR_4X 0x02
163 #define CAPTOUCH2_DATA_SCALING_FACTOR_8X 0x03
164 #define CAPTOUCH2_DATA_SCALING_FACTOR_16X 0x04
165 #define CAPTOUCH2_DATA_SCALING_FACTOR_32X 0x05
166 #define CAPTOUCH2_DATA_SCALING_FACTOR_64X 0x06
167 #define CAPTOUCH2_DATA_SCALING_FACTOR_128X 0x07
168 #define CAPTOUCH2_DATA_SCALING_FACTOR_256X 0x08
169 
175 #define CAPTOUCH2_TIMEOUT_DIS 0x00
176 #define CAPTOUCH2_TIMEOUT_EN 0x80
177 #define CAPTOUCH2_WAKE_PIN_NOT_ASSERTED 0x00
178 #define CAPTOUCH2_WAKE_PIN_ASSERTED 0x40
179 #define CAPTOUCH2_DIG_NOISE_THRESHOLD_EN 0x00
180 #define CAPTOUCH2_DIG_NOISE_THRESHOLD_DIS 0x20
181 #define CAPTOUCH2_AN_NOISE_FILTER_EN 0x00
182 #define CAPTOUCH2_AN_NOISE_FILTER_DIS 0x10
183 #define CAPTOUCH2_MAX_DUR_RECALIB_DIS 0x00
184 #define CAPTOUCH2_MAX_DUR_RECALIB_EN 0x08
185 
191 #define CAPTOUCH2_NOT_INVERT_TOUCH_SIGNAL 0x00
192 #define CAPTOUCH2_INVERT_TOUCH_SIGNAL 0x80
193 #define CAPTOUCH2_ALERT_ACTIVE_HIGH 0x00
194 #define CAPTOUCH2_ALERT_ACTIVE_LOW 0x40
195 #define CAPTOUCH2_POWER_CONSUMPTION_REDUCE_EN 0x00
196 #define CAPTOUCH2_POWER_CONSUMPTION_REDUCE_DIS 0x20
197 #define CAPTOUCH2_AUTOSET_LED_MIRROR_CON 0x00
198 #define CAPTOUCH2_NOT_AUTOSET_LED_MIRROR_CON 0x10
199 #define CAPTOUCH2_SHOW_LOW_FREQ_NOISE 0x00
200 #define CAPTOUCH2_NOT_SHOW_LOW_FREQ_NOISE 0x08
201 #define CAPTOUCH2_RF_NOISE_FILTER_EN 0x00
202 #define CAPTOUCH2_RF_NOISE_FILTER_DIS 0x04
203 #define CAPTOUCH2_AN_CALIB_FAIL_INTERR_DIS 0x00
204 #define CAPTOUCH2_AN_CALIB_FAIL_INTERR_EN 0x02
205 #define CAPTOUCH2_DETECT_RELEASE_EN 0x00
206 #define CAPTOUCH2_DETECT_RELEASE_DIS 0x01
207 
213 #define CAPTOUCH2_560MILISEC_BEFORE_RECALIB 0x00
214 #define CAPTOUCH2_840MILISEC_BEFORE_RECALIB 0x10
215 #define CAPTOUCH2_1120MILISEC_BEFORE_RECALIB 0x20
216 #define CAPTOUCH2_1400MILISEC_BEFORE_RECALIB 0x30
217 #define CAPTOUCH2_1680MILISEC_BEFORE_RECALIB 0x40
218 #define CAPTOUCH2_2240MILISEC_BEFORE_RECALIB 0x50
219 #define CAPTOUCH2_2800MILISEC_BEFORE_RECALIB 0x60
220 #define CAPTOUCH2_3360MILISEC_BEFORE_RECALIB 0x70
221 #define CAPTOUCH2_3920MILISEC_BEFORE_RECALIB 0x80
222 #define CAPTOUCH2_4480MILISEC_BEFORE_RECALIB 0x90
223 #define CAPTOUCH2_5600MILISEC_BEFORE_RECALIB 0xA0
224 #define CAPTOUCH2_6720MILISEC_BEFORE_RECALIB 0xB0
225 #define CAPTOUCH2_7840MILISEC_BEFORE_RECALIB 0xC0
226 #define CAPTOUCH2_8906MILISEC_BEFORE_RECALIB 0xD0
227 #define CAPTOUCH2_10080MILISEC_BEFORE_RECALIB 0xE0
228 #define CAPTOUCH2_11200MILISEC_BEFORE_RECALIB 0xF0
229 #define CAPTOUCH2_INTERR_REPEAT_RATE_35MILISEC 0x00
230 #define CAPTOUCH2_INTERR_REPEAT_RATE_70MILISEC 0x01
231 #define CAPTOUCH2_INTERR_REPEAT_RATE_105MILISEC 0x02
232 #define CAPTOUCH2_INTERR_REPEAT_RATE_140MILISEC 0x03
233 #define CAPTOUCH2_INTERR_REPEAT_RATE_175MILISEC 0x04
234 #define CAPTOUCH2_INTERR_REPEAT_RATE_210MILISEC 0x05
235 #define CAPTOUCH2_INTERR_REPEAT_RATE_245MILISEC 0x06
236 #define CAPTOUCH2_INTERR_REPEAT_RATE_280MILISEC 0x07
237 #define CAPTOUCH2_INTERR_REPEAT_RATE_315MILISEC 0x08
238 #define CAPTOUCH2_INTERR_REPEAT_RATE_350MILISEC 0x09
239 #define CAPTOUCH2_INTERR_REPEAT_RATE_385MILISEC 0x0A
240 #define CAPTOUCH2_INTERR_REPEAT_RATE_420MILISEC 0x0B
241 #define CAPTOUCH2_INTERR_REPEAT_RATE_455MILISEC 0x0C
242 #define CAPTOUCH2_INTERR_REPEAT_RATE_490MILISEC 0x0D
243 #define CAPTOUCH2_INTERR_REPEAT_RATE_525MILISEC 0x0E
244 #define CAPTOUCH2_INTERR_REPEAT_RATE_560MILISEC 0x0F
245 
251 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_35MILISEC 0x00
252 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_70MILISEC 0x01
253 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_105MILISEC 0x02
254 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_140MILISEC 0x03
255 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_175MILISEC 0x04
256 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_210MILISEC 0x05
257 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_245MILISEC 0x06
258 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_280MILISEC 0x07
259 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_315MILISEC 0x08
260 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_350MILISEC 0x09
261 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_385MILISEC 0x0A
262 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_420MILISEC 0x0B
263 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_455MILISEC 0x0C
264 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_490MILISEC 0x0D
265 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_525MILISEC 0x0E
266 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_560MILISEC 0x0F
267 
273 #define CAPTOUCH2_1_SAMPLE 0x00
274 #define CAPTOUCH2_2_SAMPLES 0x10
275 #define CAPTOUCH2_4_SAMPLES 0x20
276 #define CAPTOUCH2_8_SAMPLES 0x30
277 #define CAPTOUCH2_16_SAMPLES 0x40
278 #define CAPTOUCH2_32_SAMPLES 0x50
279 #define CAPTOUCH2_64_SAMPLES 0x60
280 #define CAPTOUCH2_128_SAMPLES 0x70
281 #define CAPTOUCH2_SAMPLE_TIME_320MICROSEC 0x00
282 #define CAPTOUCH2_SAMPLE_TIME_640MICROSEC 0x04
283 #define CAPTOUCH2_SAMPLE_TIME_1280MICROSEC 0x08
284 #define CAPTOUCH2_SAMPLE_TIME_2560MICROSEC 0x0C
285 #define CAPTOUCH2_CYCLE_TIME_35MILISEC 0x00
286 #define CAPTOUCH2_CYCLE_TIME_70MILISEC 0x01
287 #define CAPTOUCH2_CYCLE_TIME_105MILISEC 0x02
288 #define CAPTOUCH2_CYCLE_TIME_140MILISEC 0x03
289 
295 #define CAPTOUCH2_ALL_INPUTS_CALIB_DIS 0x00
296 #define CAPTOUCH2_INPUT1_CALIB_EN 0x01
297 #define CAPTOUCH2_INPUT2_CALIB_EN 0x02
298 #define CAPTOUCH2_INPUT3_CALIB_EN 0x04
299 #define CAPTOUCH2_INPUT4_CALIB_EN 0x08
300 #define CAPTOUCH2_INPUT5_CALIB_EN 0x10
301 #define CAPTOUCH2_INPUT6_CALIB_EN 0x20
302 
308 #define CAPTOUCH2_ALL_INPUTS_INTERR_DIS 0x00
309 #define CAPTOUCH2_INPUT1_INTERR_EN 0x01
310 #define CAPTOUCH2_INPUT2_INTERR_EN 0x02
311 #define CAPTOUCH2_INPUT3_INTERR_EN 0x04
312 #define CAPTOUCH2_INPUT4_INTERR_EN 0x08
313 #define CAPTOUCH2_INPUT5_INTERR_EN 0x10
314 #define CAPTOUCH2_INPUT6_INTERR_EN 0x20
315 
321 #define CAPTOUCH2_REPEAT_RATE_DIS 0x00
322 #define CAPTOUCH2_INPUT1_REPEAT_RATE_EN 0x01
323 #define CAPTOUCH2_INPUT2_REPEAT_RATE_EN 0x02
324 #define CAPTOUCH2_INPUT3_REPEAT_RATE_EN 0x04
325 #define CAPTOUCH2_INPUT4_REPEAT_RATE_EN 0x08
326 #define CAPTOUCH2_INPUT5_REPEAT_RATE_EN 0x10
327 #define CAPTOUCH2_INPUT6_REPEAT_RATE_EN 0x20
328 
334 #define CAPTOUCH2_MULTIPLE_BLOCK_DIS 0x00
335 #define CAPTOUCH2_MULTIPLE_BLOCK_EN 0x80
336 #define CAPTOUCH2_SIMUL_TOUCH_NUM_1 0x00
337 #define CAPTOUCH2_SIMUL_TOUCH_NUM_2 0x04
338 #define CAPTOUCH2_SIMUL_TOUCH_NUM_3 0x08
339 #define CAPTOUCH2_SIMUL_TOUCH_NUM_4 0x0C
340 
346 #define CAPTOUCH2_MULTIPLE_THRESHOLD_12_PERCENTS 0x00
347 #define CAPTOUCH2_MULTIPLE_THRESHOLD_25_PERCENTS 0x04
348 #define CAPTOUCH2_MULTIPLE_THRESHOLD_37_PERCENTS 0x08
349 #define CAPTOUCH2_MULTIPLE_THRESHOLD_100_PERCENTS 0x0C
350 #define CAPTOUCH2_MLTP_TOUCH_PATTERN 0x00
351 #define CAPTOUCH2_PATTERN_RECOGNITION 0x02
352 #define CAPTOUCH2_MLTP_EVENT_ALERT_DIS 0x00
353 #define CAPTOUCH2_MLTP_EVENT_ALERT_EN 0x01
354 
360 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUTS_DIS 0x00
361 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT1_EN 0x01
362 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT2_EN 0x02
363 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT3_EN 0x04
364 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT4_EN 0x08
365 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT5_EN 0x10
366 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT6_EN 0x20
367 
373 #define CAPTOUCH2_INPUTS_THRESHOLD_UPDT_INDIVIDUALY 0x00
374 #define CAPTOUCH2_INPUT1_THRESHOLD_OVERWRITE 0x80
375 #define CAPTOUCH2_ACC_INTER_DATA_CLEAR 0x00
376 #define CAPTOUCH2_ACC_INTER_DATA_NOT_CLEAR 0x40
377 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_CLEAR 0x00
378 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_NOT_CLEAR 0x20
379 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_8 0x00
380 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_16 0x08
381 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_32 0x10
382 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_DIS 0x18
383 #define CAPTOUCH2_REC_SAMPLES_16_UPDT_TIME_16 0x00
384 #define CAPTOUCH2_REC_SAMPLES_32_UPDT_TIME_32 0x01
385 #define CAPTOUCH2_REC_SAMPLES_64_UPDT_TIME_64 0x02
386 #define CAPTOUCH2_REC_SAMPLES_128_UPDT_TIME_128 0x03
387 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_256 0x04
388 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_1024 0x05
389 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_2048 0x06
390 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_4096 0x07
391 
397 #define CAPTOUCH2_AVERAGE_BASED 0x00
398 #define CAPTOUCH2_SUMMATION_BASED 0x80
399 
405 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_128X 0x00
406 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_64X 0x01
407 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_32X 0x02
408 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_16X 0x03
409 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_8X 0x04
410 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_4X 0x05
411 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_2X 0x06
412 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_1X 0x07
413 
419 #define CAPTOUCH2_LED6_PIN_OPEN_DRAIN 0x00
420 #define CAPTOUCH2_LED6_PIN_PUSH_PULL 0x20
421 #define CAPTOUCH2_LED5_PIN_OPEN_DRAIN 0x00
422 #define CAPTOUCH2_LED5_PIN_PUSH_PULL 0x10
423 #define CAPTOUCH2_LED4_PIN_OPEN_DRAIN 0x00
424 #define CAPTOUCH2_LED4_PIN_PUSH_PULL 0x08
425 #define CAPTOUCH2_LED3_PIN_OPEN_DRAIN 0x00
426 #define CAPTOUCH2_LED3_PIN_PUSH_PULL 0x04
427 #define CAPTOUCH2_LED2_PIN_OPEN_DRAIN 0x00
428 #define CAPTOUCH2_LED2_PIN_PUSH_PULL 0x02
429 #define CAPTOUCH2_LED1_PIN_OPEN_DRAIN 0x00
430 #define CAPTOUCH2_LED1_PIN_PUSH_PULL 0x01
431 
437 #define CAPTOUCH2_LED6_IN6_NOT_LINKED 0x00
438 #define CAPTOUCH2_LED6_IN6_LINKED 0x20
439 #define CAPTOUCH2_LED5_IN5_NOT_LINKED 0x00
440 #define CAPTOUCH2_LED5_IN5_LINKED 0x10
441 #define CAPTOUCH2_LED4_IN4_NOT_LINKED 0x00
442 #define CAPTOUCH2_LED4_IN4_LINKED 0x08
443 #define CAPTOUCH2_LED3_IN3_NOT_LINKED 0x00
444 #define CAPTOUCH2_LED3_IN3_LINKED 0x04
445 #define CAPTOUCH2_LED2_IN2_NOT_LINKED 0x00
446 #define CAPTOUCH2_LED2_IN2_LINKED 0x02
447 #define CAPTOUCH2_LED1_IN1_NOT_LINKED 0x00
448 #define CAPTOUCH2_LED1_IN1_LINKED 0x01
449 
455 #define CAPTOUCH2_LED6_OUT_INVERTED 0x00
456 #define CAPTOUCH2_LED6_OUT_NOT_INVERTED 0x20
457 #define CAPTOUCH2_LED5_OUT_INVERTED 0x00
458 #define CAPTOUCH2_LED5_OUT_NOT_INVERTED 0x10
459 #define CAPTOUCH2_LED4_OUT_INVERTED 0x00
460 #define CAPTOUCH2_LED4_OUT_NOT_INVERTED 0x08
461 #define CAPTOUCH2_LED3_OUT_INVERTED 0x00
462 #define CAPTOUCH2_LED3_OUT_NOT_INVERTED 0x04
463 #define CAPTOUCH2_LED2_OUT_INVERTED 0x00
464 #define CAPTOUCH2_LED2_OUT_NOT_INVERTED 0x02
465 #define CAPTOUCH2_LED1_OUT_INVERTED 0x00
466 #define CAPTOUCH2_LED1_OUT_NOT_INVERTED 0x01
467 
473 #define CAPTOUCH2_LED6_DRIVEN_TO_MIN_DUTY 0x00
474 #define CAPTOUCH2_LED6_DRIVEN_TO_MAX_DUTY 0x20
475 #define CAPTOUCH2_LED5_DRIVEN_TO_MIN_DUTY 0x00
476 #define CAPTOUCH2_LED5_DRIVEN_TO_MAX_DUTY 0x10
477 #define CAPTOUCH2_LED4_DRIVEN_TO_MIN_DUTY 0x00
478 #define CAPTOUCH2_LED4_DRIVEN_TO_MAX_DUTY 0x08
479 #define CAPTOUCH2_LED3_DRIVEN_TO_MIN_DUTY 0x00
480 #define CAPTOUCH2_LED3_DRIVEN_TO_MAX_DUTY 0x04
481 #define CAPTOUCH2_LED2_DRIVEN_TO_MIN_DUTY 0x00
482 #define CAPTOUCH2_LED2_DRIVEN_TO_MAX_DUTY 0x02
483 #define CAPTOUCH2_LED1_DRIVEN_TO_MIN_DUTY 0x00
484 #define CAPTOUCH2_LED1_DRIVEN_TO_MAX_DUTY 0x01
485 
491 #define CAPTOUCH2_LED6_CHANGE_STATE 0x00
492 #define CAPTOUCH2_LED6_NOT_CHANGE_STATE 0x20
493 #define CAPTOUCH2_LED5_CHANGE_STATE 0x00
494 #define CAPTOUCH2_LED5_NOT_CHANGE_STATE 0x10
495 #define CAPTOUCH2_LED4_CHANGE_STATE 0x00
496 #define CAPTOUCH2_LED4_NOT_CHANGE_STATE 0x08
497 #define CAPTOUCH2_LED3_CHANGE_STATE 0x00
498 #define CAPTOUCH2_LED3_NOT_CHANGE_STATE 0x04
499 #define CAPTOUCH2_LED2_CHANGE_STATE 0x00
500 #define CAPTOUCH2_LED2_NOT_CHANGE_STATE 0x02
501 #define CAPTOUCH2_LED1_CHANGE_STATE 0x00
502 #define CAPTOUCH2_LED1_NOT_CHANGE_STATE 0x01
503 
509 #define CAPTOUCH2_LED1_DIRECT_BEHAVIOR 0x00
510 #define CAPTOUCH2_LED1_PULSE1_BEHAVIOR 0x01
511 #define CAPTOUCH2_LED1_PULSE2_BEHAVIOR 0x02
512 #define CAPTOUCH2_LED1_BREATHE_BEHAVIOR 0x03
513 #define CAPTOUCH2_LED2_DIRECT_BEHAVIOR 0x00
514 #define CAPTOUCH2_LED2_PULSE1_BEHAVIOR ( 0x01 << 2 )
515 #define CAPTOUCH2_LED2_PULSE2_BEHAVIOR ( 0x02 << 2 )
516 #define CAPTOUCH2_LED2_BREATHE_BEHAVIOR ( 0x03 << 2 )
517 #define CAPTOUCH2_LED3_DIRECT_BEHAVIOR 0x00
518 #define CAPTOUCH2_LED3_PULSE1_BEHAVIOR ( 0x01 << 4 )
519 #define CAPTOUCH2_LED3_PULSE2_BEHAVIOR ( 0x02 << 4 )
520 #define CAPTOUCH2_LED3_BREATHE_BEHAVIOR ( 0x03 << 4 )
521 #define CAPTOUCH2_LED4_DIRECT_BEHAVIOR ( 0x00 )
522 #define CAPTOUCH2_LED4_PULSE1_BEHAVIOR ( 0x01 << 6 )
523 #define CAPTOUCH2_LED4_PULSE2_BEHAVIOR ( 0x02 << 6 )
524 #define CAPTOUCH2_LED4_BREATHE_BEHAVIOR ( 0x03 << 6 )
525 
531 #define CAPTOUCH2_LED5_DIRECT_BEHAVIOR 0x00
532 #define CAPTOUCH2_LED5_PULSE1_BEHAVIOR 0x01
533 #define CAPTOUCH2_LED5_PULSE2_BEHAVIOR 0x02
534 #define CAPTOUCH2_LED5_BREATHE_BEHAVIOR 0x03
535 #define CAPTOUCH2_LED6_DIRECT_BEHAVIOR 0x00
536 #define CAPTOUCH2_LED6_PULSE1_BEHAVIOR ( 0x01 << 2 )
537 #define CAPTOUCH2_LED6_PULSE2_BEHAVIOR ( 0x02 << 2 )
538 #define CAPTOUCH2_LED6_BREATHE_BEHAVIOR ( 0x03 << 2 )
539 
545 #define CAPTOUCH2_LED_PULSE_ON_TOUCH 0x00
546 #define CAPTOUCH2_LED_PULSE_ON_RELEASE 0x80
547 #define CAPTOUCH2_LED_PULSE_PERIOD_32MILISEC 0x00
548 #define CAPTOUCH2_LED_PULSE_PERIOD_4064MILISEC 0x7F
549 
555 #define CAPTOUCH2_ALERT_NOT_ASSERTED_ON_LED_ACT 0x00
556 #define CAPTOUCH2_ALERT_ASSERTED_ON_LED_ACT 0x40
557 #define CAPTOUCH2_PULSE1_1_PULSE 0x00
558 #define CAPTOUCH2_PULSE1_2_PULSES 0x01
559 #define CAPTOUCH2_PULSE1_3_PULSES 0x02
560 #define CAPTOUCH2_PULSE1_4_PULSES 0x03
561 #define CAPTOUCH2_PULSE1_5_PULSES 0x04
562 #define CAPTOUCH2_PULSE1_6_PULSES 0x05
563 #define CAPTOUCH2_PULSE1_7_PULSES 0x06
564 #define CAPTOUCH2_PULSE1_8_PULSES 0x07
565 #define CAPTOUCH2_PULSE2_1_PULSE 0x00
566 #define CAPTOUCH2_PULSE2_2_PULSES ( 0x01 << 3 )
567 #define CAPTOUCH2_PULSE2_3_PULSES ( 0x02 << 3 )
568 #define CAPTOUCH2_PULSE2_4_PULSES ( 0x03 << 3 )
569 #define CAPTOUCH2_PULSE2_5_PULSES ( 0x04 << 3 )
570 #define CAPTOUCH2_PULSE2_6_PULSES ( 0x05 << 3 )
571 #define CAPTOUCH2_PULSE2_7_PULSES ( 0x06 << 3 )
572 #define CAPTOUCH2_PULSE2_8_PULSES ( 0x07 << 3 )
573 
579 #define CAPTOUCH2_MIN_DUTY_0_PERCENT 0x00
580 #define CAPTOUCH2_MIN_DUTY_7_PERCENTS 0x01
581 #define CAPTOUCH2_MIN_DUTY_9_PERCENTS 0x02
582 #define CAPTOUCH2_MIN_DUTY_11_PERCENTS 0x03
583 #define CAPTOUCH2_MIN_DUTY_14_PERCENTS 0x04
584 #define CAPTOUCH2_MIN_DUTY_17_PERCENTS 0x05
585 #define CAPTOUCH2_MIN_DUTY_20_PERCENTS 0x06
586 #define CAPTOUCH2_MIN_DUTY_23_PERCENTS 0x07
587 #define CAPTOUCH2_MIN_DUTY_26_PERCENTS 0x08
588 #define CAPTOUCH2_MIN_DUTY_30_PERCENTS 0x09
589 #define CAPTOUCH2_MIN_DUTY_35_PERCENTS 0x0A
590 #define CAPTOUCH2_MIN_DUTY_40_PERCENTS 0x0B
591 #define CAPTOUCH2_MIN_DUTY_46_PERCENTS 0x0C
592 #define CAPTOUCH2_MIN_DUTY_53_PERCENTS 0x0D
593 #define CAPTOUCH2_MIN_DUTY_63_PERCENTS 0x0E
594 #define CAPTOUCH2_MIN_DUTY_77_PERCENTS 0x0F
595 #define CAPTOUCH2_MAX_DUTY_7_PERCENTS 0x00
596 #define CAPTOUCH2_MAX_DUTY_9_PERCENTS 0x10
597 #define CAPTOUCH2_MAX_DUTY_11_PERCENTS 0x20
598 #define CAPTOUCH2_MAX_DUTY_14_PERCENTS 0x30
599 #define CAPTOUCH2_MAX_DUTY_17_PERCENTS 0x40
600 #define CAPTOUCH2_MAX_DUTY_20_PERCENTS 0x50
601 #define CAPTOUCH2_MAX_DUTY_23_PERCENTS 0x60
602 #define CAPTOUCH2_MAX_DUTY_26_PERCENTS 0x70
603 #define CAPTOUCH2_MAX_DUTY_30_PERCENTS 0x80
604 #define CAPTOUCH2_MAX_DUTY_35_PERCENTS 0x90
605 #define CAPTOUCH2_MAX_DUTY_40_PERCENTS 0xA0
606 #define CAPTOUCH2_MAX_DUTY_46_PERCENTS 0xB0
607 #define CAPTOUCH2_MAX_DUTY_53_PERCENTS 0xC0
608 #define CAPTOUCH2_MAX_DUTY_63_PERCENTS 0xD0
609 #define CAPTOUCH2_MAX_DUTY_77_PERCENTS 0xE0
610 #define CAPTOUCH2_MAX_DUTY_100_PERCENTS 0xF0
611 
617 #define CAPTOUCH2_GAIN_1 0x01
618 #define CAPTOUCH2_GAIN_2 0x02
619 #define CAPTOUCH2_GAIN_4 0x04
620 #define CAPTOUCH2_GAIN_8 0x08
621 #define CAPTOUCH2_ALL_INPUTS_DISABLE 0x00
622 #define CAPTOUCH2_INPUT1_EN 0x01
623 #define CAPTOUCH2_INPUT2_EN 0x02
624 #define CAPTOUCH2_INPUT3_EN 0x04
625 #define CAPTOUCH2_INPUT4_EN 0x08
626 #define CAPTOUCH2_INPUT5_EN 0x10
627 #define CAPTOUCH2_INPUT6_EN 0x20
628 #define CAPTOUCH2_ALL_INPUTS_ENABLE 0x3F
629  // End group macro
632 // --------------------------------------------------------------- PUBLIC TYPES
641 typedef struct
642 {
643  // Output pins
644 
645  digital_out_t cs;
646  digital_out_t rst;
647 
648  // Input pins
649 
650  digital_in_t alt;
651 
652  // Modules
653 
654  spi_master_t spi;
655  pin_name_t chip_select;
656 
657  // ctx variable
658  uint8_t release_check;
659  uint8_t input_check[ 6 ];
660  uint8_t cfg_byte_data;
661 
662 } captouch2_t;
663 
667 typedef struct
668 {
669  // Communication gpio pins
670 
671  pin_name_t miso;
672  pin_name_t mosi;
673  pin_name_t sck;
674  pin_name_t cs;
675 
676  // Additional gpio pins
677 
678  pin_name_t rst;
679  pin_name_t alt;
680 
681  // static variable
682 
683  uint32_t spi_speed;
684  spi_master_mode_t spi_mode;
685  spi_master_chip_select_polarity_t cs_polarity;
686 
688  // End types group
690 
691 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
692 
697 #ifdef __cplusplus
698 extern "C"{
699 #endif
700 
710 
720 
741 
753 void captouch2_generic_transfer ( captouch2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
754 
764 void captouch2_write_reg ( captouch2_t *ctx, uint8_t reg_addr, uint8_t tx_data );
765 
776 void captouch2_read_reg( captouch2_t *ctx, uint8_t reg_addr, uint8_t *rx_data, uint8_t n_bytes );
777 
790 void captouch2_detect_touch( captouch2_t *ctx, uint8_t *in_sens );
791 
801 void captouch2_set_active_mode( captouch2_t *ctx, uint8_t analog_gain, uint8_t en_input );
802 
812 void captouch2_set_standby_mode( captouch2_t *ctx, uint8_t analog_gain, uint8_t en_input );
813 
824 
834 
843 
844 #ifdef __cplusplus
845 }
846 #endif
847 #endif // _CAPTOUCH2_H_
848  // End public_function group
851 
852 // ------------------------------------------------------------------------- END
captouch2_generic_transfer
void captouch2_generic_transfer(captouch2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
captouch2_read_reg
void captouch2_read_reg(captouch2_t *ctx, uint8_t reg_addr, uint8_t *rx_data, uint8_t n_bytes)
Generic Read function.
captouch2_set_deep_sleep_mode
void captouch2_set_deep_sleep_mode(captouch2_t *ctx)
DeepSleep Mode Set function.
captouch2_init
CAPTOUCH2_RETVAL captouch2_init(captouch2_t *ctx, captouch2_cfg_t *cfg)
Initialization function.
captouch2_t::release_check
uint8_t release_check
Definition: captouch2.h:658
captouch2_t::chip_select
pin_name_t chip_select
Definition: captouch2.h:655
captouch2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: captouch2.h:685
captouch2_t::alt
digital_in_t alt
Definition: captouch2.h:650
captouch2_set_standby_mode
void captouch2_set_standby_mode(captouch2_t *ctx, uint8_t analog_gain, uint8_t en_input)
Standby Mode Set function.
captouch2_t::cs
digital_out_t cs
Definition: captouch2.h:645
captouch2_t::rst
digital_out_t rst
Definition: captouch2.h:646
captouch2_cfg_t::cs
pin_name_t cs
Definition: captouch2.h:674
captouch2_cfg_t::spi_speed
uint32_t spi_speed
Definition: captouch2.h:683
captouch2_cfg_t::alt
pin_name_t alt
Definition: captouch2.h:679
captouch2_t
Click ctx object definition.
Definition: captouch2.h:642
captouch2_default_cfg
void captouch2_default_cfg(captouch2_t *ctx)
Click Default Configuration function.
captouch2_t::cfg_byte_data
uint8_t cfg_byte_data
Definition: captouch2.h:660
captouch2_check_interrupt
uint8_t captouch2_check_interrupt(captouch2_t *ctx)
Interrupt Check function.
captouch2_write_reg
void captouch2_write_reg(captouch2_t *ctx, uint8_t reg_addr, uint8_t tx_data)
Generic Write function.
captouch2_reset
void captouch2_reset(captouch2_t *ctx)
Reset function.
captouch2_cfg_t::mosi
pin_name_t mosi
Definition: captouch2.h:672
captouch2_cfg_t::sck
pin_name_t sck
Definition: captouch2.h:673
captouch2_cfg_t::rst
pin_name_t rst
Definition: captouch2.h:678
captouch2_cfg_t::miso
pin_name_t miso
Definition: captouch2.h:671
captouch2_t::spi
spi_master_t spi
Definition: captouch2.h:654
captouch2_cfg_t
Click configuration structure definition.
Definition: captouch2.h:668
captouch2_set_active_mode
void captouch2_set_active_mode(captouch2_t *ctx, uint8_t analog_gain, uint8_t en_input)
Active Mode Set function.
captouch2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: captouch2.h:684
captouch2_detect_touch
void captouch2_detect_touch(captouch2_t *ctx, uint8_t *in_sens)
Touch Detect function.
captouch2_cfg_setup
void captouch2_cfg_setup(captouch2_cfg_t *cfg)
Config Object Initialization function.
CAPTOUCH2_RETVAL
#define CAPTOUCH2_RETVAL
Definition: captouch2.h:66