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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define TOUCHCLAMP_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define TOUCHCLAMP_RETVAL uint8_t
62 
63 #define TOUCHCLAMP_OK 0x00
64 #define TOUCHCLAMP_INIT_ERROR 0xFF
65 
67 #define TOUCHCLAMP_I2C_ADDRESS 0x5A
68 
77 #define TOUCHCLAMP_REG_TS1 0x00
78 #define TOUCHCLAMP_REG_TS2 0x01
79 #define TOUCHCLAMP_REG_OORS1 0x02
80 #define TOUCHCLAMP_REG_OORS2 0x03
81 
86 #define TOUCHCLAMP_REG_E0FDL 0x04
87 #define TOUCHCLAMP_REG_E0FDH 0x05
88 #define TOUCHCLAMP_REG_E1FDL 0x06
89 #define TOUCHCLAMP_REG_E1FDH 0x07
90 #define TOUCHCLAMP_REG_E2FDL 0x08
91 #define TOUCHCLAMP_REG_E2FDH 0x09
92 #define TOUCHCLAMP_REG_E3FDL 0x0A
93 #define TOUCHCLAMP_REG_E3FDH 0x0B
94 #define TOUCHCLAMP_REG_E4FDL 0x0C
95 #define TOUCHCLAMP_REG_E4FDH 0x0D
96 #define TOUCHCLAMP_REG_E5FDL 0x0E
97 #define TOUCHCLAMP_REG_E5FDH 0x0F
98 #define TOUCHCLAMP_REG_E6FDL 0x10
99 #define TOUCHCLAMP_REG_E6FDH 0x11
100 #define TOUCHCLAMP_REG_E7FDL 0x12
101 #define TOUCHCLAMP_REG_E7FDH 0x13
102 #define TOUCHCLAMP_REG_E8FDL 0x14
103 #define TOUCHCLAMP_REG_E8FDH 0x15
104 #define TOUCHCLAMP_REG_E9FDL 0x16
105 #define TOUCHCLAMP_REG_E9FDH 0x17
106 #define TOUCHCLAMP_REG_E10FDL 0x18
107 #define TOUCHCLAMP_REG_E10FDH 0x19
108 #define TOUCHCLAMP_REG_E11FDL 0x1A
109 #define TOUCHCLAMP_REG_E11FDH 0x1B
110 #define TOUCHCLAMP_REG_E12FDL 0x1C
111 #define TOUCHCLAMP_REG_E12FDH 0x1D
112 
117 #define TOUCHCLAMP_REG_E0BV 0x1E
118 #define TOUCHCLAMP_REG_E1BV 0x1F
119 #define TOUCHCLAMP_REG_E2BV 0x20
120 #define TOUCHCLAMP_REG_E3BV 0x21
121 #define TOUCHCLAMP_REG_E4BV 0x22
122 #define TOUCHCLAMP_REG_E5BV 0x23
123 #define TOUCHCLAMP_REG_E6BV 0x24
124 #define TOUCHCLAMP_REG_E7BV 0x25
125 #define TOUCHCLAMP_REG_E8BV 0x26
126 #define TOUCHCLAMP_REG_E9BV 0x27
127 #define TOUCHCLAMP_REG_E10BV 0x28
128 #define TOUCHCLAMP_REG_E11BV 0x29
129 #define TOUCHCLAMP_REG_E12BV 0x2A
130  // MPR121 Register Defines
140 #define TOUCHCLAMP_REG_MHDR 0x2B
141 #define TOUCHCLAMP_REG_NHDR 0x2C
142 #define TOUCHCLAMP_REG_NCLR 0x2D
143 #define TOUCHCLAMP_REG_FDLR 0x2E
144 
149 #define TOUCHCLAMP_REG_MHDF 0x2F
150 #define TOUCHCLAMP_REG_NHDF 0x30
151 #define TOUCHCLAMP_REG_NCLF 0x31
152 #define TOUCHCLAMP_REG_FDLF 0x32
153 #define TOUCHCLAMP_REG_NHDT 0x33
154 #define TOUCHCLAMP_REG_NCLT 0x34
155 #define TOUCHCLAMP_REG_FDLT 0x35
156  // General electrode touch sense baseline filters
158 
167 #define TOUCHCLAMP_REG_MHDPROXR 0x36
168 #define TOUCHCLAMP_REG_NHDPROXR 0x37
169 #define TOUCHCLAMP_REG_NCLPROXR 0x38
170 #define TOUCHCLAMP_REG_FDLPROXR 0x39
171 
176 #define TOUCHCLAMP_REG_MHDPROXF 0x3A
177 #define TOUCHCLAMP_REG_NHDPROXF 0x3B
178 #define TOUCHCLAMP_REG_NCLPROXF 0x3C
179 #define TOUCHCLAMP_REG_FDLPROXF 0x3D
180 
185 #define TOUCHCLAMP_REG_NHDPROXT 0x3E
186 #define TOUCHCLAMP_REG_NCLPROXT 0x3F
187 #define TOUCHCLAMP_REG_FDLPROXT 0x40
188 
193 #define TOUCHCLAMP_REG_E0TTH 0x41
194 #define TOUCHCLAMP_REG_E0RTH 0x42
195 #define TOUCHCLAMP_REG_E1TTH 0x43
196 #define TOUCHCLAMP_REG_E1RTH 0x44
197 #define TOUCHCLAMP_REG_E2TTH 0x45
198 #define TOUCHCLAMP_REG_E2RTH 0x46
199 #define TOUCHCLAMP_REG_E3TTH 0x47
200 #define TOUCHCLAMP_REG_E3RTH 0x48
201 #define TOUCHCLAMP_REG_E4TTH 0x49
202 #define TOUCHCLAMP_REG_E4RTH 0x4A
203 #define TOUCHCLAMP_REG_E5TTH 0x4B
204 #define TOUCHCLAMP_REG_E5RTH 0x4C
205 #define TOUCHCLAMP_REG_E6TTH 0x4D
206 #define TOUCHCLAMP_REG_E6RTH 0x4E
207 #define TOUCHCLAMP_REG_E7TTH 0x4F
208 #define TOUCHCLAMP_REG_E7RTH 0x50
209 #define TOUCHCLAMP_REG_E8TTH 0x51
210 #define TOUCHCLAMP_REG_E8RTH 0x52
211 #define TOUCHCLAMP_REG_E9TTH 0x53
212 #define TOUCHCLAMP_REG_E9RTH 0x54
213 #define TOUCHCLAMP_REG_E10TTH 0x55
214 #define TOUCHCLAMP_REG_E10RTH 0x56
215 #define TOUCHCLAMP_REG_E11TTH 0x57
216 #define TOUCHCLAMP_REG_E11RTH 0x58
217 #define TOUCHCLAMP_REG_E12TTH 0x59
218 #define TOUCHCLAMP_REG_E12RTH 0x5A
219 
224 #define TOUCHCLAMP_REG_DTR 0x5B
225 
230 #define TOUCHCLAMP_REG_AFE1 0x5C
231 #define TOUCHCLAMP_REG_AFE2 0x5D
232 #define TOUCHCLAMP_REG_ECR 0x5E
233 
238 #define TOUCHCLAMP_REG_CDC0 0x5F
239 #define TOUCHCLAMP_REG_CDC1 0x60
240 #define TOUCHCLAMP_REG_CDC2 0x61
241 #define TOUCHCLAMP_REG_CDC3 0x62
242 #define TOUCHCLAMP_REG_CDC4 0x63
243 #define TOUCHCLAMP_REG_CDC5 0x64
244 #define TOUCHCLAMP_REG_CDC6 0x65
245 #define TOUCHCLAMP_REG_CDC7 0x66
246 #define TOUCHCLAMP_REG_CDC8 0x67
247 #define TOUCHCLAMP_REG_CDC9 0x68
248 #define TOUCHCLAMP_REG_CDC10 0x69
249 #define TOUCHCLAMP_REG_CDC11 0x6A
250 #define TOUCHCLAMP_REG_CDC12 0x6B
251 
256 #define TOUCHCLAMP_REG_CDT01 0x6C
257 #define TOUCHCLAMP_REG_CDT23 0x6D
258 #define TOUCHCLAMP_REG_CDT45 0x6E
259 #define TOUCHCLAMP_REG_CDT67 0x6F
260 #define TOUCHCLAMP_REG_CDT89 0x70
261 #define TOUCHCLAMP_REG_CDT1011 0x71
262 #define TOUCHCLAMP_REG_CDT11 0x72
263 
268 #define TOUCHCLAMP_REG_CTL0 0x73
269 #define TOUCHCLAMP_REG_CTL1 0x74
270 #define TOUCHCLAMP_REG_DAT 0x75
271 #define TOUCHCLAMP_REG_DIR 0x76
272 #define TOUCHCLAMP_REG_EN 0x77
273 #define TOUCHCLAMP_REG_SET 0x78
274 #define TOUCHCLAMP_REG_CLR 0x79
275 #define TOUCHCLAMP_REG_TOG 0x7A
276 
281 #define TOUCHCLAMP_REG_ACCR0 0x7B
282 #define TOUCHCLAMP_REG_ACCR1 0x7C
283 #define TOUCHCLAMP_REG_USL 0x7D
284 #define TOUCHCLAMP_REG_LSL 0x7E
285 #define TOUCHCLAMP_REG_TL 0x7F
286 
291 #define TOUCHCLAMP_REG_SRST 0x80
292  // Proximity electrode touch sense baseline filters
294 
303 #define TOUCHCLAMP_ECR_INIT_VAL 0x00
304 
309 #define TOUCHCLAMP_MHDR_MAX_VAL 0x01
310 
315 #define TOUCHCLAMP_NHDR_MIN_VAL 0x01
316 
321 #define TOUCHCLAMP_NCLR_DEF_VAL 0x10
322 
327 #define TOUCHCLAMP_FDLR_DEF_VAL 0x20
328 
333 #define TOUCHCLAMP_MHDF_DEF_VAL 0x01
334 
339 #define TOUCHCLAMP_NHDF_DEF_VAL 0x01
340 
345 #define TOUCHCLAMP_NCLF_DEF_VAL 0x10
346 
351 #define TOUCHCLAMP_FDLF_DEF_VAL 0x20
352 
357 #define TOUCHCLAMP_NHDT_DEF_VAL 0x01
358 
363 #define TOUCHCLAMP_NCLT_DEF_VAL 0x10
364 
369 #define TOUCHCLAMP_FDLT_DEF_VAL 0xFF
370 
375 #define TOUCHCLAMP_MHDPROXR_DEF_VAL 0x0F
376 
381 #define TOUCHCLAMP_NHDPROXR_DEF_VAL 0x0F
382 
387 #define TOUCHCLAMP_NCLPROXR_DEF_VAL 0x00
388 
393 #define TOUCHCLAMP_FDLPROXR_DEF_VAL 0x00
394 
399 #define TOUCHCLAMP_MHDPROXF_DEF_VAL 0x01
400 
405 #define TOUCHCLAMP_NHDPROXF_DEF_VAL 0x01
406 
411 #define TOUCHCLAMP_NCLPROXF_DEF_VAL 0xFF
412 
417 #define TOUCHCLAMP_NHDPROXT_DEF_VAL 0x00
418 
423 #define TOUCHCLAMP_DTR_DEF_VAL 0x11
424 
429 #define TOUCHCLAMP_AFE1_DEF_VAL 0xFF
430 
435 #define TOUCHCLAMP_AFE2_DEF_VAL 0x30
436 
441 #define TOUCHCLAMP_ECR_DEF_VAL 0x88
442  // Default configuration value
444 
449 #define TOUCHCLAMP_BIT_MASK_SCRATCH 0xF8
450 #define TOUCHCLAMP_BIT_MASK_SAMP_PER 0x07
451 #define TOUCHCLAMP_BIT_MASK_STOP_BIT 0xC0
452 #define TOUCHCLAMP_BIT_MASK_SW_RESET 0x63
453 
459 #define TOUCHCLAMP_TOUCH_POSITION_A 0x80
460 #define TOUCHCLAMP_TOUCH_POSITION_B 0x40
461 #define TOUCHCLAMP_TOUCH_POSITION_C 0x20
462 #define TOUCHCLAMP_TOUCH_POSITION_D 0x08
463 #define TOUCHCLAMP_TOUCH_POSITION_E 0x04
464 #define TOUCHCLAMP_TOUCH_POSITION_F 0x02
465 #define TOUCHCLAMP_TOUCH_POSITION_G 0x01
466 #define TOUCHCLAMP_TOUCH_POSITION_H 0x10
467 #define TOUCHCLAMP_NO_TOUCH 0x00
468  // End group macro
471 // --------------------------------------------------------------- PUBLIC TYPES
480 typedef struct
481 {
482  // Input pins
483 
484  digital_in_t int_pin;
485 
486  // Modules
487 
488  i2c_master_t i2c;
489 
490  // ctx variable
491 
492  uint8_t slave_address;
493 
494 } touchclamp_t;
495 
499 typedef struct
500 {
501  // Communication gpio pins
502 
503  pin_name_t scl;
504  pin_name_t sda;
505 
506  // Additional gpio pins
507 
508  pin_name_t int_pin;
509 
510  // static variable
511 
512  uint32_t i2c_speed;
513  uint8_t i2c_address;
514 
516  // End types group
518 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
519 
525 #ifdef __cplusplus
526 extern "C"{
527 #endif
528 
538 
548 
710 
721 void touchclamp_generic_write ( touchclamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
722 
733 void touchclamp_generic_read ( touchclamp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
734 
742 void touchclamp_soft_reset ( touchclamp_t *ctx );
743 
753 void touchclamp_set_touch_threshold ( touchclamp_t *ctx, uint8_t th_data );
754 
766 uint8_t touchclamp_get_touch_threshold ( touchclamp_t *ctx, uint8_t electrode );
767 
777 void touchclamp_set_release_threshold ( touchclamp_t *ctx, uint8_t rth_data );
778 
790 uint8_t touchclamp_get_release_threshold ( touchclamp_t *ctx, uint8_t electrode );
791 
801 uint16_t touchclamp_get_touch_data ( touchclamp_t *ctx );
802 
813 void touchclamp_set_sample_period ( touchclamp_t *ctx, uint8_t sample_per );
814 
825 void touchclamp_digital_toggle ( touchclamp_t *ctx, uint8_t electrode );
826 
835 void touchclamp_stop ( touchclamp_t *ctx );
836 
854 uint8_t touchclamp_get_interrupt ( touchclamp_t *ctx );
855 
856 #ifdef __cplusplus
857 }
858 #endif
859 #endif // _TOUCHCLAMP_H_
860  // End public_function group
863 
864 // ------------------------------------------------------------------------- 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:484
touchclamp_cfg_t::scl
pin_name_t scl
Definition: touchclamp.h:503
TOUCHCLAMP_RETVAL
#define TOUCHCLAMP_RETVAL
Definition: touchclamp.h:61
touchclamp_t
Click ctx object definition.
Definition: touchclamp.h:480
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:508
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:499
touchclamp_cfg_t::i2c_address
uint8_t i2c_address
Definition: touchclamp.h:513
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:492
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:488
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:512
touchclamp_cfg_t::sda
pin_name_t sda
Definition: touchclamp.h:504
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.