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 
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 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define C6DOFIMU16_REG_ACCEL_DATA_X1_UI 0x00
72 #define C6DOFIMU16_REG_ACCEL_DATA_X0_UI 0x01
73 #define C6DOFIMU16_REG_ACCEL_DATA_Y1_UI 0x02
74 #define C6DOFIMU16_REG_ACCEL_DATA_Y0_UI 0x03
75 #define C6DOFIMU16_REG_ACCEL_DATA_Z1_UI 0x04
76 #define C6DOFIMU16_REG_ACCEL_DATA_Z0_UI 0x05
77 #define C6DOFIMU16_REG_GYRO_DATA_X1_UI 0x06
78 #define C6DOFIMU16_REG_GYRO_DATA_X0_UI 0x07
79 #define C6DOFIMU16_REG_GYRO_DATA_Y1_UI 0x08
80 #define C6DOFIMU16_REG_GYRO_DATA_Y0_UI 0x09
81 #define C6DOFIMU16_REG_GYRO_DATA_Z1_UI 0x0A
82 #define C6DOFIMU16_REG_GYRO_DATA_Z0_UI 0x0B
83 #define C6DOFIMU16_REG_TEMP_DATA1_UI 0x0C
84 #define C6DOFIMU16_REG_TEMP_DATA0_UI 0x0D
85 #define C6DOFIMU16_REG_TMST_FSYNCH 0x0E
86 #define C6DOFIMU16_REG_TMST_FSYNCL 0x0F
87 #define C6DOFIMU16_REG_PWR_MGMNT0 0x10
88 #define C6DOFIMU16_REG_FIFO_COUNT_0 0x12
89 #define C6DOFIMU16_REG_FIFO_COUNT_1 0x13
90 #define C6DOFIMU16_REG_FIFO_DATA 0x14
91 #define C6DOFIMU16_REG_INT1_CONFIG0 0x16
92 #define C6DOFIMU16_REG_INT1_CONFIG1 0x17
93 #define C6DOFIMU16_REG_INT1_CONFIG2 0x18
94 #define C6DOFIMU16_REG_INT1_STATUS0 0x19
95 #define C6DOFIMU16_REG_ACCEL_CONFIG0 0x1B
96 #define C6DOFIMU16_REG_GYRO_CONFIG0 0x1C
97 #define C6DOFIMU16_REG_FIFO_CONFIG0 0x1D
98 #define C6DOFIMU16_REG_FIFO_CONFIG1_0 0x1E
99 #define C6DOFIMU16_REG_FIFO_CONFIG1_1 0x1F
100 #define C6DOFIMU16_REG_FIFO_CONFIG2 0x20
101 #define C6DOFIMU16_REG_FIFO_CONFIG3 0x21
102 #define C6DOFIMU16_REG_FIFO_CONFIG4 0x22
103 #define C6DOFIMU16_REG_DMP_EXT_SEN_ODR_CFG 0x27
104 #define C6DOFIMU16_REG_EDMP_APEX_EN0 0x29
105 #define C6DOFIMU16_REG_EDMP_APEX_EN1 0x2A
106 #define C6DOFIMU16_REG_APEX_BUFFER_MGMT 0x2B
107 #define C6DOFIMU16_REG_INTF_CONFIG0 0x2C
108 #define C6DOFIMU16_REG_INTF_CONFIG1_OVRD 0x2D
109 #define C6DOFIMU16_REG_IOC_PAD_SCENARIO 0x2F
110 #define C6DOFIMU16_REG_IOC_PAD_SCENARIO_AUX_OVRD 0x30
111 #define C6DOFIMU16_REG_IOC_PAD_SCENARIO_OVRD 0x31
112 #define C6DOFIMU16_REG_DRIVE_CONFIG0 0x32
113 #define C6DOFIMU16_REG_DRIVE_CONFIG1 0x33
114 #define C6DOFIMU16_REG_DRIVE_CONFIG2 0x34
115 #define C6DOFIMU16_REG_INT_APEX_CONFIG1 0x3A
116 #define C6DOFIMU16_REG_INT_APEX_STATUS0 0x3B
117 #define C6DOFIMU16_REG_INT_APEX_STATUS1 0x3C
118 #define C6DOFIMU16_REG_INT2_CONFIG0 0x56
119 #define C6DOFIMU16_REG_INT2_CONFIG1 0x57
120 #define C6DOFIMU16_REG_INT2_CONFIG2 0x58
121 #define C6DOFIMU16_REG_INT2_STATUS0 0x59
122 #define C6DOFIMU16_REG_WHO_AM_I 0x72
123 #define C6DOFIMU16_REG_REG_HOST_MSG 0x73
124 #define C6DOFIMU16_REG_IREG_ADDR_15_8 0x7C
125 #define C6DOFIMU16_REG_IREG_ADDR_7_0 0x7D
126 #define C6DOFIMU16_REG_IREG_DATA 0x7E
127 #define C6DOFIMU16_REG_REG_MISC2 0x7F
128  // c6dofimu16_reg
130 
145 #define C6DOFIMU16_GYRO_MODE_OFF 0x00
146 #define C6DOFIMU16_GYRO_MODE_STANDBY 0x04
147 #define C6DOFIMU16_GYRO_MODE_LOW_POWER 0x08
148 #define C6DOFIMU16_GYRO_MODE_LOW_NOISE 0x0C
149 #define C6DOFIMU16_ACCEL_MODE_OFF 0x00
150 #define C6DOFIMU16_ACCEL_MODE_STANDBY 0x01
151 #define C6DOFIMU16_ACCEL_MODE_LOW_POWER 0x02
152 #define C6DOFIMU16_ACCEL_MODE_LOW_NOISE 0x03
153 
158 #define C6DOFIMU16_GYRO_UI_FS_SEL_MASK 0xF0
159 #define C6DOFIMU16_GYRO_UI_FS_SEL_2000DPS 0x10
160 #define C6DOFIMU16_GYRO_UI_FS_SEL_1000DPS 0x20
161 #define C6DOFIMU16_GYRO_UI_FS_SEL_500DPS 0x30
162 #define C6DOFIMU16_GYRO_UI_FS_SEL_250DPS 0x40
163 #define C6DOFIMU16_GYRO_UI_FS_SEL_125DPS 0x50
164 #define C6DOFIMU16_GYRO_UI_FS_SEL_62_5DPS 0x60
165 #define C6DOFIMU16_GYRO_UI_FS_SEL_31_25DPS 0x70
166 #define C6DOFIMU16_GYRO_UI_FS_SEL_15_625DPS 0x80
167 
172 #define C6DOFIMU16_ACCEL_UI_FS_SEL_MASK 0x70
173 #define C6DOFIMU16_ACCEL_UI_FS_SEL_16g 0x10
174 #define C6DOFIMU16_ACCEL_UI_FS_SEL_8g 0x20
175 #define C6DOFIMU16_ACCEL_UI_FS_SEL_4g 0x30
176 #define C6DOFIMU16_ACCEL_UI_FS_SEL_2g 0x40
177 
182 #define C6DOFIMU16_ACCEL_ODR_6_4_KHZ 0x03
183 #define C6DOFIMU16_ACCEL_ODR_3_2_KHZ 0x04
184 #define C6DOFIMU16_ACCEL_ODR_1_6_KHZ 0x05
185 #define C6DOFIMU16_ACCEL_ODR_800_HZ 0x06
186 #define C6DOFIMU16_ACCEL_ODR_400_HZ 0x07
187 #define C6DOFIMU16_ACCEL_ODR_200_HZ 0x08
188 #define C6DOFIMU16_ACCEL_ODR_100_HZ 0x09
189 #define C6DOFIMU16_ACCEL_ODR_50_HZ 0x0A
190 #define C6DOFIMU16_ACCEL_ODR_25_HZ 0x0B
191 #define C6DOFIMU16_ACCEL_ODR_12_5_HZ 0x0C
192 #define C6DOFIMU16_ACCEL_ODR_6_25_HZ 0x0D
193 #define C6DOFIMU16_ACCEL_ODR_3_125_HZ 0x0E
194 #define C6DOFIMU16_ACCEL_ODR_1_5625_HZ 0x0F
195 
200 #define C6DOFIMU16_GYRO_ODR_6_4_KHZ 0x03
201 #define C6DOFIMU16_GYRO_ODR_3_2_KHZ 0x04
202 #define C6DOFIMU16_GYRO_ODR_1_6_KHZ 0x05
203 #define C6DOFIMU16_GYRO_ODR_800_HZ 0x06
204 #define C6DOFIMU16_GYRO_ODR_400_HZ 0x07
205 #define C6DOFIMU16_GYRO_ODR_200_HZ 0x08
206 #define C6DOFIMU16_GYRO_ODR_100_HZ 0x09
207 #define C6DOFIMU16_GYRO_ODR_50_HZ 0x0A
208 #define C6DOFIMU16_GYRO_ODR_25_HZ 0x0B
209 #define C6DOFIMU16_GYRO_ODR_12_5_HZ 0x0C
210 #define C6DOFIMU16_GYRO_ODR_6_25_HZ 0x0D
211 #define C6DOFIMU16_GYRO_ODR_3_125_HZ 0x0E
212 #define C6DOFIMU16_GYRO_ODR_1_5625_HZ 0x0F
213 
218 #define C6DOFIMU16_SOFTWARE_RESET 0x02
219 
224 #define C6DOFIMU16_DEVICE_ID 0xE5
225 
231 #define C6DOFIMU16_ACCEL_2G_CONV_MUL 16384u
232 #define C6DOFIMU16_ACCEL_4G_CONV_MUL 8192u
233 #define C6DOFIMU16_ACCEL_8G_CONV_MUL 4096u
234 #define C6DOFIMU16_ACCEL_16G_CONV_MUL 2048u
235 #define C6DOFIMU16_GYRO_2000DPS_CONV_MUL 16.4f
236 #define C6DOFIMU16_GYRO_1000DPS_CONV_MUL 32.8f
237 #define C6DOFIMU16_GYRO_500DPS_CONV_MUL 65.5f
238 #define C6DOFIMU16_GYRO_250DPS_CONV_MUL 131.0f
239 #define C6DOFIMU16_GYRO_125DPS_CONV_MUL 262.0f
240 #define C6DOFIMU16_GYRO_62_5DPS_CONV_MUL 524.3f
241 #define C6DOFIMU16_GYRO_31_25DPS_CONV_MUL 1048.6f
242 #define C6DOFIMU16_GYRO_15_625DPS_CONV_MUL 2097.2f
243 
249 #define C6DOFIMU16_DEVICE_ADDRESS_0 0x68
250 #define C6DOFIMU16_DEVICE_ADDRESS_1 0x69
251 
260 #define C6DOFIMU16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
261 #define C6DOFIMU16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
262  // c6dofimu16_set
264 
279 #define C6DOFIMU16_MAP_MIKROBUS( cfg, mikrobus ) \
280  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
281  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
282  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
283  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
284  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
285  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
286  cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
287  cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_INT )
288  // c6dofimu16_map // c6dofimu16
291 
296 typedef enum
297 {
302 
307 struct c6dofimu16_s;
308 typedef err_t ( *c6dofimu16_master_io_t )( struct c6dofimu16_s*, uint8_t, uint8_t*, uint8_t );
314 typedef struct c6dofimu16_s
315 {
316  digital_in_t int1;
317  digital_in_t int2;
319  i2c_master_t i2c;
320  spi_master_t spi;
322  uint8_t slave_address;
323  pin_name_t chip_select;
330 
335 typedef struct
336 {
337  pin_name_t scl;
338  pin_name_t sda;
339  pin_name_t miso;
340  pin_name_t mosi;
341  pin_name_t sck;
342  pin_name_t cs;
343  pin_name_t int1;
344  pin_name_t int2;
346  uint32_t i2c_speed;
347  uint8_t i2c_address;
349  uint32_t spi_speed;
350  spi_master_mode_t spi_mode;
351  spi_master_chip_select_polarity_t cs_polarity;
356 
361 typedef struct
362 {
363  float x_data;
364  float y_data;
365  float z_data;
366 
368 
373 typedef enum
374 {
376  C6DOFIMU16_ERROR = -1
377 
379 
396 
412 
427 
441 
456 err_t c6dofimu16_generic_write ( c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
457 
472 err_t c6dofimu16_generic_read ( c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
473 
483 
493 
506 err_t c6dofimu16_reg_write ( c6dofimu16_t *ctx, uint8_t reg, uint8_t data_in );
507 
521 err_t c6dofimu16_reg_read ( c6dofimu16_t *ctx, uint8_t reg, uint8_t *data_out );
522 
534 
548 
562 
563 #ifdef __cplusplus
564 }
565 #endif
566 #endif // C6DOFIMU16_H
567  // c6dofimu16
569 
570 // ------------------------------------------------------------------------ END
c6dofimu16_return_value_t
c6dofimu16_return_value_t
6DOF IMU 16 Click return value data.
Definition: c6dofimu16.h:374
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:343
c6dofimu16_s::int2
digital_in_t int2
Definition: c6dofimu16.h:317
c6dofimu16_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu16.h:347
c6dofimu16_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu16.h:349
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:362
c6dofimu16_s
6DOF IMU 16 Click context object.
Definition: c6dofimu16.h:315
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:323
c6dofimu16_axis_t::y_data
float y_data
Definition: c6dofimu16.h:364
c6dofimu16_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu16.h:350
c6dofimu16_master_io_t
err_t(* c6dofimu16_master_io_t)(struct c6dofimu16_s *, uint8_t, uint8_t *, uint8_t)
Definition: c6dofimu16.h:308
c6dofimu16_cfg_t
6DOF IMU 16 Click configuration object.
Definition: c6dofimu16.h:336
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:319
c6dofimu16_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu16.h:351
c6dofimu16_s::read_f
c6dofimu16_master_io_t read_f
Definition: c6dofimu16.h:327
c6dofimu16_cfg_t::cs
pin_name_t cs
Definition: c6dofimu16.h:342
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:340
C6DOFIMU16_ERROR
@ C6DOFIMU16_ERROR
Definition: c6dofimu16.h:376
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:298
c6dofimu16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu16.h:346
c6dofimu16_s::drv_sel
c6dofimu16_drv_t drv_sel
Definition: c6dofimu16.h:324
c6dofimu16_s::spi
spi_master_t spi
Definition: c6dofimu16.h:320
c6dofimu16_cfg_t::miso
pin_name_t miso
Definition: c6dofimu16.h:339
C6DOFIMU16_DRV_SEL_I2C
@ C6DOFIMU16_DRV_SEL_I2C
Definition: c6dofimu16.h:299
c6dofimu16_cfg_t::sda
pin_name_t sda
Definition: c6dofimu16.h:338
c6dofimu16_drv_t
c6dofimu16_drv_t
6DOF IMU 16 Click driver selector.
Definition: c6dofimu16.h:297
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:363
c6dofimu16_s::int1
digital_in_t int1
Definition: c6dofimu16.h:316
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:344
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:365
C6DOFIMU16_OK
@ C6DOFIMU16_OK
Definition: c6dofimu16.h:375
c6dofimu16_cfg_t::scl
pin_name_t scl
Definition: c6dofimu16.h:337
c6dofimu16_cfg_t::drv_sel
c6dofimu16_drv_t drv_sel
Definition: c6dofimu16.h:353
c6dofimu16_s::slave_address
uint8_t slave_address
Definition: c6dofimu16.h:322
c6dofimu16_cfg_t::sck
pin_name_t sck
Definition: c6dofimu16.h:341
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:326