capsense2 2.0.0.0
capsense2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef CAPSENSE2_H
29#define CAPSENSE2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define CAPSENSE2_REG_MAIN_STATUS_CONTROL 0x00
74#define CAPSENSE2_REG_BUTTON_STATUS_1 0x03
75#define CAPSENSE2_REG_BUTTON_STATUS_2 0x04
76#define CAPSENSE2_REG_BUILD_REVISION 0x05
77#define CAPSENSE2_REG_SLIDER_POSITION_DATA 0x06
78#define CAPSENSE2_REG_VENDOR_ID 0x08
79#define CAPSENSE2_REG_VOLUMETRIC_STEP 0x09
80#define CAPSENSE2_REG_NOISE_STATUS_1 0x0A
81#define CAPSENSE2_REG_NOISE_STATUS_2 0x0B
82#define CAPSENSE2_REG_LID_CLOSURE_STATUS_1 0x0C
83#define CAPSENSE2_REG_LID_CLOSURE_STATUS_2 0x0D
84#define CAPSENSE2_REG_GPIO_STATUS 0x0E
85#define CAPSENSE2_REG_GROUP_STATUS 0x0F
86#define CAPSENSE2_REG_SENSOR_1_DELTA_COUNT 0x10
87#define CAPSENSE2_REG_SENSOR_2_DELTA_COUNT 0x11
88#define CAPSENSE2_REG_SENSOR_3_DELTA_COUNT 0x12
89#define CAPSENSE2_REG_SENSOR_4_DELTA_COUNT 0x13
90#define CAPSENSE2_REG_SENSOR_5_DELTA_COUNT 0x14
91#define CAPSENSE2_REG_SENSOR_6_DELTA_COUNT 0x15
92#define CAPSENSE2_REG_SENSOR_7_DELTA_COUNT 0x16
93#define CAPSENSE2_REG_SENSOR_8_DELTA_COUNT 0x17
94#define CAPSENSE2_REG_SENSOR_9_DELTA_COUNT 0x18
95#define CAPSENSE2_REG_SENSOR_10_DELTA_COUNT 0x19
96#define CAPSENSE2_REG_SENSOR_11_DELTA_COUNT 0x1A
97#define CAPSENSE2_REG_SENSOR_12_DELTA_COUNT 0x1B
98#define CAPSENSE2_REG_SENSOR_13_DELTA_COUNT 0x1C
99#define CAPSENSE2_REG_SENSOR_14_DELTA_COUNT 0x1D
100#define CAPSENSE2_REG_QUEUE_CONTROL 0x1E
101#define CAPSENSE2_REG_DATA_SENSITIVITY 0x1F
102#define CAPSENSE2_REG_CONFIGURATION 0x20
103#define CAPSENSE2_REG_SENSOR_ENABLE 0x21
104#define CAPSENSE2_REG_BUTTON_CONFIGURATION 0x22
105#define CAPSENSE2_REG_GROUP_CONFIGURATION_1 0x23
106#define CAPSENSE2_REG_GROUP_CONFIGURATION_2 0x24
107#define CAPSENSE2_REG_CALIBRATION_ENABLE 0x25
108#define CAPSENSE2_REG_CALIBRATION_ACTIVATE 0x26
109#define CAPSENSE2_REG_INTERRUPT_ENABLE_1 0x27
110#define CAPSENSE2_REG_INTERRUPT_ENABLE_2 0x28
111#define CAPSENSE2_REG_SLEEP_CHANNEL_CONTROL 0x29
112#define CAPSENSE2_REG_MULTIPLE_PRESS_CONFIGURATION 0x2A
113#define CAPSENSE2_REG_LID_CLOSURE_CONFIGURATION 0x2B
114#define CAPSENSE2_REG_LID_CLOSURE_QUEUE_CONTROL 0x2C
115#define CAPSENSE2_REG_LID_CLOSURE_PATTERN_1 0x2D
116#define CAPSENSE2_REG_LID_CLOSURE_PATTERN_2 0x2E
117#define CAPSENSE2_REG_RECALIBRATION_CONFIGURATION 0x2F
118#define CAPSENSE2_REG_SENSOR_1_THRESHOLD 0x30
119#define CAPSENSE2_REG_SENSOR_2_THRESHOLD 0x31
120#define CAPSENSE2_REG_SENSOR_3_THRESHOLD 0x32
121#define CAPSENSE2_REG_SENSOR_4_THRESHOLD 0x33
122#define CAPSENSE2_REG_SENSOR_5_THRESHOLD 0x34
123#define CAPSENSE2_REG_SENSOR_6_THRESHOLD 0x35
124#define CAPSENSE2_REG_SENSOR_7_THRESHOLD 0x36
125#define CAPSENSE2_REG_GROUP_THRESHOLD 0x37
126#define CAPSENSE2_REG_BUTTON_NOISE_THRESHOLD_1 0x38
127#define CAPSENSE2_REG_BUTTON_NOISE_THRESHOLD_2 0x39
128#define CAPSENSE2_REG_LID_CLOSURE_THRESHOLD_1 0x3A
129#define CAPSENSE2_REG_LID_CLOSURE_THRESHOLD_2 0x3B
130#define CAPSENSE2_REG_LID_CLOSURE_THRESHOLD_3 0x3C
131#define CAPSENSE2_REG_LID_CLOSURE_THRESHOLD_4 0x3D
132#define CAPSENSE2_REG_SLIDER_VELOCITY_CONFIGURATION 0x3E
133#define CAPSENSE2_REG_DIGITAL_RECALIBRATION 0x3F
134#define CAPSENSE2_REG_CONFIGURATION_2 0x40
135#define CAPSENSE2_REG_GROUPED_CHANNEL_SENSOR_ENABLE 0x41
136#define CAPSENSE2_REG_PROXIMITY_CONTROL 0x42
137#define CAPSENSE2_REG_GROUPED_SENSOR_CALIB_ACTIVATE 0x46
138#define CAPSENSE2_REG_SAMPLING_CHANNEL_SELECT 0x4E
139#define CAPSENSE2_REG_SAMPLING_CONFIGURATION 0x4F
140#define CAPSENSE2_REG_SENSOR_1_BASE_COUNT 0x50
141#define CAPSENSE2_REG_SENSOR_2_BASE_COUNT 0x51
142#define CAPSENSE2_REG_SENSOR_3_BASE_COUNT 0x52
143#define CAPSENSE2_REG_SENSOR_4_BASE_COUNT 0x53
144#define CAPSENSE2_REG_SENSOR_5_BASE_COUNT 0x54
145#define CAPSENSE2_REG_SENSOR_6_BASE_COUNT 0x55
146#define CAPSENSE2_REG_SENSOR_7_BASE_COUNT 0x56
147#define CAPSENSE2_REG_SENSOR_8_BASE_COUNT 0x57
148#define CAPSENSE2_REG_SENSOR_9_BASE_COUNT 0x58
149#define CAPSENSE2_REG_SENSOR_10_BASE_COUNT 0x59
150#define CAPSENSE2_REG_SENSOR_11_BASE_COUNT 0x5A
151#define CAPSENSE2_REG_SENSOR_12_BASE_COUNT 0x5B
152#define CAPSENSE2_REG_SENSOR_13_BASE_COUNT 0x5C
153#define CAPSENSE2_REG_SENSOR_14_BASE_COUNT 0x5D
154#define CAPSENSE2_REG_LED_STATUS_1 0x60
155#define CAPSENSE2_REG_LED_STATUS_2 0x61
156#define CAPSENSE2_REG_LED_DIRECTION 0x70
157#define CAPSENSE2_REG_LED_OUTPUT_TYPE 0x71
158#define CAPSENSE2_REG_GPIO_INPUT 0x72
159#define CAPSENSE2_REG_LED_OUTPUT_CONTROL_1 0x73
160#define CAPSENSE2_REG_LED_OUTPUT_CONTROL_2 0x74
161#define CAPSENSE2_REG_LED_POLARITY_1 0x75
162#define CAPSENSE2_REG_LED_POLARITY_2 0x76
163#define CAPSENSE2_REG_LINKED_LED_TRANSITION_CONTROL_1 0x77
164#define CAPSENSE2_REG_LINKED_LED_TRANSITION_CONTROL_2 0x78
165#define CAPSENSE2_REG_LED_MIRROR_CONTROL_1 0x79
166#define CAPSENSE2_REG_LED_MIRROR_CONTROL_2 0x7A
167#define CAPSENSE2_REG_SENSOR_LED_LINKING 0x80
168#define CAPSENSE2_REG_LED_BEHAVIOR_1 0x81
169#define CAPSENSE2_REG_LED_BEHAVIOR_2 0x82
170#define CAPSENSE2_REG_LED_BEHAVIOR_3 0x83
171#define CAPSENSE2_REG_LED_PULSE_1_PERIOD 0x84
172#define CAPSENSE2_REG_LED_PULSE_2_PERIOD 0x85
173#define CAPSENSE2_REG_LED_BREATHE_PERIOD 0x86
174#define CAPSENSE2_REG_LED_CONFIGURATION 0x88
175#define CAPSENSE2_REG_LED_PULSE_1_DUTY_CYCLE 0x90
176#define CAPSENSE2_REG_LED_PULSE_2_DUTY_CYCLE 0x91
177#define CAPSENSE2_REG_LED_BREATHE_DUTY_CYCLE 0x92
178#define CAPSENSE2_REG_LED_DIRECT_DUTY_CYCLE 0x93
179#define CAPSENSE2_REG_LED_DIRECT_RAMP_RATES 0x94
180#define CAPSENSE2_REG_LED_OFF_DELAY 0x95
181#define CAPSENSE2_REG_SENSOR_1_CALIBRATION 0xB1
182#define CAPSENSE2_REG_SENSOR_2_CALIBRATION 0xB2
183#define CAPSENSE2_REG_SENSOR_3_CALIBRATION 0xB3
184#define CAPSENSE2_REG_SENSOR_4_CALIBRATION 0xB4
185#define CAPSENSE2_REG_SENSOR_5_CALIBRATION 0xB5
186#define CAPSENSE2_REG_SENSOR_6_CALIBRATION 0xB6
187#define CAPSENSE2_REG_SENSOR_7_CALIBRATION 0xB7
188#define CAPSENSE2_REG_SENSOR_8_CALIBRATION 0xB8
189#define CAPSENSE2_REG_SENSOR_9_CALIBRATION 0xB9
190#define CAPSENSE2_REG_SENSOR_10_CALIBRATION 0xBA
191#define CAPSENSE2_REG_SENSOR_11_CALIBRATION 0xBB
192#define CAPSENSE2_REG_SENSOR_12_CALIBRATION 0xBC
193#define CAPSENSE2_REG_SENSOR_13_CALIBRATION 0xBD
194#define CAPSENSE2_REG_SENSOR_14_CALIBRATION 0xBE
195#define CAPSENSE2_REG_PRODUCT_ID 0xFD
196#define CAPSENSE2_REG_MANUFACTURER_ID 0xFE
197#define CAPSENSE2_REG_REVISION 0xFF
198
199 // capsense2_reg
200
215#define CAPSENSE2_MAIN_STATUS_CONTROL_DEACT 0x40
216#define CAPSENSE2_MAIN_STATUS_CONTROL_SLEEP 0x20
217#define CAPSENSE2_MAIN_STATUS_CONTROL_DSLEEP 0x10
218#define CAPSENSE2_MAIN_STATUS_CONTROL_PWR_LED 0x02
219#define CAPSENSE2_MAIN_STATUS_CONTROL_INT 0x01
220
225#define CAPSENSE2_BUTTON_STATUS_1_UP_SLIDER 0x80
226#define CAPSENSE2_BUTTON_STATUS_1_DOWN_SLIDER 0x40
227#define CAPSENSE2_BUTTON_STATUS_1_BUTTON_2 0x02
228#define CAPSENSE2_BUTTON_STATUS_1_BUTTON_1 0x01
229
234#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_ENABLE 0x80
235#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_BUTTONS_1 0x00
236#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_BUTTONS_2 0x04
237#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_BUTTONS_3 0x08
238#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_BUTTONS_4 0x0C
239#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_GROUP_2 0x00
240#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_GROUP_3 0x01
241#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_GROUP_4 0x02
242#define CAPSENSE2_MULTIPLE_PRESS_CONFIG_GROUP_1 0x03
243
248#define CAPSENSE2_CONFIGURATION_TIMEOUT 0x80
249#define CAPSENSE2_CONFIGURATION_POS_VOL 0x40
250#define CAPSENSE2_CONFIGURATION_BLK_DIG_NOISE 0x20
251#define CAPSENSE2_CONFIGURATION_BLK_ANA_NOISE 0x10
252#define CAPSENSE2_CONFIGURATION_MAX_DUR_EN_B 0x08
253#define CAPSENSE2_CONFIGURATION_RPT_EN_B 0x04
254#define CAPSENSE2_CONFIGURATION_MAX_DUR_EN_G 0x02
255#define CAPSENSE2_CONFIGURATION_RPT_EN_G 0x01
256
261#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_EXTRA_INT_EN 0x80
262#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_0 0x00
263#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_1 0x10
264#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_2 0x20
265#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_3 0x30
266#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_4 0x40
267#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_5 0x50
268#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_6 0x60
269#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_MAX_INT_7 0x70
270#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_SLIDE_TIME_350 0x00
271#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_SLIDE_TIME_560 0x04
272#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_SLIDE_TIME_770 0x08
273#define CAPSENSE2_SLIDER_VELOCITY_CONFIG_SLIDE_TIME_980 0x0C
274
279#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED1 0x01
280#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED2 0x02
281#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED3 0x04
282#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED4 0x08
283#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED5 0x10
284#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED6 0x20
285#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED7 0x40
286#define CAPSENSE2_LED_DIRECTION_OUTPUT_LED8 0x80
287
292#define CAPSENSE2_SENSOR_LED_LINKING_CS1_LED1 0x01
293#define CAPSENSE2_SENSOR_LED_LINKING_CS2_LED2 0x02
294#define CAPSENSE2_SENSOR_LED_LINKING_CS3_LED3 0x04
295#define CAPSENSE2_SENSOR_LED_LINKING_CS4_LED4 0x08
296#define CAPSENSE2_SENSOR_LED_LINKING_CS5_LED5 0x10
297#define CAPSENSE2_SENSOR_LED_LINKING_CS6_LED6 0x20
298#define CAPSENSE2_SENSOR_LED_LINKING_CS7_LED7 0x40
299#define CAPSENSE2_SENSOR_LED_LINKING_UP_DOWN_LINK 0x80
300
305#define CAPSENSE2_VENDOR_ID 0x5D
306#define CAPSENSE2_MANUFACTURER_ID 0x5D
307#define CAPSENSE2_PRODUCT_ID 0x3A
308
314#define CAPSENSE2_SET_DEV_ADDR 0x28
315
316 // capsense2_set
317
332#define CAPSENSE2_MAP_MIKROBUS( cfg, mikrobus ) \
333 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
334 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
335 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
336 cfg.alt = MIKROBUS( mikrobus, MIKROBUS_INT )
337
338 // capsense2_map
339 // capsense2
340
345typedef struct
346{
347 // Output pins
348 digital_out_t rst;
350 // Input pins
351 digital_in_t alt;
353 // Modules
354 i2c_master_t i2c;
356 // I2C slave address
360
365typedef struct
366{
367 pin_name_t scl;
368 pin_name_t sda;
370 pin_name_t rst;
371 pin_name_t alt;
373 uint32_t i2c_speed;
374 uint8_t i2c_address;
377
388
405
421
436
452err_t capsense2_generic_write ( capsense2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
453
469err_t capsense2_generic_read ( capsense2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
470
484err_t capsense2_write_register ( capsense2_t *ctx, uint8_t reg, uint8_t data_in );
485
499err_t capsense2_read_register ( capsense2_t *ctx, uint8_t reg, uint8_t *data_out );
500
510void capsense2_set_reset_pin ( capsense2_t *ctx, uint8_t state );
511
521
531
544
557
558#ifdef __cplusplus
559}
560#endif
561#endif // CAPSENSE2_H
562
563 // capsense2
564
565// ------------------------------------------------------------------------ END
capsense2_return_value_t
CapSense 2 Click return value data.
Definition capsense2.h:383
@ CAPSENSE2_ERROR
Definition capsense2.h:385
@ CAPSENSE2_OK
Definition capsense2.h:384
uint8_t capsense2_get_alert_pin(capsense2_t *ctx)
CapSense 2 get alert pin function.
err_t capsense2_default_cfg(capsense2_t *ctx)
CapSense 2 default configuration function.
err_t capsense2_read_register(capsense2_t *ctx, uint8_t reg, uint8_t *data_out)
CapSense 2 read register function.
err_t capsense2_generic_write(capsense2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
CapSense 2 I2C writing function.
void capsense2_cfg_setup(capsense2_cfg_t *cfg)
CapSense 2 configuration object setup function.
err_t capsense2_clear_interrupt(capsense2_t *ctx)
CapSense 2 clear interrupt function.
err_t capsense2_write_register(capsense2_t *ctx, uint8_t reg, uint8_t data_in)
CapSense 2 write register function.
err_t capsense2_init(capsense2_t *ctx, capsense2_cfg_t *cfg)
CapSense 2 initialization function.
void capsense2_set_reset_pin(capsense2_t *ctx, uint8_t state)
CapSense 2 set reset pin function.
err_t capsense2_generic_read(capsense2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
CapSense 2 I2C reading function.
err_t capsense2_check_communication(capsense2_t *ctx)
CapSense 2 check communication function.
void capsense2_reset_device(capsense2_t *ctx)
CapSense 2 reset device function.
CapSense 2 Click configuration object.
Definition capsense2.h:366
pin_name_t alt
Definition capsense2.h:371
uint32_t i2c_speed
Definition capsense2.h:373
pin_name_t scl
Definition capsense2.h:367
pin_name_t sda
Definition capsense2.h:368
pin_name_t rst
Definition capsense2.h:370
uint8_t i2c_address
Definition capsense2.h:374
CapSense 2 Click context object.
Definition capsense2.h:346
digital_in_t alt
Definition capsense2.h:351
i2c_master_t i2c
Definition capsense2.h:354
digital_out_t rst
Definition capsense2.h:348
uint8_t slave_address
Definition capsense2.h:357