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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define C6DOFIMU13_MAG_SELFTEST_RESP 0x0C
70 #define C6DOFIMU13_MAG_MORE_INFO_VER 0x0D
71 #define C6DOFIMU13_MAG_MORE_INFO 0x0E
72 #define C6DOFIMU13_MAG_WHO_I_AM 0x0F
73 #define C6DOFIMU13_MAG_OUT_X_LSB 0x10
74 #define C6DOFIMU13_MAG_OUT_X_MSB 0x11
75 #define C6DOFIMU13_MAG_OUT_Y_LSB 0x12
76 #define C6DOFIMU13_MAG_OUT_Y_MSB 0x13
77 #define C6DOFIMU13_MAG_OUT_Z_LSB 0x14
78 #define C6DOFIMU13_MAG_OUT_Z_MSB 0x15
79 #define C6DOFIMU13_MAG_STAT 0x18
80 #define C6DOFIMU13_MAG_CTL_1 0x1B
81 #define C6DOFIMU13_MAG_CTL_2 0x1C
82 #define C6DOFIMU13_MAG_CTL_3 0x1D
83 #define C6DOFIMU13_MAG_CTL_4 0x1E
84 #define C6DOFIMU13_MAG_OFFS_X_LSB 0x20
85 #define C6DOFIMU13_MAG_OFFS_X_MSB 0x21
86 #define C6DOFIMU13_MAG_OFFS_Y_LSB 0x22
87 #define C6DOFIMU13_MAG_OFFS_Y_MSB 0x23
88 #define C6DOFIMU13_MAG_OFFS_Z_LSB 0x24
89 #define C6DOFIMU13_MAG_OFFS_Z_MSB 0x25
90 #define C6DOFIMU13_MAG_ITHR_L 0x26
91 #define C6DOFIMU13_MAG_ITHR_H 0x27
92 #define C6DOFIMU13_MAG_TEMP_VAL 0x31
93 
98 #define C6DOFIMU13_ACCEL_SR 0x03
99 #define C6DOFIMU13_ACCEL_OPSTAT 0x04
100 #define C6DOFIMU13_ACCEL_INTEN 0x06
101 #define C6DOFIMU13_ACCEL_MODE 0x07
102 #define C6DOFIMU13_ACCEL_SRTFR 0x08
103 #define C6DOFIMU13_ACCEL_TAPEN 0x09
104 #define C6DOFIMU13_ACCEL_TTTRX 0x0A
105 #define C6DOFIMU13_ACCEL_TTTRY 0x0B
106 #define C6DOFIMU13_ACCEL_TTTRZ 0x0C
107 #define C6DOFIMU13_ACCEL_XOUT_EX_L 0x0D
108 #define C6DOFIMU13_ACCEL_XOUT_EX_H 0x0E
109 #define C6DOFIMU13_ACCEL_YOUT_EX_L 0x0F
110 #define C6DOFIMU13_ACCEL_YOUT_EX_H 0x10
111 #define C6DOFIMU13_ACCEL_ZOUT_EX_L 0x11
112 #define C6DOFIMU13_ACCEL_ZOUT_EX_H 0x12
113 #define C6DOFIMU13_ACCEL_OUTCFG 0x20
114 #define C6DOFIMU13_ACCEL_XOFFL 0x21
115 #define C6DOFIMU13_ACCEL_XOFFH 0x22
116 #define C6DOFIMU13_ACCEL_YOFFL 0x23
117 #define C6DOFIMU13_ACCEL_YOFFH 0x24
118 #define C6DOFIMU13_ACCEL_ZOFFL 0x25
119 #define C6DOFIMU13_ACCEL_ZOFFH 0x26
120 #define C6DOFIMU13_ACCEL_XGAIN 0x27
121 #define C6DOFIMU13_ACCEL_YGAIN 0x28
122 #define C6DOFIMU13_ACCEL_ZGAIN 0x29
123 #define C6DOFIMU13_ACCEL_PCODE 0x3B
124  // c6dofimu13_reg
126 
141 #define C6DOFIMU13_MAG_STAT_DRDY 0x40
142 #define C6DOFIMU13_MAG_STAT_DOR 0x20
143 
148 #define C6DOFIMU13_MAG_CTL_1_PC_NORM 0x80
149 #define C6DOFIMU13_MAG_CTL_1_PC_STBY 0x00
150 #define C6DOFIMU13_MAG_CTL_1_ODR_05 0x00
151 #define C6DOFIMU13_MAG_CTL_1_ODR_10 0x08
152 #define C6DOFIMU13_MAG_CTL_1_ODR_20 0x10
153 #define C6DOFIMU13_MAG_CTL_1_ODR_100 0x18
154 #define C6DOFIMU13_MAG_CTL_1_FS_DEF 0x02
155 #define C6DOFIMU13_MAG_CTL_1_FS_NORM 0x00
156 
161 #define C6DOFIMU13_MAG_CTL_3_SRST_SR 0x80
162 #define C6DOFIMU13_MAG_CTL_3_SRST_NOP 0x00
163 #define C6DOFIMU13_MAG_CTL_3_FRC_SM 0x40
164 #define C6DOFIMU13_MAG_CTL_3_FRC_NOP 0x00
165 #define C6DOFIMU13_MAG_CTL_3_STC_EN 0x10
166 #define C6DOFIMU13_MAG_CTL_3_STC_NOP 0x00
167 #define C6DOFIMU13_MAG_CTL_3_TCS_EN 0x02
168 #define C6DOFIMU13_MAG_CTL_3_TCS_NOP 0x00
169 #define C6DOFIMU13_MAG_CTL_3_OCL_EN 0x01
170 #define C6DOFIMU13_MAG_CTL_3_OCL_NOP 0x00
171 
176 #define C6DOFIMU13_MAG_CTL_4_RS_S_14 0x00
177 #define C6DOFIMU13_MAG_CTL_4_RS_S_15 0x10
178 
183 #define C6DOFIMU13_MAG_SENS 0.15
184 #define C6DOFIMU13_MAG_ORIENTATION_COEF -1.0
185 
190 #define C6DOFIMU13_MAG_RES_14_BIT 0x00
191 #define C6DOFIMU13_MAG_RES_15_BIT 0x01
192 #define C6DOFIMU13_MAG_OP_MODE_S_SHOT 0x00
193 #define C6DOFIMU13_MAG_OP_MODE_CONT 0x01
194 #define C6DOFIMU13_MAG_TEMP_MEAS_OFF 0x00
195 #define C6DOFIMU13_MAG_TEMP_MEAS_ON 0x01
196 
201 #define C6DOFIMU13_MAG_AXIS_X 0x00
202 #define C6DOFIMU13_MAG_AXIS_Y 0x01
203 #define C6DOFIMU13_MAG_AXIS_Z 0x02
204 
209 #define C6DOFIMU13_ACCEL_SR_TAP_XP 0x01
210 #define C6DOFIMU13_ACCEL_SR_TAP_XN 0x02
211 #define C6DOFIMU13_ACCEL_SR_TAP_YP 0x04
212 #define C6DOFIMU13_ACCEL_SR_TAP_YN 0x08
213 #define C6DOFIMU13_ACCEL_SR_TAP_ZP 0x10
214 #define C6DOFIMU13_ACCEL_SR_TAP_ZN 0x20
215 #define C6DOFIMU13_ACCEL_SR_AC_INT 0x80
216 
221 #define C6DOFIMU13_ACCEL_OPSTAT_WAKE 0x01
222 #define C6DOFIMU13_ACCEL_OPSTAT_WDT 0x10
223 #define C6DOFIMU13_ACCEL_OPSTAT_OTPA 0x80
224 
229 #define C6DOFIMU13_ACCEL_INTEN_TIXPEN 0x01
230 #define C6DOFIMU13_ACCEL_INTEN_TIXNEN 0x02
231 #define C6DOFIMU13_ACCEL_INTEN_TIYPEN 0x04
232 #define C6DOFIMU13_ACCEL_INTEN_TIYNEN 0x08
233 #define C6DOFIMU13_ACCEL_INTEN_TIZPEN 0x10
234 #define C6DOFIMU13_ACCEL_INTEN_TIZNEN 0x20
235 #define C6DOFIMU13_ACCEL_INTEN_AC_INT_EN 0x80
236 
241 #define C6DOFIMU13_ACCEL_MODE_STDBY 0x00
242 #define C6DOFIMU13_ACCEL_MODE_WAKE 0x01
243 #define C6DOFIMU13_ACCEL_MODE_WDT_NEG 0x10
244 #define C6DOFIMU13_ACCEL_MODE_WDT_POS 0x20
245 #define C6DOFIMU13_ACCEL_MODE_IPP 0x40
246 #define C6DOFIMU13_ACCEL_MODE_IAH 0x80
247 
252 #define C6DOFIMU13_ACCEL_SRTFR_RATE_32 0x00
253 #define C6DOFIMU13_ACCEL_SRTFR_RATE_16 0x01
254 #define C6DOFIMU13_ACCEL_SRTFR_RATE_8 0x02
255 #define C6DOFIMU13_ACCEL_SRTFR_RATE_4 0x03
256 #define C6DOFIMU13_ACCEL_SRTFR_RATE_2 0x04
257 #define C6DOFIMU13_ACCEL_SRTFR_RATE_1 0x05
258 #define C6DOFIMU13_ACCEL_SRTFR_RATE_0_5 0x06
259 #define C6DOFIMU13_ACCEL_SRTFR_RATE_0_25 0x07
260 #define C6DOFIMU13_ACCEL_SRTFR_RATE_64 0x08
261 #define C6DOFIMU13_ACCEL_SRTFR_RATE_128 0x09
262 #define C6DOFIMU13_ACCEL_SRTFR_RATE_256 0x0A
263 #define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPX 0x10
264 #define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPY 0x20
265 #define C6DOFIMU13_ACCEL_SRTFR_FLIP_TAPZ 0x40
266 #define C6DOFIMU13_ACCEL_SRTFR_TAP_LATCH 0x80
267 
272 #define C6DOFIMU13_ACCEL_TAPEN_TAPXPEN 0x01
273 #define C6DOFIMU13_ACCEL_TAPEN_TAPXNEN 0x02
274 #define C6DOFIMU13_ACCEL_TAPEN_TAPYPEN 0x04
275 #define C6DOFIMU13_ACCEL_TAPEN_TAPYNEN 0x08
276 #define C6DOFIMU13_ACCEL_TAPEN_TAPZPEN 0x10
277 #define C6DOFIMU13_ACCEL_TAPEN_TAPZNEN 0x20
278 #define C6DOFIMU13_ACCEL_TAPEN_THRDUR 0x40
279 #define C6DOFIMU13_ACCEL_TAPEN_TAP_EN 0x80
280 
285 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_2 0x00
286 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_4 0x10
287 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_8 0x20
288 #define C6DOFIMU13_ACCEL_OUTCFG_RANGE_16 0x30
289 #define C6DOFIMU13_ACCEL_OUTCFG_RES_6 0x00
290 #define C6DOFIMU13_ACCEL_OUTCFG_RES_7 0x01
291 #define C6DOFIMU13_ACCEL_OUTCFG_RES_8 0x02
292 #define C6DOFIMU13_ACCEL_OUTCFG_RES_10 0x03
293 #define C6DOFIMU13_ACCEL_OUTCFG_RES_12 0x04
294 #define C6DOFIMU13_ACCEL_OUTCFG_RES_14 0x05
295 
300 #define C6DOFIMU13_ACCEL_AXIS_X 0x00
301 #define C6DOFIMU13_ACCEL_AXIS_Y 0x01
302 #define C6DOFIMU13_ACCEL_AXIS_Z 0x02
303 
304 
310 #define C6DOFIMU13_DEV_ADDRESS_ACCEL_GND 0x4C
311 #define C6DOFIMU13_DEV_ADDRESS_ACCEL_VCC 0x6C
312 #define C6DOFIMU13_DEV_ADDRESS_MAG 0x0C
313  // c6dofimu13_set
315 
330 #define C6DOFIMU13_MAP_MIKROBUS( cfg, mikrobus ) \
331  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
332  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
333  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
334  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
335  // c6dofimu13_map // c6dofimu13
338 
343 typedef struct
344 {
345  // Input pins
346 
347  digital_in_t in2;
348  digital_in_t in1;
350  // Modules
351 
352  i2c_master_t i2c;
354  // I2C slave address
355 
356  uint8_t slave_address;
359  float calc_coef;
361 } c6dofimu13_t;
362 
367 typedef struct
368 {
369  pin_name_t scl;
370  pin_name_t sda;
372  pin_name_t in2;
373  pin_name_t in1;
375  uint32_t i2c_speed;
376  uint8_t i2c_address;
379 
384 typedef enum
385 {
387  C6DOFIMU13_ERROR = -1
388 
390 
409 
427 
444 
459 err_t c6dofimu13_set_slave_address ( c6dofimu13_t *ctx, uint8_t slave_address );
460 
478 err_t c6dofimu13_generic_write ( c6dofimu13_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
479 
497 err_t c6dofimu13_generic_read ( c6dofimu13_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
498 
515 err_t c6dofimu13_mag_init ( c6dofimu13_t *ctx, uint8_t res, uint8_t op_mode, uint8_t temp_meas );
516 
531 err_t c6dofimu13_mag_get_x ( c6dofimu13_t *ctx, float *result );
532 
547 err_t c6dofimu13_mag_get_y ( c6dofimu13_t *ctx, float *result );
548 
563 err_t c6dofimu13_mag_get_z ( c6dofimu13_t *ctx, float *result );
564 
581 err_t c6dofimu13_mag_get_data ( c6dofimu13_t *ctx, float *mag_x, float *mag_y, float *mag_z );
582 
598 err_t c6dofimu13_mag_offset ( c6dofimu13_t *ctx, int16_t offset, uint8_t axis );
599 
616 err_t c6dofimu13_accel_init ( c6dofimu13_t *ctx, uint8_t samp_rate, uint8_t samp_range, uint8_t samp_res );
617 
632 err_t c6dofimu13_accel_get_raw_x ( c6dofimu13_t *ctx, int16_t *result );
633 
648 err_t c6dofimu13_accel_get_raw_y ( c6dofimu13_t *ctx, int16_t *result );
649 
664 err_t c6dofimu13_accel_get_raw_z ( c6dofimu13_t *ctx, int16_t *result );
665 
680 err_t c6dofimu13_accel_get_x ( c6dofimu13_t *ctx, float *result );
681 
696 err_t c6dofimu13_accel_get_y ( c6dofimu13_t *ctx, float *result );
697 
712 err_t c6dofimu13_accel_get_z ( c6dofimu13_t *ctx, float *result );
713 
730 err_t c6dofimu13_accel_get_data ( c6dofimu13_t *ctx, float *accel_x, float *accel_y, float *accel_z );
731 
747 err_t c6dofimu13_accel_offset ( c6dofimu13_t *ctx, int16_t offset, uint8_t axis );
748 
759 
770 
771 #ifdef __cplusplus
772 }
773 #endif
774 #endif // C6DOFIMU13_H
775  // c6dofimu13
777 
778 // ------------------------------------------------------------------------ END
c6dofimu13_cfg_t::in2
pin_name_t in2
Definition: c6dofimu13.h:372
c6dofimu13_init
err_t c6dofimu13_init(c6dofimu13_t *ctx, c6dofimu13_cfg_t *cfg)
6DOF IMU 13 initialization function.
c6dofimu13_t::calc_coef
float calc_coef
Definition: c6dofimu13.h:359
c6dofimu13_return_value_t
c6dofimu13_return_value_t
6DOF IMU 13 Click return value data.
Definition: c6dofimu13.h:385
c6dofimu13_cfg_t::in1
pin_name_t in1
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_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu13.h:376
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:368
C6DOFIMU13_ERROR
@ C6DOFIMU13_ERROR
Definition: c6dofimu13.h:387
c6dofimu13_cfg_t::scl
pin_name_t scl
Definition: c6dofimu13.h:369
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_t::in1
digital_in_t in1
Definition: c6dofimu13.h:348
c6dofimu13_cfg_t::sda
pin_name_t sda
Definition: c6dofimu13.h:370
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_t::i2c
i2c_master_t i2c
Definition: c6dofimu13.h:352
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
@ C6DOFIMU13_OK
Definition: c6dofimu13.h:386
c6dofimu13_t::in2
digital_in_t in2
Definition: c6dofimu13.h:347
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_t::slave_address
uint8_t slave_address
Definition: c6dofimu13.h:356
c6dofimu13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu13.h:375
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:344
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.