icm20948/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3#![warn(missing_docs)]
4
5pub mod device;
6pub mod interface;
7pub mod registers;
8pub mod sensors;
9
10pub mod fifo;
11pub mod interrupt;
12pub mod power;
13
14// DMP support (feature-gated)
15#[cfg(feature = "dmp")]
16pub mod dmp;
17
18// Re-export main types
19pub use device::{AccelData, GyroData, Icm20948Driver, MagData};
20pub use interface::{I2cInterface, SpiInterface};
21pub use sensors::{
22    AccelCalibration, AccelConfig, AccelDataG, AccelDlpf, AccelFullScale, GyroCalibration,
23    GyroConfig, GyroDataDps, GyroDataRps, GyroDlpf, GyroFullScale, MagCalibration, MagConfig,
24    MagDataUT, MagMode,
25};
26
27pub use fifo::{
28    FIFO_SIZE, FifoConfig, FifoConfigAdvanced, FifoMode, FifoOverflowStatus, FifoRecord,
29    FifoWatermark,
30};
31pub use interrupt::{
32    DataReadyStatus, FsyncConfig, InterruptConfig, InterruptPinConfig, InterruptStatus, WomStatus,
33};
34pub use power::{
35    ClockSource, CycleConfig, LowPowerConfig, LowPowerRate, PowerMode, PowerStatus,
36    SensorPowerConfig, WomMode,
37};
38
39/// ICM-20948 I2C address when AD0 pin is low (default: 0x68)
40///
41/// This is the most common configuration. The AD0 pin is typically pulled low
42/// or left floating (has internal pull-down). Use [`I2cInterface::default()`]
43/// for this configuration.
44pub const I2C_ADDRESS_AD0_LOW: u8 = 0x68;
45
46/// ICM-20948 I2C address when AD0 pin is high (alternative: 0x69)
47///
48/// Use this address when the AD0 pin is explicitly pulled high to VDD.
49/// Use [`I2cInterface::alternative()`] for this configuration.
50pub const I2C_ADDRESS_AD0_HIGH: u8 = 0x69;
51
52/// Expected value of `WHO_AM_I` register
53pub const WHO_AM_I_VALUE: u8 = 0xEA;
54
55/// Register bank identifiers
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
57#[cfg_attr(feature = "defmt", derive(defmt::Format))]
58pub enum Bank {
59    /// Bank 0 - Primary configuration and data registers
60    Bank0 = 0,
61    /// Bank 1 - Self-test and advanced features
62    Bank1 = 1,
63    /// Bank 2 - Gyro and accelerometer configuration
64    Bank2 = 2,
65    /// Bank 3 - I2C master configuration
66    Bank3 = 3,
67}
68
69/// Driver errors
70#[derive(Debug)]
71#[cfg_attr(feature = "defmt", derive(defmt::Format))]
72pub enum Error<E> {
73    /// Communication error with the device
74    Bus(E),
75    /// Invalid `WHO_AM_I` register value (contains the actual value read)
76    InvalidDevice(u8),
77    /// Invalid configuration parameter
78    InvalidConfig,
79    /// Register bank switching error
80    BankSwitch,
81    /// Magnetometer error
82    Magnetometer,
83    /// Device is moving during calibration (variance exceeds threshold)
84    DeviceMoving,
85    /// Calibration overflow (averaged samples exceed i16 range)
86    CalibrationOverflow,
87    /// FIFO buffer overflow - more records than can fit in output vector (max 64)
88    FifoOverflow,
89}
90
91impl<E> From<E> for Error<E> {
92    fn from(error: E) -> Self {
93        Self::Bus(error)
94    }
95}