| ICM42370P eMD Driver 2.2.7 Documentation of the eMD Driver API

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

Files | Classes | Macros | Enumerations | Functions
Driver

High-level functions to drive the device. More...

## Files
file | inv_imu_driver.h

## Classes
struct | inv_imu_sensor_event_t
| Sensor event structure definition. More...
struct | inv_imu_device
| IMU driver states definition. More...
struct | inv_imu_interrupt_parameter_t
| Interrupt definition. More...

## Macros
#define | ACCEL_CONFIG0_FS_SEL_MAX ACCEL_CONFIG0_FS_SEL_16g
| Max FSR values for accel. More...
#define | ACCEL_OFFUSER_MAX_MG 1000
| Max user offset value for accel (mg) More...
#define | ACC_STARTUP_TIME_US 10000
| Accel start-up time. More...
#define | FIFO_MIRRORING_SIZE 16 * 258
| Max buffer size mirrored from FIFO at polling time. More...

## Enumerations
enum | inv_imu_sensor { INV_SENSOR_ACCEL , INV_SENSOR_RESERVED1 , INV_SENSOR_RESERVED2 , INV_SENSOR_TEMPERATURE , INV_SENSOR_DMP_PEDOMETER_EVENT , INV_SENSOR_DMP_PEDOMETER_COUNT , INV_SENSOR_DMP_TILT , INV_SENSOR_DMP_FF , INV_SENSOR_DMP_LOWG , INV_SENSOR_DMP_SMD , INV_SENSOR_MAX }
| Sensor identifier for UI control function. More...
enum | INV_IMU_FIFO_CONFIG_t { INV_IMU_FIFO_DISABLED = 0 , INV_IMU_FIFO_ENABLED = 1 }
| Configure Fifo usage. More...
enum | inv_imu_interrupt_value { INV_IMU_DISABLE = 0 , INV_IMU_ENABLE }
| Interrupt enum state for INT1, INT2, and IBI. More...

## Functions
int | inv_imu_init (struct inv_imu_device *s, const struct inv_imu_serif *serif, void(*sensor_event_cb)(inv_imu_sensor_event_t *event))
| Initializes device. More...
int | inv_imu_device_reset (struct inv_imu_device *s)
| Reset device by reloading OTPs. More...
int | inv_imu_get_who_am_i (struct inv_imu_device *s, uint8_t *who_am_i)
| return WHOAMI value. More...
int | inv_imu_enable_accel_low_power_mode (struct inv_imu_device *s)
| Enable/put accel in low power mode. More...
int | inv_imu_enable_accel_low_noise_mode (struct inv_imu_device *s)
| Enable/put accel in low noise mode. More...
int | inv_imu_disable_accel (struct inv_imu_device *s)
| Disable all 3 axes of accel. More...
int | inv_imu_set_accel_frequency (struct inv_imu_device *s, const ACCEL_CONFIG0_ODR_t frequency)
| Configure accel Output Data Rate. More...
int | inv_imu_set_accel_lp_avg (struct inv_imu_device *s, ACCEL_CONFIG1_ACCEL_FILT_AVG_t acc_avg)
| Set accel Low-Power averaging value. More...
int | inv_imu_set_accel_ln_bw (struct inv_imu_device *s, ACCEL_CONFIG1_ACCEL_FILT_BW_t acc_bw)
| Set accel Low-Noise bandwidth value. More...
int | inv_imu_set_accel_fsr (struct inv_imu_device *s, ACCEL_CONFIG0_FS_SEL_t accel_fsr_g)
| Set accel full scale range. More...
int | inv_imu_get_accel_fsr (struct inv_imu_device *s, ACCEL_CONFIG0_FS_SEL_t *accel_fsr_g)
| Access accel full scale range. More...
int | inv_imu_set_config_int1 (struct inv_imu_device *s, const inv_imu_interrupt_parameter_t *it)
| Configure which interrupt source can trigger INT1. More...
int | inv_imu_get_config_int1 (struct inv_imu_device *s, inv_imu_interrupt_parameter_t *it)
| Retrieve interrupts configuration. More...
int | inv_imu_set_config_int2 (struct inv_imu_device *s, const inv_imu_interrupt_parameter_t *it)
| Configure which interrupt source can trigger INT2. More...
int | inv_imu_get_config_int2 (struct inv_imu_device *s, inv_imu_interrupt_parameter_t *it)
| Retrieve interrupts configuration. More...
int | inv_imu_get_data_from_registers (struct inv_imu_device *s)
| Read all registers containing data (temperature, accelerometer and gyroscope). More...
int | inv_imu_get_data_from_fifo (struct inv_imu_device *s)
| Read all available packets from the FIFO. More...
uint32_t | inv_imu_convert_odr_bitfield_to_us (uint32_t odr_bitfield)
| Converts ACCEL_CONFIG0_ODR_t or GYRO_CONFIG0_ODR_t enums to period expressed in us. More...
int | inv_imu_set_timestamp_resolution (struct inv_imu_device *s, const TMST_CONFIG1_RESOL_t timestamp_resol)
| Set timestamp resolution. More...
int | inv_imu_reset_fifo (struct inv_imu_device *s)
| Reset IMU fifo. More...
int | inv_imu_enable_high_resolution_fifo (struct inv_imu_device *s)
| Enable 20 bits raw acc and raw gyr data in fifo. More...
int | inv_imu_disable_high_resolution_fifo (struct inv_imu_device *s)
| Disable 20 bits raw acc and raw gyr data in fifo. More...
int | inv_imu_configure_fifo (struct inv_imu_device *s, INV_IMU_FIFO_CONFIG_t fifo_config)
| Configure Fifo. More...
uint32_t | inv_imu_get_timestamp_resolution_us (struct inv_imu_device *s)
| Get timestamp resolution. More...
int | inv_imu_configure_wom (struct inv_imu_device *s, const uint8_t wom_x_th, const uint8_t wom_y_th, const uint8_t wom_z_th, WOM_CONFIG_WOM_INT_MODE_t wom_int, WOM_CONFIG_WOM_INT_DUR_t wom_dur)
| Enable Wake On Motion. More...
int | inv_imu_enable_wom (struct inv_imu_device *s)
| Enable Wake On Motion. More...
int | inv_imu_disable_wom (struct inv_imu_device *s)
| Disable Wake On Motion. More...
int | inv_imu_start_dmp (struct inv_imu_device *s)
| Start DMP for APEX algorithms and selftest. More...
int | inv_imu_reset_dmp (struct inv_imu_device *s, const APEX_CONFIG0_DMP_MEM_RESET_t sram_reset)
| Reset DMP for APEX algorithms and selftest. More...
int | inv_imu_set_endianness (struct inv_imu_device *s, INTF_CONFIG0_DATA_ENDIAN_t endianness)
| Set the UI endianness and set the inv_device endianness field. More...
int | inv_imu_get_endianness (struct inv_imu_device *s)
| Read the UI endianness and set the inv_device endianness field. More...
int | inv_imu_configure_fifo_data_rate (struct inv_imu_device *s, FDR_CONFIG_FDR_SEL_t dec_factor)
| Configure Fifo decimation. More...
const char * | inv_imu_get_version (void)
| Return driver version x.y.z-suffix as a char array. More...
static void | format_u16_data (uint8_t endianness, const uint8_t *in, uint16_t *out)
| Converts two bytes in one unsigned half-word depending on endianness. More...
static void | format_s16_data (uint8_t endianness, const uint8_t *in, int16_t *out)
| Converts two bytes in one signed half-word depending on endianness. More...

## Detailed Description

High-level functions to drive the device.

## Macro Definition Documentation

## ◆ ACC_STARTUP_TIME_US

#define ACC_STARTUP_TIME_US 10000

Accel start-up time.

## ◆ ACCEL_CONFIG0_FS_SEL_MAX

#define ACCEL_CONFIG0_FS_SEL_MAX ACCEL_CONFIG0_FS_SEL_16g

Max FSR values for accel.

## ◆ ACCEL_OFFUSER_MAX_MG

#define ACCEL_OFFUSER_MAX_MG 1000

Max user offset value for accel (mg)

## ◆ FIFO_MIRRORING_SIZE

#define FIFO_MIRRORING_SIZE 16 * 258

Max buffer size mirrored from FIFO at polling time.

## Enumeration Type Documentation

## ◆ INV_IMU_FIFO_CONFIG_t

enum INV_IMU_FIFO_CONFIG_t

Configure Fifo usage.

Enumerator
INV_IMU_FIFO_DISABLED | Fifo is disabled and data source is sensors registers.
INV_IMU_FIFO_ENABLED | Fifo is used as data source.

## ◆ inv_imu_interrupt_value

enum inv_imu_interrupt_value

Interrupt enum state for INT1, INT2, and IBI.

Enumerator
INV_IMU_DISABLE |
INV_IMU_ENABLE |

## ◆ inv_imu_sensor

enum inv_imu_sensor

Sensor identifier for UI control function.

Enumerator
INV_SENSOR_ACCEL | Accelerometer.
INV_SENSOR_RESERVED1 |
INV_SENSOR_RESERVED2 |
INV_SENSOR_TEMPERATURE | Chip temperature.
INV_SENSOR_DMP_PEDOMETER_EVENT | Pedometer: step detected.
INV_SENSOR_DMP_PEDOMETER_COUNT | Pedometer: step counter.
INV_SENSOR_DMP_TILT | Tilt.
INV_SENSOR_DMP_FF | FreeFall.
INV_SENSOR_DMP_LOWG | Low G.
INV_SENSOR_DMP_SMD | Significant Motion Detection.
INV_SENSOR_MAX |

## Function Documentation

## ◆ format_s16_data()

static void format_s16_data | ( | uint8_t | endianness,
|  | const uint8_t * | in,
|  | int16_t * | out
| ) |  |
| inline static

Converts two bytes in one signed half-word depending on endianness.

Parameters

  [in] | endianness | IMU's endianness.
  [in] | in | Pointer to input.
  [out] | out | Pointer to output.

## ◆ format_u16_data()

static void format_u16_data | ( | uint8_t | endianness,
|  | const uint8_t * | in,
|  | uint16_t * | out
| ) |  |
| inline static

Converts two bytes in one unsigned half-word depending on endianness.

Parameters

  [in] | endianness | IMU's endianness.
  [in] | in | Pointer to input.
  [out] | out | Pointer to output.

## ◆ inv_imu_configure_fifo()

int inv_imu_configure_fifo | ( | struct inv_imu_device * | s,
|  | INV_IMU_FIFO_CONFIG_t | fifo_config
| ) |  |

Configure Fifo.

Parameters

  [in] | s | Pointer to device.
  [in] | fifo_config | Fifo configuration method. Enabled: data are pushed to FIFO and FIFO THS interrupt is set. Disabled: data are not pused to FIFO and DRDY interrupt is set.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_configure_fifo_data_rate()

int inv_imu_configure_fifo_data_rate | ( | struct inv_imu_device * | s,
|  | FDR_CONFIG_FDR_SEL_t | dec_factor
| ) |  |

Configure Fifo decimation.

Parameters

  [in] | s | Pointer to device.
  [in] | dec_factor | Requested decimation factor value from 2 to 256.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_configure_wom()

int inv_imu_configure_wom | ( | struct inv_imu_device * | s,
|  | const uint8_t | wom_x_th,
|  | const uint8_t | wom_y_th,
|  | const uint8_t | wom_z_th,
|  | WOM_CONFIG_WOM_INT_MODE_t | wom_int,
|  | WOM_CONFIG_WOM_INT_DUR_t | wom_dur
| ) |  |

Enable Wake On Motion.

Parameters

  [in] | s | Pointer to device.
  [in] | wom_x_th | Threshold value for the Wake on Motion Interrupt for X-axis accel.
  [in] | wom_y_th | Threshold value for the Wake on Motion Interrupt for Y-axis accel.
  [in] | wom_z_th | Threshold value for the Wake on Motion Interrupt for Z-axis accel.
  [in] | wom_int | Select which mode between AND/OR is used to generate interrupt.
  [in] | wom_dur | Select the number of overthreshold event to wait before generating interrupt.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_convert_odr_bitfield_to_us()

uint32_t inv_imu_convert_odr_bitfield_to_us | ( | uint32_t | odr_bitfield | ) |

Converts ACCEL_CONFIG0_ODR_t or GYRO_CONFIG0_ODR_t enums to period expressed in us.

Parameters

  [in] | odr_bitfield | An ACCEL_CONFIG0_ODR_t or GYRO_CONFIG0_ODR_t enum.

Returns
  The corresponding period expressed in us.

## ◆ inv_imu_device_reset()

int inv_imu_device_reset | ( | struct inv_imu_device * | s | ) |

Reset device by reloading OTPs.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_disable_accel()

int inv_imu_disable_accel | ( | struct inv_imu_device * | s | ) |

Disable all 3 axes of accel.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_disable_high_resolution_fifo()

int inv_imu_disable_high_resolution_fifo | ( | struct inv_imu_device * | s | ) |

Disable 20 bits raw acc and raw gyr data in fifo.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_disable_wom()

int inv_imu_disable_wom | ( | struct inv_imu_device * | s | ) |

Disable Wake On Motion.

Fifo water-mark interrupt is re-enabled when WoM is disabled.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_enable_accel_low_noise_mode()

int inv_imu_enable_accel_low_noise_mode | ( | struct inv_imu_device * | s | ) |

Enable/put accel in low noise mode.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_enable_accel_low_power_mode()

int inv_imu_enable_accel_low_power_mode | ( | struct inv_imu_device * | s | ) |

Enable/put accel in low power mode.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_enable_high_resolution_fifo()

int inv_imu_enable_high_resolution_fifo | ( | struct inv_imu_device * | s | ) |

Enable 20 bits raw acc and raw gyr data in fifo.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_enable_wom()

int inv_imu_enable_wom | ( | struct inv_imu_device * | s | ) |

Enable Wake On Motion.

WoM requests to have the accelerometer enabled to work. As a consequence Fifo water-mark interrupt is disabled to only trigger WoM interrupts. To have good performance, it's recommended to set accel ODR to 20ms and in Low Power Mode.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_get_accel_fsr()

int inv_imu_get_accel_fsr | ( | struct inv_imu_device * | s,
|  | ACCEL_CONFIG0_FS_SEL_t * | accel_fsr_g
| ) |  |

Access accel full scale range.

Parameters

  [in] | s | Pointer to device.
  [out] | accel_fsr_g | Current full scale range.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_get_config_int1()

int inv_imu_get_config_int1 | ( | struct inv_imu_device * | s,
|  | inv_imu_interrupt_parameter_t * | it
| ) |  |

Retrieve interrupts configuration.

Parameters

  [in] | s | Pointer to device.
  [out] | it | Structure with the corresponding state to manage INT1.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_get_config_int2()

int inv_imu_get_config_int2 | ( | struct inv_imu_device * | s,
|  | inv_imu_interrupt_parameter_t * | it
| ) |  |

Retrieve interrupts configuration.

Parameters

  [in] | s | Pointer to device.
  [out] | it | Structure with the corresponding state to manage INT2.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_get_data_from_fifo()

int inv_imu_get_data_from_fifo | ( | struct inv_imu_device * | s | ) |

Read all available packets from the FIFO.

For each packet function builds a sensor event containing packet data and validity information. Then it calls sensor_event_cb funtion passed at init for each packet.

Parameters

  [in] | s | Pointer to device.

Returns
  Number of valid packets read on success, negative value on error.

## ◆ inv_imu_get_data_from_registers()

int inv_imu_get_data_from_registers | ( | struct inv_imu_device * | s | ) |

Read all registers containing data (temperature, accelerometer and gyroscope).

Then it calls sensor_event_cb function passed at init for each packet.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_get_endianness()

int inv_imu_get_endianness | ( | struct inv_imu_device * | s | ) |

Read the UI endianness and set the inv_device endianness field.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_get_timestamp_resolution_us()

uint32_t inv_imu_get_timestamp_resolution_us | ( | struct inv_imu_device * | s | ) |

Get timestamp resolution.

Parameters

  [in] | s | Pointer to device.

Returns
  The timestamp resolution in us or 0 in case of error

## ◆ inv_imu_get_version()

const char* inv_imu_get_version | ( | void |  | ) |

Return driver version x.y.z-suffix as a char array.

Returns
  driver version a char array "x.y.z-suffix"

## ◆ inv_imu_get_who_am_i()

int inv_imu_get_who_am_i | ( | struct inv_imu_device * | s,
|  | uint8_t * | who_am_i
| ) |  |

return WHOAMI value.

Parameters

  [in] | s | Pointer to device.
  [out] | who_am_i | WHOAMI for device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_init()

int inv_imu_init | ( | struct inv_imu_device * | s,
|  | const struct inv_imu_serif * | serif,
|  | void(*)(inv_imu_sensor_event_t *event) | sensor_event_cb
| ) |  |

Initializes device.

Parameters

  [in] | s | Pointer to device.
  [in] | serif | Pointer on serial interface structure.
  [in] | sensor_event_cb | Callback executed when a new sensor event is available. *

Returns
  0 on success, negative value on error.

## ◆ inv_imu_reset_dmp()

int inv_imu_reset_dmp | ( | struct inv_imu_device * | s,
|  | const APEX_CONFIG0_DMP_MEM_RESET_t | sram_reset
| ) |  |

Reset DMP for APEX algorithms and selftest.

Parameters

  [in] | s | Pointer to device.
  [in] | sram_reset | Reset mode for the SRAM.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_reset_fifo()

int inv_imu_reset_fifo | ( | struct inv_imu_device * | s | ) |

Reset IMU fifo.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_accel_frequency()

int inv_imu_set_accel_frequency | ( | struct inv_imu_device * | s,
|  | const ACCEL_CONFIG0_ODR_t | frequency
| ) |  |

Configure accel Output Data Rate.

Parameters

  [in] | s | Pointer to device.
  [in] | frequency | The requested frequency.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_accel_fsr()

int inv_imu_set_accel_fsr | ( | struct inv_imu_device * | s,
|  | ACCEL_CONFIG0_FS_SEL_t | accel_fsr_g
| ) |  |

Set accel full scale range.

Parameters

  [in] | s | Pointer to device.
  [in] | accel_fsr_g | Requested full scale range.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_accel_ln_bw()

int inv_imu_set_accel_ln_bw | ( | struct inv_imu_device * | s,
|  | ACCEL_CONFIG1_ACCEL_FILT_BW_t | acc_bw
| ) |  |

Set accel Low-Noise bandwidth value.

Parameters

  [in] | s | Pointer to device.
  [in] | acc_bw | Requested averaging value.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_accel_lp_avg()

int inv_imu_set_accel_lp_avg | ( | struct inv_imu_device * | s,
|  | ACCEL_CONFIG1_ACCEL_FILT_AVG_t | acc_avg
| ) |  |

Set accel Low-Power averaging value.

Parameters

  [in] | s | Pointer to device.
  [in] | acc_avg | Requested averaging value.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_config_int1()

int inv_imu_set_config_int1 | ( | struct inv_imu_device * | s,
|  | const inv_imu_interrupt_parameter_t * | it
| ) |  |

Configure which interrupt source can trigger INT1.

Parameters

  [in] | s | Pointer to device.
  [in] | it | Structure with the corresponding state to manage INT1.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_config_int2()

int inv_imu_set_config_int2 | ( | struct inv_imu_device * | s,
|  | const inv_imu_interrupt_parameter_t * | it
| ) |  |

Configure which interrupt source can trigger INT2.

Parameters

  [in] | s | Pointer to device.
  [in] | it | Structure with the corresponding state to INT2.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_endianness()

int inv_imu_set_endianness | ( | struct inv_imu_device * | s,
|  | INTF_CONFIG0_DATA_ENDIAN_t | endianness
| ) |  |

Set the UI endianness and set the inv_device endianness field.

Parameters

  [in] | s | Pointer to device.
  [in] | endianness | Endianness to be set.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_set_timestamp_resolution()

int inv_imu_set_timestamp_resolution | ( | struct inv_imu_device * | s,
|  | const TMST_CONFIG1_RESOL_t | timestamp_resol
| ) |  |

Set timestamp resolution.

Parameters

  [in] | s | Pointer to device.
  [in] | timestamp_resol | Requested timestamp resolution.

Returns
  0 on success, negative value on error.

## ◆ inv_imu_start_dmp()

int inv_imu_start_dmp | ( | struct inv_imu_device * | s | ) |

Start DMP for APEX algorithms and selftest.

Parameters

  [in] | s | Pointer to device.

Returns
  0 on success, negative value on error.