c6dofimu7  2.0.0.0
c6dofimu7.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 C6DOFIMU7_H
36 #define C6DOFIMU7_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_in.h"
53 #include "drv_i2c_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define C6DOFIMU7_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define C6DOFIMU7_RETVAL uint8_t
77 
78 #define C6DOFIMU7_OK 0x00
79 #define C6DOFIMU7_INIT_ERROR 0xFF
80 
86 #define C6DOFIMU7_SLAVE_ADDRESS 0x68
87 #define C6DOFIMU7_PWR_MGMT 0x06
88 #define C6DOFIMU7_PWM_MGMT_L 0x80
89 #define C6DOFIMU7_PWM_MGMT_H 0x01
90 #define C6DOFIMU7_TEMP_OUT_H 0x39
91 #define C6DOFIMU7_ACCEL_XOUT_H 0x2D
92 #define C6DOFIMU7_ACCEL_YOUT_H 0x2F
93 #define C6DOFIMU7_ACCEL_ZOUT_H 0x31
94 #define C6DOFIMU7_GYRO_XOUT_H 0x33
95 #define C6DOFIMU7_GYRO_YOUT_H 0x35
96 #define C6DOFIMU7_GYRO_ZOUT_H 0x37
97 
103 #define C6DOFIMU7_TEMPERATURE_SENSITIVITY 333.87
104 #define C6DOFIMU7_TEMPERATURE_OFFSET 6.3
105 #define C6DOFIMU7_ACCEL_SENSITIVITY 8.192
106 #define C6DOFIMU7_GYRO_SENSITIVITY 65.5
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
119 typedef struct
120 {
121  float x_axis;
122  float y_axis;
123  float z_axis;
124 
126 
130 typedef struct
131 {
132  // Input pins
133 
134  digital_in_t int2;
135  digital_in_t int1;
136 
137  // Modules
138 
139  i2c_master_t i2c;
140 
141  // ctx variable
142 
143  uint8_t slave_address;
144 
145 } c6dofimu7_t;
146 
150 typedef struct
151 {
152  // Communication gpio pins
153 
154  pin_name_t scl;
155  pin_name_t sda;
156 
157  // Additional gpio pins
158 
159  pin_name_t int2;
160  pin_name_t int1;
161 
162  // static variable
163 
164  uint32_t i2c_speed;
165  uint8_t i2c_address;
166 
168  // End types group
170 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
171 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 
200 
209 
220 void c6dofimu7_generic_write ( c6dofimu7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
221 
232 void c6dofimu7_generic_read ( c6dofimu7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
233 
242 int16_t c6dofimu7_read_word ( c6dofimu7_t *ctx, uint8_t address );
243 
253 float c6dofimu7_get_temp_data ( c6dofimu7_t *ctx, float temp_sensitivity, float temp_offset );
254 
264 void c6dofimu7_get_accel_data ( c6dofimu7_t *ctx, c6dofimu7_axis_t *accel, float sensitivity );
265 
275 void c6dofimu7_get_gyro_data ( c6dofimu7_t *ctx, c6dofimu7_axis_t *gyro, float sensitivity );
276 
285 
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // _C6DOFIMU7_H_
299  // End public_function group
302 
303 // ------------------------------------------------------------------------- END
c6dofimu7_cfg_t::int1
pin_name_t int1
Definition: c6dofimu7.h:160
c6dofimu7_t::int2
digital_in_t int2
Definition: c6dofimu7.h:134
c6dofimu7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu7.h:164
c6dofimu7_cfg_t::scl
pin_name_t scl
Definition: c6dofimu7.h:154
C6DOFIMU7_RETVAL
#define C6DOFIMU7_RETVAL
Definition: c6dofimu7.h:76
c6dofimu7_axis_t::z_axis
float z_axis
Definition: c6dofimu7.h:123
c6dofimu7_axis_t::x_axis
float x_axis
Definition: c6dofimu7.h:121
c6dofimu7_generic_read
void c6dofimu7_generic_read(c6dofimu7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c6dofimu7_cfg_t
Click configuration structure definition.
Definition: c6dofimu7.h:151
c6dofimu7_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu7.h:165
c6dofimu7_cfg_setup
void c6dofimu7_cfg_setup(c6dofimu7_cfg_t *cfg)
Config Object Initialization function.
c6dofimu7_get_int_input
uint8_t c6dofimu7_get_int_input(c6dofimu7_t *ctx)
Get INT input function.
c6dofimu7_get_gyro_data
void c6dofimu7_get_gyro_data(c6dofimu7_t *ctx, c6dofimu7_axis_t *gyro, float sensitivity)
Get gyroscope data function.
c6dofimu7_read_word
int16_t c6dofimu7_read_word(c6dofimu7_t *ctx, uint8_t address)
Read word function.
c6dofimu7_axis_t
Sensor axis structure.
Definition: c6dofimu7.h:120
c6dofimu7_get_pwm_input
uint8_t c6dofimu7_get_pwm_input(c6dofimu7_t *ctx)
Get PWM input function.
c6dofimu7_t::i2c
i2c_master_t i2c
Definition: c6dofimu7.h:139
c6dofimu7_cfg_t::sda
pin_name_t sda
Definition: c6dofimu7.h:155
c6dofimu7_cfg_t::int2
pin_name_t int2
Definition: c6dofimu7.h:159
c6dofimu7_generic_write
void c6dofimu7_generic_write(c6dofimu7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c6dofimu7_t
Click ctx object definition.
Definition: c6dofimu7.h:131
c6dofimu7_axis_t::y_axis
float y_axis
Definition: c6dofimu7.h:122
c6dofimu7_t::int1
digital_in_t int1
Definition: c6dofimu7.h:135
c6dofimu7_default_cfg
void c6dofimu7_default_cfg(c6dofimu7_t *ctx)
Click Default Configuration function.
c6dofimu7_get_temp_data
float c6dofimu7_get_temp_data(c6dofimu7_t *ctx, float temp_sensitivity, float temp_offset)
Get temperature data function.
c6dofimu7_init
C6DOFIMU7_RETVAL c6dofimu7_init(c6dofimu7_t *ctx, c6dofimu7_cfg_t *cfg)
Initialization function.
c6dofimu7_get_accel_data
void c6dofimu7_get_accel_data(c6dofimu7_t *ctx, c6dofimu7_axis_t *accel, float sensitivity)
Get accelerometer data function.
c6dofimu7_t::slave_address
uint8_t slave_address
Definition: c6dofimu7.h:143