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 
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_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define C6DOFIMU7_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
65  cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define C6DOFIMU7_RETVAL uint8_t
73 
74 #define C6DOFIMU7_OK 0x00
75 #define C6DOFIMU7_INIT_ERROR 0xFF
76 
82 #define C6DOFIMU7_SLAVE_ADDRESS 0x68
83 #define C6DOFIMU7_PWR_MGMT 0x06
84 #define C6DOFIMU7_PWM_MGMT_L 0x80
85 #define C6DOFIMU7_PWM_MGMT_H 0x01
86 #define C6DOFIMU7_TEMP_OUT_H 0x39
87 #define C6DOFIMU7_ACCEL_XOUT_H 0x2D
88 #define C6DOFIMU7_ACCEL_YOUT_H 0x2F
89 #define C6DOFIMU7_ACCEL_ZOUT_H 0x31
90 #define C6DOFIMU7_GYRO_XOUT_H 0x33
91 #define C6DOFIMU7_GYRO_YOUT_H 0x35
92 #define C6DOFIMU7_GYRO_ZOUT_H 0x37
93 
99 #define C6DOFIMU7_TEMPERATURE_SENSITIVITY 333.87
100 #define C6DOFIMU7_TEMPERATURE_OFFSET 6.3
101 #define C6DOFIMU7_ACCEL_SENSITIVITY 8.192
102 #define C6DOFIMU7_GYRO_SENSITIVITY 65.5
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  float x_axis;
118  float y_axis;
119  float z_axis;
120 
122 
126 typedef struct
127 {
128  // Input pins
129 
130  digital_in_t int2;
131  digital_in_t int1;
132 
133  // Modules
134 
135  i2c_master_t i2c;
136 
137  // ctx variable
138 
139  uint8_t slave_address;
140 
141 } c6dofimu7_t;
142 
146 typedef struct
147 {
148  // Communication gpio pins
149 
150  pin_name_t scl;
151  pin_name_t sda;
152 
153  // Additional gpio pins
154 
155  pin_name_t int2;
156  pin_name_t int1;
157 
158  // static variable
159 
160  uint32_t i2c_speed;
161  uint8_t i2c_address;
162 
164  // End types group
166 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
186 
196 
205 
216 void c6dofimu7_generic_write ( c6dofimu7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
217 
228 void c6dofimu7_generic_read ( c6dofimu7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
229 
238 int16_t c6dofimu7_read_word ( c6dofimu7_t *ctx, uint8_t address );
239 
249 float c6dofimu7_get_temp_data ( c6dofimu7_t *ctx, float temp_sensitivity, float temp_offset );
250 
260 void c6dofimu7_get_accel_data ( c6dofimu7_t *ctx, c6dofimu7_axis_t *accel, float sensitivity );
261 
271 void c6dofimu7_get_gyro_data ( c6dofimu7_t *ctx, c6dofimu7_axis_t *gyro, float sensitivity );
272 
281 
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 #endif // _C6DOFIMU7_H_
295  // End public_function group
298 
299 // ------------------------------------------------------------------------- END
c6dofimu7_cfg_t::int1
pin_name_t int1
Definition: c6dofimu7.h:156
c6dofimu7_t::int2
digital_in_t int2
Definition: c6dofimu7.h:130
c6dofimu7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu7.h:160
c6dofimu7_cfg_t::scl
pin_name_t scl
Definition: c6dofimu7.h:150
C6DOFIMU7_RETVAL
#define C6DOFIMU7_RETVAL
Definition: c6dofimu7.h:72
c6dofimu7_axis_t::z_axis
float z_axis
Definition: c6dofimu7.h:119
c6dofimu7_axis_t::x_axis
float x_axis
Definition: c6dofimu7.h:117
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:147
c6dofimu7_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu7.h:161
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:116
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:135
c6dofimu7_cfg_t::sda
pin_name_t sda
Definition: c6dofimu7.h:151
c6dofimu7_cfg_t::int2
pin_name_t int2
Definition: c6dofimu7.h:155
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:127
c6dofimu7_axis_t::y_axis
float y_axis
Definition: c6dofimu7.h:118
c6dofimu7_t::int1
digital_in_t int1
Definition: c6dofimu7.h:131
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:139