captouch5  2.0.0.0
captouch5.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 CAPTOUCH5_H
36 #define CAPTOUCH5_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_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define CAPTOUCH5_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
66 
73 #define CAPTOUCH5_RETVAL uint8_t
74 
75 #define CAPTOUCH5_OK 0x00
76 #define CAPTOUCH5_INIT_ERROR 0xFF
77 
79 #define CAPTOUCH5_I2C_SLAVE_ADDRESS 0x37
80 
85 #define CAPTOUCH5_REG_SENSOR_EN 0x00
86 #define CAPTOUCH5_REG_FSS_EN 0x02
87 #define CAPTOUCH5_REG_SENSITIVITY0 0x08
88 #define CAPTOUCH5_REG_SENSITIVITY1 0x09
89 #define CAPTOUCH5_REG_SENSITIVITY2 0x0A
90 #define CAPTOUCH5_REG_SENSITIVITY3 0x0B
91 #define CAPTOUCH5_REG_BASE_THRESHOLD0 0x0C
92 #define CAPTOUCH5_REG_BASE_THRESHOLD1 0x0D
93 #define CAPTOUCH5_REG_FINGER_THRESHOLD2 0x0E
94 #define CAPTOUCH5_REG_FINGER_THRESHOLD3 0x0F
95 #define CAPTOUCH5_REG_FINGER_THRESHOLD4 0x10
96 #define CAPTOUCH5_REG_FINGER_THRESHOLD5 0x11
97 #define CAPTOUCH5_REG_FINGER_THRESHOLD6 0x12
98 #define CAPTOUCH5_REG_FINGER_THRESHOLD7 0x13
99 #define CAPTOUCH5_REG_FINGER_THRESHOLD8 0x14
100 #define CAPTOUCH5_REG_FINGER_THRESHOLD9 0x15
101 #define CAPTOUCH5_REG_FINGER_THRESHOLD10 0x16
102 #define CAPTOUCH5_REG_FINGER_THRESHOLD11 0x17
103 #define CAPTOUCH5_REG_FINGER_THRESHOLD12 0x18
104 #define CAPTOUCH5_REG_FINGER_THRESHOLD13 0x19
105 #define CAPTOUCH5_REG_FINGER_THRESHOLD14 0x1A
106 #define CAPTOUCH5_REG_FINGER_THRESHOLD15 0x1B
107 #define CAPTOUCH5_REG_SENSOR_DEBOUNCE 0x1C
108 #define CAPTOUCH5_REG_BUTTON_HYS 0x1D
109 #define CAPTOUCH5_REG_BUTTON_LBR 0x1F
110 #define CAPTOUCH5_REG_BUTTON_NNT 0x20
111 #define CAPTOUCH5_REG_BUTTON_NT 0x21
112 #define CAPTOUCH5_REG_PROX_EN 0x26
113 #define CAPTOUCH5_REG_PROX_CFG 0x27
114 #define CAPTOUCH5_REG_PROX_TOUCH_TH0 0x28
115 #define CAPTOUCH5_REG_PROX_TOUCH_TH1 0x2A
116 #define CAPTOUCH5_REG_PROX_RESOLUTION0 0x2E
117 #define CAPTOUCH5_REG_PROX_RESOLUTION1 0x2F
118 #define CAPTOUCH5_REG_PROX_HYS 0x30
119 #define CAPTOUCH5_REG_PROX_LBR 0x32
120 #define CAPTOUCH5_REG_PROX_NNT 0x33
121 #define CAPTOUCH5_REG_PROX_NT 0x34
122 #define CAPTOUCH5_REG_BUZZER_CFG 0x3E
123 #define CAPTOUCH5_REG_BUZZER_ON_TIME 0x3F
124 #define CAPTOUCH5_REG_SPO_CFG 0x4C
125 #define CAPTOUCH5_REG_DEVICE_CFG0 0x4D
126 #define CAPTOUCH5_REG_DEVICE_CFG1 0x4E
127 #define CAPTOUCH5_REG_DEVICE_CFG2 0x4F
128 #define CAPTOUCH5_REG_DEVICE_CFG3 0x50
129 #define CAPTOUCH5_REG_I2C_ADDR 0x51
130 #define CAPTOUCH5_REG_REFRESH_CTRL 0x52
131 #define CAPTOUCH5_REG_STATE_TIMEOUT 0x55
132 #define CAPTOUCH5_REG_SLIDER_CFG 0x5D
133 #define CAPTOUCH5_REG_SLIDER1_CFG 0x61
134 #define CAPTOUCH5_REG_SLIDER1_RESOLUTION 0x62
135 #define CAPTOUCH5_REG_SLIDER1_THRESHOLD 0x63
136 #define CAPTOUCH5_REG_SLIDER2_CFG 0x67
137 #define CAPTOUCH5_REG_SLIDER2_RESOLUTION 0x68
138 #define CAPTOUCH5_REG_SLIDER2_THRESHOLD 0x69
139 #define CAPTOUCH5_REG_SLIDER_LBR 0x71
140 #define CAPTOUCH5_REG_SLIDER_NNT 0x72
141 #define CAPTOUCH5_REG_SLIDER_NT 0x73
142 #define CAPTOUCH5_REG_SCRATCHPAD0 0x7A
143 #define CAPTOUCH5_REG_SCRATCHPAD1 0x7B
144 #define CAPTOUCH5_REG_CONFIG_CRC 0x7E
145 #define CAPTOUCH5_REG_SENSOR_ID 0x82
146 #define CAPTOUCH5_REG_CTRL_CMD 0x86
147 #define CAPTOUCH5_REG_CTRL_CMD_STATUS 0x88
148 #define CAPTOUCH5_REG_CTRL_CMD_ERR 0x89
149 #define CAPTOUCH5_REG_SYSTEM_STATUS 0x8A
150 #define CAPTOUCH5_REG_PREV_CTRL_CMD_CODE 0x8C
151 #define CAPTOUCH5_REG_FAMILY_ID 0x8F
152 #define CAPTOUCH5_REG_DEVICE_ID 0x90
153 #define CAPTOUCH5_REG_DEVICE_REV 0x92
154 #define CAPTOUCH5_REG_CALC_CRC 0x94
155 #define CAPTOUCH5_REG_TOTAL_WORKING_SNS 0x97
156 #define CAPTOUCH5_REG_SNS_CP_HIGH 0x98
157 #define CAPTOUCH5_REG_SNS_VDD_SHORT 0x9A
158 #define CAPTOUCH5_REG_SNS_GND_SHORT 0x9C
159 #define CAPTOUCH5_REG_CMOD_SHIELD_TEST 0xA0
160 #define CAPTOUCH5_REG_BUTTON_STAT 0xAA
161 #define CAPTOUCH5_REG_LATCHED_BUTTON_STAT 0xAC
162 #define CAPTOUCH5_REG_PROX_STAT 0xAE
163 #define CAPTOUCH5_REG_LATCHED_PROx_STAT 0xAF
164 #define CAPTOUCH5_REG_SLIDER1_POSITION 0xB0
165 #define CAPTOUCH5_REG_LIFTOFF_SLIDER1_POSITION 0xB1
166 #define CAPTOUCH5_REG_SLIDER2_POSITION 0xB2
167 #define CAPTOUCH5_REG_LIFTOFF_SLIDER2_POSITION 0xB3
168 #define CAPTOUCH5_REG_SYNC_COUNTER0 0xB9
169 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR0 0xBA
170 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR1 0xBC
171 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR2 0xBE
172 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR3 0xC0
173 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR4 0xC2
174 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR5 0xC4
175 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR6 0xC6
176 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR7 0xC8
177 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR8 0xCA
178 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR9 0xCC
179 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR10 0xCE
180 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR11 0xD0
181 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR12 0xD2
182 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR13 0xD4
183 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR14 0xD6
184 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR15 0xD8
185 #define CAPTOUCH5_REG_SYNC_COUNTER1 0xDB
186 #define CAPTOUCH5_REG_DEBUG_SENSOR_ID 0xDC
187 #define CAPTOUCH5_REG_DEBUG_CP 0xDD
188 #define CAPTOUCH5_REG_DIFFERENCE_COUNT0 0xDE
189 #define CAPTOUCH5_REG_DEBUG_BASELINE0 0xE0
190 #define CAPTOUCH5_REG_DEBUG_RAW_COUNT0 0xE2
191 #define CAPTOUCH5_REG_DEBUG_AVG_RAW_COUNT0 0xE4
192 #define CAPTOUCH5_REG_SYNC_COUNTER2 0xE7
193 
199 #define CAPTOUCH5_BUTTON_PRESSED 1
200 #define CAPTOUCH5_BUTTON_NOT_PRESSED 0
201 
207 #define CAPTOUCH5_CFG0_IIR_FILTER_ENABLED 1
208 #define CAPTOUCH5_CFG0_IIR_FILTER_DISABLED 1
209 #define CAPTOUCH5_CFG0_MED_FILTER_ENABLED 1
210 #define CAPTOUCH5_CFG0_MED_FILTER_DISABLED 1
211 
217 #define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_ENABLED 1
218 #define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_DISABLED 1
219 
225 #define CAPTOUCH5_CFG2_SHIELD_ENABLED 1
226 #define CAPTOUCH5_CFG2_SHIELD_DISABLED 0
227 #define CAPTOUCH5_CFG2_GUARD_SENS_ENABLED 1
228 #define CAPTOUCH5_CFG2_GUARD_SENS_DISABLED 0
229 #define CAPTOUCH5_CFG2_EMC_ENABLED 1
230 #define CAPTOUCH5_CFG2_EMC_DISABLED 0
231 #define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_ENABLED 1
232 #define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_DISABLED 0
233 #define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_DISABLED 0
234 #define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_5_SEC 1
235 #define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_20_SEC 2
236 #define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_DISABLED 0
237 #define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_5_SEC 1
238 #define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_20_SEC 2
239 
245 #define CAPTOUCH5_CFG3_POWER_SUPPLY_INTERNALLY 0
246 #define CAPTOUCH5_CFG3_POWER_SUPPLY_EXTERNALLY 1
247 
253 #define CAPTOUCH5_SLIDER_SENS_0p1 0
254 #define CAPTOUCH5_SLIDER_SENS_0p2 1
255 #define CAPTOUCH5_SLIDER_SENS_0p3 2
256 #define CAPTOUCH5_SLIDER_SENS_0p4 3
257 
263 #define CAPTOUCH5_BUTTON_SENS_ENABLED 0xFFFF
264 #define CAPTOUCH5_BUTTON_SENS_DISABLED 0x0000
265 
271 #define CAPTOUCH5_DEVICE_ID 2566
272 #define CAPTOUCH5_FAMILY_ID 154
273 
280 #define CAPTOUCH5_ERROR 1
281 #define CAPTOUCH5_NO_ERROR 0
282  // End group macro
285 // --------------------------------------------------------------- PUBLIC TYPES
294 typedef struct
295 {
296 
297  // Modules
298 
299  i2c_master_t i2c;
300 
301  // ctx variable
302 
303  uint8_t slave_address;
304 
305 } captouch5_t;
306 
310 typedef struct
311 {
312  // Communication gpio pins
313 
314  pin_name_t scl;
315  pin_name_t sda;
316 
317  // static variable
318 
319  uint32_t i2c_speed;
320  uint8_t i2c_address;
321 
323 
324 
325 typedef struct
326 {
327  uint8_t button1;
328  uint8_t button2;
329  uint8_t button3;
330  uint8_t button4;
332 
333 typedef struct
334 {
335  uint8_t iirFilter;
336  uint8_t medFilter;
338 
339 typedef struct
340 {
341  uint8_t sysDiagnostic;
343 
344 typedef struct
345 {
348  uint8_t autoThreshold;
349  uint8_t emcSolution;
350  uint8_t guardSens;
351  uint8_t shieldSens;
353 
354 typedef struct
355 {
356  uint8_t powerSupply;
358 
359 
360 typedef struct
361 {
367  // End types group
369 
370 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
371 
377 #ifdef __cplusplus
378 extern "C"{
379 #endif
380 
390 
399 
409 
420 void captouch5_generic_write ( captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
421 
433 void captouch5_generic_read ( captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
434 
444 
455 uint16_t captouch5_read_two_bytes ( captouch5_t *ctx, uint8_t reg_addr );
456 
466 void captouch5_write_two_bytes ( captouch5_t *ctx, uint8_t reg_addr, uint16_t data_buf );
467 
478 uint8_t captouch5_read_byte ( captouch5_t *ctx, uint8_t reg_addr );
479 
489 void captouch5_write_byte ( captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf );
490 
501 
512 
523 
533 
544 
553 
562 void captouch5_config_sensors ( captouch5_t *ctx, uint16_t sens_data );
563 
572 void captouch5_config_slider ( captouch5_t *ctx, uint8_t slider_data );
573 
574 
575 #ifdef __cplusplus
576 }
577 #endif
578 #endif // _CAPTOUCH5_H_
579  // End public_function group
582 
583 // ------------------------------------------------------------------------- END
T_CAPTOUCH5_CONFIG2::proximityAutoReset
uint8_t proximityAutoReset
Definition: captouch5.h:346
T_CAPTOUCH5_BUTTONS::button1
uint8_t button1
Definition: captouch5.h:327
T_CAPTOUCH5_DEVICE_CONFIG::cfg3
T_CAPTOUCH5_CONFIG3 cfg3
Definition: captouch5.h:365
T_CAPTOUCH5_CONFIG0
Definition: captouch5.h:334
T_CAPTOUCH5_CONFIG2::guardSens
uint8_t guardSens
Definition: captouch5.h:350
captouch5_generic_read
void captouch5_generic_read(captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
T_CAPTOUCH5_CONFIG2::autoThreshold
uint8_t autoThreshold
Definition: captouch5.h:348
T_CAPTOUCH5_CONFIG3
Definition: captouch5.h:355
captouch5_default_cfg
void captouch5_default_cfg(captouch5_t *ctx, T_CAPTOUCH5_DEVICE_CONFIG *device_cfg)
Click Default Configuration function.
captouch5_read_button_status
void captouch5_read_button_status(captouch5_t *ctx, T_CAPTOUCH5_BUTTONS *buttons)
Function read button status.
captouch5_cfg_t::i2c_address
uint8_t i2c_address
Definition: captouch5.h:320
T_CAPTOUCH5_CONFIG2::buttonAutoReset
uint8_t buttonAutoReset
Definition: captouch5.h:347
T_CAPTOUCH5_DEVICE_CONFIG
Definition: captouch5.h:361
captouch5_cfg_t::sda
pin_name_t sda
Definition: captouch5.h:315
captouch5_cfg_t::scl
pin_name_t scl
Definition: captouch5.h:314
T_CAPTOUCH5_CONFIG3::powerSupply
uint8_t powerSupply
Definition: captouch5.h:356
CAPTOUCH5_RETVAL
#define CAPTOUCH5_RETVAL
Definition: captouch5.h:73
T_CAPTOUCH5_CONFIG2::shieldSens
uint8_t shieldSens
Definition: captouch5.h:351
captouch5_write_byte
void captouch5_write_byte(captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf)
Generic write 8bit data function.
captouch5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: captouch5.h:319
T_CAPTOUCH5_CONFIG2::emcSolution
uint8_t emcSolution
Definition: captouch5.h:349
T_CAPTOUCH5_CONFIG0::medFilter
uint8_t medFilter
Definition: captouch5.h:336
T_CAPTOUCH5_DEVICE_CONFIG::cfg0
T_CAPTOUCH5_CONFIG0 cfg0
Definition: captouch5.h:362
captouch5_get_device_id
uint16_t captouch5_get_device_id(captouch5_t *ctx)
Function for geting device id.
captouch5_config_sensors
void captouch5_config_sensors(captouch5_t *ctx, uint16_t sens_data)
Function for configuring sensor.
captouch5_t::slave_address
uint8_t slave_address
Definition: captouch5.h:303
captouch5_write_two_bytes
void captouch5_write_two_bytes(captouch5_t *ctx, uint8_t reg_addr, uint16_t data_buf)
Generic write 16bit data function.
T_CAPTOUCH5_BUTTONS::button3
uint8_t button3
Definition: captouch5.h:329
captouch5_cfg_setup
void captouch5_cfg_setup(captouch5_cfg_t *cfg)
Config Object Initialization function.
captouch5_read_byte
uint8_t captouch5_read_byte(captouch5_t *ctx, uint8_t reg_addr)
Generic read 8bit data function.
T_CAPTOUCH5_CONFIG2
Definition: captouch5.h:345
T_CAPTOUCH5_BUTTONS::button2
uint8_t button2
Definition: captouch5.h:328
captouch5_software_reset
void captouch5_software_reset(captouch5_t *ctx)
Function to reset device.
captouch5_get_family_id
uint8_t captouch5_get_family_id(captouch5_t *ctx)
Function for geting family id.
captouch5_read_two_bytes
uint16_t captouch5_read_two_bytes(captouch5_t *ctx, uint8_t reg_addr)
Generic read 16bit data function.
captouch5_process
uint8_t captouch5_process(captouch5_t *ctx)
Function for checking error.
T_CAPTOUCH5_BUTTONS::button4
uint8_t button4
Definition: captouch5.h:330
T_CAPTOUCH5_CONFIG0::iirFilter
uint8_t iirFilter
Definition: captouch5.h:335
captouch5_t::i2c
i2c_master_t i2c
Definition: captouch5.h:299
captouch5_read_slider_position
uint16_t captouch5_read_slider_position(captouch5_t *ctx)
Function for reading slider position.
T_CAPTOUCH5_CONFIG1
Definition: captouch5.h:340
captouch5_init
CAPTOUCH5_RETVAL captouch5_init(captouch5_t *ctx, captouch5_cfg_t *cfg)
Initialization function.
T_CAPTOUCH5_BUTTONS
Definition: captouch5.h:326
captouch5_t
Click ctx object definition.
Definition: captouch5.h:295
captouch5_cfg_t
Click configuration structure definition.
Definition: captouch5.h:311
T_CAPTOUCH5_CONFIG1::sysDiagnostic
uint8_t sysDiagnostic
Definition: captouch5.h:341
captouch5_config_slider
void captouch5_config_slider(captouch5_t *ctx, uint8_t slider_data)
Function for configuring slider.
captouch5_generic_write
void captouch5_generic_write(captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
T_CAPTOUCH5_DEVICE_CONFIG::cfg1
T_CAPTOUCH5_CONFIG1 cfg1
Definition: captouch5.h:363
captouch5_device_config
void captouch5_device_config(captouch5_t *ctx, T_CAPTOUCH5_DEVICE_CONFIG *device_cfg)
Function for configuring device.
T_CAPTOUCH5_DEVICE_CONFIG::cfg2
T_CAPTOUCH5_CONFIG2 cfg2
Definition: captouch5.h:364