captouch5  2.0.0.0
captouch5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef CAPTOUCH5_H
36 #define CAPTOUCH5_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define CAPTOUCH5_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
56 
63 #define CAPTOUCH5_RETVAL uint8_t
64 
65 #define CAPTOUCH5_OK 0x00
66 #define CAPTOUCH5_INIT_ERROR 0xFF
67 
69 #define CAPTOUCH5_I2C_SLAVE_ADDRESS 0x37
70 
75 #define CAPTOUCH5_REG_SENSOR_EN 0x00
76 #define CAPTOUCH5_REG_FSS_EN 0x02
77 #define CAPTOUCH5_REG_SENSITIVITY0 0x08
78 #define CAPTOUCH5_REG_SENSITIVITY1 0x09
79 #define CAPTOUCH5_REG_SENSITIVITY2 0x0A
80 #define CAPTOUCH5_REG_SENSITIVITY3 0x0B
81 #define CAPTOUCH5_REG_BASE_THRESHOLD0 0x0C
82 #define CAPTOUCH5_REG_BASE_THRESHOLD1 0x0D
83 #define CAPTOUCH5_REG_FINGER_THRESHOLD2 0x0E
84 #define CAPTOUCH5_REG_FINGER_THRESHOLD3 0x0F
85 #define CAPTOUCH5_REG_FINGER_THRESHOLD4 0x10
86 #define CAPTOUCH5_REG_FINGER_THRESHOLD5 0x11
87 #define CAPTOUCH5_REG_FINGER_THRESHOLD6 0x12
88 #define CAPTOUCH5_REG_FINGER_THRESHOLD7 0x13
89 #define CAPTOUCH5_REG_FINGER_THRESHOLD8 0x14
90 #define CAPTOUCH5_REG_FINGER_THRESHOLD9 0x15
91 #define CAPTOUCH5_REG_FINGER_THRESHOLD10 0x16
92 #define CAPTOUCH5_REG_FINGER_THRESHOLD11 0x17
93 #define CAPTOUCH5_REG_FINGER_THRESHOLD12 0x18
94 #define CAPTOUCH5_REG_FINGER_THRESHOLD13 0x19
95 #define CAPTOUCH5_REG_FINGER_THRESHOLD14 0x1A
96 #define CAPTOUCH5_REG_FINGER_THRESHOLD15 0x1B
97 #define CAPTOUCH5_REG_SENSOR_DEBOUNCE 0x1C
98 #define CAPTOUCH5_REG_BUTTON_HYS 0x1D
99 #define CAPTOUCH5_REG_BUTTON_LBR 0x1F
100 #define CAPTOUCH5_REG_BUTTON_NNT 0x20
101 #define CAPTOUCH5_REG_BUTTON_NT 0x21
102 #define CAPTOUCH5_REG_PROX_EN 0x26
103 #define CAPTOUCH5_REG_PROX_CFG 0x27
104 #define CAPTOUCH5_REG_PROX_TOUCH_TH0 0x28
105 #define CAPTOUCH5_REG_PROX_TOUCH_TH1 0x2A
106 #define CAPTOUCH5_REG_PROX_RESOLUTION0 0x2E
107 #define CAPTOUCH5_REG_PROX_RESOLUTION1 0x2F
108 #define CAPTOUCH5_REG_PROX_HYS 0x30
109 #define CAPTOUCH5_REG_PROX_LBR 0x32
110 #define CAPTOUCH5_REG_PROX_NNT 0x33
111 #define CAPTOUCH5_REG_PROX_NT 0x34
112 #define CAPTOUCH5_REG_BUZZER_CFG 0x3E
113 #define CAPTOUCH5_REG_BUZZER_ON_TIME 0x3F
114 #define CAPTOUCH5_REG_SPO_CFG 0x4C
115 #define CAPTOUCH5_REG_DEVICE_CFG0 0x4D
116 #define CAPTOUCH5_REG_DEVICE_CFG1 0x4E
117 #define CAPTOUCH5_REG_DEVICE_CFG2 0x4F
118 #define CAPTOUCH5_REG_DEVICE_CFG3 0x50
119 #define CAPTOUCH5_REG_I2C_ADDR 0x51
120 #define CAPTOUCH5_REG_REFRESH_CTRL 0x52
121 #define CAPTOUCH5_REG_STATE_TIMEOUT 0x55
122 #define CAPTOUCH5_REG_SLIDER_CFG 0x5D
123 #define CAPTOUCH5_REG_SLIDER1_CFG 0x61
124 #define CAPTOUCH5_REG_SLIDER1_RESOLUTION 0x62
125 #define CAPTOUCH5_REG_SLIDER1_THRESHOLD 0x63
126 #define CAPTOUCH5_REG_SLIDER2_CFG 0x67
127 #define CAPTOUCH5_REG_SLIDER2_RESOLUTION 0x68
128 #define CAPTOUCH5_REG_SLIDER2_THRESHOLD 0x69
129 #define CAPTOUCH5_REG_SLIDER_LBR 0x71
130 #define CAPTOUCH5_REG_SLIDER_NNT 0x72
131 #define CAPTOUCH5_REG_SLIDER_NT 0x73
132 #define CAPTOUCH5_REG_SCRATCHPAD0 0x7A
133 #define CAPTOUCH5_REG_SCRATCHPAD1 0x7B
134 #define CAPTOUCH5_REG_CONFIG_CRC 0x7E
135 #define CAPTOUCH5_REG_SENSOR_ID 0x82
136 #define CAPTOUCH5_REG_CTRL_CMD 0x86
137 #define CAPTOUCH5_REG_CTRL_CMD_STATUS 0x88
138 #define CAPTOUCH5_REG_CTRL_CMD_ERR 0x89
139 #define CAPTOUCH5_REG_SYSTEM_STATUS 0x8A
140 #define CAPTOUCH5_REG_PREV_CTRL_CMD_CODE 0x8C
141 #define CAPTOUCH5_REG_FAMILY_ID 0x8F
142 #define CAPTOUCH5_REG_DEVICE_ID 0x90
143 #define CAPTOUCH5_REG_DEVICE_REV 0x92
144 #define CAPTOUCH5_REG_CALC_CRC 0x94
145 #define CAPTOUCH5_REG_TOTAL_WORKING_SNS 0x97
146 #define CAPTOUCH5_REG_SNS_CP_HIGH 0x98
147 #define CAPTOUCH5_REG_SNS_VDD_SHORT 0x9A
148 #define CAPTOUCH5_REG_SNS_GND_SHORT 0x9C
149 #define CAPTOUCH5_REG_CMOD_SHIELD_TEST 0xA0
150 #define CAPTOUCH5_REG_BUTTON_STAT 0xAA
151 #define CAPTOUCH5_REG_LATCHED_BUTTON_STAT 0xAC
152 #define CAPTOUCH5_REG_PROX_STAT 0xAE
153 #define CAPTOUCH5_REG_LATCHED_PROx_STAT 0xAF
154 #define CAPTOUCH5_REG_SLIDER1_POSITION 0xB0
155 #define CAPTOUCH5_REG_LIFTOFF_SLIDER1_POSITION 0xB1
156 #define CAPTOUCH5_REG_SLIDER2_POSITION 0xB2
157 #define CAPTOUCH5_REG_LIFTOFF_SLIDER2_POSITION 0xB3
158 #define CAPTOUCH5_REG_SYNC_COUNTER0 0xB9
159 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR0 0xBA
160 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR1 0xBC
161 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR2 0xBE
162 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR3 0xC0
163 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR4 0xC2
164 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR5 0xC4
165 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR6 0xC6
166 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR7 0xC8
167 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR8 0xCA
168 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR9 0xCC
169 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR10 0xCE
170 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR11 0xD0
171 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR12 0xD2
172 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR13 0xD4
173 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR14 0xD6
174 #define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR15 0xD8
175 #define CAPTOUCH5_REG_SYNC_COUNTER1 0xDB
176 #define CAPTOUCH5_REG_DEBUG_SENSOR_ID 0xDC
177 #define CAPTOUCH5_REG_DEBUG_CP 0xDD
178 #define CAPTOUCH5_REG_DIFFERENCE_COUNT0 0xDE
179 #define CAPTOUCH5_REG_DEBUG_BASELINE0 0xE0
180 #define CAPTOUCH5_REG_DEBUG_RAW_COUNT0 0xE2
181 #define CAPTOUCH5_REG_DEBUG_AVG_RAW_COUNT0 0xE4
182 #define CAPTOUCH5_REG_SYNC_COUNTER2 0xE7
183 
189 #define CAPTOUCH5_BUTTON_PRESSED 1
190 #define CAPTOUCH5_BUTTON_NOT_PRESSED 0
191 
197 #define CAPTOUCH5_CFG0_IIR_FILTER_ENABLED 1
198 #define CAPTOUCH5_CFG0_IIR_FILTER_DISABLED 1
199 #define CAPTOUCH5_CFG0_MED_FILTER_ENABLED 1
200 #define CAPTOUCH5_CFG0_MED_FILTER_DISABLED 1
201 
207 #define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_ENABLED 1
208 #define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_DISABLED 1
209 
215 #define CAPTOUCH5_CFG2_SHIELD_ENABLED 1
216 #define CAPTOUCH5_CFG2_SHIELD_DISABLED 0
217 #define CAPTOUCH5_CFG2_GUARD_SENS_ENABLED 1
218 #define CAPTOUCH5_CFG2_GUARD_SENS_DISABLED 0
219 #define CAPTOUCH5_CFG2_EMC_ENABLED 1
220 #define CAPTOUCH5_CFG2_EMC_DISABLED 0
221 #define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_ENABLED 1
222 #define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_DISABLED 0
223 #define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_DISABLED 0
224 #define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_5_SEC 1
225 #define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_20_SEC 2
226 #define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_DISABLED 0
227 #define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_5_SEC 1
228 #define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_20_SEC 2
229 
235 #define CAPTOUCH5_CFG3_POWER_SUPPLY_INTERNALLY 0
236 #define CAPTOUCH5_CFG3_POWER_SUPPLY_EXTERNALLY 1
237 
243 #define CAPTOUCH5_SLIDER_SENS_0p1 0
244 #define CAPTOUCH5_SLIDER_SENS_0p2 1
245 #define CAPTOUCH5_SLIDER_SENS_0p3 2
246 #define CAPTOUCH5_SLIDER_SENS_0p4 3
247 
253 #define CAPTOUCH5_BUTTON_SENS_ENABLED 0xFFFF
254 #define CAPTOUCH5_BUTTON_SENS_DISABLED 0x0000
255 
261 #define CAPTOUCH5_DEVICE_ID 2566
262 #define CAPTOUCH5_FAMILY_ID 154
263 
270 #define CAPTOUCH5_ERROR 1
271 #define CAPTOUCH5_NO_ERROR 0
272  // End group macro
275 // --------------------------------------------------------------- PUBLIC TYPES
284 typedef struct
285 {
286 
287  // Modules
288 
289  i2c_master_t i2c;
290 
291  // ctx variable
292 
293  hal_i2c_address_t slave_address;
294 
295 } captouch5_t;
296 
300 typedef struct
301 {
302  // Communication gpio pins
303 
304  pin_name_t scl;
305  pin_name_t sda;
306 
307  // static variable
308 
309  hal_i2c_speed_t i2c_speed;
310  hal_i2c_address_t i2c_address;
311 
313 
314 
315 typedef struct
316 {
317  uint8_t button1;
318  uint8_t button2;
319  uint8_t button3;
320  uint8_t button4;
322 
323 typedef struct
324 {
325  uint8_t iirFilter;
326  uint8_t medFilter;
328 
329 typedef struct
330 {
331  uint8_t sysDiagnostic;
333 
334 typedef struct
335 {
338  uint8_t autoThreshold;
339  uint8_t emcSolution;
340  uint8_t guardSens;
341  uint8_t shieldSens;
343 
344 typedef struct
345 {
346  uint8_t powerSupply;
348 
349 
350 typedef struct
351 {
357  // End types group
359 
360 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
361 
367 #ifdef __cplusplus
368 extern "C"{
369 #endif
370 
380 
389 
399 
410 void captouch5_generic_write ( captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
411 
423 void captouch5_generic_read ( captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
424 
434 
445 uint16_t captouch5_read_two_bytes ( captouch5_t *ctx, uint8_t reg_addr );
446 
456 void captouch5_write_two_bytes ( captouch5_t *ctx, uint8_t reg_addr, uint16_t data_buf );
457 
468 uint8_t captouch5_read_byte ( captouch5_t *ctx, uint8_t reg_addr );
469 
479 void captouch5_write_byte ( captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf );
480 
490 uint8_t captouch5_process ( captouch5_t *ctx );
491 
501 uint16_t captouch5_get_device_id ( captouch5_t *ctx );
502 
512 uint8_t captouch5_get_family_id ( captouch5_t *ctx );
513 
523 
534 
543 
552 void captouch5_config_sensors ( captouch5_t *ctx, uint16_t sens_data );
553 
562 void captouch5_config_slider ( captouch5_t *ctx, uint8_t slider_data );
563 
564 
565 #ifdef __cplusplus
566 }
567 #endif
568 #endif // _CAPTOUCH5_H_
569  // End public_function group
572 
573 // ------------------------------------------------------------------------- END
T_CAPTOUCH5_CONFIG2::proximityAutoReset
uint8_t proximityAutoReset
Definition: captouch5.h:336
T_CAPTOUCH5_BUTTONS::button1
uint8_t button1
Definition: captouch5.h:317
T_CAPTOUCH5_DEVICE_CONFIG::cfg3
T_CAPTOUCH5_CONFIG3 cfg3
Definition: captouch5.h:355
captouch5_t::slave_address
hal_i2c_address_t slave_address
Definition: captouch5.h:293
T_CAPTOUCH5_CONFIG0
Definition: captouch5.h:323
T_CAPTOUCH5_CONFIG2::guardSens
uint8_t guardSens
Definition: captouch5.h:340
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:338
T_CAPTOUCH5_CONFIG3
Definition: captouch5.h:344
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.
T_CAPTOUCH5_CONFIG2::buttonAutoReset
uint8_t buttonAutoReset
Definition: captouch5.h:337
T_CAPTOUCH5_DEVICE_CONFIG
Definition: captouch5.h:350
captouch5_cfg_t::sda
pin_name_t sda
Definition: captouch5.h:305
captouch5_cfg_t::scl
pin_name_t scl
Definition: captouch5.h:304
T_CAPTOUCH5_CONFIG3::powerSupply
uint8_t powerSupply
Definition: captouch5.h:346
CAPTOUCH5_RETVAL
#define CAPTOUCH5_RETVAL
Definition: captouch5.h:63
T_CAPTOUCH5_CONFIG2::shieldSens
uint8_t shieldSens
Definition: captouch5.h:341
captouch5_write_byte
void captouch5_write_byte(captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf)
Generic write 8bit data function.
T_CAPTOUCH5_CONFIG2::emcSolution
uint8_t emcSolution
Definition: captouch5.h:339
T_CAPTOUCH5_CONFIG0::medFilter
uint8_t medFilter
Definition: captouch5.h:326
T_CAPTOUCH5_DEVICE_CONFIG::cfg0
T_CAPTOUCH5_CONFIG0 cfg0
Definition: captouch5.h:352
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_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:319
captouch5_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: captouch5.h:310
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:334
T_CAPTOUCH5_BUTTONS::button2
uint8_t button2
Definition: captouch5.h:318
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:320
T_CAPTOUCH5_CONFIG0::iirFilter
uint8_t iirFilter
Definition: captouch5.h:325
captouch5_t::i2c
i2c_master_t i2c
Definition: captouch5.h:289
captouch5_read_slider_position
uint16_t captouch5_read_slider_position(captouch5_t *ctx)
Function for reading slider position.
T_CAPTOUCH5_CONFIG1
Definition: captouch5.h:329
captouch5_init
CAPTOUCH5_RETVAL captouch5_init(captouch5_t *ctx, captouch5_cfg_t *cfg)
Initialization function.
T_CAPTOUCH5_BUTTONS
Definition: captouch5.h:315
captouch5_t
Click ctx object definition.
Definition: captouch5.h:284
captouch5_cfg_t
Click configuration structure definition.
Definition: captouch5.h:300
captouch5_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: captouch5.h:309
T_CAPTOUCH5_CONFIG1::sysDiagnostic
uint8_t sysDiagnostic
Definition: captouch5.h:331
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:353
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:354