ICM42670 Portable Driver
Public API reference for the ICM-42670-P IMU driver
Loading...
Searching...
No Matches
ICM42670_fifo.h File Reference

Simple FIFO and interrupt routing API for the ICM-42670-P. More...

#include "ICM42670_driver.h"
#include <stdint.h>
Include dependency graph for ICM42670_fifo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ICM42670_FifoPacket_t
 Parsed FIFO packet using the default 16-bit FIFO format. More...
 

Macros

#define ICM42670_FIFO_DEFAULT_WATERMARK_BYTES   64U
 Default FIFO watermark used by ICM42670_FIFO_Init().
 
#define ICM42670_FIFO_DEFAULT_PACKET_BYTES   16U
 Maximum bytes in the default 16-bit accel + gyro FIFO packet.
 

Enumerations

enum  ICM42670_IntPin_t { ICM42670_INT_PIN1 = 0U , ICM42670_INT_PIN2 = 1U }
 ICM-42670-P interrupt output pins. More...
 
enum  ICM42670_FifoIntSource_t { ICM42670_FIFO_INT_NONE = 0x00U , ICM42670_FIFO_INT_THRESHOLD = 0x04U , ICM42670_FIFO_INT_FULL = 0x02U , ICM42670_FIFO_INT_THRESHOLD_AND_FULL }
 FIFO interrupt sources that can be routed to INT1 or INT2. More...
 

Functions

ICM42670_Status_t ICM42670_FIFO_Init (const ICM42670_Config *config)
 Initialize the FIFO with simple 16-bit accel and gyro packet defaults.
 
ICM42670_Status_t ICM42670_FIFO_UseFullBuffer (const ICM42670_Config *config)
 Disable APEX features so the FIFO can use the full 2.25 KB buffer.
 
ICM42670_Status_t ICM42670_FIFO_SetWatermark (const ICM42670_Config *config, uint16_t watermark_bytes)
 Set the FIFO watermark level in bytes.
 
ICM42670_Status_t ICM42670_FIFO_Flush (const ICM42670_Config *config)
 Flush all unread FIFO data.
 
ICM42670_Status_t ICM42670_FIFO_Read (const ICM42670_Config *config, ICM42670_FifoPacket_t *packets, uint16_t max_packets, uint16_t *packets_read)
 Read and parse available FIFO packets.
 
ICM42670_Status_t ICM42670_FIFO_RouteInterrupt (const ICM42670_Config *config, ICM42670_IntPin_t pin, ICM42670_FifoIntSource_t sources)
 Route FIFO threshold and/or FIFO full interrupts to INT1 or INT2.
 

Detailed Description

Simple FIFO and interrupt routing API for the ICM-42670-P.

Enumeration Type Documentation

◆ ICM42670_FifoIntSource_t

FIFO interrupt sources that can be routed to INT1 or INT2.

Enumerator
ICM42670_FIFO_INT_NONE 

Clear FIFO interrupt routing.

ICM42670_FIFO_INT_THRESHOLD 

FIFO watermark interrupt.

ICM42670_FIFO_INT_FULL 

FIFO full interrupt.

ICM42670_FIFO_INT_THRESHOLD_AND_FULL 

Both FIFO sources.

◆ ICM42670_IntPin_t

ICM-42670-P interrupt output pins.

Enumerator
ICM42670_INT_PIN1 

INT1 output pin.

ICM42670_INT_PIN2 

INT2 output pin.

Function Documentation

◆ ICM42670_FIFO_Flush()

ICM42670_Status_t ICM42670_FIFO_Flush ( const ICM42670_Config config)

Flush all unread FIFO data.

Parameters
configDriver configuration with write and delay callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_Config::delay_ms, ICM42670_ERROR, and ICM42670_OK.

Referenced by ICM42670_FIFO_Init().

◆ ICM42670_FIFO_Init()

ICM42670_Status_t ICM42670_FIFO_Init ( const ICM42670_Config config)

Initialize the FIFO with simple 16-bit accel and gyro packet defaults.

Configures stream mode, disables FIFO bypass, enables accel and gyro FIFO packets, uses byte-based FIFO counts, applies a small watermark, and flushes stale FIFO data before use.

Parameters
configDriver configuration with read, write, and delay callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, ICM42670_FIFO_DEFAULT_WATERMARK_BYTES, ICM42670_FIFO_Flush(), ICM42670_FIFO_SetWatermark(), and ICM42670_OK.

◆ ICM42670_FIFO_Read()

ICM42670_Status_t ICM42670_FIFO_Read ( const ICM42670_Config config,
ICM42670_FifoPacket_t packets,
uint16_t  max_packets,
uint16_t *  packets_read 
)

Read and parse available FIFO packets.

Reads up to max_packets parsed FIFO records into packets and writes the number of parsed packets to packets_read.

Parameters
configDriver configuration with a read callback.
packetsDestination array for parsed packets.
max_packetsMaximum number of packets to parse into packets.
packets_readNumber of packets parsed by this call.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, ICM42670_FIFO_DEFAULT_PACKET_BYTES, and ICM42670_OK.

◆ ICM42670_FIFO_RouteInterrupt()

ICM42670_Status_t ICM42670_FIFO_RouteInterrupt ( const ICM42670_Config config,
ICM42670_IntPin_t  pin,
ICM42670_FifoIntSource_t  sources 
)

Route FIFO threshold and/or FIFO full interrupts to INT1 or INT2.

Passing ICM42670_FIFO_INT_NONE clears FIFO routing for the selected pin while preserving other interrupt sources.

Parameters
configDriver configuration with read and write callbacks.
pinTarget interrupt pin.
sourcesFIFO interrupt sources to route.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, ICM42670_FIFO_INT_FULL, ICM42670_FIFO_INT_THRESHOLD, ICM42670_INT_PIN1, ICM42670_INT_PIN2, and ICM42670_OK.

◆ ICM42670_FIFO_SetWatermark()

ICM42670_Status_t ICM42670_FIFO_SetWatermark ( const ICM42670_Config config,
uint16_t  watermark_bytes 
)

Set the FIFO watermark level in bytes.

The watermark is used by the FIFO threshold interrupt source. Values larger than the 12-bit FIFO watermark field are clamped.

Parameters
configDriver configuration with read and write callbacks.
watermark_bytesFIFO threshold in bytes.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR.

References ICM42670_ERROR, and ICM42670_OK.

Referenced by ICM42670_FIFO_Init().

◆ ICM42670_FIFO_UseFullBuffer()

ICM42670_Status_t ICM42670_FIFO_UseFullBuffer ( const ICM42670_Config config)

Disable APEX features so the FIFO can use the full 2.25 KB buffer.

APEX and full FIFO capacity share SRAM. Call this only when APEX features are not needed.

Parameters
configDriver configuration with read, write, and delay callbacks.
Returns
ICM42670_OK on success, otherwise ICM42670_ERROR or ICM42670_BUSY.

References ICM42670_ERROR, and ICM42670_OK.