c6dofimu21  2.1.0.0
c6dofimu21.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 C6DOFIMU21_H
29 #define C6DOFIMU21_H
30 
31 #ifdef __cplusplus
32 extern "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 #include "drv_spi_master.h"
53 #include "spi_specifics.h"
54 
75 #define C6DOFIMU21_REG_FIFO_CTRL1 0x06
76 #define C6DOFIMU21_REG_FIFO_CTRL2 0x07
77 #define C6DOFIMU21_REG_FIFO_CTRL3 0x08
78 #define C6DOFIMU21_REG_FIFO_CTRL4 0x09
79 #define C6DOFIMU21_REG_FIFO_CTRL5 0x0A
80 #define C6DOFIMU21_REG_DRDY_PULSE_CFG 0x0B
81 #define C6DOFIMU21_REG_INT0_CTRL 0x0D
82 #define C6DOFIMU21_REG_INT1_CTRL 0x0E
83 #define C6DOFIMU21_REG_DEVICE_ID 0x0F
84 #define C6DOFIMU21_REG_CTRL1_XL 0x10
85 #define C6DOFIMU21_REG_CTRL2_G 0x11
86 #define C6DOFIMU21_REG_CTRL3_C 0x12
87 #define C6DOFIMU21_REG_CTRL4_C 0x13
88 #define C6DOFIMU21_REG_CTRL5_C 0x14
89 #define C6DOFIMU21_REG_CTRL6_C 0x15
90 #define C6DOFIMU21_REG_CTRL7_G 0x16
91 #define C6DOFIMU21_REG_CTRL8_XL 0x17
92 #define C6DOFIMU21_REG_CTRL9_XL 0x18
93 #define C6DOFIMU21_REG_CTRL10_C 0x19
94 #define C6DOFIMU21_REG_MASTER_CFG 0x1A
95 #define C6DOFIMU21_REG_WAKE_UP_SRC 0x1B
96 #define C6DOFIMU21_REG_TAP_SRC 0x1C
97 #define C6DOFIMU21_REG_D6D_SRC 0x1D
98 #define C6DOFIMU21_REG_STATUS 0x1E
99 #define C6DOFIMU21_REG_T_OUT_L 0x20
100 #define C6DOFIMU21_REG_T_OUT_H 0x21
101 #define C6DOFIMU21_REG_G_X_OUT_L 0x22
102 #define C6DOFIMU21_REG_G_X_OUT_H 0x23
103 #define C6DOFIMU21_REG_G_Y_OUT_L 0x24
104 #define C6DOFIMU21_REG_G_Y_OUT_H 0x25
105 #define C6DOFIMU21_REG_G_Z_OUT_L 0x26
106 #define C6DOFIMU21_REG_G_Z_OUT_H 0x27
107 #define C6DOFIMU21_REG_XL_X_OUT_L 0x28
108 #define C6DOFIMU21_REG_XL_X_OUT_H 0x29
109 #define C6DOFIMU21_REG_XL_Y_OUT_L 0x2A
110 #define C6DOFIMU21_REG_XL_Y_OUT_H 0x2B
111 #define C6DOFIMU21_REG_XL_Z_OUT_L 0x2C
112 #define C6DOFIMU21_REG_XL_Z_OUT_H 0x2D
113 #define C6DOFIMU21_REG_FIFO_STATUS1 0x3A
114 #define C6DOFIMU21_REG_FIFO_STATUS2 0x3B
115 #define C6DOFIMU21_REG_FIFO_STATUS3 0x3C
116 #define C6DOFIMU21_REG_FIFO_STATUS4 0x3D
117 #define C6DOFIMU21_REG_FIFO_DATA_OUT_L 0x3E
118 #define C6DOFIMU21_REG_FIFO_DATA_OUT_H 0x3F
119 #define C6DOFIMU21_REG_FUNC_SRC1 0x53
120 #define C6DOFIMU21_REG_TAP_CFG 0x58
121 #define C6DOFIMU21_REG_TAP_THS_6D 0x59
122 #define C6DOFIMU21_REG_INT_DUR2 0x5A
123 #define C6DOFIMU21_REG_WAKE_UP_THS 0x5B
124 #define C6DOFIMU21_REG_WAKE_UP_DUR 0x5C
125 #define C6DOFIMU21_REG_FREE_FALL 0x5D
126 #define C6DOFIMU21_REG_MD1_CFG 0x5E
127 #define C6DOFIMU21_REG_MD2_CFG 0x5F
128 #define C6DOFIMU21_REG_X_OFS_USR 0x73
129 #define C6DOFIMU21_REG_Y_OFS_USR 0x74
130 #define C6DOFIMU21_REG_Z_OFS_USR 0x75
131  // c6dofimu21_reg
133 
148 #define C6DOFIMU21_FULL_SCALE_MASK 0x0C
149 #define C6DOFIMU21_ACCLE_FS_2G 0x00
150 #define C6DOFIMU21_ACCLE_FS_16G 0x04
151 #define C6DOFIMU21_ACCLE_FS_4G 0x08
152 #define C6DOFIMU21_ACCLE_FS_8G 0x0C
153 #define C6DOFIMU21_GYRO_FS_250DPS 0x00
154 #define C6DOFIMU21_GYRO_FS_500DPS 0x04
155 #define C6DOFIMU21_GYRO_FS_1000DPS 0x08
156 #define C6DOFIMU21_GYRO_FS_2000DPS 0x0C
157 
162 #define C6DOFIMU21_ODR_XL_POWER_DOWN 0x00
163 #define C6DOFIMU21_ODR_XL_1_6_HZ 0xB0
164 #define C6DOFIMU21_ODR_XL_12_5_HZ 0x10
165 #define C6DOFIMU21_ODR_XL_26_HZ 0x20
166 #define C6DOFIMU21_ODR_XL_52_HZ 0x30
167 #define C6DOFIMU21_ODR_XL_104_HZ 0x40
168 #define C6DOFIMU21_ODR_XL_208_HZ 0x50
169 #define C6DOFIMU21_ODR_XL_416_HZ 0x60
170 #define C6DOFIMU21_ODR_XL_833_HZ 0x70
171 #define C6DOFIMU21_ODR_XL_1_66_KHZ 0x80
172 #define C6DOFIMU21_ODR_XL_3_33_KHZ 0x90
173 #define C6DOFIMU21_ODR_XL_6_66_KHZ 0xA0
174 
179 #define C6DOFIMU21_ODR_G_POWER_DOWN 0x00
180 #define C6DOFIMU21_ODR_G_12_5_HZ 0x10
181 #define C6DOFIMU21_ODR_G_26_HZ 0x20
182 #define C6DOFIMU21_ODR_G_52_HZ 0x30
183 #define C6DOFIMU21_ODR_G_104_HZ 0x40
184 #define C6DOFIMU21_ODR_G_208_HZ 0x50
185 #define C6DOFIMU21_ODR_G_416_HZ 0x60
186 #define C6DOFIMU21_ODR_G_833_HZ 0x70
187 #define C6DOFIMU21_ODR_G_1_66_KHZ 0x80
188 #define C6DOFIMU21_ODR_G_3_33_KHZ 0x90
189 #define C6DOFIMU21_ODR_G_6_66_KHZ 0xA0
190 
195 #define C6DOFIMU21_SOFTWARE_RESET 0x01
196 
197 
202 #define C6DOFIMU21_DEVICE_ID 0x6A
203 
209 #define C6DOFIMU21_ACCEL_2G_CONV_MUL 0.061f
210 #define C6DOFIMU21_ACCEL_4G_CONV_MUL 0.122f
211 #define C6DOFIMU21_ACCEL_8G_CONV_MUL 0.244f
212 #define C6DOFIMU21_ACCEL_16G_CONV_MUL 0.488f
213 #define C6DOFIMU21_GYRO_250DPS_CONV_MUL 8.75f
214 #define C6DOFIMU21_GYRO_500DPS_CONV_MUL 17.5f
215 #define C6DOFIMU21_GYRO_1000DPS_CONV_MUL 35.0f
216 #define C6DOFIMU21_GYRO_2000DPS_CONV_MUL 70.0f
217 
223 #define C6DOFIMU21_DEVICE_ADDRESS_0 0x6A
224 #define C6DOFIMU21_DEVICE_ADDRESS_1 0x6B
225 
234 #define C6DOFIMU21_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
235 #define C6DOFIMU21_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
236  // c6dofimu21_set
238 
253 #define C6DOFIMU21_MAP_MIKROBUS( cfg, mikrobus ) \
254  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
255  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
256  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
257  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
258  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
259  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
260  cfg.i1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
261  cfg.i0 = MIKROBUS( mikrobus, MIKROBUS_INT )
262  // c6dofimu21_map // c6dofimu21
265 
270 typedef enum
271 {
276 
281 struct c6dofimu21_s;
282 typedef err_t ( *c6dofimu21_master_io_t )( struct c6dofimu21_s*, uint8_t, uint8_t*, uint8_t );
288 typedef struct c6dofimu21_s
289 {
290  digital_in_t i1;
291  digital_in_t i0;
293  i2c_master_t i2c;
294  spi_master_t spi;
296  uint8_t slave_address;
297  pin_name_t chip_select;
304 
309 typedef struct
310 {
311  pin_name_t scl;
312  pin_name_t sda;
313  pin_name_t miso;
314  pin_name_t mosi;
315  pin_name_t sck;
316  pin_name_t cs;
317  pin_name_t i1;
318  pin_name_t i0;
320  uint32_t i2c_speed;
321  uint8_t i2c_address;
323  uint32_t spi_speed;
324  spi_master_mode_t spi_mode;
325  spi_master_chip_select_polarity_t cs_polarity;
330 
335 typedef struct
336 {
337  float x_data;
338  float y_data;
339  float z_data;
340 
342 
347 typedef enum
348 {
350  C6DOFIMU21_ERROR = -1
351 
353 
370 
386 
401 
415 
430 err_t c6dofimu21_generic_write ( c6dofimu21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
431 
446 err_t c6dofimu21_generic_read ( c6dofimu21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
447 
457 
467 
480 err_t c6dofimu21_write_reg ( c6dofimu21_t *ctx, uint8_t reg, uint8_t data_in );
481 
495 err_t c6dofimu21_read_reg ( c6dofimu21_t *ctx, uint8_t reg, uint8_t *data_out );
496 
508 
522 
536 
537 #ifdef __cplusplus
538 }
539 #endif
540 #endif // C6DOFIMU21_H
541  // c6dofimu21
543 
544 // ------------------------------------------------------------------------ END
c6dofimu21_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu21.h:325
c6dofimu21_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu21.h:321
c6dofimu21_cfg_t::sck
pin_name_t sck
Definition: c6dofimu21.h:315
c6dofimu21_s::drv_sel
c6dofimu21_drv_t drv_sel
Definition: c6dofimu21.h:298
c6dofimu21_data_t
6DOF IMU 21 data object.
Definition: c6dofimu21.h:336
c6dofimu21_read_reg
err_t c6dofimu21_read_reg(c6dofimu21_t *ctx, uint8_t reg, uint8_t *data_out)
6DOF IMU 21 register data reading function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
c6dofimu21_drv_interface_sel
void c6dofimu21_drv_interface_sel(c6dofimu21_cfg_t *cfg, c6dofimu21_drv_t drv_sel)
6DOF IMU 21 driver interface setup function.
c6dofimu21_cfg_t
6DOF IMU 21 Click configuration object.
Definition: c6dofimu21.h:310
C6DOFIMU21_DRV_SEL_I2C
@ C6DOFIMU21_DRV_SEL_I2C
Definition: c6dofimu21.h:273
c6dofimu21_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu21.h:323
c6dofimu21_cfg_t::cs
pin_name_t cs
Definition: c6dofimu21.h:316
c6dofimu21_s::spi
spi_master_t spi
Definition: c6dofimu21.h:294
c6dofimu21_cfg_t::sda
pin_name_t sda
Definition: c6dofimu21.h:312
c6dofimu21_cfg_t::drv_sel
c6dofimu21_drv_t drv_sel
Definition: c6dofimu21.h:327
c6dofimu21_cfg_t::scl
pin_name_t scl
Definition: c6dofimu21.h:311
c6dofimu21_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu21.h:314
c6dofimu22_get_int1_pin
uint8_t c6dofimu22_get_int1_pin(c6dofimu21_t *ctx)
6DOF IMU 21 get int1 pin function.
c6dofimu21_s::chip_select
pin_name_t chip_select
Definition: c6dofimu21.h:297
c6dofimu21_master_io_t
err_t(* c6dofimu21_master_io_t)(struct c6dofimu21_s *, uint8_t, uint8_t *, uint8_t)
Definition: c6dofimu21.h:282
c6dofimu21_s::read_f
c6dofimu21_master_io_t read_f
Definition: c6dofimu21.h:301
c6dofimu21_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu21.h:320
c6dofimu21_read_gyro_data
err_t c6dofimu21_read_gyro_data(c6dofimu21_t *ctx, c6dofimu21_data_t *gyro_data)
6DOF IMU 21 read gyro function.
c6dofimu22_get_int0_pin
uint8_t c6dofimu22_get_int0_pin(c6dofimu21_t *ctx)
6DOF IMU 21 get int0 pin function.
c6dofimu21_s::i0
digital_in_t i0
Definition: c6dofimu21.h:291
c6dofimu21_init
err_t c6dofimu21_init(c6dofimu21_t *ctx, c6dofimu21_cfg_t *cfg)
6DOF IMU 21 initialization function.
c6dofimu21_return_value_t
c6dofimu21_return_value_t
6DOF IMU 21 Click return value data.
Definition: c6dofimu21.h:348
c6dofimu21_software_reset
err_t c6dofimu21_software_reset(c6dofimu21_t *ctx)
6DOF IMU 21 software reset device function.
c6dofimu21_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu21.h:324
c6dofimu21_write_reg
err_t c6dofimu21_write_reg(c6dofimu21_t *ctx, uint8_t reg, uint8_t data_in)
6DOF IMU 21 data writing function.
c6dofimu21_s
6DOF IMU 21 Click context object.
Definition: c6dofimu21.h:289
c6dofimu21_cfg_setup
void c6dofimu21_cfg_setup(c6dofimu21_cfg_t *cfg)
6DOF IMU 21 configuration object setup function.
c6dofimu21_s::i2c
i2c_master_t i2c
Definition: c6dofimu21.h:293
c6dofimu21_data_t::z_data
float z_data
Definition: c6dofimu21.h:339
C6DOFIMU21_OK
@ C6DOFIMU21_OK
Definition: c6dofimu21.h:349
c6dofimu21_drv_t
c6dofimu21_drv_t
6DOF IMU 21 Click driver selector.
Definition: c6dofimu21.h:271
C6DOFIMU21_DRV_SEL_SPI
@ C6DOFIMU21_DRV_SEL_SPI
Definition: c6dofimu21.h:272
c6dofimu21_t
struct c6dofimu21_s c6dofimu21_t
6DOF IMU 21 Click context object.
c6dofimu21_s::write_f
c6dofimu21_master_io_t write_f
Definition: c6dofimu21.h:300
c6dofimu21_default_cfg
err_t c6dofimu21_default_cfg(c6dofimu21_t *ctx)
6DOF IMU 21 default configuration function.
c6dofimu21_data_t::x_data
float x_data
Definition: c6dofimu21.h:337
c6dofimu21_cfg_t::miso
pin_name_t miso
Definition: c6dofimu21.h:313
c6dofimu21_cfg_t::i1
pin_name_t i1
Definition: c6dofimu21.h:317
c6dofimu21_s::slave_address
uint8_t slave_address
Definition: c6dofimu21.h:296
c6dofimu21_generic_read
err_t c6dofimu21_generic_read(c6dofimu21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
6DOF IMU 21 data reading function.
c6dofimu21_data_t::y_data
float y_data
Definition: c6dofimu21.h:338
c6dofimu21_cfg_t::i0
pin_name_t i0
Definition: c6dofimu21.h:318
c6dofimu21_generic_write
err_t c6dofimu21_generic_write(c6dofimu21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
6DOF IMU 21 data writing function.
c6dofimu21_s::i1
digital_in_t i1
Definition: c6dofimu21.h:290
c6dofimu21_read_accel_data
err_t c6dofimu21_read_accel_data(c6dofimu21_t *ctx, c6dofimu21_data_t *accel_data)
6DOF IMU 21 read accel function.
C6DOFIMU21_ERROR
@ C6DOFIMU21_ERROR
Definition: c6dofimu21.h:350