touchclamp  2.0.0.0
touchclamp.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 TOUCHCLAMP_H
36 #define TOUCHCLAMP_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define TOUCHCLAMP_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
69 
75 #define TOUCHCLAMP_RETVAL uint8_t
76 
77 #define TOUCHCLAMP_OK 0x00
78 #define TOUCHCLAMP_INIT_ERROR 0xFF
79 
81 #define TOUCHCLAMP_I2C_ADDRESS 0x5A
82 
91 #define TOUCHCLAMP_REG_TS1 0x00
92 #define TOUCHCLAMP_REG_TS2 0x01
93 #define TOUCHCLAMP_REG_OORS1 0x02
94 #define TOUCHCLAMP_REG_OORS2 0x03
95 
100 #define TOUCHCLAMP_REG_E0FDL 0x04
101 #define TOUCHCLAMP_REG_E0FDH 0x05
102 #define TOUCHCLAMP_REG_E1FDL 0x06
103 #define TOUCHCLAMP_REG_E1FDH 0x07
104 #define TOUCHCLAMP_REG_E2FDL 0x08
105 #define TOUCHCLAMP_REG_E2FDH 0x09
106 #define TOUCHCLAMP_REG_E3FDL 0x0A
107 #define TOUCHCLAMP_REG_E3FDH 0x0B
108 #define TOUCHCLAMP_REG_E4FDL 0x0C
109 #define TOUCHCLAMP_REG_E4FDH 0x0D
110 #define TOUCHCLAMP_REG_E5FDL 0x0E
111 #define TOUCHCLAMP_REG_E5FDH 0x0F
112 #define TOUCHCLAMP_REG_E6FDL 0x10
113 #define TOUCHCLAMP_REG_E6FDH 0x11
114 #define TOUCHCLAMP_REG_E7FDL 0x12
115 #define TOUCHCLAMP_REG_E7FDH 0x13
116 #define TOUCHCLAMP_REG_E8FDL 0x14
117 #define TOUCHCLAMP_REG_E8FDH 0x15
118 #define TOUCHCLAMP_REG_E9FDL 0x16
119 #define TOUCHCLAMP_REG_E9FDH 0x17
120 #define TOUCHCLAMP_REG_E10FDL 0x18
121 #define TOUCHCLAMP_REG_E10FDH 0x19
122 #define TOUCHCLAMP_REG_E11FDL 0x1A
123 #define TOUCHCLAMP_REG_E11FDH 0x1B
124 #define TOUCHCLAMP_REG_E12FDL 0x1C
125 #define TOUCHCLAMP_REG_E12FDH 0x1D
126 
131 #define TOUCHCLAMP_REG_E0BV 0x1E
132 #define TOUCHCLAMP_REG_E1BV 0x1F
133 #define TOUCHCLAMP_REG_E2BV 0x20
134 #define TOUCHCLAMP_REG_E3BV 0x21
135 #define TOUCHCLAMP_REG_E4BV 0x22
136 #define TOUCHCLAMP_REG_E5BV 0x23
137 #define TOUCHCLAMP_REG_E6BV 0x24
138 #define TOUCHCLAMP_REG_E7BV 0x25
139 #define TOUCHCLAMP_REG_E8BV 0x26
140 #define TOUCHCLAMP_REG_E9BV 0x27
141 #define TOUCHCLAMP_REG_E10BV 0x28
142 #define TOUCHCLAMP_REG_E11BV 0x29
143 #define TOUCHCLAMP_REG_E12BV 0x2A
144  // MPR121 Register Defines
154 #define TOUCHCLAMP_REG_MHDR 0x2B
155 #define TOUCHCLAMP_REG_NHDR 0x2C
156 #define TOUCHCLAMP_REG_NCLR 0x2D
157 #define TOUCHCLAMP_REG_FDLR 0x2E
158 
163 #define TOUCHCLAMP_REG_MHDF 0x2F
164 #define TOUCHCLAMP_REG_NHDF 0x30
165 #define TOUCHCLAMP_REG_NCLF 0x31
166 #define TOUCHCLAMP_REG_FDLF 0x32
167 #define TOUCHCLAMP_REG_NHDT 0x33
168 #define TOUCHCLAMP_REG_NCLT 0x34
169 #define TOUCHCLAMP_REG_FDLT 0x35
170  // General electrode touch sense baseline filters
172 
181 #define TOUCHCLAMP_REG_MHDPROXR 0x36
182 #define TOUCHCLAMP_REG_NHDPROXR 0x37
183 #define TOUCHCLAMP_REG_NCLPROXR 0x38
184 #define TOUCHCLAMP_REG_FDLPROXR 0x39
185 
190 #define TOUCHCLAMP_REG_MHDPROXF 0x3A
191 #define TOUCHCLAMP_REG_NHDPROXF 0x3B
192 #define TOUCHCLAMP_REG_NCLPROXF 0x3C
193 #define TOUCHCLAMP_REG_FDLPROXF 0x3D
194 
199 #define TOUCHCLAMP_REG_NHDPROXT 0x3E
200 #define TOUCHCLAMP_REG_NCLPROXT 0x3F
201 #define TOUCHCLAMP_REG_FDLPROXT 0x40
202 
207 #define TOUCHCLAMP_REG_E0TTH 0x41
208 #define TOUCHCLAMP_REG_E0RTH 0x42
209 #define TOUCHCLAMP_REG_E1TTH 0x43
210 #define TOUCHCLAMP_REG_E1RTH 0x44
211 #define TOUCHCLAMP_REG_E2TTH 0x45
212 #define TOUCHCLAMP_REG_E2RTH 0x46
213 #define TOUCHCLAMP_REG_E3TTH 0x47
214 #define TOUCHCLAMP_REG_E3RTH 0x48
215 #define TOUCHCLAMP_REG_E4TTH 0x49
216 #define TOUCHCLAMP_REG_E4RTH 0x4A
217 #define TOUCHCLAMP_REG_E5TTH 0x4B
218 #define TOUCHCLAMP_REG_E5RTH 0x4C
219 #define TOUCHCLAMP_REG_E6TTH 0x4D
220 #define TOUCHCLAMP_REG_E6RTH 0x4E
221 #define TOUCHCLAMP_REG_E7TTH 0x4F
222 #define TOUCHCLAMP_REG_E7RTH 0x50
223 #define TOUCHCLAMP_REG_E8TTH 0x51
224 #define TOUCHCLAMP_REG_E8RTH 0x52
225 #define TOUCHCLAMP_REG_E9TTH 0x53
226 #define TOUCHCLAMP_REG_E9RTH 0x54
227 #define TOUCHCLAMP_REG_E10TTH 0x55
228 #define TOUCHCLAMP_REG_E10RTH 0x56
229 #define TOUCHCLAMP_REG_E11TTH 0x57
230 #define TOUCHCLAMP_REG_E11RTH 0x58
231 #define TOUCHCLAMP_REG_E12TTH 0x59
232 #define TOUCHCLAMP_REG_E12RTH 0x5A
233 
238 #define TOUCHCLAMP_REG_DTR 0x5B
239 
244 #define TOUCHCLAMP_REG_AFE1 0x5C
245 #define TOUCHCLAMP_REG_AFE2 0x5D
246 #define TOUCHCLAMP_REG_ECR 0x5E
247 
252 #define TOUCHCLAMP_REG_CDC0 0x5F
253 #define TOUCHCLAMP_REG_CDC1 0x60
254 #define TOUCHCLAMP_REG_CDC2 0x61
255 #define TOUCHCLAMP_REG_CDC3 0x62
256 #define TOUCHCLAMP_REG_CDC4 0x63
257 #define TOUCHCLAMP_REG_CDC5 0x64
258 #define TOUCHCLAMP_REG_CDC6 0x65
259 #define TOUCHCLAMP_REG_CDC7 0x66
260 #define TOUCHCLAMP_REG_CDC8 0x67
261 #define TOUCHCLAMP_REG_CDC9 0x68
262 #define TOUCHCLAMP_REG_CDC10 0x69
263 #define TOUCHCLAMP_REG_CDC11 0x6A
264 #define TOUCHCLAMP_REG_CDC12 0x6B
265 
270 #define TOUCHCLAMP_REG_CDT01 0x6C
271 #define TOUCHCLAMP_REG_CDT23 0x6D
272 #define TOUCHCLAMP_REG_CDT45 0x6E
273 #define TOUCHCLAMP_REG_CDT67 0x6F
274 #define TOUCHCLAMP_REG_CDT89 0x70
275 #define TOUCHCLAMP_REG_CDT1011 0x71
276 #define TOUCHCLAMP_REG_CDT11 0x72
277 
282 #define TOUCHCLAMP_REG_CTL0 0x73
283 #define TOUCHCLAMP_REG_CTL1 0x74
284 #define TOUCHCLAMP_REG_DAT 0x75
285 #define TOUCHCLAMP_REG_DIR 0x76
286 #define TOUCHCLAMP_REG_EN 0x77
287 #define TOUCHCLAMP_REG_SET 0x78
288 #define TOUCHCLAMP_REG_CLR 0x79
289 #define TOUCHCLAMP_REG_TOG 0x7A
290 
295 #define TOUCHCLAMP_REG_ACCR0 0x7B
296 #define TOUCHCLAMP_REG_ACCR1 0x7C
297 #define TOUCHCLAMP_REG_USL 0x7D
298 #define TOUCHCLAMP_REG_LSL 0x7E
299 #define TOUCHCLAMP_REG_TL 0x7F
300 
305 #define TOUCHCLAMP_REG_SRST 0x80
306  // Proximity electrode touch sense baseline filters
308 
317 #define TOUCHCLAMP_ECR_INIT_VAL 0x00
318 
323 #define TOUCHCLAMP_MHDR_MAX_VAL 0x01
324 
329 #define TOUCHCLAMP_NHDR_MIN_VAL 0x01
330 
335 #define TOUCHCLAMP_NCLR_DEF_VAL 0x10
336 
341 #define TOUCHCLAMP_FDLR_DEF_VAL 0x20
342 
347 #define TOUCHCLAMP_MHDF_DEF_VAL 0x01
348 
353 #define TOUCHCLAMP_NHDF_DEF_VAL 0x01
354 
359 #define TOUCHCLAMP_NCLF_DEF_VAL 0x10
360 
365 #define TOUCHCLAMP_FDLF_DEF_VAL 0x20
366 
371 #define TOUCHCLAMP_NHDT_DEF_VAL 0x01
372 
377 #define TOUCHCLAMP_NCLT_DEF_VAL 0x10
378 
383 #define TOUCHCLAMP_FDLT_DEF_VAL 0xFF
384 
389 #define TOUCHCLAMP_MHDPROXR_DEF_VAL 0x0F
390 
395 #define TOUCHCLAMP_NHDPROXR_DEF_VAL 0x0F
396 
401 #define TOUCHCLAMP_NCLPROXR_DEF_VAL 0x00
402 
407 #define TOUCHCLAMP_FDLPROXR_DEF_VAL 0x00
408 
413 #define TOUCHCLAMP_MHDPROXF_DEF_VAL 0x01
414 
419 #define TOUCHCLAMP_NHDPROXF_DEF_VAL 0x01
420 
425 #define TOUCHCLAMP_NCLPROXF_DEF_VAL 0xFF
426 
431 #define TOUCHCLAMP_NHDPROXT_DEF_VAL 0x00
432 
437 #define TOUCHCLAMP_DTR_DEF_VAL 0x11
438 
443 #define TOUCHCLAMP_AFE1_DEF_VAL 0xFF
444 
449 #define TOUCHCLAMP_AFE2_DEF_VAL 0x30
450 
455 #define TOUCHCLAMP_ECR_DEF_VAL 0x88
456  // Default configuration value
458 
463 #define TOUCHCLAMP_BIT_MASK_SCRATCH 0xF8
464 #define TOUCHCLAMP_BIT_MASK_SAMP_PER 0x07
465 #define TOUCHCLAMP_BIT_MASK_STOP_BIT 0xC0
466 #define TOUCHCLAMP_BIT_MASK_SW_RESET 0x63
467 
473 #define TOUCHCLAMP_TOUCH_POSITION_A 0x80
474 #define TOUCHCLAMP_TOUCH_POSITION_B 0x40
475 #define TOUCHCLAMP_TOUCH_POSITION_C 0x20
476 #define TOUCHCLAMP_TOUCH_POSITION_D 0x08
477 #define TOUCHCLAMP_TOUCH_POSITION_E 0x04
478 #define TOUCHCLAMP_TOUCH_POSITION_F 0x02
479 #define TOUCHCLAMP_TOUCH_POSITION_G 0x01
480 #define TOUCHCLAMP_TOUCH_POSITION_H 0x10
481 #define TOUCHCLAMP_NO_TOUCH 0x00
482  // End group macro
485 // --------------------------------------------------------------- PUBLIC TYPES
494 typedef struct
495 {
496  // Input pins
497 
498  digital_in_t int_pin;
499 
500  // Modules
501 
502  i2c_master_t i2c;
503 
504  // ctx variable
505 
506  uint8_t slave_address;
507 
508 } touchclamp_t;
509 
513 typedef struct
514 {
515  // Communication gpio pins
516 
517  pin_name_t scl;
518  pin_name_t sda;
519 
520  // Additional gpio pins
521 
522  pin_name_t int_pin;
523 
524  // static variable
525 
526  uint32_t i2c_speed;
527  uint8_t i2c_address;
528 
530  // End types group
532 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
533 
539 #ifdef __cplusplus
540 extern "C"{
541 #endif
542 
552 
562 
724 
735 void touchclamp_generic_write ( touchclamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
736 
747 void touchclamp_generic_read ( touchclamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
748 
757 
767 void touchclamp_set_touch_threshold ( touchclamp_t *ctx, uint8_t th_data );
768 
780 uint8_t touchclamp_get_touch_threshold ( touchclamp_t *ctx, uint8_t electrode );
781 
791 void touchclamp_set_release_threshold ( touchclamp_t *ctx, uint8_t rth_data );
792 
804 uint8_t touchclamp_get_release_threshold ( touchclamp_t *ctx, uint8_t electrode );
805 
816 
827 void touchclamp_set_sample_period ( touchclamp_t *ctx, uint8_t sample_per );
828 
839 void touchclamp_digital_toggle ( touchclamp_t *ctx, uint8_t electrode );
840 
850 
869 
870 #ifdef __cplusplus
871 }
872 #endif
873 #endif // _TOUCHCLAMP_H_
874  // End public_function group
877 
878 // ------------------------------------------------------------------------- END
touchclamp_set_sample_period
void touchclamp_set_sample_period(touchclamp_t *ctx, uint8_t sample_per)
Sets the sample period function.
touchclamp_get_release_threshold
uint8_t touchclamp_get_release_threshold(touchclamp_t *ctx, uint8_t electrode)
Get the current release threshold for a specified electrode function.
touchclamp_t::int_pin
digital_in_t int_pin
Definition: touchclamp.h:498
touchclamp_cfg_t::scl
pin_name_t scl
Definition: touchclamp.h:517
TOUCHCLAMP_RETVAL
#define TOUCHCLAMP_RETVAL
Definition: touchclamp.h:75
touchclamp_t
Click ctx object definition.
Definition: touchclamp.h:495
touchclamp_digital_toggle
void touchclamp_digital_toggle(touchclamp_t *ctx, uint8_t electrode)
Toggles electrode set as GPIO output function.
touchclamp_cfg_t::int_pin
pin_name_t int_pin
Definition: touchclamp.h:522
touchclamp_stop
void touchclamp_stop(touchclamp_t *ctx)
Stop touch clamp function.
touchclamp_get_touch_threshold
uint8_t touchclamp_get_touch_threshold(touchclamp_t *ctx, uint8_t electrode)
Get the current touch threshold for a specified electrode function.
touchclamp_set_release_threshold
void touchclamp_set_release_threshold(touchclamp_t *ctx, uint8_t rth_data)
Setting release threshold for a specified electrode function.
touchclamp_cfg_t
Click configuration structure definition.
Definition: touchclamp.h:514
touchclamp_cfg_t::i2c_address
uint8_t i2c_address
Definition: touchclamp.h:527
touchclamp_init
TOUCHCLAMP_RETVAL touchclamp_init(touchclamp_t *ctx, touchclamp_cfg_t *cfg)
Initialization function.
touchclamp_t::slave_address
uint8_t slave_address
Definition: touchclamp.h:506
touchclamp_set_touch_threshold
void touchclamp_set_touch_threshold(touchclamp_t *ctx, uint8_t th_data)
Setting touch threshold for a specified electrode function.
touchclamp_t::i2c
i2c_master_t i2c
Definition: touchclamp.h:502
touchclamp_cfg_setup
void touchclamp_cfg_setup(touchclamp_cfg_t *cfg)
Config Object Initialization function.
touchclamp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: touchclamp.h:526
touchclamp_cfg_t::sda
pin_name_t sda
Definition: touchclamp.h:518
touchclamp_default_cfg
void touchclamp_default_cfg(touchclamp_t *ctx)
Click Default Configuration function.
touchclamp_generic_write
void touchclamp_generic_write(touchclamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
touchclamp_get_touch_data
uint16_t touchclamp_get_touch_data(touchclamp_t *ctx)
Get touch data function.
touchclamp_soft_reset
void touchclamp_soft_reset(touchclamp_t *ctx)
Soft reset function.
touchclamp_get_interrupt
uint8_t touchclamp_get_interrupt(touchclamp_t *ctx)
Get state of interrupt pin function.
touchclamp_generic_read
void touchclamp_generic_read(touchclamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.