capslider2 2.0.0.0
capslider2.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 CAPSLIDER2_H
36#define CAPSLIDER2_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 CAPSLIDER2_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg. clr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57 cfg. rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define CAPSLIDER2_RETVAL uint8_t
65
66#define CAPSLIDER2_OK 0x00
67#define CAPSLIDER2_INIT_ERROR 0xFF
74#define CAPSLDR2_DEVICE_ADDR 0x64
81#define CAPSLDR2_DEVICE_INFO_REG 0x00
82#define CAPSLDR2_SYSTEM_FLAGS_REG 0x01
83#define CAPSLDR2_WHEEL_COORDNT_REG 0x02
84#define CAPSLDR2_TOUCH_BYTES_REG 0x03
85#define CAPSLDR2_COUNTS_REG 0x04
86#define CAPSLDR2_LTA_REG 0x05
87#define CAPSLDR2_MULTIPLIERS_REG 0x06
88#define CAPSLDR2_COMPENS_REG 0x07
89#define CAPSLDR2_PROXSETT_REG 0x08
90#define CAPSLDR2_THRESH_REG 0x09
91#define CAPSLDR2_TIMINGS_REG 0x0A
92#define CAPSLDR2_TARGETS_REG 0x0B
93#define CAPSLDR2_PWM_DUTY_REG 0x0C
94#define CAPSLDR2_PWM_LIM_REG 0x0D
95#define CAPSLDR2_ACTIVE_CHANN_REG 0x0E
96#define CAPSLDR2_BUZZER_REG 0x0F
103#define CAPSLDR2_DEV_INFO_NBYTES 2
104#define CAPSLDR2_SYST_FLAGS_NBYTES 1
105#define CAPSLDR2_WHEEL_NBYTES 4
106#define CAPSLDR2_TOUCH_NBYTES 2
107#define CAPSLDR2_COUNTS_NBYTES 18
108#define CAPSLDR2_LTA_NBYTES 18
109#define CAPSLDR2_MULTIPL_NBYTES 10
110#define CAPSLDR2_COMPENS_NBYTES 10
111#define CAPSLDR2_PROXSETT_NBYTES 6
112#define CAPSLDR2_THRESH_NBYTES 10
113#define CAPSLDR2_TIMINGS_NBYTES 13
114#define CAPSLDR2_TARGETS_NBYTES 10
115#define CAPSLDR2_PWM_DUTY_NBYTES 8
116#define CAPSLDR2_PWM_LIM_NBYTES 2
117#define CAPSLDR2_ACT_CHANN_NBYTES 2
118#define CAPSLDR2_BUZZER_NBYTES 1
125#define CAPSLDR2_BUZZER_EN 0x80
126#define CAPSLDR2_BUZZER_DC_HIGH 0x04
127#define CAPSLDR2_BUZZER_DC_LOW 0x00
128#define CAPSLDR2_BUZZER_PERM_EN 0x02
129#define CAPSLDR2_BUZZER_BURST_EN 0x01
136#define CAPSLDR2_CH0_PROX_EN 0x001
137#define CAPSLDR2_CH1_EN 0x002
138#define CAPSLDR2_CH2_EN 0x004
139#define CAPSLDR2_CH3_EN 0x008
140#define CAPSLDR2_CH4_EN 0x010
141#define CAPSLDR2_CH5_EN 0x020
142#define CAPSLDR2_CH6_EN 0x040
143#define CAPSLDR2_CH7_EN 0x080
144#define CAPSLDR2_CH8_EN 0x100
145#define CAPSLDR2_CH9_EN 0x200
152#define CAPSLDR2_PWM_OFF 0x00
153#define CAPSLDR2_PWM_CONST 0x20
154#define CAPSLDR2_PWM_DECR_0_PERCENTS 0x80
155#define CAPSLDR2_PWM_DECR_LIM 0xA0
156#define CAPSLDR2_PWM_INCR_100_PERCENTS 0xC0
157#define CAPSLDR2_PWM_INCR_LIM 0xE0
158#define CAPSLDR2_PWM_DUTY_0_PERCENTS 0x00
159#define CAPSLDR2_PWM_DUTY_25_PERCENTS 0x10
160#define CAPSLDR2_PWM_DUTY_50_PERCENTS 0x18
161#define CAPSLDR2_PWM_DUTY_75_PERCENTS 0x1C
162#define CAPSLDR2_PWM_DUTY_100_PERCENTS 0x1F
169#define CAPSLDR2_DATA_READY 0
170#define CAPSLDR2_DATA_NOT_READY 1
171#define CAPSLDR2_INVALID_ADDR 0xFF
172#define CAPSLDR2_INVALID_NBYTES 0xFE
173#define CAPSLDR2_INVALID_CHANNEL 0xFD
174#define CAPSLDR2_OK 0x00
181#define CAPSLDR2_LED_INTENSITY 0
182#define CAPSLDR2_LED_NUMBER 1 // End group macro
188// --------------------------------------------------------------- PUBLIC TYPES
197typedef struct
198{
199 // Output pins
200
201 digital_out_t clr;
202
203 // Input pins
204
205 digital_in_t rdy;
206
207 // Modules
208
209 i2c_master_t i2c;
210
211 // ctx variable
212
214
216
220typedef struct
221{
222 // Communication gpio pins
223
224 pin_name_t scl;
225 pin_name_t sda;
226
227 // Additional gpio pins
228
229 pin_name_t clr;
230 pin_name_t rdy;
231
232 // static variable
233
234 uint32_t i2c_speed;
235 uint8_t i2c_address;
236
238 // End types group
240// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
241
247#ifdef __cplusplus
248extern "C"{
249#endif
250
260
269
280void capslider2_generic_write ( capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
281
293void capslider2_generic_read ( capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
294
295
308uint8_t capsldr2_write_reg ( capslider2_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes );
309
322uint8_t capsldr2_read_reg ( capslider2_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes );
323
334
348uint8_t capsldr2_enable_chann ( capslider2_t *ctx, uint16_t sel_chann );
349
359void capsldr2_get_data( capslider2_t *ctx, uint16_t *wheel_data1, uint16_t *wheel_data2 );
360
373void capsldr2_set_output ( capslider2_t *ctx, uint8_t input_data, uint8_t output_mode );
374
384void capsldr2_set_threshold ( capslider2_t *ctx, uint8_t thresh_value );
385
394
403
404#ifdef __cplusplus
405}
406#endif
407#endif // _CAPSLIDER2_H_
408 // End public_function group
411
412// ------------------------------------------------------------------------- END
#define CAPSLIDER2_RETVAL
Definition: capslider2.h:64
void capslider2_cfg_setup(capslider2_cfg_t *cfg)
Config Object Initialization function.
uint8_t capsldr2_read_reg(capslider2_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes)
Generic Read function.
void capsldr2_set_threshold(capslider2_t *ctx, uint8_t thresh_value)
Threshold Set function.
uint8_t capsldr2_check_data_ready(capslider2_t *ctx)
Data Ready Check function.
CAPSLIDER2_RETVAL capslider2_init(capslider2_t *ctx, capslider2_cfg_t *cfg)
Initialization function.
void capsldr2_set_output(capslider2_t *ctx, uint8_t input_data, uint8_t output_mode)
Output Set function.
void capsldr2_get_data(capslider2_t *ctx, uint16_t *wheel_data1, uint16_t *wheel_data2)
Data Get function.
void capsldr2_reset(capslider2_t *ctx)
Reset function.
void capslider2_generic_write(capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void capsldr2_config(capslider2_t *ctx)
Config function.
void capslider2_generic_read(capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t capsldr2_write_reg(capslider2_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes)
Generic Write function.
uint8_t capsldr2_enable_chann(capslider2_t *ctx, uint16_t sel_chann)
Channel Enable function.
Click configuration structure definition.
Definition: capslider2.h:221
pin_name_t clr
Definition: capslider2.h:229
uint32_t i2c_speed
Definition: capslider2.h:234
pin_name_t scl
Definition: capslider2.h:224
pin_name_t rdy
Definition: capslider2.h:230
pin_name_t sda
Definition: capslider2.h:225
uint8_t i2c_address
Definition: capslider2.h:235
Click ctx object definition.
Definition: capslider2.h:198
i2c_master_t i2c
Definition: capslider2.h:209
uint8_t slave_address
Definition: capslider2.h:213
digital_out_t clr
Definition: capslider2.h:201
digital_in_t rdy
Definition: capslider2.h:205