#![doc = include_str!("../README.md")]
#![no_std]
#![deny(missing_docs)]
#[cfg(feature = "async")]
mod asynch;
mod register;
#[cfg(not(feature = "async"))]
mod sync;
pub use register::*;
pub struct Lis2dh<I2C> {
i2c: I2C,
addr: u8,
}
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error<I2cError> {
I2c(I2cError),
WriteToReadOnly,
InvalidParameter,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Sa0Pad {
Low = 0,
High = 1,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Mode {
LowPower,
Normal,
HighResolution,
}
#[derive(Copy, Clone)]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FullScale {
Fs2g = 0x00,
Fs4g = 0x10,
Fs8g = 0x20,
Fs16g = 0x30,
}
#[derive(Copy, Clone)]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OutputDataRate {
PowerDown = 0x00,
Hz1 = 0x10,
Hz10 = 0x20,
Hz25 = 0x30,
Hz50 = 0x40,
Hz100 = 0x50,
Hz200 = 0x60,
Hz400 = 0x70,
HighSpeed = 0x80,
HighestSpeed = 0x90,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Status {
pub xyz_overrun: bool,
pub z_overrun: bool,
pub y_overrun: bool,
pub x_overrun: bool,
pub xyz_data_available: bool,
pub z_data_available: bool,
pub y_data_available: bool,
pub x_data_available: bool,
pub temp_overrun: bool,
pub temp_data_available: bool,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum HighPassFilterMode {
NormalModeWithReset = 0x00,
ReferenceSignal = 0x40,
NormalMode = 0x80,
AutoResetOnInterrupt = 0xC0,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(missing_docs)]
#[repr(u8)]
pub enum HighPassCutoffFrequencySelection {
Cfg0 = 0x00,
Cfg1 = 0x10,
Cfg2 = 0x20,
Cfg3 = 0x30,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum HighPassFilterDataSelection {
Bypassed = 0x00,
SendDataFromFilter = 0x08,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct HighPassFilterConfig {
pub mode: HighPassFilterMode,
pub cutoff_frequency: HighPassCutoffFrequencySelection,
pub data_selection: HighPassFilterDataSelection,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum IntPin {
Int1,
Int2,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FifoConfig {
Bypass,
Fifo,
Stream {
watermark: u8,
},
StreamToFifo {
pin: IntPin,
},
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FifoStatus {
pub watermark_exceeded: bool,
pub full: bool,
pub empty: bool,
pub sample_count: u8,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum MovementIntMode {
OrCombination = 0x00,
MovementRecognition = 0x40,
AndCombination = 0x80,
PositionRecognition = 0xC0,
}
#[derive(Copy, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MovementInterrupts {
pub x_high: bool,
pub x_low: bool,
pub y_high: bool,
pub y_low: bool,
pub z_high: bool,
pub z_low: bool,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MovementIntConfig {
pub mode: MovementIntMode,
pub enable: MovementInterrupts,
pub threshold: u8,
pub duration: u8,
pub latch: bool,
pub only_4d: bool,
pub high_pass_filter: bool,
}
#[derive(Copy, Clone, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ClickInterrupts {
pub x_single: bool,
pub x_double: bool,
pub y_single: bool,
pub y_double: bool,
pub z_single: bool,
pub z_double: bool,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ClickIntConfig {
pub enable: ClickInterrupts,
pub threshold: u8,
pub time_limit: u8,
pub time_latency: u8,
pub time_window: u8,
pub latch: bool,
pub high_pass_filter: bool,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ClickIntSrc {
pub x: bool,
pub y: bool,
pub z: bool,
pub positive: bool,
pub single_click_enabled: bool,
pub double_click_enabled: bool,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ActivityIntConfig {
pub threshold: u8,
pub duration: u8,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Int1Config {
Unused,
Click(ClickIntConfig),
MovementInt1(MovementIntConfig),
MovementInt2(MovementIntConfig),
DataAvailableXYZ,
FifoWatermark,
FifoOverrun,
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Int2Config {
Unused,
Click(ClickIntConfig),
MovementInt1(MovementIntConfig),
MovementInt2(MovementIntConfig),
Boot,
Activity(ActivityIntConfig),
}
#[derive(Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum IntPolarity {
ActiveHigh,
ActiveLow,
}
#[derive(Copy, Clone, Default)]
pub struct AccelerationData {
pub x: i16,
pub y: i16,
pub z: i16,
}
#[cfg(feature = "defmt")]
impl defmt::Format for AccelerationData {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "({}, {}, {})", self.x, self.y, self.z)
}
}