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
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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define CAPTOUCH5_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
70
77#define CAPTOUCH5_RETVAL uint8_t
78
79#define CAPTOUCH5_OK 0x00
80#define CAPTOUCH5_INIT_ERROR 0xFF
83#define CAPTOUCH5_I2C_SLAVE_ADDRESS 0x37
84
89#define CAPTOUCH5_REG_SENSOR_EN 0x00
90#define CAPTOUCH5_REG_FSS_EN 0x02
91#define CAPTOUCH5_REG_SENSITIVITY0 0x08
92#define CAPTOUCH5_REG_SENSITIVITY1 0x09
93#define CAPTOUCH5_REG_SENSITIVITY2 0x0A
94#define CAPTOUCH5_REG_SENSITIVITY3 0x0B
95#define CAPTOUCH5_REG_BASE_THRESHOLD0 0x0C
96#define CAPTOUCH5_REG_BASE_THRESHOLD1 0x0D
97#define CAPTOUCH5_REG_FINGER_THRESHOLD2 0x0E
98#define CAPTOUCH5_REG_FINGER_THRESHOLD3 0x0F
99#define CAPTOUCH5_REG_FINGER_THRESHOLD4 0x10
100#define CAPTOUCH5_REG_FINGER_THRESHOLD5 0x11
101#define CAPTOUCH5_REG_FINGER_THRESHOLD6 0x12
102#define CAPTOUCH5_REG_FINGER_THRESHOLD7 0x13
103#define CAPTOUCH5_REG_FINGER_THRESHOLD8 0x14
104#define CAPTOUCH5_REG_FINGER_THRESHOLD9 0x15
105#define CAPTOUCH5_REG_FINGER_THRESHOLD10 0x16
106#define CAPTOUCH5_REG_FINGER_THRESHOLD11 0x17
107#define CAPTOUCH5_REG_FINGER_THRESHOLD12 0x18
108#define CAPTOUCH5_REG_FINGER_THRESHOLD13 0x19
109#define CAPTOUCH5_REG_FINGER_THRESHOLD14 0x1A
110#define CAPTOUCH5_REG_FINGER_THRESHOLD15 0x1B
111#define CAPTOUCH5_REG_SENSOR_DEBOUNCE 0x1C
112#define CAPTOUCH5_REG_BUTTON_HYS 0x1D
113#define CAPTOUCH5_REG_BUTTON_LBR 0x1F
114#define CAPTOUCH5_REG_BUTTON_NNT 0x20
115#define CAPTOUCH5_REG_BUTTON_NT 0x21
116#define CAPTOUCH5_REG_PROX_EN 0x26
117#define CAPTOUCH5_REG_PROX_CFG 0x27
118#define CAPTOUCH5_REG_PROX_TOUCH_TH0 0x28
119#define CAPTOUCH5_REG_PROX_TOUCH_TH1 0x2A
120#define CAPTOUCH5_REG_PROX_RESOLUTION0 0x2E
121#define CAPTOUCH5_REG_PROX_RESOLUTION1 0x2F
122#define CAPTOUCH5_REG_PROX_HYS 0x30
123#define CAPTOUCH5_REG_PROX_LBR 0x32
124#define CAPTOUCH5_REG_PROX_NNT 0x33
125#define CAPTOUCH5_REG_PROX_NT 0x34
126#define CAPTOUCH5_REG_BUZZER_CFG 0x3E
127#define CAPTOUCH5_REG_BUZZER_ON_TIME 0x3F
128#define CAPTOUCH5_REG_SPO_CFG 0x4C
129#define CAPTOUCH5_REG_DEVICE_CFG0 0x4D
130#define CAPTOUCH5_REG_DEVICE_CFG1 0x4E
131#define CAPTOUCH5_REG_DEVICE_CFG2 0x4F
132#define CAPTOUCH5_REG_DEVICE_CFG3 0x50
133#define CAPTOUCH5_REG_I2C_ADDR 0x51
134#define CAPTOUCH5_REG_REFRESH_CTRL 0x52
135#define CAPTOUCH5_REG_STATE_TIMEOUT 0x55
136#define CAPTOUCH5_REG_SLIDER_CFG 0x5D
137#define CAPTOUCH5_REG_SLIDER1_CFG 0x61
138#define CAPTOUCH5_REG_SLIDER1_RESOLUTION 0x62
139#define CAPTOUCH5_REG_SLIDER1_THRESHOLD 0x63
140#define CAPTOUCH5_REG_SLIDER2_CFG 0x67
141#define CAPTOUCH5_REG_SLIDER2_RESOLUTION 0x68
142#define CAPTOUCH5_REG_SLIDER2_THRESHOLD 0x69
143#define CAPTOUCH5_REG_SLIDER_LBR 0x71
144#define CAPTOUCH5_REG_SLIDER_NNT 0x72
145#define CAPTOUCH5_REG_SLIDER_NT 0x73
146#define CAPTOUCH5_REG_SCRATCHPAD0 0x7A
147#define CAPTOUCH5_REG_SCRATCHPAD1 0x7B
148#define CAPTOUCH5_REG_CONFIG_CRC 0x7E
149#define CAPTOUCH5_REG_SENSOR_ID 0x82
150#define CAPTOUCH5_REG_CTRL_CMD 0x86
151#define CAPTOUCH5_REG_CTRL_CMD_STATUS 0x88
152#define CAPTOUCH5_REG_CTRL_CMD_ERR 0x89
153#define CAPTOUCH5_REG_SYSTEM_STATUS 0x8A
154#define CAPTOUCH5_REG_PREV_CTRL_CMD_CODE 0x8C
155#define CAPTOUCH5_REG_FAMILY_ID 0x8F
156#define CAPTOUCH5_REG_DEVICE_ID 0x90
157#define CAPTOUCH5_REG_DEVICE_REV 0x92
158#define CAPTOUCH5_REG_CALC_CRC 0x94
159#define CAPTOUCH5_REG_TOTAL_WORKING_SNS 0x97
160#define CAPTOUCH5_REG_SNS_CP_HIGH 0x98
161#define CAPTOUCH5_REG_SNS_VDD_SHORT 0x9A
162#define CAPTOUCH5_REG_SNS_GND_SHORT 0x9C
163#define CAPTOUCH5_REG_CMOD_SHIELD_TEST 0xA0
164#define CAPTOUCH5_REG_BUTTON_STAT 0xAA
165#define CAPTOUCH5_REG_LATCHED_BUTTON_STAT 0xAC
166#define CAPTOUCH5_REG_PROX_STAT 0xAE
167#define CAPTOUCH5_REG_LATCHED_PROx_STAT 0xAF
168#define CAPTOUCH5_REG_SLIDER1_POSITION 0xB0
169#define CAPTOUCH5_REG_LIFTOFF_SLIDER1_POSITION 0xB1
170#define CAPTOUCH5_REG_SLIDER2_POSITION 0xB2
171#define CAPTOUCH5_REG_LIFTOFF_SLIDER2_POSITION 0xB3
172#define CAPTOUCH5_REG_SYNC_COUNTER0 0xB9
173#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR0 0xBA
174#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR1 0xBC
175#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR2 0xBE
176#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR3 0xC0
177#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR4 0xC2
178#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR5 0xC4
179#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR6 0xC6
180#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR7 0xC8
181#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR8 0xCA
182#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR9 0xCC
183#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR10 0xCE
184#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR11 0xD0
185#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR12 0xD2
186#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR13 0xD4
187#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR14 0xD6
188#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR15 0xD8
189#define CAPTOUCH5_REG_SYNC_COUNTER1 0xDB
190#define CAPTOUCH5_REG_DEBUG_SENSOR_ID 0xDC
191#define CAPTOUCH5_REG_DEBUG_CP 0xDD
192#define CAPTOUCH5_REG_DIFFERENCE_COUNT0 0xDE
193#define CAPTOUCH5_REG_DEBUG_BASELINE0 0xE0
194#define CAPTOUCH5_REG_DEBUG_RAW_COUNT0 0xE2
195#define CAPTOUCH5_REG_DEBUG_AVG_RAW_COUNT0 0xE4
196#define CAPTOUCH5_REG_SYNC_COUNTER2 0xE7
203#define CAPTOUCH5_BUTTON_PRESSED 1
204#define CAPTOUCH5_BUTTON_NOT_PRESSED 0
211#define CAPTOUCH5_CFG0_IIR_FILTER_ENABLED 1
212#define CAPTOUCH5_CFG0_IIR_FILTER_DISABLED 1
213#define CAPTOUCH5_CFG0_MED_FILTER_ENABLED 1
214#define CAPTOUCH5_CFG0_MED_FILTER_DISABLED 1
221#define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_ENABLED 1
222#define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_DISABLED 1
229#define CAPTOUCH5_CFG2_SHIELD_ENABLED 1
230#define CAPTOUCH5_CFG2_SHIELD_DISABLED 0
231#define CAPTOUCH5_CFG2_GUARD_SENS_ENABLED 1
232#define CAPTOUCH5_CFG2_GUARD_SENS_DISABLED 0
233#define CAPTOUCH5_CFG2_EMC_ENABLED 1
234#define CAPTOUCH5_CFG2_EMC_DISABLED 0
235#define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_ENABLED 1
236#define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_DISABLED 0
237#define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_DISABLED 0
238#define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_5_SEC 1
239#define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_20_SEC 2
240#define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_DISABLED 0
241#define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_5_SEC 1
242#define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_20_SEC 2
249#define CAPTOUCH5_CFG3_POWER_SUPPLY_INTERNALLY 0
250#define CAPTOUCH5_CFG3_POWER_SUPPLY_EXTERNALLY 1
257#define CAPTOUCH5_SLIDER_SENS_0p1 0
258#define CAPTOUCH5_SLIDER_SENS_0p2 1
259#define CAPTOUCH5_SLIDER_SENS_0p3 2
260#define CAPTOUCH5_SLIDER_SENS_0p4 3
267#define CAPTOUCH5_BUTTON_SENS_ENABLED 0xFFFF
268#define CAPTOUCH5_BUTTON_SENS_DISABLED 0x0000
275#define CAPTOUCH5_DEVICE_ID 2566
276#define CAPTOUCH5_FAMILY_ID 154
284#define CAPTOUCH5_ERROR 1
285#define CAPTOUCH5_NO_ERROR 0
288 // End group macro
289// --------------------------------------------------------------- PUBLIC TYPES
298typedef struct
299{
300
301 // Modules
302
303 i2c_master_t i2c;
304
305 // ctx variable
306
308
310
314typedef struct
315{
316 // Communication gpio pins
317
318 pin_name_t scl;
319 pin_name_t sda;
320
321 // static variable
322
323 uint32_t i2c_speed;
324 uint8_t i2c_address;
325
327
328
329typedef struct
330{
331 uint8_t button1;
332 uint8_t button2;
333 uint8_t button3;
334 uint8_t button4;
336
337typedef struct
338{
339 uint8_t iirFilter;
340 uint8_t medFilter;
342
343typedef struct
344{
347
348typedef struct
349{
353 uint8_t emcSolution;
354 uint8_t guardSens;
355 uint8_t shieldSens;
357
358typedef struct
359{
360 uint8_t powerSupply;
362
363
371
372 // End types group
373
374// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
375
381#ifdef __cplusplus
382extern "C"{
383#endif
384
394
403
413
424void captouch5_generic_write ( captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
425
437void captouch5_generic_read ( captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
438
448
459uint16_t captouch5_read_two_bytes ( captouch5_t *ctx, uint8_t reg_addr );
460
470void captouch5_write_two_bytes ( captouch5_t *ctx, uint8_t reg_addr, uint16_t data_buf );
471
482uint8_t captouch5_read_byte ( captouch5_t *ctx, uint8_t reg_addr );
483
493void captouch5_write_byte ( captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf );
494
505
516
527
537
548
557
566void captouch5_config_sensors ( captouch5_t *ctx, uint16_t sens_data );
567
576void captouch5_config_slider ( captouch5_t *ctx, uint8_t slider_data );
577
578
579#ifdef __cplusplus
580}
581#endif
582#endif // _CAPTOUCH5_H_
583
584 // End public_function group
586
587// ------------------------------------------------------------------------- END
#define CAPTOUCH5_RETVAL
Definition captouch5.h:77
void captouch5_config_slider(captouch5_t *ctx, uint8_t slider_data)
Function for configuring slider.
uint8_t captouch5_read_byte(captouch5_t *ctx, uint8_t reg_addr)
Generic read 8bit data function.
uint16_t captouch5_read_slider_position(captouch5_t *ctx)
Function for reading slider position.
void captouch5_generic_write(captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void captouch5_default_cfg(captouch5_t *ctx, T_CAPTOUCH5_DEVICE_CONFIG *device_cfg)
Click Default Configuration function.
void captouch5_write_two_bytes(captouch5_t *ctx, uint8_t reg_addr, uint16_t data_buf)
Generic write 16bit data function.
void captouch5_config_sensors(captouch5_t *ctx, uint16_t sens_data)
Function for configuring sensor.
void captouch5_device_config(captouch5_t *ctx, T_CAPTOUCH5_DEVICE_CONFIG *device_cfg)
Function for configuring device.
uint16_t captouch5_get_device_id(captouch5_t *ctx)
Function for geting device id.
void captouch5_generic_read(captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void captouch5_write_byte(captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf)
Generic write 8bit data function.
uint16_t captouch5_read_two_bytes(captouch5_t *ctx, uint8_t reg_addr)
Generic read 16bit data function.
uint8_t captouch5_process(captouch5_t *ctx)
Function for checking error.
void captouch5_software_reset(captouch5_t *ctx)
Function to reset device.
uint8_t captouch5_get_family_id(captouch5_t *ctx)
Function for geting family id.
void captouch5_read_button_status(captouch5_t *ctx, T_CAPTOUCH5_BUTTONS *buttons)
Function read button status.
void captouch5_cfg_setup(captouch5_cfg_t *cfg)
Config Object Initialization function.
CAPTOUCH5_RETVAL captouch5_init(captouch5_t *ctx, captouch5_cfg_t *cfg)
Initialization function.
Definition captouch5.h:330
uint8_t button4
Definition captouch5.h:334
uint8_t button3
Definition captouch5.h:333
uint8_t button2
Definition captouch5.h:332
uint8_t button1
Definition captouch5.h:331
Definition captouch5.h:338
uint8_t iirFilter
Definition captouch5.h:339
uint8_t medFilter
Definition captouch5.h:340
Definition captouch5.h:344
uint8_t sysDiagnostic
Definition captouch5.h:345
Definition captouch5.h:349
uint8_t autoThreshold
Definition captouch5.h:352
uint8_t shieldSens
Definition captouch5.h:355
uint8_t emcSolution
Definition captouch5.h:353
uint8_t guardSens
Definition captouch5.h:354
uint8_t buttonAutoReset
Definition captouch5.h:351
uint8_t proximityAutoReset
Definition captouch5.h:350
Definition captouch5.h:359
uint8_t powerSupply
Definition captouch5.h:360
Definition captouch5.h:365
T_CAPTOUCH5_CONFIG0 cfg0
Definition captouch5.h:366
T_CAPTOUCH5_CONFIG3 cfg3
Definition captouch5.h:369
T_CAPTOUCH5_CONFIG1 cfg1
Definition captouch5.h:367
T_CAPTOUCH5_CONFIG2 cfg2
Definition captouch5.h:368
Click configuration structure definition.
Definition captouch5.h:315
uint32_t i2c_speed
Definition captouch5.h:323
pin_name_t scl
Definition captouch5.h:318
pin_name_t sda
Definition captouch5.h:319
uint8_t i2c_address
Definition captouch5.h:324
Click ctx object definition.
Definition captouch5.h:299
i2c_master_t i2c
Definition captouch5.h:303
uint8_t slave_address
Definition captouch5.h:307