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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define CAPTOUCH2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT );
70 
76 #define CAPTOUCH2_RETVAL uint8_t
77 
78 #define CAPTOUCH2_OK 0x00
79 #define CAPTOUCH2_INIT_ERROR 0xFF
80 
86 #define CAPTOUCH2_MAIN_CONTROL_REG 0x00
87 #define CAPTOUCH2_GEN_STATUS_REG 0x02
88 #define CAPTOUCH2_SENS_IN_STATUS_REG 0x03
89 #define CAPTOUCH2_NOISE_FLAG_REG 0x0A
90 #define CAPTOUCH2_SENS_IN1_DELTA_CNT_REG 0x10
91 #define CAPTOUCH2_SENS_IN2_DELTA_CNT_REG 0x11
92 #define CAPTOUCH2_SENS_IN3_DELTA_CNT_REG 0x12
93 #define CAPTOUCH2_SENS_IN4_DELTA_CNT_REG 0x13
94 #define CAPTOUCH2_SENS_IN5_DELTA_CNT_REG 0x14
95 #define CAPTOUCH2_SENS_IN6_DELTA_CNT_REG 0x15
96 #define CAPTOUCH2_SENSITIVITY_CON_REG 0x1F
97 #define CAPTOUCH2_CONFIG_REG 0x20
98 #define CAPTOUCH2_SENS_IN_EN_REG 0x21
99 #define CAPTOUCH2_SENS_IN_CONFIG_REG 0x22
100 #define CAPTOUCH2_SENS_IN_CONFIG2_REG 0x23
101 #define CAPTOUCH2_AVRG_AND_SAMPL_CONFIG_REG 0x24
102 #define CAPTOUCH2_CALIB_ACTIVATE_REG 0x26
103 #define CAPTOUCH2_INTERR_EN_REG 0x27
104 #define CAPTOUCH2_REPEAT_RATE_EN_REG 0x28
105 #define CAPTOUCH2_MULTIPLE_TOUCH_CONFIG_REG 0x2A
106 #define CAPTOUCH2_MULTIPLE_TOUCH_PATTERN_CONFIG_REG 0x2B
107 #define CAPTOUCH2_MULTIPLE_TOUCH_PATTERN_REG 0x2D
108 #define CAPTOUCH2_RECALIB_CONFIG_REG 0x2F
109 #define CAPTOUCH2_SENS_IN1_THRESHOLD_REG 0x30
110 #define CAPTOUCH2_SENS_IN2_THRESHOLD_REG 0x31
111 #define CAPTOUCH2_SENS_IN3_THRESHOLD_REG 0x32
112 #define CAPTOUCH2_SENS_IN4_THRESHOLD_REG 0x33
113 #define CAPTOUCH2_SENS_IN5_THRESHOLD_REG 0x34
114 #define CAPTOUCH2_SENS_IN6_THRESHOLD_REG 0x35
115 #define CAPTOUCH2_SENS_IN_NOISE_THRESHOLD_REG 0x38
116 #define CAPTOUCH2_STANDBY_CHANN_REG 0x40
117 #define CAPTOUCH2_STANDBY_CONFIG_REG 0x41
118 #define CAPTOUCH2_STANDBY_SENSITIVITY_REG 0x42
119 #define CAPTOUCH2_STANDBY_THRESHOLD_REG 0x43
120 #define CAPTOUCH2_CONFIG2_REG 0x44
121 #define CAPTOUCH2_SENS_IN1_BASE_CNT_REG 0x50
122 #define CAPTOUCH2_SENS_IN2_BASE_CNT_REG 0x51
123 #define CAPTOUCH2_SENS_IN3_BASE_CNT_REG 0x52
124 #define CAPTOUCH2_SENS_IN4_BASE_CNT_REG 0x53
125 #define CAPTOUCH2_SENS_IN5_BASE_CNT_REG 0x54
126 #define CAPTOUCH2_SENS_IN6_BASE_CNT_REG 0x55
127 #define CAPTOUCH2_LED_OUTPUT_TYPE_REG 0x71
128 #define CAPTOUCH2_SENS_IN_LED_LINK_REG 0x72
129 #define CAPTOUCH2_LED_POLARITY_REG 0x73
130 #define CAPTOUCH2_LED_OUT_CON_REG 0x74
131 #define CAPTOUCH2_LED_LINK_TRANS_CON_REG 0x77
132 #define CAPTOUCH2_LED_MIRROR_CON_REG 0x79
133 #define CAPTOUCH2_LED_BEHAVIOR1_REG 0x81
134 #define CAPTOUCH2_LED_BEHAVIOR2_REG 0x82
135 #define CAPTOUCH2_LED_PULSE1_PERIOD_REG 0x84
136 #define CAPTOUCH2_LED_PULSE2_PERIOD_REG 0x85
137 #define CAPTOUCH2_LED_BREATHE_PERIOD_REG 0x86
138 #define CAPTOUCH2_LED_CONFIG_REG 0x88
139 #define CAPTOUCH2_LED_PULSE1_DUTY_REG 0x90
140 #define CAPTOUCH2_LED_PULSE2_DUTY_REG 0x91
141 #define CAPTOUCH2_LED_BREATHE_DUTY_REG 0x92
142 #define CAPTOUCH2_LED_DIRECT_DUTY_REG 0x93
143 #define CAPTOUCH2_LED_DIRECT_RAMP_RATES_REG 0x94
144 #define CAPTOUCH2_LED_OFF_DELAY_REG 0x95
145 #define CAPTOUCH2_SENS_IN1_CALIB_REG 0xB1
146 #define CAPTOUCH2_SENS_IN2_CALIB_REG 0xB2
147 #define CAPTOUCH2_SENS_IN3_CALIB_REG 0xB3
148 #define CAPTOUCH2_SENS_IN4_CALIB_REG 0xB4
149 #define CAPTOUCH2_SENS_IN5_CALIB_REG 0xB5
150 #define CAPTOUCH2_SENS_IN6_CALIB_REG 0xB6
151 #define CAPTOUCH2_SENS_IN_CALIB_LSB1_REG 0xB9
152 #define CAPTOUCH2_SENS_IN_CALIB_LSB2_REG 0xBA
153 #define CAPTOUCH2_PRODUCT_ID_REG 0xFD
154 #define CAPTOUCH2_MANUFACT_ID_REG 0xFE
155 #define CAPTOUCH2_REVISION_REG 0xFF
156 
162 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_128X 0x00
163 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_64X 0x10
164 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_32X 0x20
165 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_16X 0x30
166 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_8X 0x40
167 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_4X 0x50
168 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_2X 0x60
169 #define CAPTOUCH2_SENSITIVITY_MULTIPLIER_1X 0x70
170 #define CAPTOUCH2_DATA_SCALING_FACTOR_1X 0x00
171 #define CAPTOUCH2_DATA_SCALING_FACTOR_2X 0x01
172 #define CAPTOUCH2_DATA_SCALING_FACTOR_4X 0x02
173 #define CAPTOUCH2_DATA_SCALING_FACTOR_8X 0x03
174 #define CAPTOUCH2_DATA_SCALING_FACTOR_16X 0x04
175 #define CAPTOUCH2_DATA_SCALING_FACTOR_32X 0x05
176 #define CAPTOUCH2_DATA_SCALING_FACTOR_64X 0x06
177 #define CAPTOUCH2_DATA_SCALING_FACTOR_128X 0x07
178 #define CAPTOUCH2_DATA_SCALING_FACTOR_256X 0x08
179 
185 #define CAPTOUCH2_TIMEOUT_DIS 0x00
186 #define CAPTOUCH2_TIMEOUT_EN 0x80
187 #define CAPTOUCH2_WAKE_PIN_NOT_ASSERTED 0x00
188 #define CAPTOUCH2_WAKE_PIN_ASSERTED 0x40
189 #define CAPTOUCH2_DIG_NOISE_THRESHOLD_EN 0x00
190 #define CAPTOUCH2_DIG_NOISE_THRESHOLD_DIS 0x20
191 #define CAPTOUCH2_AN_NOISE_FILTER_EN 0x00
192 #define CAPTOUCH2_AN_NOISE_FILTER_DIS 0x10
193 #define CAPTOUCH2_MAX_DUR_RECALIB_DIS 0x00
194 #define CAPTOUCH2_MAX_DUR_RECALIB_EN 0x08
195 
201 #define CAPTOUCH2_NOT_INVERT_TOUCH_SIGNAL 0x00
202 #define CAPTOUCH2_INVERT_TOUCH_SIGNAL 0x80
203 #define CAPTOUCH2_ALERT_ACTIVE_HIGH 0x00
204 #define CAPTOUCH2_ALERT_ACTIVE_LOW 0x40
205 #define CAPTOUCH2_POWER_CONSUMPTION_REDUCE_EN 0x00
206 #define CAPTOUCH2_POWER_CONSUMPTION_REDUCE_DIS 0x20
207 #define CAPTOUCH2_AUTOSET_LED_MIRROR_CON 0x00
208 #define CAPTOUCH2_NOT_AUTOSET_LED_MIRROR_CON 0x10
209 #define CAPTOUCH2_SHOW_LOW_FREQ_NOISE 0x00
210 #define CAPTOUCH2_NOT_SHOW_LOW_FREQ_NOISE 0x08
211 #define CAPTOUCH2_RF_NOISE_FILTER_EN 0x00
212 #define CAPTOUCH2_RF_NOISE_FILTER_DIS 0x04
213 #define CAPTOUCH2_AN_CALIB_FAIL_INTERR_DIS 0x00
214 #define CAPTOUCH2_AN_CALIB_FAIL_INTERR_EN 0x02
215 #define CAPTOUCH2_DETECT_RELEASE_EN 0x00
216 #define CAPTOUCH2_DETECT_RELEASE_DIS 0x01
217 
223 #define CAPTOUCH2_560MILISEC_BEFORE_RECALIB 0x00
224 #define CAPTOUCH2_840MILISEC_BEFORE_RECALIB 0x10
225 #define CAPTOUCH2_1120MILISEC_BEFORE_RECALIB 0x20
226 #define CAPTOUCH2_1400MILISEC_BEFORE_RECALIB 0x30
227 #define CAPTOUCH2_1680MILISEC_BEFORE_RECALIB 0x40
228 #define CAPTOUCH2_2240MILISEC_BEFORE_RECALIB 0x50
229 #define CAPTOUCH2_2800MILISEC_BEFORE_RECALIB 0x60
230 #define CAPTOUCH2_3360MILISEC_BEFORE_RECALIB 0x70
231 #define CAPTOUCH2_3920MILISEC_BEFORE_RECALIB 0x80
232 #define CAPTOUCH2_4480MILISEC_BEFORE_RECALIB 0x90
233 #define CAPTOUCH2_5600MILISEC_BEFORE_RECALIB 0xA0
234 #define CAPTOUCH2_6720MILISEC_BEFORE_RECALIB 0xB0
235 #define CAPTOUCH2_7840MILISEC_BEFORE_RECALIB 0xC0
236 #define CAPTOUCH2_8906MILISEC_BEFORE_RECALIB 0xD0
237 #define CAPTOUCH2_10080MILISEC_BEFORE_RECALIB 0xE0
238 #define CAPTOUCH2_11200MILISEC_BEFORE_RECALIB 0xF0
239 #define CAPTOUCH2_INTERR_REPEAT_RATE_35MILISEC 0x00
240 #define CAPTOUCH2_INTERR_REPEAT_RATE_70MILISEC 0x01
241 #define CAPTOUCH2_INTERR_REPEAT_RATE_105MILISEC 0x02
242 #define CAPTOUCH2_INTERR_REPEAT_RATE_140MILISEC 0x03
243 #define CAPTOUCH2_INTERR_REPEAT_RATE_175MILISEC 0x04
244 #define CAPTOUCH2_INTERR_REPEAT_RATE_210MILISEC 0x05
245 #define CAPTOUCH2_INTERR_REPEAT_RATE_245MILISEC 0x06
246 #define CAPTOUCH2_INTERR_REPEAT_RATE_280MILISEC 0x07
247 #define CAPTOUCH2_INTERR_REPEAT_RATE_315MILISEC 0x08
248 #define CAPTOUCH2_INTERR_REPEAT_RATE_350MILISEC 0x09
249 #define CAPTOUCH2_INTERR_REPEAT_RATE_385MILISEC 0x0A
250 #define CAPTOUCH2_INTERR_REPEAT_RATE_420MILISEC 0x0B
251 #define CAPTOUCH2_INTERR_REPEAT_RATE_455MILISEC 0x0C
252 #define CAPTOUCH2_INTERR_REPEAT_RATE_490MILISEC 0x0D
253 #define CAPTOUCH2_INTERR_REPEAT_RATE_525MILISEC 0x0E
254 #define CAPTOUCH2_INTERR_REPEAT_RATE_560MILISEC 0x0F
255 
261 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_35MILISEC 0x00
262 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_70MILISEC 0x01
263 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_105MILISEC 0x02
264 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_140MILISEC 0x03
265 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_175MILISEC 0x04
266 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_210MILISEC 0x05
267 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_245MILISEC 0x06
268 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_280MILISEC 0x07
269 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_315MILISEC 0x08
270 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_350MILISEC 0x09
271 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_385MILISEC 0x0A
272 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_420MILISEC 0x0B
273 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_455MILISEC 0x0C
274 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_490MILISEC 0x0D
275 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_525MILISEC 0x0E
276 #define CAPTOUCH2_PRESS_AND_HOLD_EVENT_AFTER_560MILISEC 0x0F
277 
283 #define CAPTOUCH2_1_SAMPLE 0x00
284 #define CAPTOUCH2_2_SAMPLES 0x10
285 #define CAPTOUCH2_4_SAMPLES 0x20
286 #define CAPTOUCH2_8_SAMPLES 0x30
287 #define CAPTOUCH2_16_SAMPLES 0x40
288 #define CAPTOUCH2_32_SAMPLES 0x50
289 #define CAPTOUCH2_64_SAMPLES 0x60
290 #define CAPTOUCH2_128_SAMPLES 0x70
291 #define CAPTOUCH2_SAMPLE_TIME_320MICROSEC 0x00
292 #define CAPTOUCH2_SAMPLE_TIME_640MICROSEC 0x04
293 #define CAPTOUCH2_SAMPLE_TIME_1280MICROSEC 0x08
294 #define CAPTOUCH2_SAMPLE_TIME_2560MICROSEC 0x0C
295 #define CAPTOUCH2_CYCLE_TIME_35MILISEC 0x00
296 #define CAPTOUCH2_CYCLE_TIME_70MILISEC 0x01
297 #define CAPTOUCH2_CYCLE_TIME_105MILISEC 0x02
298 #define CAPTOUCH2_CYCLE_TIME_140MILISEC 0x03
299 
305 #define CAPTOUCH2_ALL_INPUTS_CALIB_DIS 0x00
306 #define CAPTOUCH2_INPUT1_CALIB_EN 0x01
307 #define CAPTOUCH2_INPUT2_CALIB_EN 0x02
308 #define CAPTOUCH2_INPUT3_CALIB_EN 0x04
309 #define CAPTOUCH2_INPUT4_CALIB_EN 0x08
310 #define CAPTOUCH2_INPUT5_CALIB_EN 0x10
311 #define CAPTOUCH2_INPUT6_CALIB_EN 0x20
312 
318 #define CAPTOUCH2_ALL_INPUTS_INTERR_DIS 0x00
319 #define CAPTOUCH2_INPUT1_INTERR_EN 0x01
320 #define CAPTOUCH2_INPUT2_INTERR_EN 0x02
321 #define CAPTOUCH2_INPUT3_INTERR_EN 0x04
322 #define CAPTOUCH2_INPUT4_INTERR_EN 0x08
323 #define CAPTOUCH2_INPUT5_INTERR_EN 0x10
324 #define CAPTOUCH2_INPUT6_INTERR_EN 0x20
325 
331 #define CAPTOUCH2_REPEAT_RATE_DIS 0x00
332 #define CAPTOUCH2_INPUT1_REPEAT_RATE_EN 0x01
333 #define CAPTOUCH2_INPUT2_REPEAT_RATE_EN 0x02
334 #define CAPTOUCH2_INPUT3_REPEAT_RATE_EN 0x04
335 #define CAPTOUCH2_INPUT4_REPEAT_RATE_EN 0x08
336 #define CAPTOUCH2_INPUT5_REPEAT_RATE_EN 0x10
337 #define CAPTOUCH2_INPUT6_REPEAT_RATE_EN 0x20
338 
344 #define CAPTOUCH2_MULTIPLE_BLOCK_DIS 0x00
345 #define CAPTOUCH2_MULTIPLE_BLOCK_EN 0x80
346 #define CAPTOUCH2_SIMUL_TOUCH_NUM_1 0x00
347 #define CAPTOUCH2_SIMUL_TOUCH_NUM_2 0x04
348 #define CAPTOUCH2_SIMUL_TOUCH_NUM_3 0x08
349 #define CAPTOUCH2_SIMUL_TOUCH_NUM_4 0x0C
350 
356 #define CAPTOUCH2_MULTIPLE_THRESHOLD_12_PERCENTS 0x00
357 #define CAPTOUCH2_MULTIPLE_THRESHOLD_25_PERCENTS 0x04
358 #define CAPTOUCH2_MULTIPLE_THRESHOLD_37_PERCENTS 0x08
359 #define CAPTOUCH2_MULTIPLE_THRESHOLD_100_PERCENTS 0x0C
360 #define CAPTOUCH2_MLTP_TOUCH_PATTERN 0x00
361 #define CAPTOUCH2_PATTERN_RECOGNITION 0x02
362 #define CAPTOUCH2_MLTP_EVENT_ALERT_DIS 0x00
363 #define CAPTOUCH2_MLTP_EVENT_ALERT_EN 0x01
364 
370 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUTS_DIS 0x00
371 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT1_EN 0x01
372 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT2_EN 0x02
373 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT3_EN 0x04
374 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT4_EN 0x08
375 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT5_EN 0x10
376 #define CAPTOUCH2_MLTP_TOUCH_PATTERN_INPUT6_EN 0x20
377 
383 #define CAPTOUCH2_INPUTS_THRESHOLD_UPDT_INDIVIDUALY 0x00
384 #define CAPTOUCH2_INPUT1_THRESHOLD_OVERWRITE 0x80
385 #define CAPTOUCH2_ACC_INTER_DATA_CLEAR 0x00
386 #define CAPTOUCH2_ACC_INTER_DATA_NOT_CLEAR 0x40
387 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_CLEAR 0x00
388 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_NOT_CLEAR 0x20
389 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_8 0x00
390 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_16 0x08
391 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_32 0x10
392 #define CAPTOUCH2_CONS_NEG_DELTA_CNT_DIS 0x18
393 #define CAPTOUCH2_REC_SAMPLES_16_UPDT_TIME_16 0x00
394 #define CAPTOUCH2_REC_SAMPLES_32_UPDT_TIME_32 0x01
395 #define CAPTOUCH2_REC_SAMPLES_64_UPDT_TIME_64 0x02
396 #define CAPTOUCH2_REC_SAMPLES_128_UPDT_TIME_128 0x03
397 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_256 0x04
398 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_1024 0x05
399 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_2048 0x06
400 #define CAPTOUCH2_REC_SAMPLES_256_UPDT_TIME_4096 0x07
401 
407 #define CAPTOUCH2_AVERAGE_BASED 0x00
408 #define CAPTOUCH2_SUMMATION_BASED 0x80
409 
415 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_128X 0x00
416 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_64X 0x01
417 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_32X 0x02
418 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_16X 0x03
419 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_8X 0x04
420 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_4X 0x05
421 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_2X 0x06
422 #define CAPTOUCH2_STBY_SENSE_MULTIPLIER_1X 0x07
423 
429 #define CAPTOUCH2_LED6_PIN_OPEN_DRAIN 0x00
430 #define CAPTOUCH2_LED6_PIN_PUSH_PULL 0x20
431 #define CAPTOUCH2_LED5_PIN_OPEN_DRAIN 0x00
432 #define CAPTOUCH2_LED5_PIN_PUSH_PULL 0x10
433 #define CAPTOUCH2_LED4_PIN_OPEN_DRAIN 0x00
434 #define CAPTOUCH2_LED4_PIN_PUSH_PULL 0x08
435 #define CAPTOUCH2_LED3_PIN_OPEN_DRAIN 0x00
436 #define CAPTOUCH2_LED3_PIN_PUSH_PULL 0x04
437 #define CAPTOUCH2_LED2_PIN_OPEN_DRAIN 0x00
438 #define CAPTOUCH2_LED2_PIN_PUSH_PULL 0x02
439 #define CAPTOUCH2_LED1_PIN_OPEN_DRAIN 0x00
440 #define CAPTOUCH2_LED1_PIN_PUSH_PULL 0x01
441 
447 #define CAPTOUCH2_LED6_IN6_NOT_LINKED 0x00
448 #define CAPTOUCH2_LED6_IN6_LINKED 0x20
449 #define CAPTOUCH2_LED5_IN5_NOT_LINKED 0x00
450 #define CAPTOUCH2_LED5_IN5_LINKED 0x10
451 #define CAPTOUCH2_LED4_IN4_NOT_LINKED 0x00
452 #define CAPTOUCH2_LED4_IN4_LINKED 0x08
453 #define CAPTOUCH2_LED3_IN3_NOT_LINKED 0x00
454 #define CAPTOUCH2_LED3_IN3_LINKED 0x04
455 #define CAPTOUCH2_LED2_IN2_NOT_LINKED 0x00
456 #define CAPTOUCH2_LED2_IN2_LINKED 0x02
457 #define CAPTOUCH2_LED1_IN1_NOT_LINKED 0x00
458 #define CAPTOUCH2_LED1_IN1_LINKED 0x01
459 
465 #define CAPTOUCH2_LED6_OUT_INVERTED 0x00
466 #define CAPTOUCH2_LED6_OUT_NOT_INVERTED 0x20
467 #define CAPTOUCH2_LED5_OUT_INVERTED 0x00
468 #define CAPTOUCH2_LED5_OUT_NOT_INVERTED 0x10
469 #define CAPTOUCH2_LED4_OUT_INVERTED 0x00
470 #define CAPTOUCH2_LED4_OUT_NOT_INVERTED 0x08
471 #define CAPTOUCH2_LED3_OUT_INVERTED 0x00
472 #define CAPTOUCH2_LED3_OUT_NOT_INVERTED 0x04
473 #define CAPTOUCH2_LED2_OUT_INVERTED 0x00
474 #define CAPTOUCH2_LED2_OUT_NOT_INVERTED 0x02
475 #define CAPTOUCH2_LED1_OUT_INVERTED 0x00
476 #define CAPTOUCH2_LED1_OUT_NOT_INVERTED 0x01
477 
483 #define CAPTOUCH2_LED6_DRIVEN_TO_MIN_DUTY 0x00
484 #define CAPTOUCH2_LED6_DRIVEN_TO_MAX_DUTY 0x20
485 #define CAPTOUCH2_LED5_DRIVEN_TO_MIN_DUTY 0x00
486 #define CAPTOUCH2_LED5_DRIVEN_TO_MAX_DUTY 0x10
487 #define CAPTOUCH2_LED4_DRIVEN_TO_MIN_DUTY 0x00
488 #define CAPTOUCH2_LED4_DRIVEN_TO_MAX_DUTY 0x08
489 #define CAPTOUCH2_LED3_DRIVEN_TO_MIN_DUTY 0x00
490 #define CAPTOUCH2_LED3_DRIVEN_TO_MAX_DUTY 0x04
491 #define CAPTOUCH2_LED2_DRIVEN_TO_MIN_DUTY 0x00
492 #define CAPTOUCH2_LED2_DRIVEN_TO_MAX_DUTY 0x02
493 #define CAPTOUCH2_LED1_DRIVEN_TO_MIN_DUTY 0x00
494 #define CAPTOUCH2_LED1_DRIVEN_TO_MAX_DUTY 0x01
495 
501 #define CAPTOUCH2_LED6_CHANGE_STATE 0x00
502 #define CAPTOUCH2_LED6_NOT_CHANGE_STATE 0x20
503 #define CAPTOUCH2_LED5_CHANGE_STATE 0x00
504 #define CAPTOUCH2_LED5_NOT_CHANGE_STATE 0x10
505 #define CAPTOUCH2_LED4_CHANGE_STATE 0x00
506 #define CAPTOUCH2_LED4_NOT_CHANGE_STATE 0x08
507 #define CAPTOUCH2_LED3_CHANGE_STATE 0x00
508 #define CAPTOUCH2_LED3_NOT_CHANGE_STATE 0x04
509 #define CAPTOUCH2_LED2_CHANGE_STATE 0x00
510 #define CAPTOUCH2_LED2_NOT_CHANGE_STATE 0x02
511 #define CAPTOUCH2_LED1_CHANGE_STATE 0x00
512 #define CAPTOUCH2_LED1_NOT_CHANGE_STATE 0x01
513 
519 #define CAPTOUCH2_LED1_DIRECT_BEHAVIOR 0x00
520 #define CAPTOUCH2_LED1_PULSE1_BEHAVIOR 0x01
521 #define CAPTOUCH2_LED1_PULSE2_BEHAVIOR 0x02
522 #define CAPTOUCH2_LED1_BREATHE_BEHAVIOR 0x03
523 #define CAPTOUCH2_LED2_DIRECT_BEHAVIOR 0x00
524 #define CAPTOUCH2_LED2_PULSE1_BEHAVIOR ( 0x01 << 2 )
525 #define CAPTOUCH2_LED2_PULSE2_BEHAVIOR ( 0x02 << 2 )
526 #define CAPTOUCH2_LED2_BREATHE_BEHAVIOR ( 0x03 << 2 )
527 #define CAPTOUCH2_LED3_DIRECT_BEHAVIOR 0x00
528 #define CAPTOUCH2_LED3_PULSE1_BEHAVIOR ( 0x01 << 4 )
529 #define CAPTOUCH2_LED3_PULSE2_BEHAVIOR ( 0x02 << 4 )
530 #define CAPTOUCH2_LED3_BREATHE_BEHAVIOR ( 0x03 << 4 )
531 #define CAPTOUCH2_LED4_DIRECT_BEHAVIOR ( 0x00 )
532 #define CAPTOUCH2_LED4_PULSE1_BEHAVIOR ( 0x01 << 6 )
533 #define CAPTOUCH2_LED4_PULSE2_BEHAVIOR ( 0x02 << 6 )
534 #define CAPTOUCH2_LED4_BREATHE_BEHAVIOR ( 0x03 << 6 )
535 
541 #define CAPTOUCH2_LED5_DIRECT_BEHAVIOR 0x00
542 #define CAPTOUCH2_LED5_PULSE1_BEHAVIOR 0x01
543 #define CAPTOUCH2_LED5_PULSE2_BEHAVIOR 0x02
544 #define CAPTOUCH2_LED5_BREATHE_BEHAVIOR 0x03
545 #define CAPTOUCH2_LED6_DIRECT_BEHAVIOR 0x00
546 #define CAPTOUCH2_LED6_PULSE1_BEHAVIOR ( 0x01 << 2 )
547 #define CAPTOUCH2_LED6_PULSE2_BEHAVIOR ( 0x02 << 2 )
548 #define CAPTOUCH2_LED6_BREATHE_BEHAVIOR ( 0x03 << 2 )
549 
555 #define CAPTOUCH2_LED_PULSE_ON_TOUCH 0x00
556 #define CAPTOUCH2_LED_PULSE_ON_RELEASE 0x80
557 #define CAPTOUCH2_LED_PULSE_PERIOD_32MILISEC 0x00
558 #define CAPTOUCH2_LED_PULSE_PERIOD_4064MILISEC 0x7F
559 
565 #define CAPTOUCH2_ALERT_NOT_ASSERTED_ON_LED_ACT 0x00
566 #define CAPTOUCH2_ALERT_ASSERTED_ON_LED_ACT 0x40
567 #define CAPTOUCH2_PULSE1_1_PULSE 0x00
568 #define CAPTOUCH2_PULSE1_2_PULSES 0x01
569 #define CAPTOUCH2_PULSE1_3_PULSES 0x02
570 #define CAPTOUCH2_PULSE1_4_PULSES 0x03
571 #define CAPTOUCH2_PULSE1_5_PULSES 0x04
572 #define CAPTOUCH2_PULSE1_6_PULSES 0x05
573 #define CAPTOUCH2_PULSE1_7_PULSES 0x06
574 #define CAPTOUCH2_PULSE1_8_PULSES 0x07
575 #define CAPTOUCH2_PULSE2_1_PULSE 0x00
576 #define CAPTOUCH2_PULSE2_2_PULSES ( 0x01 << 3 )
577 #define CAPTOUCH2_PULSE2_3_PULSES ( 0x02 << 3 )
578 #define CAPTOUCH2_PULSE2_4_PULSES ( 0x03 << 3 )
579 #define CAPTOUCH2_PULSE2_5_PULSES ( 0x04 << 3 )
580 #define CAPTOUCH2_PULSE2_6_PULSES ( 0x05 << 3 )
581 #define CAPTOUCH2_PULSE2_7_PULSES ( 0x06 << 3 )
582 #define CAPTOUCH2_PULSE2_8_PULSES ( 0x07 << 3 )
583 
589 #define CAPTOUCH2_MIN_DUTY_0_PERCENT 0x00
590 #define CAPTOUCH2_MIN_DUTY_7_PERCENTS 0x01
591 #define CAPTOUCH2_MIN_DUTY_9_PERCENTS 0x02
592 #define CAPTOUCH2_MIN_DUTY_11_PERCENTS 0x03
593 #define CAPTOUCH2_MIN_DUTY_14_PERCENTS 0x04
594 #define CAPTOUCH2_MIN_DUTY_17_PERCENTS 0x05
595 #define CAPTOUCH2_MIN_DUTY_20_PERCENTS 0x06
596 #define CAPTOUCH2_MIN_DUTY_23_PERCENTS 0x07
597 #define CAPTOUCH2_MIN_DUTY_26_PERCENTS 0x08
598 #define CAPTOUCH2_MIN_DUTY_30_PERCENTS 0x09
599 #define CAPTOUCH2_MIN_DUTY_35_PERCENTS 0x0A
600 #define CAPTOUCH2_MIN_DUTY_40_PERCENTS 0x0B
601 #define CAPTOUCH2_MIN_DUTY_46_PERCENTS 0x0C
602 #define CAPTOUCH2_MIN_DUTY_53_PERCENTS 0x0D
603 #define CAPTOUCH2_MIN_DUTY_63_PERCENTS 0x0E
604 #define CAPTOUCH2_MIN_DUTY_77_PERCENTS 0x0F
605 #define CAPTOUCH2_MAX_DUTY_7_PERCENTS 0x00
606 #define CAPTOUCH2_MAX_DUTY_9_PERCENTS 0x10
607 #define CAPTOUCH2_MAX_DUTY_11_PERCENTS 0x20
608 #define CAPTOUCH2_MAX_DUTY_14_PERCENTS 0x30
609 #define CAPTOUCH2_MAX_DUTY_17_PERCENTS 0x40
610 #define CAPTOUCH2_MAX_DUTY_20_PERCENTS 0x50
611 #define CAPTOUCH2_MAX_DUTY_23_PERCENTS 0x60
612 #define CAPTOUCH2_MAX_DUTY_26_PERCENTS 0x70
613 #define CAPTOUCH2_MAX_DUTY_30_PERCENTS 0x80
614 #define CAPTOUCH2_MAX_DUTY_35_PERCENTS 0x90
615 #define CAPTOUCH2_MAX_DUTY_40_PERCENTS 0xA0
616 #define CAPTOUCH2_MAX_DUTY_46_PERCENTS 0xB0
617 #define CAPTOUCH2_MAX_DUTY_53_PERCENTS 0xC0
618 #define CAPTOUCH2_MAX_DUTY_63_PERCENTS 0xD0
619 #define CAPTOUCH2_MAX_DUTY_77_PERCENTS 0xE0
620 #define CAPTOUCH2_MAX_DUTY_100_PERCENTS 0xF0
621 
627 #define CAPTOUCH2_GAIN_1 0x01
628 #define CAPTOUCH2_GAIN_2 0x02
629 #define CAPTOUCH2_GAIN_4 0x04
630 #define CAPTOUCH2_GAIN_8 0x08
631 #define CAPTOUCH2_ALL_INPUTS_DISABLE 0x00
632 #define CAPTOUCH2_INPUT1_EN 0x01
633 #define CAPTOUCH2_INPUT2_EN 0x02
634 #define CAPTOUCH2_INPUT3_EN 0x04
635 #define CAPTOUCH2_INPUT4_EN 0x08
636 #define CAPTOUCH2_INPUT5_EN 0x10
637 #define CAPTOUCH2_INPUT6_EN 0x20
638 #define CAPTOUCH2_ALL_INPUTS_ENABLE 0x3F
639  // End group macro
642 // --------------------------------------------------------------- PUBLIC TYPES
651 typedef struct
652 {
653  // Output pins
654 
655  digital_out_t cs;
656  digital_out_t rst;
657 
658  // Input pins
659 
660  digital_in_t alt;
661 
662  // Modules
663 
664  spi_master_t spi;
665  pin_name_t chip_select;
666 
667  // ctx variable
668  uint8_t release_check;
669  uint8_t input_check[ 6 ];
670  uint8_t cfg_byte_data;
671 
672 } captouch2_t;
673 
677 typedef struct
678 {
679  // Communication gpio pins
680 
681  pin_name_t miso;
682  pin_name_t mosi;
683  pin_name_t sck;
684  pin_name_t cs;
685 
686  // Additional gpio pins
687 
688  pin_name_t rst;
689  pin_name_t alt;
690 
691  // static variable
692 
693  uint32_t spi_speed;
694  spi_master_mode_t spi_mode;
695  spi_master_chip_select_polarity_t cs_polarity;
696 
698  // End types group
700 
701 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
702 
707 #ifdef __cplusplus
708 extern "C"{
709 #endif
710 
720 
730 
751 
763 void captouch2_generic_transfer ( captouch2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
764 
774 void captouch2_write_reg ( captouch2_t *ctx, uint8_t reg_addr, uint8_t tx_data );
775 
786 void captouch2_read_reg( captouch2_t *ctx, uint8_t reg_addr, uint8_t *rx_data, uint8_t n_bytes );
787 
800 void captouch2_detect_touch( captouch2_t *ctx, uint8_t *in_sens );
801 
811 void captouch2_set_active_mode( captouch2_t *ctx, uint8_t analog_gain, uint8_t en_input );
812 
822 void captouch2_set_standby_mode( captouch2_t *ctx, uint8_t analog_gain, uint8_t en_input );
823 
834 
844 
853 
854 #ifdef __cplusplus
855 }
856 #endif
857 #endif // _CAPTOUCH2_H_
858  // End public_function group
861 
862 // ------------------------------------------------------------------------- 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:668
captouch2_t::chip_select
pin_name_t chip_select
Definition: captouch2.h:665
captouch2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: captouch2.h:695
captouch2_t::alt
digital_in_t alt
Definition: captouch2.h:660
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:655
captouch2_t::rst
digital_out_t rst
Definition: captouch2.h:656
captouch2_cfg_t::cs
pin_name_t cs
Definition: captouch2.h:684
captouch2_cfg_t::spi_speed
uint32_t spi_speed
Definition: captouch2.h:693
captouch2_cfg_t::alt
pin_name_t alt
Definition: captouch2.h:689
captouch2_t
Click ctx object definition.
Definition: captouch2.h:652
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:670
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:682
captouch2_cfg_t::sck
pin_name_t sck
Definition: captouch2.h:683
captouch2_cfg_t::rst
pin_name_t rst
Definition: captouch2.h:688
captouch2_cfg_t::miso
pin_name_t miso
Definition: captouch2.h:681
captouch2_t::spi
spi_master_t spi
Definition: captouch2.h:664
captouch2_cfg_t
Click configuration structure definition.
Definition: captouch2.h:678
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:694
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:76