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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define CAPWHEEL_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg. clr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg. rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define CAPWHEEL_RETVAL uint8_t
75 
76 #define CAPWHEEL_OK 0x00
77 #define CAPWHEEL_INIT_ERROR 0xFF
78 
84 #define CAPWHEEL_DEVICE_ADDR 0x64
85 
91 #define CAPWHEEL_DEVICE_INFO_REG 0x00
92 #define CAPWHEEL_SYSTEM_FLAGS_REG 0x01
93 #define CAPWHEEL_WHEEL_COORDNT_REG 0x02
94 #define CAPWHEEL_TOUCH_BYTES_REG 0x03
95 #define CAPWHEEL_COUNTS_REG 0x04
96 #define CAPWHEEL_LTA_REG 0x05
97 #define CAPWHEEL_MULTIPLIERS_REG 0x06
98 #define CAPWHEEL_COMPENS_REG 0x07
99 #define CAPWHEEL_PROXSETT_REG 0x08
100 #define CAPWHEEL_THRESH_REG 0x09
101 #define CAPWHEEL_TIMINGS_REG 0x0A
102 #define CAPWHEEL_TARGETS_REG 0x0B
103 #define CAPWHEEL_PWM_DUTY_REG 0x0C
104 #define CAPWHEEL_PWM_LIM_REG 0x0D
105 #define CAPWHEEL_ACTIVE_CHANN_REG 0x0E
106 #define CAPWHEEL_BUZZER_REG 0x0F
107 
113 #define CAPWHEEL_DEV_INFO_NBYTES 2
114 #define CAPWHEEL_SYST_FLAGS_NBYTES 1
115 #define CAPWHEEL_WHEEL_NBYTES 4
116 #define CAPWHEEL_TOUCH_NBYTES 2
117 #define CAPWHEEL_COUNTS_NBYTES 18
118 #define CAPWHEEL_LTA_NBYTES 18
119 #define CAPWHEEL_MULTIPL_NBYTES 9
120 #define CAPWHEEL_COMPENS_NBYTES 9
121 #define CAPWHEEL_PROXSETT_NBYTES 6
122 #define CAPWHEEL_THRESH_NBYTES 10
123 #define CAPWHEEL_TIMINGS_NBYTES 13
124 #define CAPWHEEL_TARGETS_NBYTES 10
125 #define CAPWHEEL_PWM_DUTY_NBYTES 8
126 #define CAPWHEEL_PWM_LIM_NBYTES 2
127 #define CAPWHEEL_ACT_CHANN_NBYTES 2
128 #define CAPWHEEL_BUZZER_NBYTES 1
129 
135 #define CAPWHEEL_BUZZER_EN 0x80
136 #define CAPWHEEL_BUZZER_DC_HIGH 0x04
137 #define CAPWHEEL_BUZZER_DC_LOW 0x00
138 #define CAPWHEEL_BUZZER_PERM_EN 0x02
139 #define CAPWHEEL_BUZZER_BURST_EN 0x01
140 
146 #define CAPWHEEL_CH0_PROX_EN 0x001
147 #define CAPWHEEL_CH1_EN 0x002
148 #define CAPWHEEL_CH2_EN 0x004
149 #define CAPWHEEL_CH3_EN 0x008
150 #define CAPWHEEL_CH4_EN 0x010
151 #define CAPWHEEL_CH5_EN 0x020
152 #define CAPWHEEL_CH6_EN 0x040
153 #define CAPWHEEL_CH7_EN 0x080
154 #define CAPWHEEL_CH8_EN 0x100
155 #define CAPWHEEL_CH9_EN 0x200
156 
162 #define CAPWHEEL_PWM_OFF 0x00
163 #define CAPWHEEL_PWM_CONST 0x20
164 #define CAPWHEEL_PWM_DECR_0_PERCENTS 0x80
165 #define CAPWHEEL_PWM_DECR_LIM 0xA0
166 #define CAPWHEEL_PWM_INCR_100_PERCENTS 0xC0
167 #define CAPWHEEL_PWM_INCR_LIM 0xE0
168 #define CAPWHEEL_PWM_DUTY_0_PERCENTS 0x00
169 #define CAPWHEEL_PWM_DUTY_25_PERCENTS 0x10
170 #define CAPWHEEL_PWM_DUTY_50_PERCENTS 0x18
171 #define CAPWHEEL_PWM_DUTY_75_PERCENTS 0x1C
172 #define CAPWHEEL_PWM_DUTY_100_PERCENTS 0x1F
173 
179 #define CAPWHEEL_DATA_READY 0
180 #define CAPWHEEL_DATA_NOT_READY 1
181 #define CAPWHEEL_ADDR_ERROR 0xFF
182 #define CAPWHEEL_NBYTES_ERROR 0xFE
183 #define CAPWHEEL_CH_SEL_ERROR 0xFD
184 #define CAPWHEEL_OK 0x00
185 
191 #define CAPWHEEL_LED_BRIGHTNESS_INTENSITY 0
192 #define CAPWHEEL_LED_BRIGHTNESS_NUMBER 1
193  // End group macro
196 // --------------------------------------------------------------- PUBLIC TYPES
205 typedef struct
206 {
207  // Output pins
208 
209  digital_out_t clr;
210 
211  // Input pins
212 
213  digital_in_t rdy;
214 
215  // Modules
216 
217  i2c_master_t i2c;
218 
219  // ctx variable
220 
221  uint8_t slave_address;
222 
223 } capwheel_t;
224 
228 typedef struct
229 {
230  // Communication gpio pins
231 
232  pin_name_t scl;
233  pin_name_t sda;
234 
235  // Additional gpio pins
236 
237  pin_name_t clr;
238  pin_name_t rdy;
239 
240  // static variable
241 
242  uint32_t i2c_speed;
243  uint8_t i2c_address;
244 
246  // End types group
248 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
249 
255 #ifdef __cplusplus
256 extern "C"{
257 #endif
258 
268 
277 
286 
297 void capwheel_generic_write ( capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
298 
310 void capwheel_generic_read ( capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
311 
324 uint8_t capwheel_write_reg ( capwheel_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes );
325 
338 uint8_t capwheel_read_reg ( capwheel_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes );
339 
350 
363 uint8_t capwheel_enable_chann ( capwheel_t *ctx, uint16_t sel_chann );
364 
373 void capwheel_get_data ( capwheel_t *ctx, uint16_t *wheel_data );
374 
386 void capwheel_set_output( capwheel_t *ctx, uint16_t input_data, uint8_t output_mode );
387 
397 void capwheel_set_threshold ( capwheel_t *ctx, uint8_t thresh_value );
398 
407 
408 #ifdef __cplusplus
409 }
410 #endif
411 #endif // _CAPWHEEL_H_
412  // End public_function group
415 
416 // ------------------------------------------------------------------------- END
capwheel_default_cfg
void capwheel_default_cfg(capwheel_t *ctx)
Click Default Configuration function.
capwheel_get_data
void capwheel_get_data(capwheel_t *ctx, uint16_t *wheel_data)
Data Get function.
capwheel_cfg_t::i2c_address
uint8_t i2c_address
Definition: capwheel.h:243
capwheel_write_reg
uint8_t capwheel_write_reg(capwheel_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes)
Generic Write function.
capwheel_cfg_t::scl
pin_name_t scl
Definition: capwheel.h:232
capwheel_generic_read
void capwheel_generic_read(capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
capwheel_cfg_setup
void capwheel_cfg_setup(capwheel_cfg_t *cfg)
Config Object Initialization function.
capwheel_check_data_ready
uint8_t capwheel_check_data_ready(capwheel_t *ctx)
Data Ready Check function.
capwheel_cfg_t::clr
pin_name_t clr
Definition: capwheel.h:237
capwheel_cfg_t::rdy
pin_name_t rdy
Definition: capwheel.h:238
capwheel_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: capwheel.h:242
capwheel_reset
void capwheel_reset(capwheel_t *ctx)
Reset function.
capwheel_t::clr
digital_out_t clr
Definition: capwheel.h:209
capwheel_generic_write
void capwheel_generic_write(capwheel_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
capwheel_set_output
void capwheel_set_output(capwheel_t *ctx, uint16_t input_data, uint8_t output_mode)
Output Set function.
capwheel_t::i2c
i2c_master_t i2c
Definition: capwheel.h:217
capwheel_t
Click ctx object definition.
Definition: capwheel.h:206
capwheel_cfg_t::sda
pin_name_t sda
Definition: capwheel.h:233
capwheel_t::slave_address
uint8_t slave_address
Definition: capwheel.h:221
capwheel_enable_chann
uint8_t capwheel_enable_chann(capwheel_t *ctx, uint16_t sel_chann)
Channel Enable function.
capwheel_cfg_t
Click configuration structure definition.
Definition: capwheel.h:229
capwheel_t::rdy
digital_in_t rdy
Definition: capwheel.h:213
CAPWHEEL_RETVAL
#define CAPWHEEL_RETVAL
Definition: capwheel.h:74
capwheel_read_reg
uint8_t capwheel_read_reg(capwheel_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes)
Generic Read function.
capwheel_set_threshold
void capwheel_set_threshold(capwheel_t *ctx, uint8_t thresh_value)
Threshold Set function.
capwheel_init
CAPWHEEL_RETVAL capwheel_init(capwheel_t *ctx, capwheel_cfg_t *cfg)
Initialization function.