| ICM45686 eMD driver Documentation of the eMD Driver API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

inv_imu_driver.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) [2020] by InvenSense, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 */
17
25 #ifndef _INV_IMU_DRIVER_H_
26 #define _INV_IMU_DRIVER_H_
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include "imu/inv_imu_defs.h"
33 #include "imu/inv_imu_transport.h"
34
35 #include <stdint.h>
36 #include <string.h>
37
38 /*
39 * Driver's structures definitions
40 */
41
43 typedef struct {
45 inv_imu_transport_t transport;
46
48 uint8_t fifo_frame_size;
49
54 uint8_t endianness_data;
55
60 uint64_t adv_var[6];
61
62 } inv_imu_device_t;
63
65 typedef union {
66 fifo_header_t header;
67 struct {
68 fifo_header_t header;
69 int16_t sensor_data[3];
70 int8_t temp_data;
71 } byte_8;
72 struct {
73 fifo_header_t header;
74 int16_t accel_data[3];
75 int16_t gyro_data[3];
76 int8_t temp_data;
77 uint16_t timestamp;
78 } byte_16;
79 struct {
80 fifo_header_t header;
81 int32_t accel_data[3];
82 int32_t gyro_data[3];
83 int16_t temp_data;
84 uint16_t timestamp;
85 } byte_20;
86 } inv_imu_fifo_data_t;
87
89 typedef struct {
90 /* INTx_CONFIG0 */
91 uint8_t INV_FIFO_FULL;
92 uint8_t INV_FIFO_THS;
93 uint8_t INV_UI_DRDY;
94 uint8_t INV_OIS1;
95 uint8_t INV_UI_FSYNC;
96 uint8_t INV_AGC_RDY;
97 uint8_t INV_OIS1_AGC_RDY;
98 uint8_t INV_RESET_DONE;
99
100 /* INTx_CONFIG1 */
101 uint8_t INV_PLL_RDY;
102 uint8_t INV_WOM_X;
103 uint8_t INV_WOM_Y;
104 uint8_t INV_WOM_Z;
105 uint8_t INV_I3C_PROT_ERR;
106 uint8_t INV_I2CM_DONE;
107 uint8_t INV_EDMP_EVENT;
108 } inv_imu_int_state_t;
109
111 typedef struct {
112 uint8_t gyro_en;
113 uint8_t accel_en;
114 uint8_t hires_en;
115 uint16_t fifo_wm_th;
116 fifo_config0_fifo_mode_t fifo_mode;
117 fifo_config0_fifo_depth_t fifo_depth;
118 } inv_imu_fifo_config_t;
119
121 #define FORMAT_16_BITS_DATA(is_big_endian, pIn8, pOut16) \
122 *(pOut16) = ((is_big_endian) == 1) ? ((pIn8)[0] << 8) | (pIn8)[1] : ((pIn8)[1] << 8) | (pIn8)[0]
123
124 /*
125 * API definitions
126 */
127
132 void inv_imu_sleep_us(inv_imu_device_t *s, uint32_t us);
133
138 int inv_imu_soft_reset(inv_imu_device_t *s);
139
145 int inv_imu_get_who_am_i(inv_imu_device_t *s, uint8_t *who_am_i);
146
152 int inv_imu_set_accel_mode(inv_imu_device_t *s, pwr_mgmt0_accel_mode_t accel_mode);
153
159 int inv_imu_set_gyro_mode(inv_imu_device_t *s, pwr_mgmt0_gyro_mode_t gyro_mode);
160
166 int inv_imu_set_accel_frequency(inv_imu_device_t *s, const accel_config0_accel_odr_t frequency);
167
173 int inv_imu_set_gyro_frequency(inv_imu_device_t *s, const gyro_config0_gyro_odr_t frequency);
174
180 int inv_imu_set_accel_fsr(inv_imu_device_t *s, accel_config0_accel_ui_fs_sel_t accel_fsr);
181
187 int inv_imu_set_gyro_fsr(inv_imu_device_t *s, gyro_config0_gyro_ui_fs_sel_t gyro_fsr);
188
194 int inv_imu_set_accel_lp_avg(inv_imu_device_t *s, ipreg_sys2_reg_129_accel_lp_avg_sel_t acc_avg);
195
201 int inv_imu_set_gyro_lp_avg(inv_imu_device_t *s, ipreg_sys1_reg_170_gyro_lp_avg_sel_t gyr_avg);
202
208 int inv_imu_set_accel_ln_bw(inv_imu_device_t *s, ipreg_sys2_reg_131_accel_ui_lpfbw_t acc_bw);
209
215 int inv_imu_set_gyro_ln_bw(inv_imu_device_t *s, ipreg_sys1_reg_172_gyro_ui_lpfbw_sel_t gyr_bw);
216
222 int inv_imu_get_register_data(inv_imu_device_t *s, inv_imu_sensor_data_t *data);
223
229 int inv_imu_set_fifo_config(inv_imu_device_t *s, const inv_imu_fifo_config_t *fifo_config);
230
236 int inv_imu_get_fifo_config(inv_imu_device_t *s, inv_imu_fifo_config_t *fifo_config);
237
242 int inv_imu_flush_fifo(inv_imu_device_t *s);
243
249 int inv_imu_get_frame_count(inv_imu_device_t *s, uint16_t *frame_count);
250
256 int inv_imu_get_fifo_frame(inv_imu_device_t *s, inv_imu_fifo_data_t *data);
257
264 int inv_imu_set_config_int(inv_imu_device_t *s, const inv_imu_int_num_t num,
265 const inv_imu_int_state_t *it);
266
273 int inv_imu_get_config_int(inv_imu_device_t *s, const inv_imu_int_num_t num,
274 inv_imu_int_state_t *it);
275
282 int inv_imu_set_pin_config_int(inv_imu_device_t *s, const inv_imu_int_num_t num,
283 const inv_imu_int_pin_config_t *conf);
284
291 int inv_imu_get_int_status(inv_imu_device_t *s, const inv_imu_int_num_t num,
292 inv_imu_int_state_t *it);
293
298 int inv_imu_get_endianness(inv_imu_device_t *s);
299
309 int inv_imu_select_accel_lp_clk(inv_imu_device_t *s, smc_control_0_accel_lp_clk_sel_t clk_sel);
310
314 const char *inv_imu_get_version(void);
315
316 #ifdef __cplusplus
317 }
318 #endif
319
320 #endif /* _INV_IMU_DRIVER_H_ */
321
inv_imu_defs.h
inv_imu_transport.h
fifo_config0_fifo_mode_t
fifo_config0_fifo_mode_t
Definition: inv_imu_defs.h:316
smc_control_0_accel_lp_clk_sel_t
smc_control_0_accel_lp_clk_sel_t
Definition: inv_imu_defs.h:578
accel_config0_accel_odr_t
accel_config0_accel_odr_t
Definition: inv_imu_defs.h:259
ipreg_sys1_reg_170_gyro_lp_avg_sel_t
ipreg_sys1_reg_170_gyro_lp_avg_sel_t
Definition: inv_imu_defs.h:625
ipreg_sys2_reg_129_accel_lp_avg_sel_t
ipreg_sys2_reg_129_accel_lp_avg_sel_t
Definition: inv_imu_defs.h:676
pwr_mgmt0_gyro_mode_t
pwr_mgmt0_gyro_mode_t
Definition: inv_imu_defs.h:198
pwr_mgmt0_accel_mode_t
pwr_mgmt0_accel_mode_t
Definition: inv_imu_defs.h:206
ipreg_sys1_reg_172_gyro_ui_lpfbw_sel_t
ipreg_sys1_reg_172_gyro_ui_lpfbw_sel_t
Definition: inv_imu_defs.h:646
fifo_config0_fifo_depth_t
fifo_config0_fifo_depth_t
Definition: inv_imu_defs.h:323
accel_config0_accel_ui_fs_sel_t
accel_config0_accel_ui_fs_sel_t
Definition: inv_imu_defs.h:248
inv_imu_int_num_t
inv_imu_int_num_t
Interrupt number.
Definition: inv_imu_defs.h:102
ipreg_sys2_reg_131_accel_ui_lpfbw_t
ipreg_sys2_reg_131_accel_ui_lpfbw_t
Definition: inv_imu_defs.h:697
gyro_config0_gyro_odr_t
gyro_config0_gyro_odr_t
Definition: inv_imu_defs.h:295
gyro_config0_gyro_ui_fs_sel_t
gyro_config0_gyro_ui_fs_sel_t
Definition: inv_imu_defs.h:280
inv_imu_set_gyro_frequency
int inv_imu_set_gyro_frequency(inv_imu_device_t *s, const gyro_config0_gyro_odr_t frequency)
Configure gyro Output Data Rate.
inv_imu_get_who_am_i
int inv_imu_get_who_am_i(inv_imu_device_t *s, uint8_t *who_am_i)
return WHOAMI value
inv_imu_set_gyro_fsr
int inv_imu_set_gyro_fsr(inv_imu_device_t *s, gyro_config0_gyro_ui_fs_sel_t gyro_fsr)
Set gyro full scale range.
inv_imu_set_accel_fsr
int inv_imu_set_accel_fsr(inv_imu_device_t *s, accel_config0_accel_ui_fs_sel_t accel_fsr)
Set accel full scale range.
inv_imu_get_fifo_frame
int inv_imu_get_fifo_frame(inv_imu_device_t *s, inv_imu_fifo_data_t *data)
Get one frame of FIFO data.
inv_imu_set_accel_mode
int inv_imu_set_accel_mode(inv_imu_device_t *s, pwr_mgmt0_accel_mode_t accel_mode)
Configure accel mode.
inv_imu_get_endianness
int inv_imu_get_endianness(inv_imu_device_t *s)
Read the UI endianness and set the inv_device endianness field.
inv_imu_get_config_int
int inv_imu_get_config_int(inv_imu_device_t *s, const inv_imu_int_num_t num, inv_imu_int_state_t *it)
Retrieve interrupts configuration.
inv_imu_set_accel_ln_bw
int inv_imu_set_accel_ln_bw(inv_imu_device_t *s, ipreg_sys2_reg_131_accel_ui_lpfbw_t acc_bw)
Set accel Low-Noise bandwidth value.
inv_imu_set_accel_frequency
int inv_imu_set_accel_frequency(inv_imu_device_t *s, const accel_config0_accel_odr_t frequency)
Configure accel Output Data Rate.
inv_imu_set_fifo_config
int inv_imu_set_fifo_config(inv_imu_device_t *s, const inv_imu_fifo_config_t *fifo_config)
Configures the FIFO to the specified state.
inv_imu_set_config_int
int inv_imu_set_config_int(inv_imu_device_t *s, const inv_imu_int_num_t num, const inv_imu_int_state_t *it)
Configure interrupts source.
inv_imu_set_gyro_lp_avg
int inv_imu_set_gyro_lp_avg(inv_imu_device_t *s, ipreg_sys1_reg_170_gyro_lp_avg_sel_t gyr_avg)
Set gyro Low-Power averaging value.
inv_imu_get_version
const char * inv_imu_get_version(void)
Return driver version x.y.z-suffix as a char array.
inv_imu_flush_fifo
int inv_imu_flush_fifo(inv_imu_device_t *s)
Flush FIFO content.
inv_imu_select_accel_lp_clk
int inv_imu_select_accel_lp_clk(inv_imu_device_t *s, smc_control_0_accel_lp_clk_sel_t clk_sel)
Select which clock to use when in Low Power mode.
inv_imu_set_accel_lp_avg
int inv_imu_set_accel_lp_avg(inv_imu_device_t *s, ipreg_sys2_reg_129_accel_lp_avg_sel_t acc_avg)
Set accel Low-Power averaging value.
inv_imu_set_pin_config_int
int inv_imu_set_pin_config_int(inv_imu_device_t *s, const inv_imu_int_num_t num, const inv_imu_int_pin_config_t *conf)
Configure pin behavior.
inv_imu_soft_reset
int inv_imu_soft_reset(inv_imu_device_t *s)
Performs a soft reset of the device.
inv_imu_set_gyro_mode
int inv_imu_set_gyro_mode(inv_imu_device_t *s, pwr_mgmt0_gyro_mode_t gyro_mode)
Configure gyro mode.
inv_imu_get_frame_count
int inv_imu_get_frame_count(inv_imu_device_t *s, uint16_t *frame_count)
Get FIFO frame count.
inv_imu_set_gyro_ln_bw
int inv_imu_set_gyro_ln_bw(inv_imu_device_t *s, ipreg_sys1_reg_172_gyro_ui_lpfbw_sel_t gyr_bw)
Set gyro Low-Noise bandwidth value.
inv_imu_get_register_data
int inv_imu_get_register_data(inv_imu_device_t *s, inv_imu_sensor_data_t *data)
Get current sensor data from the registers.
inv_imu_sleep_us
void inv_imu_sleep_us(inv_imu_device_t *s, uint32_t us)
Sleep function.
inv_imu_get_fifo_config
int inv_imu_get_fifo_config(inv_imu_device_t *s, inv_imu_fifo_config_t *fifo_config)
Gets the current FIFO configuration.
inv_imu_get_int_status
int inv_imu_get_int_status(inv_imu_device_t *s, const inv_imu_int_num_t num, inv_imu_int_state_t *it)
Read interrupt 1 status.
inv_imu_sensor_data_t
Sensor data from registers.
Definition: inv_imu_defs.h:95
fifo_header_t
Describe the content of the FIFO header.
Definition: inv_imu_defs.h:108
inv_imu_int_pin_config_t
Interrupts pin configuration.
Definition: inv_imu_defs.h:237
inv_imu_device_t
Basic driver configuration structure.
Definition: inv_imu_driver.h:43
inv_imu_device_t::transport
inv_imu_transport_t transport
Transport structure.
Definition: inv_imu_driver.h:45
inv_imu_device_t::endianness_data
uint8_t endianness_data
Keeps track of data endianness mode 0 : data in Sensor Registers and FIFO are in Little Endian format...
Definition: inv_imu_driver.h:54
inv_imu_device_t::fifo_frame_size
uint8_t fifo_frame_size
The calculated FIFO frame size in Bytes.
Definition: inv_imu_driver.h:48
inv_imu_fifo_data_t
One frame of FIFO header+data.
Definition: inv_imu_driver.h:65
inv_imu_fifo_data_t::temp_data
int16_t temp_data
Definition: inv_imu_driver.h:83
inv_imu_fifo_data_t::timestamp
uint16_t timestamp
Definition: inv_imu_driver.h:77
inv_imu_fifo_data_t::header
fifo_header_t header
Definition: inv_imu_driver.h:66
inv_imu_fifo_data_t::temp_data
int8_t temp_data
Definition: inv_imu_driver.h:70
inv_imu_int_state_t
Interrupts definition.
Definition: inv_imu_driver.h:89
inv_imu_int_state_t::INV_I2CM_DONE
uint8_t INV_I2CM_DONE
Definition: inv_imu_driver.h:106
inv_imu_int_state_t::INV_RESET_DONE
uint8_t INV_RESET_DONE
Definition: inv_imu_driver.h:98
inv_imu_int_state_t::INV_UI_DRDY
uint8_t INV_UI_DRDY
Definition: inv_imu_driver.h:93
inv_imu_int_state_t::INV_AGC_RDY
uint8_t INV_AGC_RDY
Definition: inv_imu_driver.h:96
inv_imu_int_state_t::INV_WOM_Y
uint8_t INV_WOM_Y
Definition: inv_imu_driver.h:103
inv_imu_int_state_t::INV_FIFO_THS
uint8_t INV_FIFO_THS
Definition: inv_imu_driver.h:92
inv_imu_int_state_t::INV_FIFO_FULL
uint8_t INV_FIFO_FULL
Definition: inv_imu_driver.h:91
inv_imu_int_state_t::INV_WOM_X
uint8_t INV_WOM_X
Definition: inv_imu_driver.h:102
inv_imu_int_state_t::INV_PLL_RDY
uint8_t INV_PLL_RDY
Definition: inv_imu_driver.h:101
inv_imu_int_state_t::INV_OIS1
uint8_t INV_OIS1
Definition: inv_imu_driver.h:94
inv_imu_int_state_t::INV_I3C_PROT_ERR
uint8_t INV_I3C_PROT_ERR
Definition: inv_imu_driver.h:105
inv_imu_int_state_t::INV_UI_FSYNC
uint8_t INV_UI_FSYNC
Definition: inv_imu_driver.h:95
inv_imu_int_state_t::INV_OIS1_AGC_RDY
uint8_t INV_OIS1_AGC_RDY
Definition: inv_imu_driver.h:97
inv_imu_int_state_t::INV_EDMP_EVENT
uint8_t INV_EDMP_EVENT
Definition: inv_imu_driver.h:107
inv_imu_int_state_t::INV_WOM_Z
uint8_t INV_WOM_Z
Definition: inv_imu_driver.h:104
inv_imu_fifo_config_t
Basic FIFO configuration.
Definition: inv_imu_driver.h:111
inv_imu_fifo_config_t::fifo_mode
fifo_config0_fifo_mode_t fifo_mode
Operating mode of the FIFO.
Definition: inv_imu_driver.h:116
inv_imu_fifo_config_t::hires_en
uint8_t hires_en
Enable High Resolution mode (20-bits long data)
Definition: inv_imu_driver.h:114
inv_imu_fifo_config_t::gyro_en
uint8_t gyro_en
Enable Gyro in FIFO.
Definition: inv_imu_driver.h:112
inv_imu_fifo_config_t::fifo_wm_th
uint16_t fifo_wm_th
Watermark threshold value.
Definition: inv_imu_driver.h:115
inv_imu_fifo_config_t::accel_en
uint8_t accel_en
Enable Accel in FIFO.
Definition: inv_imu_driver.h:113
inv_imu_fifo_config_t::fifo_depth
fifo_config0_fifo_depth_t fifo_depth
FIFO size.
Definition: inv_imu_driver.h:117
inv_imu_transport_t
Structure dedicated to transport layer transport interface.
Definition: inv_imu_transport.h:62