| ICM40609D eMD Driver 2.0.0 Documentation of the eMD Driver API

- Main Page
- Modules
- Classes
- Files

Files | Classes | Macros | Enumerations | Functions
Icm406xx driver high level functions

High-level function to setup an Icm406xx device. More...

## Files
file | Icm406xxDriver_HL.h
| High-level function to setup an Icm406xx device.

## Classes
struct | inv_icm406xx_sensor_event_t
| Sensor event structure definition. More...
struct | inv_icm406xx
| Icm406xx driver states definition. More...

## Macros
#define | ICM406XX_FIFO_MIRRORING_SIZE 1041
| Icm406xx maximum buffer size mirrored from FIFO at polling time. More...

## Enumerations
enum | inv_icm406xx_sensor { INV_ICM406XX_SENSOR_ACCEL , INV_ICM406XX_SENSOR_GYRO , INV_ICM406XX_SENSOR_FSYNC_EVENT , INV_ICM406XX_SENSOR_OIS , INV_ICM406XX_SENSOR_TEMPERATURE , INV_ICM406XX_SENSOR_MAX }
| Sensor identifier for UI control and OIS function. More...

## Functions
int | inv_icm406xx_init (struct inv_icm406xx *s, struct inv_icm406xx_serif *serif, void(*sensor_event_cb)(inv_icm406xx_sensor_event_t *event))
| Configure the serial interface used to access the device and execute hardware initialization. More...
int | inv_icm406xx_device_reset (struct inv_icm406xx *s)
| Perform a soft reset of the device. More...
int | inv_icm406xx_get_who_am_i (struct inv_icm406xx *s, uint8_t *who_am_i)
| return WHOAMI value More...
int | inv_icm406xx_enable_accel_low_power_mode (struct inv_icm406xx *s)
| Put accel in low power mode. More...
int | inv_icm406xx_enable_accel_low_noise_mode (struct inv_icm406xx *s)
| Put accel in low noise mode. More...
int | inv_icm406xx_disable_accel (struct inv_icm406xx *s)
| Disable all 3 axes of accel. More...
int | inv_icm406xx_enable_gyro_low_noise_mode (struct inv_icm406xx *s)
| Put gyro in low noise mode. More...
int | inv_icm406xx_disable_gyro (struct inv_icm406xx *s)
| Disable all 3 axes of gyro. More...
int | inv_icm406xx_enable_fsync (struct inv_icm406xx *s)
| Enable fsync tagging functionnality. More...
int | inv_icm406xx_disable_fsync (struct inv_icm406xx *s)
| Disable fsync tagging functionnality. More...
int | inv_icm406xx_configure_wom (struct inv_icm406xx *s, const uint8_t wom_x_th, const uint8_t wom_y_th, const uint8_t wom_z_th)
| Enable Wake On Motion. More...
int | inv_icm406xx_enable_wom (struct inv_icm406xx *s)
| Enable Wake On Motion. More...
int | inv_icm406xx_disable_wom (struct inv_icm406xx *s)
| Disable Wake On Motion. More...
int | inv_icm406xx_get_data_from_fifo (struct inv_icm406xx *s)
| Read all available packets from the FIFO. More...
int | inv_icm406xx_set_accel_frequency (struct inv_icm406xx *s, const ICM406XX_ACCEL_CONFIG0_ODR_t frequency)
| Configure accel Output Data Rate. More...
int | inv_icm406xx_set_gyro_frequency (struct inv_icm406xx *s, const ICM406XX_GYRO_CONFIG0_ODR_t frequency)
| Configure gyro Output Data Rate. More...
int | inv_icm406xx_set_accel_fsr (struct inv_icm406xx *s, ICM406XX_ACCEL_CONFIG0_FS_SEL_t accel_fsr_g)
| Set accel full scale range. More...
int | inv_icm406xx_set_gyro_fsr (struct inv_icm406xx *s, ICM406XX_GYRO_CONFIG0_FS_SEL_t gyro_fsr_dps)
| Set gyro full scale range. More...
int | inv_icm406xx_reset_fifo (struct inv_icm406xx *s)
| reset ICM406XX fifo More...
int | inv_icm406xx_enable_timestamp_to_register (struct inv_icm406xx *s)
| Enable the 20bits-timestamp register access to read in a reliable way the strobed timestamp. More...
int | inv_icm406xx_disable_timestamp_to_register (struct inv_icm406xx *s)
| Disable the 20bits-timestamp register access. More...
int | inv_icm406xx_get_current_timestamp (struct inv_icm406xx *s, uint32_t *icm_time)
| Get the timestamp value of icm406xx from register. More...

## Detailed Description

High-level function to setup an Icm406xx device.

## Macro Definition Documentation

## ◆ ICM406XX_FIFO_MIRRORING_SIZE

#define ICM406XX_FIFO_MIRRORING_SIZE 1041

Icm406xx maximum buffer size mirrored from FIFO at polling time.

Warning
  fifo_idx type variable must be large enough to parse the FIFO_MIRRORING_SIZE

## Enumeration Type Documentation

## ◆ inv_icm406xx_sensor

enum inv_icm406xx_sensor

Sensor identifier for UI control and OIS function.

Enumerator
INV_ICM406XX_SENSOR_ACCEL | Accelerometer (UI control path)
INV_ICM406XX_SENSOR_GYRO | Gyroscope (UI control path)
INV_ICM406XX_SENSOR_FSYNC_EVENT | Used by OIS and UI control layers.
INV_ICM406XX_SENSOR_OIS | Only used by OIS layer.
INV_ICM406XX_SENSOR_TEMPERATURE | Chip temperature, enabled by default. However, it will be reported only if Accel and/or Gyro are also enabled. The Temperature's ODR (Output Data Rate) will match the ODR of Accel or Gyro, or the fastest if both are enabled

## Function Documentation

## ◆ inv_icm406xx_configure_wom()

int inv_icm406xx_configure_wom | ( | struct inv_icm406xx * | s,
|  | const uint8_t | wom_x_th,
|  | const uint8_t | wom_y_th,
|  | const uint8_t | wom_z_th
| ) |  |

Enable Wake On Motion.

Parameters

  [in] | wom_x_th | threshold value for the Wake on Motion Interrupt for X-axis accelerometer.
  [in] | wom_y_th | threshold value for the Wake on Motion Interrupt for Y-axis accelerometer.
  [in] | wom_z_th | threshold value for the Wake on Motion Interrupt for Z-axis accelerometer.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_device_reset()

int inv_icm406xx_device_reset | ( | struct inv_icm406xx * | s | ) |

Perform a soft reset of the device.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_disable_accel()

int inv_icm406xx_disable_accel | ( | struct inv_icm406xx * | s | ) |

Disable all 3 axes of accel.

Returns
  0 on success, negative value on error.

If both accel and gyro are turned off as a result of this function, they will also be removed from the FIFO and a FIFO reset will be performed (to guarantee no side effects until the next enable sensor call)

## ◆ inv_icm406xx_disable_fsync()

int inv_icm406xx_disable_fsync | ( | struct inv_icm406xx * | s | ) |

Disable fsync tagging functionnality.

In details it:

- disables fsync
- disables timestamp to registers. Once fysnc is disabled timestamp is pushed to fifo instead of fsync counter. So in order to decrease power consumption, timestamp is no more available in registers.
- disables fsync related interrupt
  Returns
    0 on success, negative value on error.

## ◆ inv_icm406xx_disable_gyro()

int inv_icm406xx_disable_gyro | ( | struct inv_icm406xx * | s | ) |

Disable all 3 axes of gyro.

Returns
  0 on success, negative value on error.

If both accel and gyro are turned off as a result of this function, they will also be removed from the FIFO and a FIFO reset will be performed (to guarantee no side effects until the next enable sensor call)

## ◆ inv_icm406xx_disable_timestamp_to_register()

int inv_icm406xx_disable_timestamp_to_register | ( | struct inv_icm406xx * | s | ) |

Disable the 20bits-timestamp register access.

Register read always return 0's.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_disable_wom()

int inv_icm406xx_disable_wom | ( | struct inv_icm406xx * | s | ) |

Disable Wake On Motion.

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

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_enable_accel_low_noise_mode()

int inv_icm406xx_enable_accel_low_noise_mode | ( | struct inv_icm406xx * | s | ) |

Put accel in low noise mode.

Returns
  0 on success, negative value on error.

It enables accel and gyro data in the FIFO (so the packet format is 16 bytes). If called first, the configuration will be applied, otherwise it will be ignored if the FIFO is not empty (but since the new configuration is identical it is not a issue).

## ◆ inv_icm406xx_enable_accel_low_power_mode()

int inv_icm406xx_enable_accel_low_power_mode | ( | struct inv_icm406xx * | s | ) |

Put accel in low power mode.

Returns
  0 on success, negative value on error.

It enables accel and gyro data in the FIFO (so the packet format is 16 bytes). If called first, the configuration will be applied, otherwise it will be ignored if the FIFO is not empty (but since the new configuration is identical it is not a issue).

## ◆ inv_icm406xx_enable_fsync()

int inv_icm406xx_enable_fsync | ( | struct inv_icm406xx * | s | ) |

Enable fsync tagging functionnality.

In details it:

- enables fsync
- enables timestamp to registers. Once fysnc is enabled fsync counter is pushed to fifo instead of timestamp. So timestamp is made available in registers. Note that this increase power consumption.
- enables fsync related interrupt
  Returns
    0 on success, negative value on error.

## ◆ inv_icm406xx_enable_gyro_low_noise_mode()

int inv_icm406xx_enable_gyro_low_noise_mode | ( | struct inv_icm406xx * | s | ) |

Put gyro in low noise mode.

Returns
  0 on success, negative value on error.

It enables gyro and accel data in the FIFO (so the packet format is 16 bytes). If called first, the configuration will be applied, otherwise it will be ignored if the FIFO is not empty (but since the new configuration is identical it is not a issue).

## ◆ inv_icm406xx_enable_timestamp_to_register()

int inv_icm406xx_enable_timestamp_to_register | ( | struct inv_icm406xx * | s | ) |

Enable the 20bits-timestamp register access to read in a reliable way the strobed timestamp.

To do that, the fine clock is forced enabled at some power cost.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_enable_wom()

int inv_icm406xx_enable_wom | ( | struct inv_icm406xx * | s | ) |

Enable Wake On Motion.

note : 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 accelerometer ODR (Output Data Rate) to 20ms and the accelerometer in Low Power Mode.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_get_current_timestamp()

int inv_icm406xx_get_current_timestamp | ( | struct inv_icm406xx * | s,
|  | uint32_t * | icm_time
| ) |  |

Get the timestamp value of icm406xx from register.

Parameters

  [in] | icm_time | timestamp read from register

Returns
  0 on success, negative value on error.

Warning
  Prior to call this API, the read access to timestamp register msut be enabled (see inv_icm406xx_enable_timestamp_to_register() function)

## ◆ inv_icm406xx_get_data_from_fifo()

int inv_icm406xx_get_data_from_fifo | ( | struct inv_icm406xx * | 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 in parameter of inv_icm406xx_init function for each packet.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_get_who_am_i()

int inv_icm406xx_get_who_am_i | ( | struct inv_icm406xx * | s,
|  | uint8_t * | who_am_i
| ) |  |

return WHOAMI value

Parameters

  [out] | who_am_i | WHOAMI for device

Returns
  0 on success, negative value on error

## ◆ inv_icm406xx_init()

int inv_icm406xx_init | ( | struct inv_icm406xx * | s,
|  | struct inv_icm406xx_serif * | serif,
|  | void(*)(inv_icm406xx_sensor_event_t *event) | sensor_event_cb
| ) |  |

Configure the serial interface used to access the device and execute hardware initialization.

This functions first configures serial interface passed in parameter to make sure device is accessible both in read and write. Thus no serial access should be done before succesfully executing the present function.

Then if requested serial interface is a primary interface (aka UI interface or AP interface), this function initializes the device using the following hardware settings:

- gyroscope fsr = 2000dps
- accelerometer fsr = 4g
- set timestamp resolution to 16us
- enable FIFO mechanism with the following configuration:
  - FIFO record mode i.e FIFO count unit is packet
  - FIFO snapshot mode i.e drop the data when the FIFO overflows
  - Timestamp is logged in FIFO
  - Little Endian fifo_count and fifo_data
  - generate FIFO threshold interrupt when packet count reaches FIFO watermark
  - set FIFO watermark to 1 packet
  - enable temperature and timestamp data to go to FIFO

In case requested serial interface is an auxliary interface (i.e. AUX1 or AUX2) this function does not perform any hardware initialization as write accesses are restricted from auxiliary ports. Hardware should then be initialized through primary interface prior to using auxiliary interface.

Parameters

  [in] | s | driver structure. Note that first field of this structure MUST be a struct inv_icm406xx_serif.
  [in] | serif | pointer on serial interface structure to be used to access icm406xx.
  [in] | sensor_event_cb | callback executed by inv_icm406xx_get_data_from_fifo function each time it extracts some valid data from fifo. Thus this parameter is optional as long as inv_icm406xx_get_data_from_fifo function is not used.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_reset_fifo()

int inv_icm406xx_reset_fifo | ( | struct inv_icm406xx * | s | ) |

reset ICM406XX fifo

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_set_accel_frequency()

int inv_icm406xx_set_accel_frequency | ( | struct inv_icm406xx * | s,
|  | const ICM406XX_ACCEL_CONFIG0_ODR_t | frequency
| ) |  |

Configure accel Output Data Rate.

Parameters

  [in] | frequency | The requested frequency. See

See also
  ICM406XX_ACCEL_CONFIG0_ODR_t

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_set_accel_fsr()

int inv_icm406xx_set_accel_fsr | ( | struct inv_icm406xx * | s,
|  | ICM406XX_ACCEL_CONFIG0_FS_SEL_t | accel_fsr_g
| ) |  |

Set accel full scale range.

Parameters

  [in] | accel_fsr_g | requested full scale range. See

See also
  ICM406XX_ACCEL_CONFIG0_FS_SEL_t.

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_set_gyro_frequency()

int inv_icm406xx_set_gyro_frequency | ( | struct inv_icm406xx * | s,
|  | const ICM406XX_GYRO_CONFIG0_ODR_t | frequency
| ) |  |

Configure gyro Output Data Rate.

Parameters

  [in] | frequency | The requested frequency. See

See also
  ICM406XX_GYRO_CONFIG0_ODR_t

Returns
  0 on success, negative value on error.

## ◆ inv_icm406xx_set_gyro_fsr()

int inv_icm406xx_set_gyro_fsr | ( | struct inv_icm406xx * | s,
|  | ICM406XX_GYRO_CONFIG0_FS_SEL_t | gyro_fsr_dps
| ) |  |

Set gyro full scale range.

Parameters

  [in] | gyro_fsr_dps | requested full scale range. See

See also
  ICM406XX_GYRO_CONFIG0_FS_SEL_t.

Returns
  0 on success, negative value on error.