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
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_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define C9DOF_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define C9DOF_RETVAL uint8_t
78
79#define C9DOF_OK 0x00
80#define C9DOF_INIT_ERROR 0xFF
87#define C9DOF_SLAVE_ADDRESS_ACCEL_GYRO_0 0x6A
88#define C9DOF_SLAVE_ADDRESS_MAG_0 0x1C
89#define C9DOF_SLAVE_ADDRESS_ACCEL_GYRO_1 0x6B
90#define C9DOF_SLAVE_ADDRESS_MAG_1 0x1E
97#define C9DOF_REG_ACT_THS 0x04
98#define C9DOF_REG_ACT_DUR 0x05
99#define C9DOF_REG_INT_GEN_CFG_XL 0x06
100#define C9DOF_REG_INT_GEN_THS_X_XL 0x07
101#define C9DOF_REG_INT_GEN_THS_Y_XL 0x08
102#define C9DOF_REG_INT_GEN_THS_Z_XL 0x09
103#define C9DOF_REG_INT_GEN_DUR_XL 0x0A
104#define C9DOF_REG_REFERENCE_G 0x0B
105#define C9DOF_REG_INT1_CTRL 0x0C
106#define C9DOF_REG_INT2_CTRL 0x0D
107#define C9DOF_REG_WHO_AM_I 0x0F
108#define C9DOF_REG_CTRL_REG1_G 0x10
109#define C9DOF_REG_CTRL_REG2_G 0x11
110#define C9DOF_REG_CTRL_REG3_G 0x12
111#define C9DOF_REG_ORIENT_CFG_G 0x13
112#define C9DOF_REG_INT_GEN_SRC_G 0x14
113#define C9DOF_REG_OUT_TEMP_L 0x15
114#define C9DOF_REG_OUT_TEMP_H 0x16
115#define C9DOF_REG_STATUS_REG 0x17
116#define C9DOF_REG_OUT_X_L_G 0x18
117#define C9DOF_REG_OUT_X_H_G 0x19
118#define C9DOF_REG_OUT_Y_L_G 0x1A
119#define C9DOF_REG_OUT_Y_H_G 0x1B
120#define C9DOF_REG_OUT_Z_L_G 0x1C
121#define C9DOF_REG_OUT_Z_H_G 0x1D
122#define C9DOF_REG_CTRL_REG4 0x1E
123#define C9DOF_REG_CTRL_REG5_XL 0x1F
124#define C9DOF_REG_CTRL_REG6_XL 0x20
125#define C9DOF_REG_CTRL_REG7_XL 0x21
126#define C9DOF_REG_CTRL_REG8 0x22
127#define C9DOF_REG_CTRL_REG9 0x23
128#define C9DOF_REG_CTRL_REG10 0x24
129#define C9DOF_REG_INT_GEN_SRC_XL 0x26
130#define C9DOF_REG_OUT_X_L_XL 0x28
131#define C9DOF_REG_OUT_X_H_XL 0x29
132#define C9DOF_REG_OUT_Y_L_XL 0x2A
133#define C9DOF_REG_OUT_Y_H_XL 0x2B
134#define C9DOF_REG_OUT_Z_L_XL 0x2C
135#define C9DOF_REG_OUT_Z_H_XL 0x2D
136#define C9DOF_REG_FIFO_CTRL 0x2E
137#define C9DOF_REG_FIFO_SRC 0x2F
138#define C9DOF_REG_INT_GEN_CFG_G 0x30
139#define C9DOF_REG_INT_GEN_THS_XH_G 0x31
140#define C9DOF_REG_INT_GEN_THS_XL_G 0x32
141#define C9DOF_REG_INT_GEN_THS_YH_G 0x33
142#define C9DOF_REG_INT_GEN_THS_YL_G 0x34
143#define C9DOF_REG_INT_GEN_THS_ZH_G 0x35
144#define C9DOF_REG_INT_GEN_THS_ZL_G 0x36
145#define C9DOF_REG_INT_GEN_DUR_G 0x37
152#define C9DOF_REG_OFFSET_X_REG_L_M 0x05
153#define C9DOF_REG_OFFSET_X_REG_H_M 0x06
154#define C9DOF_REG_OFFSET_Y_REG_L_M 0x07
155#define C9DOF_REG_OFFSET_Y_REG_H_M 0x08
156#define C9DOF_REG_OFFSET_Z_REG_L_M 0x09
157#define C9DOF_REG_OFFSET_Z_REG_H_M 0x0A
158#define C9DOF_REG_CTRL_REG1_M 0x20
159#define C9DOF_REG_CTRL_REG2_M 0x21
160#define C9DOF_REG_CTRL_REG3_M 0x22
161#define C9DOF_REG_CTRL_REG4_M 0x23
162#define C9DOF_REG_CTRL_REG5_M 0x24
163#define C9DOF_REG_STATUS_REG_M 0x27
164#define C9DOF_REG_OUT_X_L_M 0x28
165#define C9DOF_REG_OUT_X_H_M 0x29
166#define C9DOF_REG_OUT_Y_L_M 0x2A
167#define C9DOF_REG_OUT_Y_H_M 0x2B
168#define C9DOF_REG_OUT_Z_L_M 0x2C
169#define C9DOF_REG_OUT_Z_H_M 0x2D
170#define C9DOF_REG_INT_CFG_M 0x30
171#define C9DOF_REG_INT_SRC_M 0x31
172#define C9DOF_REG_INT_THS_L_M 0x32
173#define C9DOF_REG_INT_THS_H_M 0x33
180#define C9DOF_REG_XG_ID 0x68
181#define C9DOF_REG_MAG_ID 0x3D
188#define C9DOF_CTRL_REG4_CONFIG 0x38
189#define C9DOF_CTRL_REG1_G_CONFIG 0x82
190#define C9DOF_CTRL_REG5_XL_CONFIG 0x38
191#define C9DOF_CTRL_REG6_XL_CONFIG 0x83
192#define C9DOF_CTRL_REG8_CONFIG 0x44
193#define C9DOF_CTRL_REG1_M_CONFIG 0xD0
194#define C9DOF_CTRL_REG2_M_CONFIG 0x00
195#define C9DOF_CTRL_REG3_M_CONFIG 0x00
196#define C9DOF_CTRL_REG4_M_CONFIG 0x08
197#define C9DOF_CTRL_REG5_M_CONFIG 0x40
200 // End group macro
201// --------------------------------------------------------------- PUBLIC TYPES
210typedef struct
211{
212 // Output pins
213
214 digital_out_t en;
215
216 // Input pins
217
218 digital_in_t int_pin;
219
220 // Modules
221
222 i2c_master_t i2c;
223
224 // ctx variable
225
228
229} c9dof_t;
230
234typedef struct
235{
236 // Communication gpio pins
237
238 pin_name_t scl;
239 pin_name_t sda;
240
241 // Additional gpio pins
242
243 pin_name_t en;
244 pin_name_t int_pin;
245
246 // static variable
247
248 uint32_t i2c_speed;
251
253
254 // End types group
255
264typedef struct
265{
266 int16_t x;
267 int16_t y;
268 int16_t z;
269
271
275typedef struct
276{
277 int16_t x;
278 int16_t y;
279 int16_t z;
280
282
286typedef struct
287{
288 int16_t x;
289 int16_t y;
290 int16_t z;
291
293
294 // Measurement data
295// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
296
302#ifdef __cplusplus
303extern "C"{
304#endif
305
315
325
401
417void c9dof_set_power_mode ( c9dof_t *ctx, uint8_t pwr_mode );
418
430void c9dof_generic_write_accel_gyro ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
431
444void c9dof_generic_read_accel_gyro ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
445
457void c9dof_generic_write_mag ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
458
471void c9dof_generic_read_mag ( c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
472
483
494
505
525
526#ifdef __cplusplus
527}
528#endif
529#endif // _C9DOF_H_
530
531 // End public_function group
533
534// ------------------------------------------------------------------------- END
#define C9DOF_RETVAL
Definition c9dof.h:77
void c9dof_read_accel(c9dof_t *ctx, c9dof_accel_data_t *accel_data)
Get accelerometer data function.
uint8_t c9dof_get_interrupt(c9dof_t *ctx)
Get state of the Magnetic sensor interrupt function.
void c9dof_default_cfg(c9dof_t *ctx)
Click Default Configuration function.
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.
void c9dof_generic_read_mag(c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic mag read function.
void c9dof_set_power_mode(c9dof_t *ctx, uint8_t pwr_mode)
Set accel and gyro power mode function.
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.
void c9dof_cfg_setup(c9dof_cfg_t *cfg)
Config Object Initialization function.
void c9dof_read_gyro(c9dof_t *ctx, c9dof_gyro_data_t *gyro_data)
Get gyroscope data function.
C9DOF_RETVAL c9dof_init(c9dof_t *ctx, c9dof_cfg_t *cfg)
Initialization function.
void c9dof_generic_write_mag(c9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic mag write function.
void c9dof_read_mag(c9dof_t *ctx, c9dof_mag_data_t *mag_data)
Get magnetometer data function.
c9dof_gyro_data_t gyro_data
Definition main.c:34
c9dof_accel_data_t accel_data
Definition main.c:33
c9dof_mag_data_t mag_data
Definition main.c:35
Accel data object definition.
Definition c9dof.h:265
int16_t z
Definition c9dof.h:268
int16_t x
Definition c9dof.h:266
int16_t y
Definition c9dof.h:267
Click configuration structure definition.
Definition c9dof.h:235
uint32_t i2c_speed
Definition c9dof.h:248
uint8_t i2c_address_ag
Definition c9dof.h:249
pin_name_t scl
Definition c9dof.h:238
pin_name_t en
Definition c9dof.h:243
pin_name_t int_pin
Definition c9dof.h:244
uint8_t i2c_address_m
Definition c9dof.h:250
pin_name_t sda
Definition c9dof.h:239
Gyro data object definition.
Definition c9dof.h:276
int16_t z
Definition c9dof.h:279
int16_t x
Definition c9dof.h:277
int16_t y
Definition c9dof.h:278
Magnetometer data object definition.
Definition c9dof.h:287
int16_t z
Definition c9dof.h:290
int16_t x
Definition c9dof.h:288
int16_t y
Definition c9dof.h:289
Click ctx object definition.
Definition c9dof.h:211
uint8_t slave_address_m
Definition c9dof.h:227
digital_in_t int_pin
Definition c9dof.h:218
i2c_master_t i2c
Definition c9dof.h:222
digital_out_t en
Definition c9dof.h:214
uint8_t slave_address_ag
Definition c9dof.h:226