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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
78#define VIBRASENSE2_RESOLUTION 4096
79#define VIBRASENSE2_12_BIT_DATA 0x0FFF
80
85#define VIBRASENSE2_VIBRA_LVL_ERROR -1
86#define VIBRASENSE2_VIBRA_LVL_0 0
87#define VIBRASENSE2_VIBRA_LVL_1 1
88#define VIBRASENSE2_VIBRA_LVL_2 2
89#define VIBRASENSE2_VIBRA_LVL_3 3
90#define VIBRASENSE2_VIBRA_LVL_4 4
91#define VIBRASENSE2_VIBRA_LVL_5 5
92#define VIBRASENSE2_VIBRA_LVL_6 6
93
99#define VIBRASENSE2_SET_DEV_ADDR 0x4D
100
101 // vibrasense2_set
102
117#define VIBRASENSE2_MAP_MIKROBUS( cfg, mikrobus ) \
118 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
119 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
120 // vibrasense2_map
121 // vibrasense2
122
127typedef struct
128{
129 // Modules
130 i2c_master_t i2c;
132 // I2C slave address
136
141typedef struct
142{
143 pin_name_t scl;
144 pin_name_t sda;
146 uint32_t i2c_speed;
147 uint8_t i2c_address;
150
161
178
193
208err_t vibrasense2_generic_write ( vibrasense2_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
209
224err_t vibrasense2_generic_read ( vibrasense2_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
225
234
243uint16_t vibrasense2_read_voltage ( vibrasense2_t *ctx, uint16_t v_ref );
244
256
257#ifdef __cplusplus
258}
259#endif
260#endif // VIBRASENSE2_H
261
262 // vibrasense2
263
264// ------------------------------------------------------------------------ END
uint16_t vibrasense2_read_data(vibrasense2_t *ctx)
Read data function.
int8_t vibrasense2_vibration_level(vibrasense2_t *ctx)
Get Vibration Level function.
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.
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.
void vibrasense2_cfg_setup(vibrasense2_cfg_t *cfg)
Vibra Sense 2 configuration object setup function.
err_t vibrasense2_init(vibrasense2_t *ctx, vibrasense2_cfg_t *cfg)
Vibra Sense 2 initialization function.
uint16_t vibrasense2_read_voltage(vibrasense2_t *ctx, uint16_t v_ref)
Read voltage function.
Vibra Sense 2 Click configuration object.
Definition vibrasense2.h:142
uint32_t i2c_speed
Definition vibrasense2.h:146
pin_name_t scl
Definition vibrasense2.h:143
pin_name_t sda
Definition vibrasense2.h:144
uint8_t i2c_address
Definition vibrasense2.h:147
Vibra Sense 2 Click context object.
Definition vibrasense2.h:128
i2c_master_t i2c
Definition vibrasense2.h:130
uint8_t slave_address
Definition vibrasense2.h:133
vibrasense2_return_value_t
Vibra Sense 2 Click return value data.
Definition vibrasense2.h:156
@ VIBRASENSE2_OK
Definition vibrasense2.h:157
@ VIBRASENSE2_ERROR
Definition vibrasense2.h:158