c6dofimu13 2.0.0.0
c6dofimu13.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 C6DOFIMU13_H
29#define C6DOFIMU13_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
73#define C6DOFIMU13_MAG_SELFTEST_RESP 0x0C
74#define C6DOFIMU13_MAG_MORE_INFO_VER 0x0D
75#define C6DOFIMU13_MAG_MORE_INFO 0x0E
76#define C6DOFIMU13_MAG_WHO_I_AM 0x0F
77#define C6DOFIMU13_MAG_OUT_X_LSB 0x10
78#define C6DOFIMU13_MAG_OUT_X_MSB 0x11
79#define C6DOFIMU13_MAG_OUT_Y_LSB 0x12
80#define C6DOFIMU13_MAG_OUT_Y_MSB 0x13
81#define C6DOFIMU13_MAG_OUT_Z_LSB 0x14
82#define C6DOFIMU13_MAG_OUT_Z_MSB 0x15
83#define C6DOFIMU13_MAG_STAT 0x18
84#define C6DOFIMU13_MAG_CTL_1 0x1B
85#define C6DOFIMU13_MAG_CTL_2 0x1C
86#define C6DOFIMU13_MAG_CTL_3 0x1D
87#define C6DOFIMU13_MAG_CTL_4 0x1E
88#define C6DOFIMU13_MAG_OFFS_X_LSB 0x20
89#define C6DOFIMU13_MAG_OFFS_X_MSB 0x21
90#define C6DOFIMU13_MAG_OFFS_Y_LSB 0x22
91#define C6DOFIMU13_MAG_OFFS_Y_MSB 0x23
92#define C6DOFIMU13_MAG_OFFS_Z_LSB 0x24
93#define C6DOFIMU13_MAG_OFFS_Z_MSB 0x25
94#define C6DOFIMU13_MAG_ITHR_L 0x26
95#define C6DOFIMU13_MAG_ITHR_H 0x27
96#define C6DOFIMU13_MAG_TEMP_VAL 0x31
97
102#define C6DOFIMU13_ACCEL_SR 0x03
103#define C6DOFIMU13_ACCEL_OPSTAT 0x04
104#define C6DOFIMU13_ACCEL_INTEN 0x06
105#define C6DOFIMU13_ACCEL_MODE 0x07
106#define C6DOFIMU13_ACCEL_SRTFR 0x08
107#define C6DOFIMU13_ACCEL_TAPEN 0x09
108#define C6DOFIMU13_ACCEL_TTTRX 0x0A
109#define C6DOFIMU13_ACCEL_TTTRY 0x0B
110#define C6DOFIMU13_ACCEL_TTTRZ 0x0C
111#define C6DOFIMU13_ACCEL_XOUT_EX_L 0x0D
112#define C6DOFIMU13_ACCEL_XOUT_EX_H 0x0E
113#define C6DOFIMU13_ACCEL_YOUT_EX_L 0x0F
114#define C6DOFIMU13_ACCEL_YOUT_EX_H 0x10
115#define C6DOFIMU13_ACCEL_ZOUT_EX_L 0x11
116#define C6DOFIMU13_ACCEL_ZOUT_EX_H 0x12
117#define C6DOFIMU13_ACCEL_OUTCFG 0x20
118#define C6DOFIMU13_ACCEL_XOFFL 0x21
119#define C6DOFIMU13_ACCEL_XOFFH 0x22
120#define C6DOFIMU13_ACCEL_YOFFL 0x23
121#define C6DOFIMU13_ACCEL_YOFFH 0x24
122#define C6DOFIMU13_ACCEL_ZOFFL 0x25
123#define C6DOFIMU13_ACCEL_ZOFFH 0x26
124#define C6DOFIMU13_ACCEL_XGAIN 0x27
125#define C6DOFIMU13_ACCEL_YGAIN 0x28
126#define C6DOFIMU13_ACCEL_ZGAIN 0x29
127#define C6DOFIMU13_ACCEL_PCODE 0x3B
128
129 // c6dofimu13_reg
130
145#define C6DOFIMU13_MAG_STAT_DRDY 0x40
146#define C6DOFIMU13_MAG_STAT_DOR 0x20
147
152#define C6DOFIMU13_MAG_CTL_1_PC_NORM 0x80
153#define C6DOFIMU13_MAG_CTL_1_PC_STBY 0x00
154#define C6DOFIMU13_MAG_CTL_1_ODR_05 0x00
155#define C6DOFIMU13_MAG_CTL_1_ODR_10 0x08
156#define C6DOFIMU13_MAG_CTL_1_ODR_20 0x10
157#define C6DOFIMU13_MAG_CTL_1_ODR_100 0x18
158#define C6DOFIMU13_MAG_CTL_1_FS_DEF 0x02
159#define C6DOFIMU13_MAG_CTL_1_FS_NORM 0x00
160
165#define C6DOFIMU13_MAG_CTL_3_SRST_SR 0x80
166#define C6DOFIMU13_MAG_CTL_3_SRST_NOP 0x00
167#define C6DOFIMU13_MAG_CTL_3_FRC_SM 0x40
168#define C6DOFIMU13_MAG_CTL_3_FRC_NOP 0x00
169#define C6DOFIMU13_MAG_CTL_3_STC_EN 0x10
170#define C6DOFIMU13_MAG_CTL_3_STC_NOP 0x00
171#define C6DOFIMU13_MAG_CTL_3_TCS_EN 0x02
172#define C6DOFIMU13_MAG_CTL_3_TCS_NOP 0x00
173#define C6DOFIMU13_MAG_CTL_3_OCL_EN 0x01
174#define C6DOFIMU13_MAG_CTL_3_OCL_NOP 0x00
175
180#define C6DOFIMU13_MAG_CTL_4_RS_S_14 0x00
181#define C6DOFIMU13_MAG_CTL_4_RS_S_15 0x10
182
187#define C6DOFIMU13_MAG_SENS 0.15
188#define C6DOFIMU13_MAG_ORIENTATION_COEF -1.0
189
194#define C6DOFIMU13_MAG_RES_14_BIT 0x00
195#define C6DOFIMU13_MAG_RES_15_BIT 0x01
196#define C6DOFIMU13_MAG_OP_MODE_S_SHOT 0x00
197#define C6DOFIMU13_MAG_OP_MODE_CONT 0x01
198#define C6DOFIMU13_MAG_TEMP_MEAS_OFF 0x00
199#define C6DOFIMU13_MAG_TEMP_MEAS_ON 0x01
200
205#define C6DOFIMU13_MAG_AXIS_X 0x00
206#define C6DOFIMU13_MAG_AXIS_Y 0x01
207#define C6DOFIMU13_MAG_AXIS_Z 0x02
208
213#define C6DOFIMU13_ACCEL_SR_TAP_XP 0x01
214#define C6DOFIMU13_ACCEL_SR_TAP_XN 0x02
215#define C6DOFIMU13_ACCEL_SR_TAP_YP 0x04
216#define C6DOFIMU13_ACCEL_SR_TAP_YN 0x08
217#define C6DOFIMU13_ACCEL_SR_TAP_ZP 0x10
218#define C6DOFIMU13_ACCEL_SR_TAP_ZN 0x20
219#define C6DOFIMU13_ACCEL_SR_AC_INT 0x80
220
225#define C6DOFIMU13_ACCEL_OPSTAT_WAKE 0x01
226#define C6DOFIMU13_ACCEL_OPSTAT_WDT 0x10
227#define C6DOFIMU13_ACCEL_OPSTAT_OTPA 0x80
228
233#define C6DOFIMU13_ACCEL_INTEN_TIXPEN 0x01
234#define C6DOFIMU13_ACCEL_INTEN_TIXNEN 0x02
235#define C6DOFIMU13_ACCEL_INTEN_TIYPEN 0x04
236#define C6DOFIMU13_ACCEL_INTEN_TIYNEN 0x08
237#define C6DOFIMU13_ACCEL_INTEN_TIZPEN 0x10
238#define C6DOFIMU13_ACCEL_INTEN_TIZNEN 0x20
239#define C6DOFIMU13_ACCEL_INTEN_AC_INT_EN 0x80
240
245#define C6DOFIMU13_ACCEL_MODE_STDBY 0x00
246#define C6DOFIMU13_ACCEL_MODE_WAKE 0x01
247#define C6DOFIMU13_ACCEL_MODE_WDT_NEG 0x10
248#define C6DOFIMU13_ACCEL_MODE_WDT_POS 0x20
249#define C6DOFIMU13_ACCEL_MODE_IPP 0x40
250#define C6DOFIMU13_ACCEL_MODE_IAH 0x80
251
256#define C6DOFIMU13_ACCEL_SRTFR_RATE_32 0x00
257#define C6DOFIMU13_ACCEL_SRTFR_RATE_16 0x01
258#define C6DOFIMU13_ACCEL_SRTFR_RATE_8 0x02
259#define C6DOFIMU13_ACCEL_SRTFR_RATE_4 0x03
260#define C6DOFIMU13_ACCEL_SRTFR_RATE_2 0x04
261#define C6DOFIMU13_ACCEL_SRTFR_RATE_1 0x05
262#define C6DOFIMU13_ACCEL_SRTFR_RATE_0_5 0x06
263#define C6DOFIMU13_ACCEL_SRTFR_RATE_0_25 0x07
264#define C6DOFIMU13_ACCEL_SRTFR_RATE_64 0x08
265#define C6DOFIMU13_ACCEL_SRTFR_RATE_128 0x09
266#define C6DOFIMU13_ACCEL_SRTFR_RATE_256 0x0A
267#define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPX 0x10
268#define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPY 0x20
269#define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPZ 0x40
270#define C6DOFIMU13_ACCEL_SRTFR_TAP_LATCH 0x80
271
276#define C6DOFIMU13_ACCEL_TAPEN_TAPXPEN 0x01
277#define C6DOFIMU13_ACCEL_TAPEN_TAPXNEN 0x02
278#define C6DOFIMU13_ACCEL_TAPEN_TAPYPEN 0x04
279#define C6DOFIMU13_ACCEL_TAPEN_TAPYNEN 0x08
280#define C6DOFIMU13_ACCEL_TAPEN_TAPZPEN 0x10
281#define C6DOFIMU13_ACCEL_TAPEN_TAPZNEN 0x20
282#define C6DOFIMU13_ACCEL_TAPEN_THRDUR 0x40
283#define C6DOFIMU13_ACCEL_TAPEN_TAP_EN 0x80
284
289#define C6DOFIMU13_ACCEL_OUTCFG_RANGE_2 0x00
290#define C6DOFIMU13_ACCEL_OUTCFG_RANGE_4 0x10
291#define C6DOFIMU13_ACCEL_OUTCFG_RANGE_8 0x20
292#define C6DOFIMU13_ACCEL_OUTCFG_RANGE_16 0x30
293#define C6DOFIMU13_ACCEL_OUTCFG_RES_6 0x00
294#define C6DOFIMU13_ACCEL_OUTCFG_RES_7 0x01
295#define C6DOFIMU13_ACCEL_OUTCFG_RES_8 0x02
296#define C6DOFIMU13_ACCEL_OUTCFG_RES_10 0x03
297#define C6DOFIMU13_ACCEL_OUTCFG_RES_12 0x04
298#define C6DOFIMU13_ACCEL_OUTCFG_RES_14 0x05
299
304#define C6DOFIMU13_ACCEL_AXIS_X 0x00
305#define C6DOFIMU13_ACCEL_AXIS_Y 0x01
306#define C6DOFIMU13_ACCEL_AXIS_Z 0x02
307
308
314#define C6DOFIMU13_DEV_ADDRESS_ACCEL_GND 0x4C
315#define C6DOFIMU13_DEV_ADDRESS_ACCEL_VCC 0x6C
316#define C6DOFIMU13_DEV_ADDRESS_MAG 0x0C
317
318 // c6dofimu13_set
319
334#define C6DOFIMU13_MAP_MIKROBUS( cfg, mikrobus ) \
335 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
336 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
337 cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
338 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
339
340 // c6dofimu13_map
341 // c6dofimu13
342
347typedef struct
348{
349 // Input pins
350
351 digital_in_t in2;
352 digital_in_t in1;
354 // Modules
355
356 i2c_master_t i2c;
358 // I2C slave address
359
363 float calc_coef;
366
371typedef struct
372{
373 pin_name_t scl;
374 pin_name_t sda;
376 pin_name_t in2;
377 pin_name_t in1;
379 uint32_t i2c_speed;
380 uint8_t i2c_address;
383
394
413
431
448
463err_t c6dofimu13_set_slave_address ( c6dofimu13_t *ctx, uint8_t slave_address );
464
482err_t c6dofimu13_generic_write ( c6dofimu13_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
483
501err_t c6dofimu13_generic_read ( c6dofimu13_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
502
519err_t c6dofimu13_mag_init ( c6dofimu13_t *ctx, uint8_t res, uint8_t op_mode, uint8_t temp_meas );
520
535err_t c6dofimu13_mag_get_x ( c6dofimu13_t *ctx, float *result );
536
551err_t c6dofimu13_mag_get_y ( c6dofimu13_t *ctx, float *result );
552
567err_t c6dofimu13_mag_get_z ( c6dofimu13_t *ctx, float *result );
568
585err_t c6dofimu13_mag_get_data ( c6dofimu13_t *ctx, float *mag_x, float *mag_y, float *mag_z );
586
602err_t c6dofimu13_mag_offset ( c6dofimu13_t *ctx, int16_t offset, uint8_t axis );
603
620err_t c6dofimu13_accel_init ( c6dofimu13_t *ctx, uint8_t samp_rate, uint8_t samp_range, uint8_t samp_res );
621
636err_t c6dofimu13_accel_get_raw_x ( c6dofimu13_t *ctx, int16_t *result );
637
652err_t c6dofimu13_accel_get_raw_y ( c6dofimu13_t *ctx, int16_t *result );
653
668err_t c6dofimu13_accel_get_raw_z ( c6dofimu13_t *ctx, int16_t *result );
669
684err_t c6dofimu13_accel_get_x ( c6dofimu13_t *ctx, float *result );
685
700err_t c6dofimu13_accel_get_y ( c6dofimu13_t *ctx, float *result );
701
716err_t c6dofimu13_accel_get_z ( c6dofimu13_t *ctx, float *result );
717
734err_t c6dofimu13_accel_get_data ( c6dofimu13_t *ctx, float *accel_x, float *accel_y, float *accel_z );
735
751err_t c6dofimu13_accel_offset ( c6dofimu13_t *ctx, int16_t offset, uint8_t axis );
752
763
774
775#ifdef __cplusplus
776}
777#endif
778#endif // C6DOFIMU13_H
779
780 // c6dofimu13
781
782// ------------------------------------------------------------------------ END
c6dofimu13_return_value_t
6DOF IMU 13 Click return value data.
Definition c6dofimu13.h:389
@ C6DOFIMU13_ERROR
Definition c6dofimu13.h:391
@ C6DOFIMU13_OK
Definition c6dofimu13.h:390
err_t c6dofimu13_mag_get_data(c6dofimu13_t *ctx, float *mag_x, float *mag_y, float *mag_z)
6DOF IMU 13 Magnetometer get X, Y, and Z-Axis data function.
err_t c6dofimu13_accel_get_raw_x(c6dofimu13_t *ctx, int16_t *result)
6DOF IMU 13 Accelerometer get RAW X-Axis data function.
err_t c6dofimu13_accel_get_x(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Accelerometer get X-Axis data function.
err_t c6dofimu13_generic_write(c6dofimu13_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
6DOF IMU 13 I2C writing function.
err_t c6dofimu13_accel_get_z(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Accelerometer get Z-Axis data function.
err_t c6dofimu13_mag_offset(c6dofimu13_t *ctx, int16_t offset, uint8_t axis)
6DOF IMU 13 set magnetometer offset function.
err_t c6dofimu13_mag_get_x(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Magnetometer get X-Axis data function.
err_t c6dofimu13_init(c6dofimu13_t *ctx, c6dofimu13_cfg_t *cfg)
6DOF IMU 13 initialization function.
void c6dofimu13_cfg_setup(c6dofimu13_cfg_t *cfg)
6DOF IMU 13 configuration object setup function.
err_t c6dofimu13_accel_get_raw_z(c6dofimu13_t *ctx, int16_t *result)
6DOF IMU 13 Accelerometer get RAW Z-Axis data function.
err_t c6dofimu13_default_cfg(c6dofimu13_t *ctx)
6DOF IMU 13 default configuration function.
err_t c6dofimu13_accel_init(c6dofimu13_t *ctx, uint8_t samp_rate, uint8_t samp_range, uint8_t samp_res)
6DOF IMU 13 Accelerometer initialize function.
err_t c6dofimu13_mag_init(c6dofimu13_t *ctx, uint8_t res, uint8_t op_mode, uint8_t temp_meas)
6DOF IMU 13 Magnetometer initialize function.
err_t c6dofimu13_set_slave_address(c6dofimu13_t *ctx, uint8_t slave_address)
6DOF IMU 13 set slave address function.
err_t c6dofimu13_mag_get_y(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Magnetometer get Y-Axis data function.
err_t c6dofimu13_accel_get_raw_y(c6dofimu13_t *ctx, int16_t *result)
6DOF IMU 13 Accelerometer get RAW Y-Axis data function.
err_t c6dofimu13_generic_read(c6dofimu13_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
6DOF IMU 13 I2C reading function.
err_t c6dofimu13_accel_get_data(c6dofimu13_t *ctx, float *accel_x, float *accel_y, float *accel_z)
6DOF IMU 13 Accelerometer get X, Y, and Z-Axis data function.
err_t c6dofimu13_accel_get_y(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Accelerometer get Y-Axis data function.
err_t c6dofimu13_accel_offset(c6dofimu13_t *ctx, int16_t offset, uint8_t axis)
6DOF IMU 13 set accelerometer offset function.
uint8_t c6dofimu13_get_in2(c6dofimu13_t *ctx)
6DOF IMU 13 get in2 pin state function.
err_t c6dofimu13_mag_get_z(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Magnetometer get Z-Axis data function.
uint8_t c6dofimu13_get_in1(c6dofimu13_t *ctx)
6DOF IMU 13 get in1 pin state function.
6DOF IMU 13 Click configuration object.
Definition c6dofimu13.h:372
uint32_t i2c_speed
Definition c6dofimu13.h:379
pin_name_t in2
Definition c6dofimu13.h:376
pin_name_t scl
Definition c6dofimu13.h:373
pin_name_t in1
Definition c6dofimu13.h:377
pin_name_t sda
Definition c6dofimu13.h:374
uint8_t i2c_address
Definition c6dofimu13.h:380
6DOF IMU 13 Click context object.
Definition c6dofimu13.h:348
digital_in_t in2
Definition c6dofimu13.h:351
digital_in_t in1
Definition c6dofimu13.h:352
float calc_coef
Definition c6dofimu13.h:363
i2c_master_t i2c
Definition c6dofimu13.h:356
uint8_t slave_address
Definition c6dofimu13.h:360