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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
64 #define VIBRASENSE2_RESOLUTION 4096
65 #define VIBRASENSE2_12_BIT_DATA 0x0FFF
66 
71 #define VIBRASENSE2_VIBRA_LVL_ERROR -1
72 #define VIBRASENSE2_VIBRA_LVL_0 0
73 #define VIBRASENSE2_VIBRA_LVL_1 1
74 #define VIBRASENSE2_VIBRA_LVL_2 2
75 #define VIBRASENSE2_VIBRA_LVL_3 3
76 #define VIBRASENSE2_VIBRA_LVL_4 4
77 #define VIBRASENSE2_VIBRA_LVL_5 5
78 #define VIBRASENSE2_VIBRA_LVL_6 6
79 
85 #define VIBRASENSE2_SET_DEV_ADDR 0x4D
86  // vibrasense2_set
88 
103 #define VIBRASENSE2_MAP_MIKROBUS( cfg, mikrobus ) \
104  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
105  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
106  // vibrasense2_map // vibrasense2
108 
113 typedef struct
114 {
115  // Modules
116  i2c_master_t i2c;
118  // I2C slave address
119  uint8_t slave_address;
121 } vibrasense2_t;
122 
127 typedef struct
128 {
129  pin_name_t scl;
130  pin_name_t sda;
132  uint32_t i2c_speed;
133  uint8_t i2c_address;
136 
141 typedef enum
142 {
144  VIBRASENSE2_ERROR = -1
145 
147 
164 
179 
194 err_t vibrasense2_generic_write ( vibrasense2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
195 
210 err_t vibrasense2_generic_read ( vibrasense2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
211 
219 uint16_t vibrasense2_read_data ( vibrasense2_t *ctx );
220 
229 uint16_t vibrasense2_read_voltage ( vibrasense2_t *ctx, uint16_t v_ref );
230 
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 #endif // VIBRASENSE2_H
247  // vibrasense2
249 
250 // ------------------------------------------------------------------------ END
VIBRASENSE2_ERROR
Definition: vibrasense2.h:143
vibrasense2_t
Vibra Sense 2 Click context object.
Definition: vibrasense2.h:112
vibrasense2_read_voltage
uint16_t vibrasense2_read_voltage(vibrasense2_t *ctx, uint16_t v_ref)
Read voltage function.
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
Definition: vibrasense2.h:142
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_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:140
vibrasense2_cfg_t
Vibra Sense 2 Click configuration object.
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_setup
void vibrasense2_cfg_setup(vibrasense2_cfg_t *cfg)
Vibra Sense 2 configuration object setup function.