Struct Lis2dh12

Source
pub struct Lis2dh12<I2C> { /* private fields */ }
Expand description

LIS2DH12 driver

Implementations§

Source§

impl<I2C: I2c> Lis2dh12<I2C>

Source

pub fn new(i2c: I2C, addr: SlaveAddr) -> Result<Self, Error<I2C::Error>>

Create a new LIS2DH12 driver from the given I2C peripheral

Source

pub fn destroy(self) -> I2C

Destroy driver instance, return I2C bus instance

Source

pub fn get_device_id(&mut self) -> Result<u8, Error<I2C::Error>>

WHO_AM_I register

Source

pub fn set_mode(&mut self, mode: Mode) -> Result<(), Error<I2C::Error>>

Operating mode selection, CTRL_REG1: LPen bit, CTRL_REG4: HR bit

Source

pub fn set_odr(&mut self, odr: Odr) -> Result<(), Error<I2C::Error>>

Data rate selection, CTRL_REG1: ODR

Source

pub fn enable_axis( &mut self, (x, y, z): (bool, bool, bool), ) -> Result<(), Error<I2C::Error>>

X,Y,Z-axis enable, CTRL_REG1: Xen, Yen, Zen

Source

pub fn enable_hp_filter( &mut self, click: bool, ia2: bool, ia1: bool, ) -> Result<(), Error<I2C::Error>>

Enable high-pass filter for CLICK/IA2/IA1

Source

pub fn enable_i1_click(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

CLICK interrupt on INT1 pin, CTRL_REG3: I1_CLICK

Source

pub fn enable_i1_ia1(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

IA1 interrupt on INT1 pin, CTRL_REG3: I1_IA1

Source

pub fn enable_i1_ia2(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

IA2 interrupt on INT1 pin, CTRL_REG3: I1_IA2

Source

pub fn enable_i1_zyxda(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

ZYXDA interrupt on INT1 pin, CTRL_REG3: I2_ZYXDA

Source

pub fn enable_i1_wtm(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

FIFO watermark on INT1 pin, CTRL_REG3: I2_ZYXDA

Source

pub fn get_stored_samples(&mut self) -> Result<u8, Error<I2C::Error>>

Get the amount of samples currently stored in the FIFO queue

Source

pub fn enable_i1_overrun( &mut self, enable: bool, ) -> Result<(), Error<I2C::Error>>

FIFO overrun on INT1 pin, CTRL_REG3: I1_OVERRUN

Source

pub fn set_bdu(&mut self, bdu: bool) -> Result<(), Error<I2C::Error>>

Block data update, CTRL_REG4: BDU

Source

pub fn set_fs(&mut self, fs: FullScale) -> Result<(), Error<I2C::Error>>

Full-scale selection, CTRL_REG4: FS

Source

pub fn reboot(&mut self, reboot: bool) -> Result<(), Error<I2C::Error>>

Reboot memory content, CTRL_REG5: BOOT

Source

pub fn in_boot(&mut self) -> Result<bool, Error<I2C::Error>>

In boot, CTRL_REG5: BOOT

Source

pub fn enable_fifo(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

FIFO enable, CTRL_REG5: FIFO_EN

Source

pub fn enable_lir_int1(&mut self, latch: bool) -> Result<(), Error<I2C::Error>>

Latch interrupt request on INT1_SRC (31h), with INT1_SRC (31h) register cleared by reading INT1_SRC (31h) itself, CTRL_REG5: LIR_INT1

Source

pub fn enable_d4d_int1(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

4D enable: 4D detection is enabled on INT1 pin when 6D bit on INT1_CFG (30h) is set to 1, CTRL_REG5: D4D_INT1

Source

pub fn enable_lir_int2(&mut self, latch: bool) -> Result<(), Error<I2C::Error>>

Latch interrupt request on INT2_SRC (35h) register, with INT2_SRC (35h) register cleared by reading INT2_SRC (35h) itself, CTRL_REG5: LIR_INT2

Source

pub fn enable_d4d_int2(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

4D enable: 4D detection is enabled on INT2 pin when 6D bit on INT2_CFG (34h) is set to 1, CTRL_REG5: D4D_INT2

Source

pub fn enable_i2_click(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

CLICK interrupt on INT2 pin, CTRL_REG6: I2_CLICK

Source

pub fn enable_i2_ia1(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

IA1 interrupt on INT2 pin, CTRL_REG6: I2_IA1

Source

pub fn enable_i2_ia2(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

IA2 interrupt on INT2 pin, CTRL_REG6: I2_IA2

Source

pub fn enable_i2_boot(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

Boot interrupt on INT2 pin, CTRL_REG6: I2_BOOT

Source

pub fn enable_i2_act(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

Activity interrupt on INT2 pin, CTRL_REG6: I2_ACT

Source

pub fn set_int_polarity( &mut self, active_low: bool, ) -> Result<(), Error<I2C::Error>>

INT1/INT2 pin polarity, CTRL_REG6: INT_POLARITY

Source

pub fn get_status(&mut self) -> Result<DataStatus, Error<I2C::Error>>

Data status, STATUS_REG: as DataStatus {zyxor: ZYXOR, xyzor: (XOR, YOR, ZOR), zyxda: ZYXDA, xyzda: (XDA, YDA, ZDA)}

Source

pub fn set_fm(&mut self, fm: FifoMode) -> Result<(), Error<I2C::Error>>

FIFO mode selection, FIFO_CTRL_REG: FM

Source

pub fn set_fth(&mut self, fth: u8) -> Result<(), Error<I2C::Error>>

FIFO threshold, FIFO_CTRL_REG: FTH

Source

pub fn disable_click(&mut self) -> Result<(), Error<I2C::Error>>

Disable click interrupt, CLICK_CFG clean all bits

Source

pub fn enable_double_click( &mut self, (x, y, z): (bool, bool, bool), ) -> Result<(), Error<I2C::Error>>

Enable interrupt double-click on X,Y,Z axis, CLICK_CFG: XD, YD, ZD

Source

pub fn enable_single_click( &mut self, (x, y, z): (bool, bool, bool), ) -> Result<(), Error<I2C::Error>>

Enable interrupt single-click on X,Y,Z axis, CLICK_CFG: XS, YS, ZS

Source

pub fn get_click_src( &mut self, ) -> Result<Option<((bool, bool), bool, (bool, bool, bool))>, Error<I2C::Error>>

Click source, CLICK_SRC decoded as ((DClick, SClick), Sign, (X, Y, Z))

Source

pub fn enable_lir_click(&mut self, latch: bool) -> Result<(), Error<I2C::Error>>

If the LIR_Click bit is not set, the interrupt is kept high for the duration of the latency window. If the LIR_Click bit is set, the interrupt is kept high until the CLICK_SRC (39h) register is read. CLICK_THS: LIR_Click

Source

pub fn set_click_ths(&mut self, ths: u8) -> Result<(), Error<I2C::Error>>

Click threshold, CLICK_THS: Ths

Source

pub fn set_click_thsf(&mut self, ths: f32) -> Result<(), Error<I2C::Error>>

Click threshold as f32, CLICK_THS: Ths

Source

pub fn set_time_limit(&mut self, tli: u8) -> Result<(), Error<I2C::Error>>

Click time limit, TIME_LIMIT: TLI

Source

pub fn set_time_latency(&mut self, tla: u8) -> Result<(), Error<I2C::Error>>

Click time latency, TIME_LATENCY: TLA

Source

pub fn set_time_window(&mut self, tw: u8) -> Result<(), Error<I2C::Error>>

Click time window, TIME_WINDOW: TW

Source

pub fn set_act_ths(&mut self, ths: u8) -> Result<(), Error<I2C::Error>>

Sleep-to-wake, return-to-sleep activation threshold in low-power mode, ACT_THS: Acth

Source

pub fn set_act_thsf(&mut self, ths: f32) -> Result<(), Error<I2C::Error>>

Sleep-to-wake, return-to-sleep activation threshold as f32, ACT_THS: Acth

Source

pub fn set_act_dur(&mut self, d: u8) -> Result<(), Error<I2C::Error>>

Sleep-to-wake, return-to-sleep duration, ACT_DUR: ActD

Source

pub fn enable_temp(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

Temperature sensor enable, TEMP_CFG_REG: TEMP_EN, the BDU bit in CTRL_REG4 is also set

Source

pub fn get_temp_status(&mut self) -> Result<(bool, bool), Error<I2C::Error>>

Temperature data status, STATUS_REG_AUX: TOR - Temperature data overrun, TDA - Temperature new data available

Source

pub fn get_temp_out(&mut self) -> Result<(i8, u8), Error<I2C::Error>>

Temperature sensor data, OUT_TEMP_H, OUT_TEMP_L

Source

pub fn get_temp_outf(&mut self) -> Result<f32, Error<I2C::Error>>

Temperature sensor data as float, OUT_TEMP_H, OUT_TEMP_L converted to f32

Source

pub fn set_ref(&mut self, reference: u8) -> Result<(), Error<I2C::Error>>

REFERENCE register

Source

pub fn get_ref(&mut self) -> Result<u8, Error<I2C::Error>>

REFERENCE register

Source

pub fn int1(&mut self) -> Int<'_, Int1Regs, I2C>

INT1

Source

pub fn int2(&mut self) -> Int<'_, Int2Regs, I2C>

INT2

Source

pub fn reset(&mut self) -> Result<(), Error<I2C::Error>>

Resets all registers to their default

Source

pub fn enable_st0(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

Enable self test 0, this shouldn’t be enabled at the same time as self test 1

Source

pub fn enable_st1(&mut self, enable: bool) -> Result<(), Error<I2C::Error>>

Enable self test 1, this shouldn’t be enabled at the same time as self test 0

Source

pub fn dump_regs<W>(&mut self, w: &mut W) -> Result<(), Error<I2C::Error>>
where W: Write,

Dump registers

Trait Implementations§

Source§

impl<I2C: I2c> Accelerometer for Lis2dh12<I2C>

Source§

fn accel_norm(&mut self) -> Result<F32x3, Error<Self::Error>>

Get normalized ±g reading from the accelerometer

Source§

fn sample_rate(&mut self) -> Result<f32, Error<Self::Error>>

Get sample rate of accelerometer in Hz

Source§

type Error = <I2C as ErrorType>::Error

Error type
Source§

impl<I2C: I2c> RawAccelerometer<I16x3> for Lis2dh12<I2C>

Source§

fn accel_raw(&mut self) -> Result<I16x3, Error<Self::Error>>

Get acceleration reading from the accelerometer

Source§

type Error = <I2C as ErrorType>::Error

Error type

Auto Trait Implementations§

§

impl<I2C> Freeze for Lis2dh12<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Lis2dh12<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Lis2dh12<I2C>
where I2C: Send,

§

impl<I2C> Sync for Lis2dh12<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Lis2dh12<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Lis2dh12<I2C>
where I2C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.