pub const WHO_AM_I: u8 = 0x00;
pub const REVISION_ID: u8 = 0x01;
pub const CTRL1: u8 = 0x02;
pub const CTRL2: u8 = 0x03;
pub const CTRL3: u8 = 0x04;
pub const CTRL5: u8 = 0x06;
pub const CTRL7: u8 = 0x08;
pub const CTRL8: u8 = 0x09;
pub const CTRL9: u8 = 0x0A;
pub const CAL1_L: u8 = 0x0B;
pub const CAL1_H: u8 = 0x0C;
pub const CAL2_L: u8 = 0x0D;
pub const CAL2_H: u8 = 0x0E;
pub const CAL3_L: u8 = 0x0F;
pub const CAL3_H: u8 = 0x10;
pub const CAL4_L: u8 = 0x11;
pub const CAL4_H: u8 = 0x12;
pub const FIFO_WTM_TH: u8 = 0x13;
pub const FIFO_CTRL: u8 = 0x14;
pub const FIFO_SMPL_CNT: u8 = 0x15;
pub const FIFO_STATUS: u8 = 0x16;
pub const FIFO_DATA: u8 = 0x17;
pub const STATUSINT: u8 = 0x2D;
pub const STATUS0: u8 = 0x2E;
pub const STATUS1: u8 = 0x2F;
pub const TIMESTAMP_L: u8 = 0x30;
pub const TEMP_L: u8 = 0x33;
pub const AX_L: u8 = 0x35;
pub const GX_L: u8 = 0x3B;
pub const COD_STATUS: u8 = 0x46;
pub const DQW_L: u8 = 0x49;
pub const DVX_L: u8 = 0x51;
pub const TAP_STATUS: u8 = 0x59;
pub const STEP_CNT_L: u8 = 0x5A;
pub const RESET: u8 = 0x60;
pub const WHO_AM_I_VALUE: u8 = 0x05;
pub const SOFT_RESET_VALUE: u8 = 0xB0;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum AccelRange {
#[default]
G2 = 0,
G4 = 1,
G8 = 2,
G16 = 3,
}
impl AccelRange {
#[must_use]
pub const fn lsb_per_g(self) -> u16 {
match self {
Self::G2 => 16384,
Self::G4 => 8192,
Self::G8 => 4096,
Self::G16 => 2048,
}
}
pub(crate) const fn from_bits(bits: u8) -> Self {
match bits & 0b11 {
1 => Self::G4,
2 => Self::G8,
3 => Self::G16,
_ => Self::G2,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum GyroRange {
#[default]
Dps16 = 0,
Dps32 = 1,
Dps64 = 2,
Dps128 = 3,
Dps256 = 4,
Dps512 = 5,
Dps1024 = 6,
Dps2048 = 7,
}
impl GyroRange {
#[must_use]
pub const fn lsb_per_dps(self) -> u16 {
match self {
Self::Dps16 => 2048,
Self::Dps32 => 1024,
Self::Dps64 => 512,
Self::Dps128 => 256,
Self::Dps256 => 128,
Self::Dps512 => 64,
Self::Dps1024 => 32,
Self::Dps2048 => 16,
}
}
pub(crate) const fn from_bits(bits: u8) -> Self {
match bits & 0b111 {
1 => Self::Dps32,
2 => Self::Dps64,
3 => Self::Dps128,
4 => Self::Dps256,
5 => Self::Dps512,
6 => Self::Dps1024,
7 => Self::Dps2048,
_ => Self::Dps16,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum Odr {
#[default]
Hz7174 = 0,
Hz3587 = 1,
Hz1794 = 2,
Hz897 = 3,
Hz448 = 4,
Hz224 = 5,
Hz112 = 6,
Hz56 = 7,
Hz28 = 8,
}
impl Odr {
#[must_use]
pub const fn hz(self) -> f32 {
match self {
Self::Hz7174 => 7174.4,
Self::Hz3587 => 3587.2,
Self::Hz1794 => 1793.6,
Self::Hz897 => 896.8,
Self::Hz448 => 448.4,
Self::Hz224 => 224.2,
Self::Hz112 => 112.1,
Self::Hz56 => 56.05,
Self::Hz28 => 28.025,
}
}
pub(crate) const fn from_bits(bits: u8) -> Self {
match bits & 0b1111 {
1 => Self::Hz3587,
2 => Self::Hz1794,
3 => Self::Hz897,
4 => Self::Hz448,
5 => Self::Hz224,
6 => Self::Hz112,
7 => Self::Hz56,
8..=u8::MAX => Self::Hz28,
_ => Self::Hz7174,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum AccelStandaloneOdr {
Hz1000 = 3,
Hz500 = 4,
Hz250 = 5,
Hz125 = 6,
Hz62 = 7,
Hz31 = 8,
}
impl AccelStandaloneOdr {
#[must_use]
pub const fn hz(self) -> f32 {
match self {
Self::Hz1000 => 1000.0,
Self::Hz500 => 500.0,
Self::Hz250 => 250.0,
Self::Hz125 => 125.0,
Self::Hz62 => 62.5,
Self::Hz31 => 31.25,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum LowPowerOdr {
Hz128 = 12,
Hz21 = 13,
Hz11 = 14,
Hz3 = 15,
}
impl LowPowerOdr {
#[must_use]
pub const fn hz(self) -> f32 {
match self {
Self::Hz128 => 128.0,
Self::Hz21 => 21.0,
Self::Hz11 => 11.0,
Self::Hz3 => 3.0,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum AccelOdr {
SixDof(Odr),
Standalone(AccelStandaloneOdr),
LowPower(LowPowerOdr),
}
impl Default for AccelOdr {
fn default() -> Self {
Self::SixDof(Odr::Hz224)
}
}
impl AccelOdr {
#[must_use]
pub const fn bits(self) -> u8 {
match self {
Self::SixDof(odr) => odr as u8,
Self::Standalone(odr) => odr as u8,
Self::LowPower(odr) => odr as u8,
}
}
#[must_use]
pub const fn hz(self) -> f32 {
match self {
Self::SixDof(odr) => odr.hz(),
Self::Standalone(odr) => odr.hz(),
Self::LowPower(odr) => odr.hz(),
}
}
#[must_use]
pub const fn is_six_dof(self) -> bool {
matches!(self, Self::SixDof(_))
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum LpfMode {
#[default]
Pct2_66 = 0,
Pct3_63 = 1,
Pct5_39 = 2,
Pct13_37 = 3,
}
impl LpfMode {
pub(crate) const fn from_bits(bits: u8) -> Self {
match bits & 0b11 {
1 => Self::Pct3_63,
2 => Self::Pct5_39,
3 => Self::Pct13_37,
_ => Self::Pct2_66,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum FifoMode {
#[default]
Bypass = 0,
Fifo = 1,
Stream = 2,
}
impl FifoMode {
pub(crate) const fn from_bits(bits: u8) -> Self {
match bits & 0b11 {
1 => Self::Fifo,
2 | 3 => Self::Stream,
_ => Self::Bypass,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum FifoSize {
#[default]
Samples16 = 0,
Samples32 = 1,
Samples64 = 2,
Samples128 = 3,
}
impl FifoSize {
#[must_use]
pub const fn samples(self) -> u16 {
match self {
Self::Samples16 => 16,
Self::Samples32 => 32,
Self::Samples64 => 64,
Self::Samples128 => 128,
}
}
pub(crate) const fn from_bits(bits: u8) -> Self {
match bits & 0b11 {
1 => Self::Samples32,
2 => Self::Samples64,
3 => Self::Samples128,
_ => Self::Samples16,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum Ctrl9Command {
Ack = 0x00,
ResetFifo = 0x04,
RequestFifo = 0x05,
WriteWomSetting = 0x08,
AccelHostDeltaOffset = 0x09,
GyroHostDeltaOffset = 0x0A,
ConfigureTap = 0x0C,
ConfigurePedometer = 0x0D,
ConfigureMotion = 0x0E,
ResetPedometer = 0x0F,
CopyUsid = 0x10,
SetRpu = 0x11,
AhbClockGating = 0x12,
OnDemandCalibration = 0xA2,
ApplyGyroGains = 0xAA,
}
const fn bit(byte: u8, shift: u8) -> bool {
(byte >> shift) & 1 == 1
}
const fn put(condition: bool, shift: u8) -> u8 {
(condition as u8) << shift
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ctrl1 {
pub sim_3wire: bool,
pub addr_ai: bool,
pub big_endian: bool,
pub int2_en: bool,
pub int1_en: bool,
pub fifo_int_on_int1: bool,
pub sensor_disable: bool,
}
impl Default for Ctrl1 {
fn default() -> Self {
Self {
sim_3wire: false,
addr_ai: false,
big_endian: true,
int2_en: false,
int1_en: false,
fifo_int_on_int1: false,
sensor_disable: false,
}
}
}
impl Ctrl1 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.sim_3wire, 7)
| put(self.addr_ai, 6)
| put(self.big_endian, 5)
| put(self.int2_en, 4)
| put(self.int1_en, 3)
| put(self.fifo_int_on_int1, 2)
| put(self.sensor_disable, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
sim_3wire: bit(b, 7),
addr_ai: bit(b, 6),
big_endian: bit(b, 5),
int2_en: bit(b, 4),
int1_en: bit(b, 3),
fifo_int_on_int1: bit(b, 2),
sensor_disable: bit(b, 0),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ctrl2 {
pub self_test: bool,
pub range: AccelRange,
pub odr_bits: u8,
}
impl Ctrl2 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.self_test, 7) | ((self.range as u8) << 4) | (self.odr_bits & 0b1111)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
self_test: bit(b, 7),
range: AccelRange::from_bits(b >> 4),
odr_bits: b & 0b1111,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ctrl3 {
pub self_test: bool,
pub range: GyroRange,
pub odr: Odr,
}
impl Ctrl3 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.self_test, 7) | ((self.range as u8) << 4) | (self.odr as u8)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
self_test: bit(b, 7),
range: GyroRange::from_bits(b >> 4),
odr: Odr::from_bits(b),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ctrl5 {
pub gyro_lpf_mode: LpfMode,
pub gyro_lpf_en: bool,
pub accel_lpf_mode: LpfMode,
pub accel_lpf_en: bool,
}
impl Ctrl5 {
#[must_use]
pub const fn to_bits(self) -> u8 {
((self.gyro_lpf_mode as u8) << 5)
| put(self.gyro_lpf_en, 4)
| ((self.accel_lpf_mode as u8) << 1)
| put(self.accel_lpf_en, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
gyro_lpf_mode: LpfMode::from_bits(b >> 5),
gyro_lpf_en: bit(b, 4),
accel_lpf_mode: LpfMode::from_bits(b >> 1),
accel_lpf_en: bit(b, 0),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ctrl7 {
pub sync_sample: bool,
pub drdy_dis: bool,
pub gyro_snooze: bool,
pub gyro_en: bool,
pub accel_en: bool,
}
impl Ctrl7 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.sync_sample, 7)
| put(self.drdy_dis, 5)
| put(self.gyro_snooze, 4)
| put(self.gyro_en, 1)
| put(self.accel_en, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
sync_sample: bit(b, 7),
drdy_dis: bit(b, 5),
gyro_snooze: bit(b, 4),
gyro_en: bit(b, 1),
accel_en: bit(b, 0),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Ctrl8 {
pub ctrl9_handshake_statusint: bool,
pub activity_on_int1: bool,
pub pedometer_en: bool,
pub sig_motion_en: bool,
pub no_motion_en: bool,
pub any_motion_en: bool,
pub tap_en: bool,
}
impl Ctrl8 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.ctrl9_handshake_statusint, 7)
| put(self.activity_on_int1, 6)
| put(self.pedometer_en, 4)
| put(self.sig_motion_en, 3)
| put(self.no_motion_en, 2)
| put(self.any_motion_en, 1)
| put(self.tap_en, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
ctrl9_handshake_statusint: bit(b, 7),
activity_on_int1: bit(b, 6),
pedometer_en: bit(b, 4),
sig_motion_en: bit(b, 3),
no_motion_en: bit(b, 2),
any_motion_en: bit(b, 1),
tap_en: bit(b, 0),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FifoCtrl {
pub read_mode: bool,
pub size: FifoSize,
pub mode: FifoMode,
}
impl FifoCtrl {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.read_mode, 7) | ((self.size as u8) << 2) | (self.mode as u8)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
read_mode: bit(b, 7),
size: FifoSize::from_bits(b >> 2),
mode: FifoMode::from_bits(b),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FifoStatusReg {
pub full: bool,
pub watermark: bool,
pub overflow: bool,
pub not_empty: bool,
pub sample_count_msb: u8,
}
impl FifoStatusReg {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.full, 7)
| put(self.watermark, 6)
| put(self.overflow, 5)
| put(self.not_empty, 4)
| (self.sample_count_msb & 0b11)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
full: bit(b, 7),
watermark: bit(b, 6),
overflow: bit(b, 5),
not_empty: bit(b, 4),
sample_count_msb: b & 0b11,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct StatusInt {
pub cmd_done: bool,
pub locked: bool,
pub avail: bool,
}
impl StatusInt {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.cmd_done, 7) | put(self.locked, 1) | put(self.avail, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
cmd_done: bit(b, 7),
locked: bit(b, 1),
avail: bit(b, 0),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Status0 {
pub gyro_ready: bool,
pub accel_ready: bool,
}
impl Status0 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.gyro_ready, 1) | put(self.accel_ready, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
gyro_ready: bit(b, 1),
accel_ready: bit(b, 0),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Status1 {
pub significant_motion: bool,
pub no_motion: bool,
pub any_motion: bool,
pub pedometer: bool,
pub wake_on_motion: bool,
pub tap: bool,
}
impl Status1 {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.significant_motion, 7)
| put(self.no_motion, 6)
| put(self.any_motion, 5)
| put(self.pedometer, 4)
| put(self.wake_on_motion, 2)
| put(self.tap, 1)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
significant_motion: bit(b, 7),
no_motion: bit(b, 6),
any_motion: bit(b, 5),
pedometer: bit(b, 4),
wake_on_motion: bit(b, 2),
tap: bit(b, 1),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct CodStatus {
pub x_limit_low_fail: bool,
pub x_limit_high_fail: bool,
pub y_limit_low_fail: bool,
pub y_limit_high_fail: bool,
pub accel_check_fail: bool,
pub startup_failed: bool,
pub gyro_was_enabled: bool,
pub cod_failed: bool,
}
impl CodStatus {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.x_limit_low_fail, 7)
| put(self.x_limit_high_fail, 6)
| put(self.y_limit_low_fail, 5)
| put(self.y_limit_high_fail, 4)
| put(self.accel_check_fail, 3)
| put(self.startup_failed, 2)
| put(self.gyro_was_enabled, 1)
| put(self.cod_failed, 0)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
x_limit_low_fail: bit(b, 7),
x_limit_high_fail: bit(b, 6),
y_limit_low_fail: bit(b, 5),
y_limit_high_fail: bit(b, 4),
accel_check_fail: bit(b, 3),
startup_failed: bit(b, 2),
gyro_was_enabled: bit(b, 1),
cod_failed: bit(b, 0),
}
}
#[must_use]
pub const fn is_success(self) -> bool {
self.to_bits() == 0
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct TapStatusReg {
pub negative_polarity: bool,
pub axis_bits: u8,
pub count_bits: u8,
}
impl TapStatusReg {
#[must_use]
pub const fn to_bits(self) -> u8 {
put(self.negative_polarity, 7) | ((self.axis_bits & 0b11) << 4) | (self.count_bits & 0b11)
}
#[must_use]
pub const fn from_bits(b: u8) -> Self {
Self {
negative_polarity: bit(b, 7),
axis_bits: (b >> 4) & 0b11,
count_bits: b & 0b11,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ctrl1_round_trip() {
for b in [0x00u8, 0x20, 0x58, 0xFD, 0x84] {
assert_eq!(Ctrl1::from_bits(b).to_bits(), b & !0b10);
}
assert_eq!(Ctrl1::default().to_bits(), 0x20);
let c = Ctrl1::from_bits(0x58);
assert!(c.addr_ai && c.int1_en && c.int2_en && !c.big_endian);
}
#[test]
fn ctrl2_round_trip() {
for b in 0..=255u8 {
let expected = (b & 0x8F) | ((b >> 4) & 0b11) << 4;
assert_eq!(Ctrl2::from_bits(b).to_bits(), expected);
}
let c = Ctrl2 {
self_test: true,
range: AccelRange::G8,
odr_bits: AccelOdr::SixDof(Odr::Hz224).bits(),
};
assert_eq!(c.to_bits(), 0xA5);
}
#[test]
fn ctrl3_round_trip() {
for b in [0x00u8, 0x85, 0x78, 0x03] {
assert_eq!(Ctrl3::from_bits(b).to_bits(), b);
}
let c = Ctrl3 {
self_test: false,
range: GyroRange::Dps512,
odr: Odr::Hz224,
};
assert_eq!(c.to_bits(), 0x55);
}
#[test]
fn ctrl5_round_trip() {
for b in 0..=255u8 {
assert_eq!(Ctrl5::from_bits(b).to_bits(), b & 0x77);
}
let c = Ctrl5 {
gyro_lpf_mode: LpfMode::Pct5_39,
gyro_lpf_en: true,
accel_lpf_mode: LpfMode::Pct3_63,
accel_lpf_en: true,
};
assert_eq!(c.to_bits(), 0x53);
}
#[test]
fn ctrl7_round_trip() {
for b in [0x00u8, 0x83, 0x81, 0x82, 0x33, 0xB3] {
assert_eq!(Ctrl7::from_bits(b).to_bits(), b);
}
}
#[test]
fn ctrl8_round_trip() {
for b in 0..=255u8 {
assert_eq!(Ctrl8::from_bits(b).to_bits(), b & 0xDF);
}
}
#[test]
fn fifo_ctrl_round_trip() {
for b in [0x00u8, 0x8E, 0x0D, 0x86] {
assert_eq!(FifoCtrl::from_bits(b).to_bits(), b);
}
assert_eq!(FifoCtrl::from_bits(0x03).mode, FifoMode::Stream);
assert_eq!(FifoCtrl::from_bits(0x03).to_bits(), 0x02);
}
#[test]
fn status_round_trips() {
for b in [0x00u8, 0x83, 0x81] {
assert_eq!(StatusInt::from_bits(b).to_bits(), b);
}
for b in 0..=3u8 {
assert_eq!(Status0::from_bits(b).to_bits(), b);
}
for b in [0x00u8, 0xE0, 0x12, 0xF6] {
assert_eq!(Status1::from_bits(b).to_bits(), b);
}
for b in [0x00u8, 0xF3, 0x83] {
assert_eq!(FifoStatusReg::from_bits(b).to_bits(), b);
}
for b in 0..=255u8 {
assert_eq!(CodStatus::from_bits(b).to_bits(), b);
}
assert!(CodStatus::from_bits(0).is_success());
assert!(!CodStatus::from_bits(1).is_success());
for b in [0x00u8, 0xA2, 0x31, 0xB3] {
assert_eq!(TapStatusReg::from_bits(b).to_bits(), b);
}
}
#[test]
fn scales_match_datasheet() {
assert_eq!(AccelRange::G2.lsb_per_g(), 16384);
assert_eq!(AccelRange::G4.lsb_per_g(), 8192);
assert_eq!(AccelRange::G8.lsb_per_g(), 4096);
assert_eq!(AccelRange::G16.lsb_per_g(), 2048);
assert_eq!(GyroRange::Dps16.lsb_per_dps(), 2048);
assert_eq!(GyroRange::Dps512.lsb_per_dps(), 64);
assert_eq!(GyroRange::Dps2048.lsb_per_dps(), 16);
}
#[test]
fn odr_encodings() {
assert_eq!(Odr::Hz224 as u8, 5);
assert_eq!(AccelOdr::Standalone(AccelStandaloneOdr::Hz1000).bits(), 3);
assert_eq!(AccelOdr::LowPower(LowPowerOdr::Hz3).bits(), 15);
assert!((Odr::Hz28.hz() - 28.025).abs() < 0.001);
assert!((Odr::Hz7174.hz() - 7174.4).abs() < 0.1);
assert!(AccelOdr::SixDof(Odr::Hz112).is_six_dof());
assert!(!AccelOdr::LowPower(LowPowerOdr::Hz128).is_six_dof());
}
#[test]
fn ctrl9_command_values() {
assert_eq!(Ctrl9Command::Ack as u8, 0x00);
assert_eq!(Ctrl9Command::ResetFifo as u8, 0x04);
assert_eq!(Ctrl9Command::RequestFifo as u8, 0x05);
assert_eq!(Ctrl9Command::WriteWomSetting as u8, 0x08);
assert_eq!(Ctrl9Command::ConfigureTap as u8, 0x0C);
assert_eq!(Ctrl9Command::ConfigurePedometer as u8, 0x0D);
assert_eq!(Ctrl9Command::ConfigureMotion as u8, 0x0E);
assert_eq!(Ctrl9Command::AhbClockGating as u8, 0x12);
assert_eq!(Ctrl9Command::OnDemandCalibration as u8, 0xA2);
assert_eq!(Ctrl9Command::ApplyGyroGains as u8, 0xAA);
}
}