capwheel 2.0.0.0
capwheel.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 CAPWHEEL_H
36#define CAPWHEEL_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 CAPWHEEL_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg. clr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg. rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define CAPWHEEL_RETVAL uint8_t
79
80#define CAPWHEEL_OK 0x00
81#define CAPWHEEL_INIT_ERROR 0xFF
88#define CAPWHEEL_DEVICE_ADDR 0x64
95#define CAPWHEEL_DEVICE_INFO_REG 0x00
96#define CAPWHEEL_SYSTEM_FLAGS_REG 0x01
97#define CAPWHEEL_WHEEL_COORDNT_REG 0x02
98#define CAPWHEEL_TOUCH_BYTES_REG 0x03
99#define CAPWHEEL_COUNTS_REG 0x04
100#define CAPWHEEL_LTA_REG 0x05
101#define CAPWHEEL_MULTIPLIERS_REG 0x06
102#define CAPWHEEL_COMPENS_REG 0x07
103#define CAPWHEEL_PROXSETT_REG 0x08
104#define CAPWHEEL_THRESH_REG 0x09
105#define CAPWHEEL_TIMINGS_REG 0x0A
106#define CAPWHEEL_TARGETS_REG 0x0B
107#define CAPWHEEL_PWM_DUTY_REG 0x0C
108#define CAPWHEEL_PWM_LIM_REG 0x0D
109#define CAPWHEEL_ACTIVE_CHANN_REG 0x0E
110#define CAPWHEEL_BUZZER_REG 0x0F
117#define CAPWHEEL_DEV_INFO_NBYTES 2
118#define CAPWHEEL_SYST_FLAGS_NBYTES 1
119#define CAPWHEEL_WHEEL_NBYTES 4
120#define CAPWHEEL_TOUCH_NBYTES 2
121#define CAPWHEEL_COUNTS_NBYTES 18
122#define CAPWHEEL_LTA_NBYTES 18
123#define CAPWHEEL_MULTIPL_NBYTES 9
124#define CAPWHEEL_COMPENS_NBYTES 9
125#define CAPWHEEL_PROXSETT_NBYTES 6
126#define CAPWHEEL_THRESH_NBYTES 10
127#define CAPWHEEL_TIMINGS_NBYTES 13
128#define CAPWHEEL_TARGETS_NBYTES 10
129#define CAPWHEEL_PWM_DUTY_NBYTES 8
130#define CAPWHEEL_PWM_LIM_NBYTES 2
131#define CAPWHEEL_ACT_CHANN_NBYTES 2
132#define CAPWHEEL_BUZZER_NBYTES 1
139#define CAPWHEEL_BUZZER_EN 0x80
140#define CAPWHEEL_BUZZER_DC_HIGH 0x04
141#define CAPWHEEL_BUZZER_DC_LOW 0x00
142#define CAPWHEEL_BUZZER_PERM_EN 0x02
143#define CAPWHEEL_BUZZER_BURST_EN 0x01
150#define CAPWHEEL_CH0_PROX_EN 0x001
151#define CAPWHEEL_CH1_EN 0x002
152#define CAPWHEEL_CH2_EN 0x004
153#define CAPWHEEL_CH3_EN 0x008
154#define CAPWHEEL_CH4_EN 0x010
155#define CAPWHEEL_CH5_EN 0x020
156#define CAPWHEEL_CH6_EN 0x040
157#define CAPWHEEL_CH7_EN 0x080
158#define CAPWHEEL_CH8_EN 0x100
159#define CAPWHEEL_CH9_EN 0x200
166#define CAPWHEEL_PWM_OFF 0x00
167#define CAPWHEEL_PWM_CONST 0x20
168#define CAPWHEEL_PWM_DECR_0_PERCENTS 0x80
169#define CAPWHEEL_PWM_DECR_LIM 0xA0
170#define CAPWHEEL_PWM_INCR_100_PERCENTS 0xC0
171#define CAPWHEEL_PWM_INCR_LIM 0xE0
172#define CAPWHEEL_PWM_DUTY_0_PERCENTS 0x00
173#define CAPWHEEL_PWM_DUTY_25_PERCENTS 0x10
174#define CAPWHEEL_PWM_DUTY_50_PERCENTS 0x18
175#define CAPWHEEL_PWM_DUTY_75_PERCENTS 0x1C
176#define CAPWHEEL_PWM_DUTY_100_PERCENTS 0x1F
183#define CAPWHEEL_DATA_READY 0
184#define CAPWHEEL_DATA_NOT_READY 1
185#define CAPWHEEL_ADDR_ERROR 0xFF
186#define CAPWHEEL_NBYTES_ERROR 0xFE
187#define CAPWHEEL_CH_SEL_ERROR 0xFD
188#define CAPWHEEL_OK 0x00
195#define CAPWHEEL_LED_BRIGHTNESS_INTENSITY 0
196#define CAPWHEEL_LED_BRIGHTNESS_NUMBER 1
199 // End group macro
200// --------------------------------------------------------------- PUBLIC TYPES
209typedef struct
210{
211 // Output pins
212
213 digital_out_t clr;
214
215 // Input pins
216
217 digital_in_t rdy;
218
219 // Modules
220
221 i2c_master_t i2c;
222
223 // ctx variable
224
226
227} capwheel_t;
228
232typedef struct
233{
234 // Communication gpio pins
235
236 pin_name_t scl;
237 pin_name_t sda;
238
239 // Additional gpio pins
240
241 pin_name_t clr;
242 pin_name_t rdy;
243
244 // static variable
245
246 uint32_t i2c_speed;
247 uint8_t i2c_address;
248
250
251 // End types group
252// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
253
259#ifdef __cplusplus
260extern "C"{
261#endif
262
272
281
290
301void capwheel_generic_write ( capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
302
314void capwheel_generic_read ( capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
315
328uint8_t capwheel_write_reg ( capwheel_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes );
329
342uint8_t capwheel_read_reg ( capwheel_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes );
343
354
367uint8_t capwheel_enable_chann ( capwheel_t *ctx, uint16_t sel_chann );
368
377void capwheel_get_data ( capwheel_t *ctx, uint16_t *wheel_data );
378
390void capwheel_set_output( capwheel_t *ctx, uint16_t input_data, uint8_t output_mode );
391
401void capwheel_set_threshold ( capwheel_t *ctx, uint8_t thresh_value );
402
411
412#ifdef __cplusplus
413}
414#endif
415#endif // _CAPWHEEL_H_
416
417 // End public_function group
419
420// ------------------------------------------------------------------------- END
#define CAPWHEEL_RETVAL
Definition capwheel.h:78
CAPWHEEL_RETVAL capwheel_init(capwheel_t *ctx, capwheel_cfg_t *cfg)
Initialization function.
void capwheel_generic_read(capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void capwheel_default_cfg(capwheel_t *ctx)
Click Default Configuration function.
uint8_t capwheel_read_reg(capwheel_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes)
Generic Read function.
uint8_t capwheel_enable_chann(capwheel_t *ctx, uint16_t sel_chann)
Channel Enable function.
uint8_t capwheel_check_data_ready(capwheel_t *ctx)
Data Ready Check function.
void capwheel_get_data(capwheel_t *ctx, uint16_t *wheel_data)
Data Get function.
void capwheel_reset(capwheel_t *ctx)
Reset function.
void capwheel_set_output(capwheel_t *ctx, uint16_t input_data, uint8_t output_mode)
Output Set function.
void capwheel_cfg_setup(capwheel_cfg_t *cfg)
Config Object Initialization function.
uint8_t capwheel_write_reg(capwheel_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes)
Generic Write function.
void capwheel_generic_write(capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void capwheel_set_threshold(capwheel_t *ctx, uint8_t thresh_value)
Threshold Set function.
Click configuration structure definition.
Definition capwheel.h:233
pin_name_t clr
Definition capwheel.h:241
uint32_t i2c_speed
Definition capwheel.h:246
pin_name_t scl
Definition capwheel.h:236
pin_name_t rdy
Definition capwheel.h:242
pin_name_t sda
Definition capwheel.h:237
uint8_t i2c_address
Definition capwheel.h:247
Click ctx object definition.
Definition capwheel.h:210
i2c_master_t i2c
Definition capwheel.h:221
uint8_t slave_address
Definition capwheel.h:225
digital_out_t clr
Definition capwheel.h:213
digital_in_t rdy
Definition capwheel.h:217