c9dof  2.0.0.0
c9dof.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 C9DOF_H
36 #define C9DOF_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_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define C9DOF_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define C9DOF_RETVAL uint8_t
74 
75 #define C9DOF_OK 0x00
76 #define C9DOF_INIT_ERROR 0xFF
77 
83 #define C9DOF_SLAVE_ADDRESS_ACCEL_GYRO_0 0x6A
84 #define C9DOF_SLAVE_ADDRESS_MAG_0 0x1C
85 #define C9DOF_SLAVE_ADDRESS_ACCEL_GYRO_1 0x6B
86 #define C9DOF_SLAVE_ADDRESS_MAG_1 0x1E
87 
93 #define C9DOF_REG_ACT_THS 0x04
94 #define C9DOF_REG_ACT_DUR 0x05
95 #define C9DOF_REG_INT_GEN_CFG_XL 0x06
96 #define C9DOF_REG_INT_GEN_THS_X_XL 0x07
97 #define C9DOF_REG_INT_GEN_THS_Y_XL 0x08
98 #define C9DOF_REG_INT_GEN_THS_Z_XL 0x09
99 #define C9DOF_REG_INT_GEN_DUR_XL 0x0A
100 #define C9DOF_REG_REFERENCE_G 0x0B
101 #define C9DOF_REG_INT1_CTRL 0x0C
102 #define C9DOF_REG_INT2_CTRL 0x0D
103 #define C9DOF_REG_WHO_AM_I 0x0F
104 #define C9DOF_REG_CTRL_REG1_G 0x10
105 #define C9DOF_REG_CTRL_REG2_G 0x11
106 #define C9DOF_REG_CTRL_REG3_G 0x12
107 #define C9DOF_REG_ORIENT_CFG_G 0x13
108 #define C9DOF_REG_INT_GEN_SRC_G 0x14
109 #define C9DOF_REG_OUT_TEMP_L 0x15
110 #define C9DOF_REG_OUT_TEMP_H 0x16
111 #define C9DOF_REG_STATUS_REG 0x17
112 #define C9DOF_REG_OUT_X_L_G 0x18
113 #define C9DOF_REG_OUT_X_H_G 0x19
114 #define C9DOF_REG_OUT_Y_L_G 0x1A
115 #define C9DOF_REG_OUT_Y_H_G 0x1B
116 #define C9DOF_REG_OUT_Z_L_G 0x1C
117 #define C9DOF_REG_OUT_Z_H_G 0x1D
118 #define C9DOF_REG_CTRL_REG4 0x1E
119 #define C9DOF_REG_CTRL_REG5_XL 0x1F
120 #define C9DOF_REG_CTRL_REG6_XL 0x20
121 #define C9DOF_REG_CTRL_REG7_XL 0x21
122 #define C9DOF_REG_CTRL_REG8 0x22
123 #define C9DOF_REG_CTRL_REG9 0x23
124 #define C9DOF_REG_CTRL_REG10 0x24
125 #define C9DOF_REG_INT_GEN_SRC_XL 0x26
126 #define C9DOF_REG_OUT_X_L_XL 0x28
127 #define C9DOF_REG_OUT_X_H_XL 0x29
128 #define C9DOF_REG_OUT_Y_L_XL 0x2A
129 #define C9DOF_REG_OUT_Y_H_XL 0x2B
130 #define C9DOF_REG_OUT_Z_L_XL 0x2C
131 #define C9DOF_REG_OUT_Z_H_XL 0x2D
132 #define C9DOF_REG_FIFO_CTRL 0x2E
133 #define C9DOF_REG_FIFO_SRC 0x2F
134 #define C9DOF_REG_INT_GEN_CFG_G 0x30
135 #define C9DOF_REG_INT_GEN_THS_XH_G 0x31
136 #define C9DOF_REG_INT_GEN_THS_XL_G 0x32
137 #define C9DOF_REG_INT_GEN_THS_YH_G 0x33
138 #define C9DOF_REG_INT_GEN_THS_YL_G 0x34
139 #define C9DOF_REG_INT_GEN_THS_ZH_G 0x35
140 #define C9DOF_REG_INT_GEN_THS_ZL_G 0x36
141 #define C9DOF_REG_INT_GEN_DUR_G 0x37
142 
148 #define C9DOF_REG_OFFSET_X_REG_L_M 0x05
149 #define C9DOF_REG_OFFSET_X_REG_H_M 0x06
150 #define C9DOF_REG_OFFSET_Y_REG_L_M 0x07
151 #define C9DOF_REG_OFFSET_Y_REG_H_M 0x08
152 #define C9DOF_REG_OFFSET_Z_REG_L_M 0x09
153 #define C9DOF_REG_OFFSET_Z_REG_H_M 0x0A
154 #define C9DOF_REG_CTRL_REG1_M 0x20
155 #define C9DOF_REG_CTRL_REG2_M 0x21
156 #define C9DOF_REG_CTRL_REG3_M 0x22
157 #define C9DOF_REG_CTRL_REG4_M 0x23
158 #define C9DOF_REG_CTRL_REG5_M 0x24
159 #define C9DOF_REG_STATUS_REG_M 0x27
160 #define C9DOF_REG_OUT_X_L_M 0x28
161 #define C9DOF_REG_OUT_X_H_M 0x29
162 #define C9DOF_REG_OUT_Y_L_M 0x2A
163 #define C9DOF_REG_OUT_Y_H_M 0x2B
164 #define C9DOF_REG_OUT_Z_L_M 0x2C
165 #define C9DOF_REG_OUT_Z_H_M 0x2D
166 #define C9DOF_REG_INT_CFG_M 0x30
167 #define C9DOF_REG_INT_SRC_M 0x31
168 #define C9DOF_REG_INT_THS_L_M 0x32
169 #define C9DOF_REG_INT_THS_H_M 0x33
170 
176 #define C9DOF_REG_XG_ID 0x68
177 #define C9DOF_REG_MAG_ID 0x3D
178 
184 #define C9DOF_CTRL_REG4_CONFIG 0x38
185 #define C9DOF_CTRL_REG1_G_CONFIG 0x82
186 #define C9DOF_CTRL_REG5_XL_CONFIG 0x38
187 #define C9DOF_CTRL_REG6_XL_CONFIG 0x83
188 #define C9DOF_CTRL_REG8_CONFIG 0x44
189 #define C9DOF_CTRL_REG1_M_CONFIG 0xD0
190 #define C9DOF_CTRL_REG2_M_CONFIG 0x00
191 #define C9DOF_CTRL_REG3_M_CONFIG 0x00
192 #define C9DOF_CTRL_REG4_M_CONFIG 0x08
193 #define C9DOF_CTRL_REG5_M_CONFIG 0x40
194  // End group macro
197 // --------------------------------------------------------------- PUBLIC TYPES
206 typedef struct
207 {
208  // Output pins
209 
210  digital_out_t en;
211 
212  // Input pins
213 
214  digital_in_t int_pin;
215 
216  // Modules
217 
218  i2c_master_t i2c;
219 
220  // ctx variable
221 
224 
225 } c9dof_t;
226 
230 typedef struct
231 {
232  // Communication gpio pins
233 
234  pin_name_t scl;
235  pin_name_t sda;
236 
237  // Additional gpio pins
238 
239  pin_name_t en;
240  pin_name_t int_pin;
241 
242  // static variable
243 
244  uint32_t i2c_speed;
245  uint8_t i2c_address_ag;
246  uint8_t i2c_address_m;
247 
248 } c9dof_cfg_t;
249  // End types group
251 
260 typedef struct
261 {
262  int16_t x;
263  int16_t y;
264  int16_t z;
265 
267 
271 typedef struct
272 {
273  int16_t x;
274  int16_t y;
275  int16_t z;
276 
278 
282 typedef struct
283 {
284  int16_t x;
285  int16_t y;
286  int16_t z;
287 
289  // Measurement data
291 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
292 
298 #ifdef __cplusplus
299 extern "C"{
300 #endif
301 
311 
321 
397 
413 void c9dof_set_power_mode ( c9dof_t *ctx, uint8_t pwr_mode );
414 
426 void c9dof_generic_write_accel_gyro ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
427 
440 void c9dof_generic_read_accel_gyro ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
441 
453 void c9dof_generic_write_mag ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
454 
467 void c9dof_generic_read_mag ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
468 
479 
490 
501 
520 uint8_t c9dof_get_interrupt ( c9dof_t *ctx );
521 
522 #ifdef __cplusplus
523 }
524 #endif
525 #endif // _C9DOF_H_
526  // End public_function group
529 
530 // ------------------------------------------------------------------------- END
c9dof_mag_data_t::y
int16_t y
Definition: c9dof.h:285
C9DOF_RETVAL
#define C9DOF_RETVAL
Definition: c9dof.h:73
c9dof_default_cfg
void c9dof_default_cfg(c9dof_t *ctx)
Click Default Configuration function.
c9dof_get_interrupt
uint8_t c9dof_get_interrupt(c9dof_t *ctx)
Get state of the Magnetic sensor interrupt function.
c9dof_cfg_setup
void c9dof_cfg_setup(c9dof_cfg_t *cfg)
Config Object Initialization function.
c9dof_t::en
digital_out_t en
Definition: c9dof.h:210
c9dof_gyro_data_t::z
int16_t z
Definition: c9dof.h:275
c9dof_accel_data_t::y
int16_t y
Definition: c9dof.h:263
c9dof_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c9dof.h:244
c9dof_gyro_data_t::x
int16_t x
Definition: c9dof.h:273
c9dof_accel_data_t::z
int16_t z
Definition: c9dof.h:264
c9dof_mag_data_t
Magnetometer data object definition.
Definition: c9dof.h:283
c9dof_cfg_t::i2c_address_m
uint8_t i2c_address_m
Definition: c9dof.h:246
c9dof_t::slave_address_ag
uint8_t slave_address_ag
Definition: c9dof.h:222
c9dof_read_mag
void c9dof_read_mag(c9dof_t *ctx, c9dof_mag_data_t *mag_data)
Get magnetometer data function.
accel_data
c9dof_accel_data_t accel_data
Definition: main.c:33
c9dof_t::i2c
i2c_master_t i2c
Definition: c9dof.h:218
c9dof_mag_data_t::x
int16_t x
Definition: c9dof.h:284
c9dof_generic_write_accel_gyro
void c9dof_generic_write_accel_gyro(c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic accel and gyro write function.
c9dof_gyro_data_t
Gyro data object definition.
Definition: c9dof.h:272
c9dof_t
Click ctx object definition.
Definition: c9dof.h:207
c9dof_cfg_t::i2c_address_ag
uint8_t i2c_address_ag
Definition: c9dof.h:245
c9dof_accel_data_t::x
int16_t x
Definition: c9dof.h:262
c9dof_generic_write_mag
void c9dof_generic_write_mag(c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic mag write function.
c9dof_generic_read_accel_gyro
void c9dof_generic_read_accel_gyro(c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic accel and gyro read function.
c9dof_generic_read_mag
void c9dof_generic_read_mag(c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic mag read function.
c9dof_cfg_t::sda
pin_name_t sda
Definition: c9dof.h:235
c9dof_t::int_pin
digital_in_t int_pin
Definition: c9dof.h:214
c9dof_t::slave_address_m
uint8_t slave_address_m
Definition: c9dof.h:223
c9dof_read_gyro
void c9dof_read_gyro(c9dof_t *ctx, c9dof_gyro_data_t *gyro_data)
Get gyroscope data function.
c9dof_cfg_t::scl
pin_name_t scl
Definition: c9dof.h:234
c9dof_gyro_data_t::y
int16_t y
Definition: c9dof.h:274
c9dof_cfg_t::int_pin
pin_name_t int_pin
Definition: c9dof.h:240
gyro_data
c9dof_gyro_data_t gyro_data
Definition: main.c:34
c9dof_cfg_t
Click configuration structure definition.
Definition: c9dof.h:231
c9dof_cfg_t::en
pin_name_t en
Definition: c9dof.h:239
c9dof_mag_data_t::z
int16_t z
Definition: c9dof.h:286
c9dof_accel_data_t
Accel data object definition.
Definition: c9dof.h:261
mag_data
c9dof_mag_data_t mag_data
Definition: main.c:35
c9dof_read_accel
void c9dof_read_accel(c9dof_t *ctx, c9dof_accel_data_t *accel_data)
Get accelerometer data function.
c9dof_init
C9DOF_RETVAL c9dof_init(c9dof_t *ctx, c9dof_cfg_t *cfg)
Initialization function.
c9dof_set_power_mode
void c9dof_set_power_mode(c9dof_t *ctx, uint8_t pwr_mode)
Set accel and gyro power mode function.