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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define C6DOFIMU13_MAG_SELFTEST_RESP 0x0C
60 #define C6DOFIMU13_MAG_MORE_INFO_VER 0x0D
61 #define C6DOFIMU13_MAG_MORE_INFO 0x0E
62 #define C6DOFIMU13_MAG_WHO_I_AM 0x0F
63 #define C6DOFIMU13_MAG_OUT_X_LSB 0x10
64 #define C6DOFIMU13_MAG_OUT_X_MSB 0x11
65 #define C6DOFIMU13_MAG_OUT_Y_LSB 0x12
66 #define C6DOFIMU13_MAG_OUT_Y_MSB 0x13
67 #define C6DOFIMU13_MAG_OUT_Z_LSB 0x14
68 #define C6DOFIMU13_MAG_OUT_Z_MSB 0x15
69 #define C6DOFIMU13_MAG_STAT 0x18
70 #define C6DOFIMU13_MAG_CTL_1 0x1B
71 #define C6DOFIMU13_MAG_CTL_2 0x1C
72 #define C6DOFIMU13_MAG_CTL_3 0x1D
73 #define C6DOFIMU13_MAG_CTL_4 0x1E
74 #define C6DOFIMU13_MAG_OFFS_X_LSB 0x20
75 #define C6DOFIMU13_MAG_OFFS_X_MSB 0x21
76 #define C6DOFIMU13_MAG_OFFS_Y_LSB 0x22
77 #define C6DOFIMU13_MAG_OFFS_Y_MSB 0x23
78 #define C6DOFIMU13_MAG_OFFS_Z_LSB 0x24
79 #define C6DOFIMU13_MAG_OFFS_Z_MSB 0x25
80 #define C6DOFIMU13_MAG_ITHR_L 0x26
81 #define C6DOFIMU13_MAG_ITHR_H 0x27
82 #define C6DOFIMU13_MAG_TEMP_VAL 0x31
83 
88 #define C6DOFIMU13_ACCEL_SR 0x03
89 #define C6DOFIMU13_ACCEL_OPSTAT 0x04
90 #define C6DOFIMU13_ACCEL_INTEN 0x06
91 #define C6DOFIMU13_ACCEL_MODE 0x07
92 #define C6DOFIMU13_ACCEL_SRTFR 0x08
93 #define C6DOFIMU13_ACCEL_TAPEN 0x09
94 #define C6DOFIMU13_ACCEL_TTTRX 0x0A
95 #define C6DOFIMU13_ACCEL_TTTRY 0x0B
96 #define C6DOFIMU13_ACCEL_TTTRZ 0x0C
97 #define C6DOFIMU13_ACCEL_XOUT_EX_L 0x0D
98 #define C6DOFIMU13_ACCEL_XOUT_EX_H 0x0E
99 #define C6DOFIMU13_ACCEL_YOUT_EX_L 0x0F
100 #define C6DOFIMU13_ACCEL_YOUT_EX_H 0x10
101 #define C6DOFIMU13_ACCEL_ZOUT_EX_L 0x11
102 #define C6DOFIMU13_ACCEL_ZOUT_EX_H 0x12
103 #define C6DOFIMU13_ACCEL_OUTCFG 0x20
104 #define C6DOFIMU13_ACCEL_XOFFL 0x21
105 #define C6DOFIMU13_ACCEL_XOFFH 0x22
106 #define C6DOFIMU13_ACCEL_YOFFL 0x23
107 #define C6DOFIMU13_ACCEL_YOFFH 0x24
108 #define C6DOFIMU13_ACCEL_ZOFFL 0x25
109 #define C6DOFIMU13_ACCEL_ZOFFH 0x26
110 #define C6DOFIMU13_ACCEL_XGAIN 0x27
111 #define C6DOFIMU13_ACCEL_YGAIN 0x28
112 #define C6DOFIMU13_ACCEL_ZGAIN 0x29
113 #define C6DOFIMU13_ACCEL_PCODE 0x3B
114  // c6dofimu13_reg
116 
131 #define C6DOFIMU13_MAG_STAT_DRDY 0x40
132 #define C6DOFIMU13_MAG_STAT_DOR 0x20
133 
138 #define C6DOFIMU13_MAG_CTL_1_PC_NORM 0x80
139 #define C6DOFIMU13_MAG_CTL_1_PC_STBY 0x00
140 #define C6DOFIMU13_MAG_CTL_1_ODR_05 0x00
141 #define C6DOFIMU13_MAG_CTL_1_ODR_10 0x08
142 #define C6DOFIMU13_MAG_CTL_1_ODR_20 0x10
143 #define C6DOFIMU13_MAG_CTL_1_ODR_100 0x18
144 #define C6DOFIMU13_MAG_CTL_1_FS_DEF 0x02
145 #define C6DOFIMU13_MAG_CTL_1_FS_NORM 0x00
146 
151 #define C6DOFIMU13_MAG_CTL_3_SRST_SR 0x80
152 #define C6DOFIMU13_MAG_CTL_3_SRST_NOP 0x00
153 #define C6DOFIMU13_MAG_CTL_3_FRC_SM 0x40
154 #define C6DOFIMU13_MAG_CTL_3_FRC_NOP 0x00
155 #define C6DOFIMU13_MAG_CTL_3_STC_EN 0x10
156 #define C6DOFIMU13_MAG_CTL_3_STC_NOP 0x00
157 #define C6DOFIMU13_MAG_CTL_3_TCS_EN 0x02
158 #define C6DOFIMU13_MAG_CTL_3_TCS_NOP 0x00
159 #define C6DOFIMU13_MAG_CTL_3_OCL_EN 0x01
160 #define C6DOFIMU13_MAG_CTL_3_OCL_NOP 0x00
161 
166 #define C6DOFIMU13_MAG_CTL_4_RS_S_14 0x00
167 #define C6DOFIMU13_MAG_CTL_4_RS_S_15 0x10
168 
173 #define C6DOFIMU13_MAG_SENS 0.15
174 #define C6DOFIMU13_MAG_ORIENTATION_COEF -1.0
175 
180 #define C6DOFIMU13_MAG_RES_14_BIT 0x00
181 #define C6DOFIMU13_MAG_RES_15_BIT 0x01
182 #define C6DOFIMU13_MAG_OP_MODE_S_SHOT 0x00
183 #define C6DOFIMU13_MAG_OP_MODE_CONT 0x01
184 #define C6DOFIMU13_MAG_TEMP_MEAS_OFF 0x00
185 #define C6DOFIMU13_MAG_TEMP_MEAS_ON 0x01
186 
191 #define C6DOFIMU13_MAG_AXIS_X 0x00
192 #define C6DOFIMU13_MAG_AXIS_Y 0x01
193 #define C6DOFIMU13_MAG_AXIS_Z 0x02
194 
199 #define C6DOFIMU13_ACCEL_SR_TAP_XP 0x01
200 #define C6DOFIMU13_ACCEL_SR_TAP_XN 0x02
201 #define C6DOFIMU13_ACCEL_SR_TAP_YP 0x04
202 #define C6DOFIMU13_ACCEL_SR_TAP_YN 0x08
203 #define C6DOFIMU13_ACCEL_SR_TAP_ZP 0x10
204 #define C6DOFIMU13_ACCEL_SR_TAP_ZN 0x20
205 #define C6DOFIMU13_ACCEL_SR_AC_INT 0x80
206 
211 #define C6DOFIMU13_ACCEL_OPSTAT_WAKE 0x01
212 #define C6DOFIMU13_ACCEL_OPSTAT_WDT 0x10
213 #define C6DOFIMU13_ACCEL_OPSTAT_OTPA 0x80
214 
219 #define C6DOFIMU13_ACCEL_INTEN_TIXPEN 0x01
220 #define C6DOFIMU13_ACCEL_INTEN_TIXNEN 0x02
221 #define C6DOFIMU13_ACCEL_INTEN_TIYPEN 0x04
222 #define C6DOFIMU13_ACCEL_INTEN_TIYNEN 0x08
223 #define C6DOFIMU13_ACCEL_INTEN_TIZPEN 0x10
224 #define C6DOFIMU13_ACCEL_INTEN_TIZNEN 0x20
225 #define C6DOFIMU13_ACCEL_INTEN_AC_INT_EN 0x80
226 
231 #define C6DOFIMU13_ACCEL_MODE_STDBY 0x00
232 #define C6DOFIMU13_ACCEL_MODE_WAKE 0x01
233 #define C6DOFIMU13_ACCEL_MODE_WDT_NEG 0x10
234 #define C6DOFIMU13_ACCEL_MODE_WDT_POS 0x20
235 #define C6DOFIMU13_ACCEL_MODE_IPP 0x40
236 #define C6DOFIMU13_ACCEL_MODE_IAH 0x80
237 
242 #define C6DOFIMU13_ACCEL_SRTFR_RATE_32 0x00
243 #define C6DOFIMU13_ACCEL_SRTFR_RATE_16 0x01
244 #define C6DOFIMU13_ACCEL_SRTFR_RATE_8 0x02
245 #define C6DOFIMU13_ACCEL_SRTFR_RATE_4 0x03
246 #define C6DOFIMU13_ACCEL_SRTFR_RATE_2 0x04
247 #define C6DOFIMU13_ACCEL_SRTFR_RATE_1 0x05
248 #define C6DOFIMU13_ACCEL_SRTFR_RATE_0_5 0x06
249 #define C6DOFIMU13_ACCEL_SRTFR_RATE_0_25 0x07
250 #define C6DOFIMU13_ACCEL_SRTFR_RATE_64 0x08
251 #define C6DOFIMU13_ACCEL_SRTFR_RATE_128 0x09
252 #define C6DOFIMU13_ACCEL_SRTFR_RATE_256 0x0A
253 #define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPX 0x10
254 #define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPY 0x20
255 #define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPZ 0x40
256 #define C6DOFIMU13_ACCEL_SRTFR_TAP_LATCH 0x80
257 
262 #define C6DOFIMU13_ACCEL_TAPEN_TAPXPEN 0x01
263 #define C6DOFIMU13_ACCEL_TAPEN_TAPXNEN 0x02
264 #define C6DOFIMU13_ACCEL_TAPEN_TAPYPEN 0x04
265 #define C6DOFIMU13_ACCEL_TAPEN_TAPYNEN 0x08
266 #define C6DOFIMU13_ACCEL_TAPEN_TAPZPEN 0x10
267 #define C6DOFIMU13_ACCEL_TAPEN_TAPZNEN 0x20
268 #define C6DOFIMU13_ACCEL_TAPEN_THRDUR 0x40
269 #define C6DOFIMU13_ACCEL_TAPEN_TAP_EN 0x80
270 
275 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_2 0x00
276 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_4 0x10
277 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_8 0x20
278 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_16 0x30
279 #define C6DOFIMU13_ACCEL_OUTCFG_RES_6 0x00
280 #define C6DOFIMU13_ACCEL_OUTCFG_RES_7 0x01
281 #define C6DOFIMU13_ACCEL_OUTCFG_RES_8 0x02
282 #define C6DOFIMU13_ACCEL_OUTCFG_RES_10 0x03
283 #define C6DOFIMU13_ACCEL_OUTCFG_RES_12 0x04
284 #define C6DOFIMU13_ACCEL_OUTCFG_RES_14 0x05
285 
290 #define C6DOFIMU13_ACCEL_AXIS_X 0x00
291 #define C6DOFIMU13_ACCEL_AXIS_Y 0x01
292 #define C6DOFIMU13_ACCEL_AXIS_Z 0x02
293 
294 
300 #define C6DOFIMU13_DEV_ADDRESS_ACCEL_GND 0x4C
301 #define C6DOFIMU13_DEV_ADDRESS_ACCEL_VCC 0x6C
302 #define C6DOFIMU13_DEV_ADDRESS_MAG 0x0C
303  // c6dofimu13_set
305 
320 #define C6DOFIMU13_MAP_MIKROBUS( cfg, mikrobus ) \
321  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
322  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
323  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
324  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
325  // c6dofimu13_map // c6dofimu13
328 
333 typedef struct
334 {
335  // Input pins
336 
337  digital_in_t in2;
338  digital_in_t in1;
340  // Modules
341 
342  i2c_master_t i2c;
344  // I2C slave address
345 
346  uint8_t slave_address;
349  float calc_coef;
351 } c6dofimu13_t;
352 
357 typedef struct
358 {
359  pin_name_t scl;
360  pin_name_t sda;
362  pin_name_t in2;
363  pin_name_t in1;
365  uint32_t i2c_speed;
366  uint8_t i2c_address;
369 
374 typedef enum
375 {
377  C6DOFIMU13_ERROR = -1
378 
380 
399 
416 err_t c6dofimu13_init ( c6dofimu13_t *ctx, c6dofimu13_cfg_t *cfg );
417 
433 err_t c6dofimu13_default_cfg ( c6dofimu13_t *ctx );
434 
449 err_t c6dofimu13_set_slave_address ( c6dofimu13_t *ctx, uint8_t slave_address );
450 
468 err_t c6dofimu13_generic_write ( c6dofimu13_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
469 
487 err_t c6dofimu13_generic_read ( c6dofimu13_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
488 
505 err_t c6dofimu13_mag_init ( c6dofimu13_t *ctx, uint8_t res, uint8_t op_mode, uint8_t temp_meas );
506 
521 err_t c6dofimu13_mag_get_x ( c6dofimu13_t *ctx, float *result );
522 
537 err_t c6dofimu13_mag_get_y ( c6dofimu13_t *ctx, float *result );
538 
553 err_t c6dofimu13_mag_get_z ( c6dofimu13_t *ctx, float *result );
554 
571 err_t c6dofimu13_mag_get_data ( c6dofimu13_t *ctx, float *mag_x, float *mag_y, float *mag_z );
572 
588 err_t c6dofimu13_mag_offset ( c6dofimu13_t *ctx, int16_t offset, uint8_t axis );
589 
606 err_t c6dofimu13_accel_init ( c6dofimu13_t *ctx, uint8_t samp_rate, uint8_t samp_range, uint8_t samp_res );
607 
622 err_t c6dofimu13_accel_get_raw_x ( c6dofimu13_t *ctx, int16_t *result );
623 
638 err_t c6dofimu13_accel_get_raw_y ( c6dofimu13_t *ctx, int16_t *result );
639 
654 err_t c6dofimu13_accel_get_raw_z ( c6dofimu13_t *ctx, int16_t *result );
655 
670 err_t c6dofimu13_accel_get_x ( c6dofimu13_t *ctx, float *result );
671 
686 err_t c6dofimu13_accel_get_y ( c6dofimu13_t *ctx, float *result );
687 
702 err_t c6dofimu13_accel_get_z ( c6dofimu13_t *ctx, float *result );
703 
720 err_t c6dofimu13_accel_get_data ( c6dofimu13_t *ctx, float *accel_x, float *accel_y, float *accel_z );
721 
737 err_t c6dofimu13_accel_offset ( c6dofimu13_t *ctx, int16_t offset, uint8_t axis );
738 
748 uint8_t c6dofimu13_get_in1 ( c6dofimu13_t *ctx );
749 
759 uint8_t c6dofimu13_get_in2 ( c6dofimu13_t *ctx );
760 
761 #ifdef __cplusplus
762 }
763 #endif
764 #endif // C6DOFIMU13_H
765  // c6dofimu13
767 
768 // ------------------------------------------------------------------------ END
c6dofimu13_init
err_t c6dofimu13_init(c6dofimu13_t *ctx, c6dofimu13_cfg_t *cfg)
6DOF IMU 13 initialization function.
c6dofimu13_return_value_t
c6dofimu13_return_value_t
6DOF IMU 13 Click return value data.
Definition: c6dofimu13.h:373
c6dofimu13_get_in2
uint8_t c6dofimu13_get_in2(c6dofimu13_t *ctx)
6DOF IMU 13 get in2 pin state function.
c6dofimu13_mag_init
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.
c6dofimu13_get_in1
uint8_t c6dofimu13_get_in1(c6dofimu13_t *ctx)
6DOF IMU 13 get in1 pin state function.
c6dofimu13_accel_get_raw_y
err_t c6dofimu13_accel_get_raw_y(c6dofimu13_t *ctx, int16_t *result)
6DOF IMU 13 Accelerometer get RAW Y-Axis data function.
c6dofimu13_mag_get_z
err_t c6dofimu13_mag_get_z(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Magnetometer get Z-Axis data function.
c6dofimu13_cfg_t
6DOF IMU 13 Click configuration object.
Definition: c6dofimu13.h:356
C6DOFIMU13_ERROR
Definition: c6dofimu13.h:376
c6dofimu13_accel_offset
err_t c6dofimu13_accel_offset(c6dofimu13_t *ctx, int16_t offset, uint8_t axis)
6DOF IMU 13 set accelerometer offset function.
c6dofimu13_mag_get_x
err_t c6dofimu13_mag_get_x(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Magnetometer get X-Axis data function.
c6dofimu13_cfg_setup
void c6dofimu13_cfg_setup(c6dofimu13_cfg_t *cfg)
6DOF IMU 13 configuration object setup function.
c6dofimu13_generic_write
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.
c6dofimu13_default_cfg
err_t c6dofimu13_default_cfg(c6dofimu13_t *ctx)
6DOF IMU 13 default configuration function.
c6dofimu13_accel_get_z
err_t c6dofimu13_accel_get_z(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Accelerometer get Z-Axis data function.
c6dofimu13_accel_get_x
err_t c6dofimu13_accel_get_x(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Accelerometer get X-Axis data function.
c6dofimu13_accel_get_data
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.
c6dofimu13_accel_get_raw_x
err_t c6dofimu13_accel_get_raw_x(c6dofimu13_t *ctx, int16_t *result)
6DOF IMU 13 Accelerometer get RAW X-Axis data function.
C6DOFIMU13_OK
Definition: c6dofimu13.h:375
c6dofimu13_generic_read
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.
c6dofimu13_mag_offset
err_t c6dofimu13_mag_offset(c6dofimu13_t *ctx, int16_t offset, uint8_t axis)
6DOF IMU 13 set magnetometer offset function.
c6dofimu13_accel_get_y
err_t c6dofimu13_accel_get_y(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Accelerometer get Y-Axis data function.
c6dofimu13_accel_init
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.
c6dofimu13_mag_get_y
err_t c6dofimu13_mag_get_y(c6dofimu13_t *ctx, float *result)
6DOF IMU 13 Magnetometer get Y-Axis data function.
c6dofimu13_accel_get_raw_z
err_t c6dofimu13_accel_get_raw_z(c6dofimu13_t *ctx, int16_t *result)
6DOF IMU 13 Accelerometer get RAW Z-Axis data function.
c6dofimu13_set_slave_address
err_t c6dofimu13_set_slave_address(c6dofimu13_t *ctx, uint8_t slave_address)
6DOF IMU 13 set slave address function.
c6dofimu13_t
6DOF IMU 13 Click context object.
Definition: c6dofimu13.h:332
c6dofimu13_mag_get_data
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.