c6dofimu9  2.0.0.0
c6dofimu9.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef C6DOFIMU9_H
35 #define C6DOFIMU9_H
36 
41 #ifdef PREINIT_SUPPORTED
42 #include "preinit.h"
43 #endif
44 
45 #ifdef MikroCCoreVersion
46  #if MikroCCoreVersion >= 1
47  #include "delays.h"
48  #endif
49 #endif
50 
51 #include "drv_digital_out.h"
52 #include "drv_digital_in.h"
53 #include "drv_i2c_master.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define C6DOFIMU9_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
72  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
73  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
74  cfg.syn = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
75  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
76 
82 #define C6DOFIMU9_MASTER_I2C 0
83 #define C6DOFIMU9_MASTER_SPI 1
84 
90 #define C6DOFIMU9_RETVAL uint8_t
91 
92 
93 #define C6DOFIMU9_OK 0x00
94 #define C6DOFIMU9_INIT_ERROR 0xFF
95 
101 #define C6DOFIMU9_I2C_SLAVE_ADDRESS_0 0x68
102 #define C6DOFIMU9_I2C_SLAVE_ADDRESS_1 0x69
103 
109 #define C6DOFIMU9_SPI_WRITE_CMD 0x00
110 #define C6DOFIMU9_SPI_READ_CMD 0x80
111 
117 #define C6DOFIMU9_REG_SELF_TEST_X_GYRO 0x00
118 #define C6DOFIMU9_REG_SELF_TEST_Y_GYRO 0x01
119 #define C6DOFIMU9_REG_SELF_TEST_Z_GYRO 0x02
120 #define C6DOFIMU9_REG_SELF_TEST_X_ACCEL 0x0D
121 #define C6DOFIMU9_REG_SELF_TEST_Y_ACCEL 0x0E
122 #define C6DOFIMU9_REG_SELF_TEST_Z_ACCEL 0x0F
123 #define C6DOFIMU9_REG_XG_OFFS_USRH 0x13
124 #define C6DOFIMU9_REG_XG_OFFS_USRL 0x14
125 #define C6DOFIMU9_REG_YG_OFFS_USRH 0x15
126 #define C6DOFIMU9_REG_YG_OFFS_USRL 0x16
127 #define C6DOFIMU9_REG_ZG_OFFS_USRH 0x17
128 #define C6DOFIMU9_REG_ZG_OFFS_USRL 0x18
129 #define C6DOFIMU9_REG_SMPLRT_DIV 0x19
130 #define C6DOFIMU9_REG_CONFIG 0x1A
131 #define C6DOFIMU9_REG_GYRO_CONFIG 0x1B
132 #define C6DOFIMU9_REG_ACCEL_CONFIG 0x1C
133 #define C6DOFIMU9_REG_ACCEL_CONFIG_2 0x1D
134 #define C6DOFIMU9_REG_LP_MODE_CFG 0x1E
135 #define C6DOFIMU9_REG_ACCEL_WOM_THR 0x1F
136 #define C6DOFIMU9_REG_FIFO_EN 0x23
137 #define C6DOFIMU9_REG_FSYNC_INT 0x36
138 #define C6DOFIMU9_REG_INT_PIN_CFG 0x37
139 #define C6DOFIMU9_REG_INT_ENABLE 0x38
140 #define C6DOFIMU9_REG_INT_STATUS 0x3A
141 #define C6DOFIMU9_REG_ACCEL_XOUT_H 0x3B
142 #define C6DOFIMU9_REG_ACCEL_XOUT_L 0x3C
143 #define C6DOFIMU9_REG_ACCEL_YOUT_H 0x3D
144 #define C6DOFIMU9_REG_ACCEL_YOUT_L 0x3E
145 #define C6DOFIMU9_REG_ACCEL_ZOUT_H 0x3F
146 #define C6DOFIMU9_REG_ACCEL_ZOUT_L 0x40
147 #define C6DOFIMU9_REG_TEMP_OUT_H 0x41
148 #define C6DOFIMU9_REG_TEMP_OUT_L 0x42
149 #define C6DOFIMU9_REG_GYRO_XOUT_H 0x43
150 #define C6DOFIMU9_REG_GYRO_XOUT_L 0x44
151 #define C6DOFIMU9_REG_GYRO_YOUT_H 0x45
152 #define C6DOFIMU9_REG_GYRO_YOUT_L 0x46
153 #define C6DOFIMU9_REG_GYRO_ZOUT_H 0x47
154 #define C6DOFIMU9_REG_GYRO_ZOUT_L 0x48
155 #define C6DOFIMU9_REG_SIGNAL_PATH_RESET 0x68
156 #define C6DOFIMU9_REG_ACCEL_INTEL_CTRL 0x69
157 #define C6DOFIMU9_REG_USER_CTRL 0x6A
158 #define C6DOFIMU9_REG_PWR_MGMT_1 0x6B
159 #define C6DOFIMU9_REG_PWR_MGMT_2 0x6C
160 #define C6DOFIMU9_REG_FIFO_COUNTH 0x72
161 #define C6DOFIMU9_REG_FIFO_COUNTL 0x73
162 #define C6DOFIMU9_REG_FIFO_R_W 0x74
163 #define C6DOFIMU9_REG_WHO_AM_I 0x75
164 #define C6DOFIMU9_REG_XA_OFFSET_H 0x77
165 #define C6DOFIMU9_REG_XA_OFFSET_L 0x78
166 #define C6DOFIMU9_REG_YA_OFFSET_H 0x7A
167 #define C6DOFIMU9_REG_YA_OFFSET_L 0x7B
168 #define C6DOFIMU9_REG_ZA_OFFSET_H 0x7D
169 #define C6DOFIMU9_REG_ZA_OFFSET_L 0x7E
170 
176 #define C6DOFIMU9_BM_FIFO_MODE_FULL_REPLACE_OLD_DATA 0x00
177 #define C6DOFIMU9_BM_FIFO_MODE_FULL_NO_WRITE_DATA 0x40
178 #define C6DOFIMU9_BM_DISABLE_FSYNC_PIN 0x00
179 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_TEMP_OUT_L 0x08
180 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_GYRO_XOUT_L 0x10
181 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_GYRO_YOUT_L 0x18
182 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_GYRO_ZOUT_L 0x20
183 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_ACCEL_XOUT_L 0x28
184 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_ACCEL_YOUT_L 0x30
185 #define C6DOFIMU9_BM_ENABLE_FSYNC_PIN_ACCEL_ZOUT_L 0x38
186 
192 /* Gyro configuration */
193 #define C6DOFIMU9_GYRO_FULL_SCALE_250dps 0x00FA
194 #define C6DOFIMU9_GYRO_FULL_SCALE_500dps 0x01F4
195 #define C6DOFIMU9_GYRO_FULL_SCALE_1000dps 0x03E8
196 #define C6DOFIMU9_GYRO_FULL_SCALE_2000dps 0x07D0
197 
203 #define C6DOFIMU9_ACCEL_FULL_SCALE_2g 0x02
204 #define C6DOFIMU9_ACCEL_FULL_SCALE_4g 0x04
205 #define C6DOFIMU9_ACCEL_FULL_SCALE_8g 0x08
206 #define C6DOFIMU9_ACCEL_FULL_SCALE_16g 0x10
207 #define C6DOFIMU9_ACCEL_AVERAGE_4_SAMPLES 0x04
208 #define C6DOFIMU9_ACCEL_AVERAGE_8_SAMPLES 0x08
209 #define C6DOFIMU9_ACCEL_AVERAGE_16_SAMPLES 0x10
210 #define C6DOFIMU9_ACCEL_AVERAGE_32_SAMPLES 0x20
211 
217 #define C6DOFIMU9_GYRO_AVERAGE_1x 0x01
218 #define C6DOFIMU9_GYRO_AVERAGE_2x 0x02
219 #define C6DOFIMU9_GYRO_AVERAGE_4x 0x04
220 #define C6DOFIMU9_GYRO_AVERAGE_8x 0x08
221 #define C6DOFIMU9_GYRO_AVERAGE_16x 0x10
222 #define C6DOFIMU9_GYRO_AVERAGE_32x 0x20
223 #define C6DOFIMU9_GYRO_AVERAGE_64x 0x40
224 #define C6DOFIMU9_GYRO_AVERAGE_128x 0x80
225 
231 #define C6DOFIMU9_BM_DISABLE_TEMP_FIFO 0x00
232 #define C6DOFIMU9_BM_ENABLE_TEMP_FIFO 0x80
233 #define C6DOFIMU9_BM_DISABLE_XGYRO_FIFO 0x00
234 #define C6DOFIMU9_BM_ENABLE_XGYRO_FIFO 0x40
235 #define C6DOFIMU9_BM_DISABLE_YGYRO_FIFO 0x00
236 #define C6DOFIMU9_BM_ENABLE_YGYRO_FIFO 0x20
237 #define C6DOFIMU9_BM_DISABLE_ZGYRO_FIFO 0x00
238 #define C6DOFIMU9_BM_ENABLE_ZGYRO_FIFO 0x10
239 #define C6DOFIMU9_BM_DISABLE_ACCEL_FIFO 0x00
240 #define C6DOFIMU9_BM_ENABLE_ACCEL_FIFO 0x08
241 
247 #define C6DOFIMU9_DEVICE_ID 0xA9
248  // End group macro
251 // --------------------------------------------------------------- PUBLIC TYPES
260 typedef uint8_t c6dofimu9_select_t;
261 
265 typedef void ( *c6dofimu9_master_io_t )( struct c6dofimu9_s*, uint8_t, uint8_t*, uint8_t );
266 
270 typedef struct c6dofimu9_s
271 {
272  // Output pins
273 
274  digital_out_t syn;
275  digital_out_t cs;
276 
277  // Input pins
278 
279  digital_in_t int_pin;
280 
281  // Modules
282 
283  i2c_master_t i2c;
284  spi_master_t spi;
285 
286  // ctx variable
287 
288  uint8_t slave_address;
289  pin_name_t chip_select;
293 
295 
299 typedef struct
300 {
301  // Communication gpio pins
302 
303  pin_name_t scl;
304  pin_name_t sda;
305  pin_name_t miso;
306  pin_name_t mosi;
307  pin_name_t sck;
308  pin_name_t cs;
309 
310  // Additional gpio pins
311 
312  pin_name_t syn;
313  pin_name_t int_pin;
314 
315  // static variable
316 
317  uint32_t i2c_speed;
318  uint8_t i2c_address;
319  uint32_t spi_speed;
320  uint8_t spi_mode;
321  spi_master_chip_select_polarity_t cs_polarity;
322 
324 
326  // End types group
328 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
334 #ifdef __cplusplus
335 extern "C"{
336 #endif
337 
347 
356 
365 
376 void c6dofimu9_generic_write ( c6dofimu9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
377 
388 void c6dofimu9_generic_read ( c6dofimu9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
389 
402 
430 void c6dofimu9_set_config ( c6dofimu9_t *ctx, uint8_t config_data );
431 
455 void c6dofimu9_set_gyro_config ( c6dofimu9_t *ctx, uint8_t gyro_config_data );
456 
473 void c6dofimu9_set_gyro_measurement_range ( c6dofimu9_t *ctx, uint16_t gyro_full_scale_range );
474 
512 void c6dofimu9_set_accel_config ( c6dofimu9_t *ctx, uint16_t accel_config_data );
513 
530 void c6dofimu9_set_accel_measurement_range ( c6dofimu9_t *ctx, uint8_t accel_full_scale_range );
531 
547 void c6dofimu9_set_accel_avg_filter_mode ( c6dofimu9_t *ctx, uint8_t accel_avg_samples );
548 
574 void c6dofimu9_set_gyro_config_lp_mode ( c6dofimu9_t *ctx, uint8_t gyro_averages );
575 
585 
613 void c6dofimu9_enable_fifo ( c6dofimu9_t *ctx, uint8_t en_fifo_data );
614 
624 
634 
644 
665 
675 
685 
695 
705 
715 
725 
736 
747 int16_t c6dofimu9_get_axis ( c6dofimu9_t *ctx, uint8_t addr_reg_msb, uint8_t addr_reg_lsb );
748 
761 void c6dofimu9_get_accel_data ( c6dofimu9_t *ctx, int16_t *p_accel_x, int16_t *p_accel_y, int16_t *p_accel_z );
762 
775 void c6dofimu9_get_gyro_data ( c6dofimu9_t *ctx, int16_t *p_gyro_x, int16_t *p_gyro_y, int16_t *p_gyro_z );
776 
777 
778 #ifdef __cplusplus
779 }
780 #endif
781 #endif // _C6DOFIMU9_H_
782  // End public_function group
785 
786 // ------------------------------------------------------------------------- END
c6dofimu9_enable_accel_wake_on_motion
void c6dofimu9_enable_accel_wake_on_motion(c6dofimu9_t *ctx)
Enable the Wake-on-Motion detection function.
c6dofimu9_get_device_id
uint8_t c6dofimu9_get_device_id(c6dofimu9_t *ctx)
Get device ID function.
c6dofimu9_cfg_t::sel
c6dofimu9_select_t sel
Definition: c6dofimu9.h:323
c6dofimu9_reset_accel_signal
void c6dofimu9_reset_accel_signal(c6dofimu9_t *ctx)
Reset Accel signal path function.
c6dofimu9_s::write_f
c6dofimu9_master_io_t write_f
Definition: c6dofimu9.h:290
c6dofimu9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu9.h:317
c6dofimu9_select_t
uint8_t c6dofimu9_select_t
Communication type.
Definition: c6dofimu9.h:260
c6dofimu9_check_interrupt
uint8_t c6dofimu9_check_interrupt(c6dofimu9_t *ctx)
Check interrupt state function.
c6dofimu9_enable_gyro_interrupt
void c6dofimu9_enable_gyro_interrupt(c6dofimu9_t *ctx)
Enable Gyro interrupt function.
c6dofimu9_get_interrupt_status
uint8_t c6dofimu9_get_interrupt_status(c6dofimu9_t *ctx)
Get interrupt status function.
c6dofimu9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu9.h:321
c6dofimu9_default_cfg
void c6dofimu9_default_cfg(c6dofimu9_t *ctx)
Click Default Configuration function.
c6dofimu9_generic_read
void c6dofimu9_generic_read(c6dofimu9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c6dofimu9_set_accel_avg_filter_mode
void c6dofimu9_set_accel_avg_filter_mode(c6dofimu9_t *ctx, uint8_t accel_avg_samples)
Set Accel averaging filter settings for Low Power mode function.
c6dofimu9_set_gyro_config
void c6dofimu9_set_gyro_config(c6dofimu9_t *ctx, uint8_t gyro_config_data)
Set Gyro configuration function.
c6dofimu9_s::syn
digital_out_t syn
Definition: c6dofimu9.h:274
c6dofimu9_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu9.h:306
c6dofimu9_enable_fifo
void c6dofimu9_enable_fifo(c6dofimu9_t *ctx, uint8_t en_fifo_data)
Enable FIFO configuration function.
c6dofimu9_set_sleep_mode
void c6dofimu9_set_sleep_mode(c6dofimu9_t *ctx)
Set the device to sleep mode function.
c6dofimu9_cfg_t
Click configuration structure definition.
Definition: c6dofimu9.h:300
c6dofimu9_get_accel_data
void c6dofimu9_get_accel_data(c6dofimu9_t *ctx, int16_t *p_accel_x, int16_t *p_accel_y, int16_t *p_accel_z)
Read Accel X-axis, Y-axis and Z-axis axis function.
c6dofimu9_s::master_sel
c6dofimu9_select_t master_sel
Definition: c6dofimu9.h:292
c6dofimu9_cfg_t::spi_mode
uint8_t spi_mode
Definition: c6dofimu9.h:320
c6dofimu9_s::read_f
c6dofimu9_master_io_t read_f
Definition: c6dofimu9.h:291
c6dofimu9_enable_data_ready_interrupt
void c6dofimu9_enable_data_ready_interrupt(c6dofimu9_t *ctx)
Enable data ready interrupt function.
c6dofimu9_reset_gyro_signal
void c6dofimu9_reset_gyro_signal(c6dofimu9_t *ctx)
Reset Gyro signal path function.
c6dofimu9_enable_accel_interrupt
void c6dofimu9_enable_accel_interrupt(c6dofimu9_t *ctx)
Enable Accel interrupt function.
c6dofimu9_cfg_setup
void c6dofimu9_cfg_setup(c6dofimu9_cfg_t *cfg)
Config Object Initialization function.
c6dofimu9_cfg_t::miso
pin_name_t miso
Definition: c6dofimu9.h:305
c6dofimu9_t
struct c6dofimu9_s c6dofimu9_t
Click ctx object definition.
c6dofimu9_s::int_pin
digital_in_t int_pin
Definition: c6dofimu9.h:279
c6dofimu9_cfg_t::cs
pin_name_t cs
Definition: c6dofimu9.h:308
c6dofimu9_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu9.h:319
c6dofimu9_init
C6DOFIMU9_RETVAL c6dofimu9_init(c6dofimu9_t *ctx, c6dofimu9_cfg_t *cfg)
Initialization function.
c6dofimu9_get_accel_wake_on_motion_trsh
uint8_t c6dofimu9_get_accel_wake_on_motion_trsh(c6dofimu9_t *ctx)
Get Accel wake-on motion threshold function.
c6dofimu9_cfg_t::sda
pin_name_t sda
Definition: c6dofimu9.h:304
c6dofimu9_set_standby_mode
void c6dofimu9_set_standby_mode(c6dofimu9_t *ctx)
Set the device to standby mode function.
c6dofimu9_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu9.h:318
c6dofimu9_set_config
void c6dofimu9_set_config(c6dofimu9_t *ctx, uint8_t config_data)
Set configuration function.
c6dofimu9_get_axis
int16_t c6dofimu9_get_axis(c6dofimu9_t *ctx, uint8_t addr_reg_msb, uint8_t addr_reg_lsb)
Get axis data function.
c6dofimu9_cfg_t::scl
pin_name_t scl
Definition: c6dofimu9.h:303
c6dofimu9_generic_write
void c6dofimu9_generic_write(c6dofimu9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c6dofimu9_master_io_t
void(* c6dofimu9_master_io_t)(struct c6dofimu9_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: c6dofimu9.h:265
c6dofimu9_cfg_t::sck
pin_name_t sck
Definition: c6dofimu9.h:307
c6dofimu9_set_accel_measurement_range
void c6dofimu9_set_accel_measurement_range(c6dofimu9_t *ctx, uint8_t accel_full_scale_range)
Set Accel measurement range configuration function.
c6dofimu9_s::spi
spi_master_t spi
Definition: c6dofimu9.h:284
c6dofimu9_cfg_t::int_pin
pin_name_t int_pin
Definition: c6dofimu9.h:313
c6dofimu9_cfg_t::syn
pin_name_t syn
Definition: c6dofimu9.h:312
c6dofimu9_set_gyro_measurement_range
void c6dofimu9_set_gyro_measurement_range(c6dofimu9_t *ctx, uint16_t gyro_full_scale_range)
Set Gyro measurement range configuration function.
c6dofimu9_s::chip_select
pin_name_t chip_select
Definition: c6dofimu9.h:289
c6dofimu9_set_accel_config
void c6dofimu9_set_accel_config(c6dofimu9_t *ctx, uint16_t accel_config_data)
Set Accel configuration function.
c6dofimu9_get_gyro_data
void c6dofimu9_get_gyro_data(c6dofimu9_t *ctx, int16_t *p_gyro_x, int16_t *p_gyro_y, int16_t *p_gyro_z)
Read Gyro X-axis, Y-axis and Z-axis axis function.
c6dofimu9_set_gyro_config_lp_mode
void c6dofimu9_set_gyro_config_lp_mode(c6dofimu9_t *ctx, uint8_t gyro_averages)
Generic read function.
c6dofimu9_reset_default
void c6dofimu9_reset_default(c6dofimu9_t *ctx)
Reset the internal registers and restores the default settings function.
C6DOFIMU9_RETVAL
#define C6DOFIMU9_RETVAL
Definition: c6dofimu9.h:90
c6dofimu9_s::i2c
i2c_master_t i2c
Definition: c6dofimu9.h:283
c6dofimu9_s::slave_address
uint8_t slave_address
Definition: c6dofimu9.h:288
c6dofimu9_s
Click ctx object definition.
Definition: c6dofimu9.h:271
c6dofimu9_s::cs
digital_out_t cs
Definition: c6dofimu9.h:275