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 "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 CAPSLIDER2_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 CAPSLIDER2_RETVAL uint8_t
75 
76 #define CAPSLIDER2_OK 0x00
77 #define CAPSLIDER2_INIT_ERROR 0xFF
78 
84 #define CAPSLDR2_DEVICE_ADDR 0x64
85 
91 #define CAPSLDR2_DEVICE_INFO_REG 0x00
92 #define CAPSLDR2_SYSTEM_FLAGS_REG 0x01
93 #define CAPSLDR2_WHEEL_COORDNT_REG 0x02
94 #define CAPSLDR2_TOUCH_BYTES_REG 0x03
95 #define CAPSLDR2_COUNTS_REG 0x04
96 #define CAPSLDR2_LTA_REG 0x05
97 #define CAPSLDR2_MULTIPLIERS_REG 0x06
98 #define CAPSLDR2_COMPENS_REG 0x07
99 #define CAPSLDR2_PROXSETT_REG 0x08
100 #define CAPSLDR2_THRESH_REG 0x09
101 #define CAPSLDR2_TIMINGS_REG 0x0A
102 #define CAPSLDR2_TARGETS_REG 0x0B
103 #define CAPSLDR2_PWM_DUTY_REG 0x0C
104 #define CAPSLDR2_PWM_LIM_REG 0x0D
105 #define CAPSLDR2_ACTIVE_CHANN_REG 0x0E
106 #define CAPSLDR2_BUZZER_REG 0x0F
107 
113 #define CAPSLDR2_DEV_INFO_NBYTES 2
114 #define CAPSLDR2_SYST_FLAGS_NBYTES 1
115 #define CAPSLDR2_WHEEL_NBYTES 4
116 #define CAPSLDR2_TOUCH_NBYTES 2
117 #define CAPSLDR2_COUNTS_NBYTES 18
118 #define CAPSLDR2_LTA_NBYTES 18
119 #define CAPSLDR2_MULTIPL_NBYTES 10
120 #define CAPSLDR2_COMPENS_NBYTES 10
121 #define CAPSLDR2_PROXSETT_NBYTES 6
122 #define CAPSLDR2_THRESH_NBYTES 10
123 #define CAPSLDR2_TIMINGS_NBYTES 13
124 #define CAPSLDR2_TARGETS_NBYTES 10
125 #define CAPSLDR2_PWM_DUTY_NBYTES 8
126 #define CAPSLDR2_PWM_LIM_NBYTES 2
127 #define CAPSLDR2_ACT_CHANN_NBYTES 2
128 #define CAPSLDR2_BUZZER_NBYTES 1
129 
135 #define CAPSLDR2_BUZZER_EN 0x80
136 #define CAPSLDR2_BUZZER_DC_HIGH 0x04
137 #define CAPSLDR2_BUZZER_DC_LOW 0x00
138 #define CAPSLDR2_BUZZER_PERM_EN 0x02
139 #define CAPSLDR2_BUZZER_BURST_EN 0x01
140 
146 #define CAPSLDR2_CH0_PROX_EN 0x001
147 #define CAPSLDR2_CH1_EN 0x002
148 #define CAPSLDR2_CH2_EN 0x004
149 #define CAPSLDR2_CH3_EN 0x008
150 #define CAPSLDR2_CH4_EN 0x010
151 #define CAPSLDR2_CH5_EN 0x020
152 #define CAPSLDR2_CH6_EN 0x040
153 #define CAPSLDR2_CH7_EN 0x080
154 #define CAPSLDR2_CH8_EN 0x100
155 #define CAPSLDR2_CH9_EN 0x200
156 
162 #define CAPSLDR2_PWM_OFF 0x00
163 #define CAPSLDR2_PWM_CONST 0x20
164 #define CAPSLDR2_PWM_DECR_0_PERCENTS 0x80
165 #define CAPSLDR2_PWM_DECR_LIM 0xA0
166 #define CAPSLDR2_PWM_INCR_100_PERCENTS 0xC0
167 #define CAPSLDR2_PWM_INCR_LIM 0xE0
168 #define CAPSLDR2_PWM_DUTY_0_PERCENTS 0x00
169 #define CAPSLDR2_PWM_DUTY_25_PERCENTS 0x10
170 #define CAPSLDR2_PWM_DUTY_50_PERCENTS 0x18
171 #define CAPSLDR2_PWM_DUTY_75_PERCENTS 0x1C
172 #define CAPSLDR2_PWM_DUTY_100_PERCENTS 0x1F
173 
179 #define CAPSLDR2_DATA_READY 0
180 #define CAPSLDR2_DATA_NOT_READY 1
181 #define CAPSLDR2_INVALID_ADDR 0xFF
182 #define CAPSLDR2_INVALID_NBYTES 0xFE
183 #define CAPSLDR2_INVALID_CHANNEL 0xFD
184 #define CAPSLDR2_OK 0x00
185 
191 #define CAPSLDR2_LED_INTENSITY 0
192 #define CAPSLDR2_LED_NUMBER 1
193  // End group macro
198 // --------------------------------------------------------------- PUBLIC TYPES
207 typedef struct
208 {
209  // Output pins
210 
211  digital_out_t clr;
212 
213  // Input pins
214 
215  digital_in_t rdy;
216 
217  // Modules
218 
219  i2c_master_t i2c;
220 
221  // ctx variable
222 
223  uint8_t slave_address;
224 
225 } capslider2_t;
226 
230 typedef struct
231 {
232  // Communication gpio pins
233 
234  pin_name_t scl;
235  pin_name_t sda;
236 
237  // Additional gpio pins
238 
239  pin_name_t clr;
240  pin_name_t rdy;
241 
242  // static variable
243 
244  uint32_t i2c_speed;
245  uint8_t i2c_address;
246 
248  // End types group
250 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
251 
257 #ifdef __cplusplus
258 extern "C"{
259 #endif
260 
270 
279 
290 void capslider2_generic_write ( capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
291 
303 void capslider2_generic_read ( capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
304 
305 
318 uint8_t capsldr2_write_reg ( capslider2_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes );
319 
332 uint8_t capsldr2_read_reg ( capslider2_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes );
333 
344 
358 uint8_t capsldr2_enable_chann ( capslider2_t *ctx, uint16_t sel_chann );
359 
369 void capsldr2_get_data( capslider2_t *ctx, uint16_t *wheel_data1, uint16_t *wheel_data2 );
370 
383 void capsldr2_set_output ( capslider2_t *ctx, uint8_t input_data, uint8_t output_mode );
384 
394 void capsldr2_set_threshold ( capslider2_t *ctx, uint8_t thresh_value );
395 
404 
413 
414 #ifdef __cplusplus
415 }
416 #endif
417 #endif // _CAPSLIDER2_H_
418  // End public_function group
421 
422 // ------------------------------------------------------------------------- END
capslider2_generic_write
void capslider2_generic_write(capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
capsldr2_write_reg
uint8_t capsldr2_write_reg(capslider2_t *ctx, uint8_t register_address, uint8_t *data_in, uint8_t n_bytes)
Generic Write function.
capslider2_cfg_t::clr
pin_name_t clr
Definition: capslider2.h:239
capsldr2_read_reg
uint8_t capsldr2_read_reg(capslider2_t *ctx, uint8_t register_address, uint8_t *data_out, uint8_t n_bytes)
Generic Read function.
capslider2_t::clr
digital_out_t clr
Definition: capslider2.h:211
capslider2_cfg_setup
void capslider2_cfg_setup(capslider2_cfg_t *cfg)
Config Object Initialization function.
capslider2_generic_read
void capslider2_generic_read(capslider2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
capslider2_t
Click ctx object definition.
Definition: capslider2.h:208
capsldr2_enable_chann
uint8_t capsldr2_enable_chann(capslider2_t *ctx, uint16_t sel_chann)
Channel Enable function.
capslider2_cfg_t
Click configuration structure definition.
Definition: capslider2.h:231
capslider2_cfg_t::scl
pin_name_t scl
Definition: capslider2.h:234
capslider2_cfg_t::i2c_address
uint8_t i2c_address
Definition: capslider2.h:245
capsldr2_reset
void capsldr2_reset(capslider2_t *ctx)
Reset function.
capslider2_t::i2c
i2c_master_t i2c
Definition: capslider2.h:219
capsldr2_set_output
void capsldr2_set_output(capslider2_t *ctx, uint8_t input_data, uint8_t output_mode)
Output Set function.
capslider2_cfg_t::sda
pin_name_t sda
Definition: capslider2.h:235
capsldr2_config
void capsldr2_config(capslider2_t *ctx)
Config function.
capslider2_init
CAPSLIDER2_RETVAL capslider2_init(capslider2_t *ctx, capslider2_cfg_t *cfg)
Initialization function.
capslider2_t::rdy
digital_in_t rdy
Definition: capslider2.h:215
capslider2_t::slave_address
uint8_t slave_address
Definition: capslider2.h:223
capsldr2_get_data
void capsldr2_get_data(capslider2_t *ctx, uint16_t *wheel_data1, uint16_t *wheel_data2)
Data Get function.
capsldr2_check_data_ready
uint8_t capsldr2_check_data_ready(capslider2_t *ctx)
Data Ready Check function.
capslider2_cfg_t::rdy
pin_name_t rdy
Definition: capslider2.h:240
capslider2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: capslider2.h:244
capsldr2_set_threshold
void capsldr2_set_threshold(capslider2_t *ctx, uint8_t thresh_value)
Threshold Set function.
CAPSLIDER2_RETVAL
#define CAPSLIDER2_RETVAL
Definition: capslider2.h:74