vibrasense2  2.0.0.0
vibrasense2.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 VIBRASENSE2_H
29 #define VIBRASENSE2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
74 #define VIBRASENSE2_RESOLUTION 4096
75 #define VIBRASENSE2_12_BIT_DATA 0x0FFF
76 
81 #define VIBRASENSE2_VIBRA_LVL_ERROR -1
82 #define VIBRASENSE2_VIBRA_LVL_0 0
83 #define VIBRASENSE2_VIBRA_LVL_1 1
84 #define VIBRASENSE2_VIBRA_LVL_2 2
85 #define VIBRASENSE2_VIBRA_LVL_3 3
86 #define VIBRASENSE2_VIBRA_LVL_4 4
87 #define VIBRASENSE2_VIBRA_LVL_5 5
88 #define VIBRASENSE2_VIBRA_LVL_6 6
89 
95 #define VIBRASENSE2_SET_DEV_ADDR 0x4D
96  // vibrasense2_set
98 
113 #define VIBRASENSE2_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
115  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
116  // vibrasense2_map // vibrasense2
118 
123 typedef struct
124 {
125  // Modules
126  i2c_master_t i2c;
128  // I2C slave address
129  uint8_t slave_address;
131 } vibrasense2_t;
132 
137 typedef struct
138 {
139  pin_name_t scl;
140  pin_name_t sda;
142  uint32_t i2c_speed;
143  uint8_t i2c_address;
146 
151 typedef enum
152 {
154  VIBRASENSE2_ERROR = -1
155 
157 
174 
189 
204 err_t vibrasense2_generic_write ( vibrasense2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
205 
220 err_t vibrasense2_generic_read ( vibrasense2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
221 
230 
239 uint16_t vibrasense2_read_voltage ( vibrasense2_t *ctx, uint16_t v_ref );
240 
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 #endif // VIBRASENSE2_H
257  // vibrasense2
259 
260 // ------------------------------------------------------------------------ END
VIBRASENSE2_ERROR
@ VIBRASENSE2_ERROR
Definition: vibrasense2.h:154
vibrasense2_t
Vibra Sense 2 Click context object.
Definition: vibrasense2.h:124
vibrasense2_read_voltage
uint16_t vibrasense2_read_voltage(vibrasense2_t *ctx, uint16_t v_ref)
Read voltage function.
vibrasense2_cfg_t::scl
pin_name_t scl
Definition: vibrasense2.h:139
vibrasense2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: vibrasense2.h:142
vibrasense2_vibration_level
int8_t vibrasense2_vibration_level(vibrasense2_t *ctx)
Get Vibration Level function.
vibrasense2_read_data
uint16_t vibrasense2_read_data(vibrasense2_t *ctx)
Read data function.
VIBRASENSE2_OK
@ VIBRASENSE2_OK
Definition: vibrasense2.h:153
vibrasense2_cfg_t::sda
pin_name_t sda
Definition: vibrasense2.h:140
vibrasense2_generic_write
err_t vibrasense2_generic_write(vibrasense2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Vibra Sense 2 I2C writing function.
vibrasense2_t::slave_address
uint8_t slave_address
Definition: vibrasense2.h:129
vibrasense2_init
err_t vibrasense2_init(vibrasense2_t *ctx, vibrasense2_cfg_t *cfg)
Vibra Sense 2 initialization function.
vibrasense2_return_value_t
vibrasense2_return_value_t
Vibra Sense 2 Click return value data.
Definition: vibrasense2.h:152
vibrasense2_cfg_t
Vibra Sense 2 Click configuration object.
Definition: vibrasense2.h:138
vibrasense2_t::i2c
i2c_master_t i2c
Definition: vibrasense2.h:126
vibrasense2_generic_read
err_t vibrasense2_generic_read(vibrasense2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Vibra Sense 2 I2C reading function.
vibrasense2_cfg_t::i2c_address
uint8_t i2c_address
Definition: vibrasense2.h:143
vibrasense2_cfg_setup
void vibrasense2_cfg_setup(vibrasense2_cfg_t *cfg)
Vibra Sense 2 configuration object setup function.