c6dofimu16  2.1.0.0
c6dofimu16.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 C6DOFIMU16_H
29 #define C6DOFIMU16_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 C6DOFIMU16_REG_ACCEL_DATA_X1_UI 0x00
76 #define C6DOFIMU16_REG_ACCEL_DATA_X0_UI 0x01
77 #define C6DOFIMU16_REG_ACCEL_DATA_Y1_UI 0x02
78 #define C6DOFIMU16_REG_ACCEL_DATA_Y0_UI 0x03
79 #define C6DOFIMU16_REG_ACCEL_DATA_Z1_UI 0x04
80 #define C6DOFIMU16_REG_ACCEL_DATA_Z0_UI 0x05
81 #define C6DOFIMU16_REG_GYRO_DATA_X1_UI 0x06
82 #define C6DOFIMU16_REG_GYRO_DATA_X0_UI 0x07
83 #define C6DOFIMU16_REG_GYRO_DATA_Y1_UI 0x08
84 #define C6DOFIMU16_REG_GYRO_DATA_Y0_UI 0x09
85 #define C6DOFIMU16_REG_GYRO_DATA_Z1_UI 0x0A
86 #define C6DOFIMU16_REG_GYRO_DATA_Z0_UI 0x0B
87 #define C6DOFIMU16_REG_TEMP_DATA1_UI 0x0C
88 #define C6DOFIMU16_REG_TEMP_DATA0_UI 0x0D
89 #define C6DOFIMU16_REG_TMST_FSYNCH 0x0E
90 #define C6DOFIMU16_REG_TMST_FSYNCL 0x0F
91 #define C6DOFIMU16_REG_PWR_MGMNT0 0x10
92 #define C6DOFIMU16_REG_FIFO_COUNT_0 0x12
93 #define C6DOFIMU16_REG_FIFO_COUNT_1 0x13
94 #define C6DOFIMU16_REG_FIFO_DATA 0x14
95 #define C6DOFIMU16_REG_INT1_CONFIG0 0x16
96 #define C6DOFIMU16_REG_INT1_CONFIG1 0x17
97 #define C6DOFIMU16_REG_INT1_CONFIG2 0x18
98 #define C6DOFIMU16_REG_INT1_STATUS0 0x19
99 #define C6DOFIMU16_REG_ACCEL_CONFIG0 0x1B
100 #define C6DOFIMU16_REG_GYRO_CONFIG0 0x1C
101 #define C6DOFIMU16_REG_FIFO_CONFIG0 0x1D
102 #define C6DOFIMU16_REG_FIFO_CONFIG1_0 0x1E
103 #define C6DOFIMU16_REG_FIFO_CONFIG1_1 0x1F
104 #define C6DOFIMU16_REG_FIFO_CONFIG2 0x20
105 #define C6DOFIMU16_REG_FIFO_CONFIG3 0x21
106 #define C6DOFIMU16_REG_FIFO_CONFIG4 0x22
107 #define C6DOFIMU16_REG_DMP_EXT_SEN_ODR_CFG 0x27
108 #define C6DOFIMU16_REG_EDMP_APEX_EN0 0x29
109 #define C6DOFIMU16_REG_EDMP_APEX_EN1 0x2A
110 #define C6DOFIMU16_REG_APEX_BUFFER_MGMT 0x2B
111 #define C6DOFIMU16_REG_INTF_CONFIG0 0x2C
112 #define C6DOFIMU16_REG_INTF_CONFIG1_OVRD 0x2D
113 #define C6DOFIMU16_REG_IOC_PAD_SCENARIO 0x2F
114 #define C6DOFIMU16_REG_IOC_PAD_SCENARIO_AUX_OVRD 0x30
115 #define C6DOFIMU16_REG_IOC_PAD_SCENARIO_OVRD 0x31
116 #define C6DOFIMU16_REG_DRIVE_CONFIG0 0x32
117 #define C6DOFIMU16_REG_DRIVE_CONFIG1 0x33
118 #define C6DOFIMU16_REG_DRIVE_CONFIG2 0x34
119 #define C6DOFIMU16_REG_INT_APEX_CONFIG1 0x3A
120 #define C6DOFIMU16_REG_INT_APEX_STATUS0 0x3B
121 #define C6DOFIMU16_REG_INT_APEX_STATUS1 0x3C
122 #define C6DOFIMU16_REG_INT2_CONFIG0 0x56
123 #define C6DOFIMU16_REG_INT2_CONFIG1 0x57
124 #define C6DOFIMU16_REG_INT2_CONFIG2 0x58
125 #define C6DOFIMU16_REG_INT2_STATUS0 0x59
126 #define C6DOFIMU16_REG_WHO_AM_I 0x72
127 #define C6DOFIMU16_REG_REG_HOST_MSG 0x73
128 #define C6DOFIMU16_REG_IREG_ADDR_15_8 0x7C
129 #define C6DOFIMU16_REG_IREG_ADDR_7_0 0x7D
130 #define C6DOFIMU16_REG_IREG_DATA 0x7E
131 #define C6DOFIMU16_REG_REG_MISC2 0x7F
132  // c6dofimu16_reg
134 
149 #define C6DOFIMU16_GYRO_MODE_OFF 0x00
150 #define C6DOFIMU16_GYRO_MODE_STANDBY 0x04
151 #define C6DOFIMU16_GYRO_MODE_LOW_POWER 0x08
152 #define C6DOFIMU16_GYRO_MODE_LOW_NOISE 0x0C
153 #define C6DOFIMU16_ACCEL_MODE_OFF 0x00
154 #define C6DOFIMU16_ACCEL_MODE_STANDBY 0x01
155 #define C6DOFIMU16_ACCEL_MODE_LOW_POWER 0x02
156 #define C6DOFIMU16_ACCEL_MODE_LOW_NOISE 0x03
157 
162 #define C6DOFIMU16_GYRO_UI_FS_SEL_MASK 0xF0
163 #define C6DOFIMU16_GYRO_UI_FS_SEL_2000DPS 0x10
164 #define C6DOFIMU16_GYRO_UI_FS_SEL_1000DPS 0x20
165 #define C6DOFIMU16_GYRO_UI_FS_SEL_500DPS 0x30
166 #define C6DOFIMU16_GYRO_UI_FS_SEL_250DPS 0x40
167 #define C6DOFIMU16_GYRO_UI_FS_SEL_125DPS 0x50
168 #define C6DOFIMU16_GYRO_UI_FS_SEL_62_5DPS 0x60
169 #define C6DOFIMU16_GYRO_UI_FS_SEL_31_25DPS 0x70
170 #define C6DOFIMU16_GYRO_UI_FS_SEL_15_625DPS 0x80
171 
176 #define C6DOFIMU16_ACCEL_UI_FS_SEL_MASK 0x70
177 #define C6DOFIMU16_ACCEL_UI_FS_SEL_16g 0x10
178 #define C6DOFIMU16_ACCEL_UI_FS_SEL_8g 0x20
179 #define C6DOFIMU16_ACCEL_UI_FS_SEL_4g 0x30
180 #define C6DOFIMU16_ACCEL_UI_FS_SEL_2g 0x40
181 
186 #define C6DOFIMU16_ACCEL_ODR_6_4_KHZ 0x03
187 #define C6DOFIMU16_ACCEL_ODR_3_2_KHZ 0x04
188 #define C6DOFIMU16_ACCEL_ODR_1_6_KHZ 0x05
189 #define C6DOFIMU16_ACCEL_ODR_800_HZ 0x06
190 #define C6DOFIMU16_ACCEL_ODR_400_HZ 0x07
191 #define C6DOFIMU16_ACCEL_ODR_200_HZ 0x08
192 #define C6DOFIMU16_ACCEL_ODR_100_HZ 0x09
193 #define C6DOFIMU16_ACCEL_ODR_50_HZ 0x0A
194 #define C6DOFIMU16_ACCEL_ODR_25_HZ 0x0B
195 #define C6DOFIMU16_ACCEL_ODR_12_5_HZ 0x0C
196 #define C6DOFIMU16_ACCEL_ODR_6_25_HZ 0x0D
197 #define C6DOFIMU16_ACCEL_ODR_3_125_HZ 0x0E
198 #define C6DOFIMU16_ACCEL_ODR_1_5625_HZ 0x0F
199 
204 #define C6DOFIMU16_GYRO_ODR_6_4_KHZ 0x03
205 #define C6DOFIMU16_GYRO_ODR_3_2_KHZ 0x04
206 #define C6DOFIMU16_GYRO_ODR_1_6_KHZ 0x05
207 #define C6DOFIMU16_GYRO_ODR_800_HZ 0x06
208 #define C6DOFIMU16_GYRO_ODR_400_HZ 0x07
209 #define C6DOFIMU16_GYRO_ODR_200_HZ 0x08
210 #define C6DOFIMU16_GYRO_ODR_100_HZ 0x09
211 #define C6DOFIMU16_GYRO_ODR_50_HZ 0x0A
212 #define C6DOFIMU16_GYRO_ODR_25_HZ 0x0B
213 #define C6DOFIMU16_GYRO_ODR_12_5_HZ 0x0C
214 #define C6DOFIMU16_GYRO_ODR_6_25_HZ 0x0D
215 #define C6DOFIMU16_GYRO_ODR_3_125_HZ 0x0E
216 #define C6DOFIMU16_GYRO_ODR_1_5625_HZ 0x0F
217 
222 #define C6DOFIMU16_SOFTWARE_RESET 0x02
223 
228 #define C6DOFIMU16_DEVICE_ID 0xE5
229 
235 #define C6DOFIMU16_ACCEL_2G_CONV_MUL 16384u
236 #define C6DOFIMU16_ACCEL_4G_CONV_MUL 8192u
237 #define C6DOFIMU16_ACCEL_8G_CONV_MUL 4096u
238 #define C6DOFIMU16_ACCEL_16G_CONV_MUL 2048u
239 #define C6DOFIMU16_GYRO_2000DPS_CONV_MUL 16.4f
240 #define C6DOFIMU16_GYRO_1000DPS_CONV_MUL 32.8f
241 #define C6DOFIMU16_GYRO_500DPS_CONV_MUL 65.5f
242 #define C6DOFIMU16_GYRO_250DPS_CONV_MUL 131.0f
243 #define C6DOFIMU16_GYRO_125DPS_CONV_MUL 262.0f
244 #define C6DOFIMU16_GYRO_62_5DPS_CONV_MUL 524.3f
245 #define C6DOFIMU16_GYRO_31_25DPS_CONV_MUL 1048.6f
246 #define C6DOFIMU16_GYRO_15_625DPS_CONV_MUL 2097.2f
247 
253 #define C6DOFIMU16_DEVICE_ADDRESS_0 0x68
254 #define C6DOFIMU16_DEVICE_ADDRESS_1 0x69
255 
264 #define C6DOFIMU16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
265 #define C6DOFIMU16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
266  // c6dofimu16_set
268 
283 #define C6DOFIMU16_MAP_MIKROBUS( cfg, mikrobus ) \
284  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
285  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
286  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
287  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
288  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
289  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
290  cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
291  cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_INT )
292  // c6dofimu16_map // c6dofimu16
295 
300 typedef enum
301 {
306 
311 struct c6dofimu16_s;
312 typedef err_t ( *c6dofimu16_master_io_t )( struct c6dofimu16_s*, uint8_t, uint8_t*, uint8_t );
318 typedef struct c6dofimu16_s
319 {
320  digital_in_t int1;
321  digital_in_t int2;
323  i2c_master_t i2c;
324  spi_master_t spi;
326  uint8_t slave_address;
327  pin_name_t chip_select;
334 
339 typedef struct
340 {
341  pin_name_t scl;
342  pin_name_t sda;
343  pin_name_t miso;
344  pin_name_t mosi;
345  pin_name_t sck;
346  pin_name_t cs;
347  pin_name_t int1;
348  pin_name_t int2;
350  uint32_t i2c_speed;
351  uint8_t i2c_address;
353  uint32_t spi_speed;
354  spi_master_mode_t spi_mode;
355  spi_master_chip_select_polarity_t cs_polarity;
360 
365 typedef struct
366 {
367  float x_data;
368  float y_data;
369  float z_data;
370 
372 
377 typedef enum
378 {
380  C6DOFIMU16_ERROR = -1
381 
383 
400 
416 
431 
445 
460 err_t c6dofimu16_generic_write ( c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
461 
476 err_t c6dofimu16_generic_read ( c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
477 
487 
497 
510 err_t c6dofimu16_reg_write ( c6dofimu16_t *ctx, uint8_t reg, uint8_t data_in );
511 
525 err_t c6dofimu16_reg_read ( c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_out );
526 
538 
552 
566 
567 #ifdef __cplusplus
568 }
569 #endif
570 #endif // C6DOFIMU16_H
571  // c6dofimu16
573 
574 // ------------------------------------------------------------------------ END
c6dofimu16_return_value_t
c6dofimu16_return_value_t
6DOF IMU 16 Click return value data.
Definition: c6dofimu16.h:378
c6dofimu16_reg_write
err_t c6dofimu16_reg_write(c6dofimu16_t *ctx, uint8_t reg, uint8_t data_in)
6DOF IMU 16 data writing function.
c6dofimu16_drv_interface_sel
void c6dofimu16_drv_interface_sel(c6dofimu16_cfg_t *cfg, c6dofimu16_drv_t drv_sel)
6DOF IMU 16 driver interface setup function.
c6dofimu16_cfg_t::int1
pin_name_t int1
Definition: c6dofimu16.h:347
c6dofimu16_s::int2
digital_in_t int2
Definition: c6dofimu16.h:321
c6dofimu16_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu16.h:351
c6dofimu16_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu16.h:353
c6dofimu16_t
struct c6dofimu16_s c6dofimu16_t
6DOF IMU 16 Click context object.
c6dofimu16_axis_t
6DOF IMU 16 Click axes data structure.
Definition: c6dofimu16.h:366
c6dofimu16_s
6DOF IMU 16 Click context object.
Definition: c6dofimu16.h:319
c6dofimu16_sw_reset
err_t c6dofimu16_sw_reset(c6dofimu16_t *ctx)
6DOF IMU 16 software reset device function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
c6dofimu16_get_accel_data
err_t c6dofimu16_get_accel_data(c6dofimu16_t *ctx, c6dofimu16_axis_t *accel_data)
6DOF IMU 16 read accel function.
c6dofimu16_s::chip_select
pin_name_t chip_select
Definition: c6dofimu16.h:327
c6dofimu16_axis_t::y_data
float y_data
Definition: c6dofimu16.h:368
c6dofimu16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu16.h:354
c6dofimu16_master_io_t
err_t(* c6dofimu16_master_io_t)(struct c6dofimu16_s *, uint8_t, uint8_t *, uint8_t)
Definition: c6dofimu16.h:312
c6dofimu16_cfg_t
6DOF IMU 16 Click configuration object.
Definition: c6dofimu16.h:340
c6dofimu16_init
err_t c6dofimu16_init(c6dofimu16_t *ctx, c6dofimu16_cfg_t *cfg)
6DOF IMU 16 initialization function.
c6dofimu16_s::i2c
i2c_master_t i2c
Definition: c6dofimu16.h:323
c6dofimu16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu16.h:355
c6dofimu16_s::read_f
c6dofimu16_master_io_t read_f
Definition: c6dofimu16.h:331
c6dofimu16_cfg_t::cs
pin_name_t cs
Definition: c6dofimu16.h:346
c6dofimu16_generic_write
err_t c6dofimu16_generic_write(c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
6DOF IMU 16 data writing function.
c6dofimu16_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu16.h:344
C6DOFIMU16_ERROR
@ C6DOFIMU16_ERROR
Definition: c6dofimu16.h:380
c6dofimu16_cfg_setup
void c6dofimu16_cfg_setup(c6dofimu16_cfg_t *cfg)
6DOF IMU 16 configuration object setup function.
c6dofimu16_get_int1_pin
uint8_t c6dofimu16_get_int1_pin(c6dofimu16_t *ctx)
6DOF IMU 16 get int1 pin function.
C6DOFIMU16_DRV_SEL_SPI
@ C6DOFIMU16_DRV_SEL_SPI
Definition: c6dofimu16.h:302
c6dofimu16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu16.h:350
c6dofimu16_s::drv_sel
c6dofimu16_drv_t drv_sel
Definition: c6dofimu16.h:328
c6dofimu16_s::spi
spi_master_t spi
Definition: c6dofimu16.h:324
c6dofimu16_cfg_t::miso
pin_name_t miso
Definition: c6dofimu16.h:343
C6DOFIMU16_DRV_SEL_I2C
@ C6DOFIMU16_DRV_SEL_I2C
Definition: c6dofimu16.h:303
c6dofimu16_cfg_t::sda
pin_name_t sda
Definition: c6dofimu16.h:342
c6dofimu16_drv_t
c6dofimu16_drv_t
6DOF IMU 16 Click driver selector.
Definition: c6dofimu16.h:301
c6dofimu16_generic_read
err_t c6dofimu16_generic_read(c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
6DOF IMU 16 data reading function.
c6dofimu16_axis_t::x_data
float x_data
Definition: c6dofimu16.h:367
c6dofimu16_s::int1
digital_in_t int1
Definition: c6dofimu16.h:320
c6dofimu16_get_gyro_data
err_t c6dofimu16_get_gyro_data(c6dofimu16_t *ctx, c6dofimu16_axis_t *gyro_data)
6DOF IMU 16 read gyro function.
c6dofimu16_cfg_t::int2
pin_name_t int2
Definition: c6dofimu16.h:348
c6dofimu16_default_cfg
err_t c6dofimu16_default_cfg(c6dofimu16_t *ctx)
6DOF IMU 16 default configuration function.
c6dofimu16_axis_t::z_data
float z_data
Definition: c6dofimu16.h:369
C6DOFIMU16_OK
@ C6DOFIMU16_OK
Definition: c6dofimu16.h:379
c6dofimu16_cfg_t::scl
pin_name_t scl
Definition: c6dofimu16.h:341
c6dofimu16_cfg_t::drv_sel
c6dofimu16_drv_t drv_sel
Definition: c6dofimu16.h:357
c6dofimu16_s::slave_address
uint8_t slave_address
Definition: c6dofimu16.h:326
c6dofimu16_cfg_t::sck
pin_name_t sck
Definition: c6dofimu16.h:345
c6dofimu16_reg_read
err_t c6dofimu16_reg_read(c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_out)
6DOF IMU 16 register data reading function.
c6dofimu16_get_int2_pin
uint8_t c6dofimu16_get_int2_pin(c6dofimu16_t *ctx)
6DOF IMU 16 get int2 pin function.
c6dofimu16_s::write_f
c6dofimu16_master_io_t write_f
Definition: c6dofimu16.h:330