#[derive(Debug)]
pub enum Error<E> {
I2C(E),
InvalidSetting,
SelfTestError,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Resolution {
Low,
High,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GScale8 {
G2,
G4,
G8,
G8FP,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum GScale16 {
G4,
G8,
G16,
G16FP,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum OutputDataRate {
Hz0_781,
Hz1_563,
Hz3_125,
Hz6_25,
Hz12_5,
Hz25,
Hz50,
Hz100,
Hz200,
Hz400,
Hz800,
Hz1600,
}
#[derive(Debug, Default, Clone)]
pub struct Measurement {
pub x: f32,
pub y: f32,
pub z: f32,
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct UnscaledMeasurement {
pub x: i16,
pub y: i16,
pub z: i16,
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct InterruptInfo {
pub data_ready: bool,
pub wake_up: bool,
pub wake_up_x_negative: bool,
pub wake_up_x_positive: bool,
pub wake_up_y_negative: bool,
pub wake_up_y_positive: bool,
pub wake_up_z_negative: bool,
pub wake_up_z_positive: bool,
}
#[derive(Debug, Clone, Copy)]
pub struct WakeUpInterruptConfig {
pub trigger_motion: WakeUpTriggerMotion,
pub data_rate: WakeUpOutputDataRate,
pub fault_count: u8,
pub threshold: f32,
}
impl Default for WakeUpInterruptConfig {
fn default() -> Self {
WakeUpInterruptConfig {
trigger_motion: WakeUpTriggerMotion::default(),
data_rate: WakeUpOutputDataRate::default(),
fault_count: 1,
threshold: 0.5,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct WakeUpTriggerMotion {
pub x_negative: bool,
pub x_positive: bool,
pub y_negative: bool,
pub y_positive: bool,
pub z_negative: bool,
pub z_positive: bool,
}
impl Default for WakeUpTriggerMotion {
fn default() -> Self {
WakeUpTriggerMotion {
x_negative: true,
x_positive: true,
y_negative: true,
y_positive: true,
z_negative: true,
z_positive: true,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum WakeUpOutputDataRate {
Hz0_781,
Hz1_563,
Hz3_125,
Hz6_25,
Hz12_5,
Hz25,
Hz50,
Hz100,
}
impl Default for WakeUpOutputDataRate {
fn default() -> Self {
WakeUpOutputDataRate::Hz0_781
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum InterruptPinPolarity {
ActiveLow,
ActiveHigh,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum InterruptPinLatching {
NonLatching,
Latching,
}
#[derive(Debug, Clone, Copy)]
pub enum SlaveAddr {
Default,
Alternative(bool),
}
impl Default for SlaveAddr {
fn default() -> Self {
SlaveAddr::Default
}
}
impl SlaveAddr {
pub(crate) fn addr(self, default: u8) -> u8 {
match self {
SlaveAddr::Default => default,
SlaveAddr::Alternative(a0) => default | a0 as u8,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use DEVICE_BASE_ADDRESS as BASE_ADDR;
#[test]
fn can_get_default_address() {
let addr = SlaveAddr::default();
assert_eq!(BASE_ADDR, addr.addr(BASE_ADDR));
}
#[test]
fn can_generate_alternative_addresses() {
assert_eq!(0b000_1110, SlaveAddr::Alternative(false).addr(BASE_ADDR));
assert_eq!(0b000_1111, SlaveAddr::Alternative(true).addr(BASE_ADDR));
}
}