LIS3DH.Fifo (lis3dh v0.1.0)

Copy Markdown

FIFO protocol encoding and decoding for the LIS3DH.

The chip has a 32-level FIFO. Each level holds one X/Y/Z sample (6 bytes total, all three axes read out from OUT_X_L..OUT_Z_H). Four FIFO modes are supported, selected by FIFO_CTRL_REG.FM[1:0]:

  • :bypass — FIFO disabled. Reads of OUT_* return the latest sample live, no buffering.
  • :fifo — fills until full (32 samples) and stops collecting until the buffer is reset (by re-entering Bypass).
  • :stream — overwrites oldest sample once full (continuous streaming).
  • :stream_to_fifo — runs in Stream until an interrupt on the chosen trigger pin, then switches to FIFO mode (useful for capturing the history around an event).

The watermark interrupt fires when the number of stored samples reaches FTH[4:0] + 1. Overrun (full) is a separate flag.

References: LIS3DH Datasheet DocID17530 Rev 2 §5.1 and §8.19.

Summary

Types

FIFO operating mode for FIFO_CTRL_REG.FM.

Decoded FIFO source register flags.

Trigger pin used by Stream-to-FIFO mode (and not used by the others).

Watermark threshold (number of stored samples that triggers the WTM flag).

Functions

Decode a FIFO_CTRL_REG byte into a map of its fields.

Decode the read-only FIFO_SRC_REG byte.

Encode a FIFO_CTRL_REG byte from keyword options.

Types

mode()

@type mode() :: :bypass | :fifo | :stream | :stream_to_fifo

FIFO operating mode for FIFO_CTRL_REG.FM.

source_flags()

@type source_flags() :: %{
  watermark_reached: boolean(),
  overrun: boolean(),
  empty: boolean(),
  stored: 0..32
}

Decoded FIFO source register flags.

trigger()

@type trigger() :: :int1 | :int2

Trigger pin used by Stream-to-FIFO mode (and not used by the others).

watermark()

@type watermark() :: 1..32

Watermark threshold (number of stored samples that triggers the WTM flag).

Functions

decode_fifo_ctrl_reg(arg)

@spec decode_fifo_ctrl_reg(<<_::8>>) :: %{
  mode: mode(),
  trigger: trigger(),
  watermark: watermark()
}

Decode a FIFO_CTRL_REG byte into a map of its fields.

decode_fifo_src_reg(arg)

@spec decode_fifo_src_reg(<<_::8>>) :: source_flags()

Decode the read-only FIFO_SRC_REG byte.

encode_fifo_ctrl_reg(opts)

@spec encode_fifo_ctrl_reg(keyword()) :: <<_::8>>

Encode a FIFO_CTRL_REG byte from keyword options.

Options

  • :modemode/0 (required).
  • :triggertrigger/0 (default :int1). Only meaningful in :stream_to_fifo mode; ignored otherwise.
  • :watermarkwatermark/0 (default 16). Stored as watermark - 1 in the 5-bit FTH field.