Struct lis3dh_async::Lis3dh

source ·
pub struct Lis3dh<CORE> { /* private fields */ }
Expand description

LIS3DH driver.

Implementations§

source§

impl<I2C, E> Lis3dh<Lis3dhI2C<I2C>>
where I2C: I2c<Error = E>,

source

pub async fn new_i2c(i2c: I2C, address: SlaveAddr) -> Result<Self, Error<E>>

Create a new LIS3DH driver from the given I2C peripheral using the default config. Default is Hz_400 HighResolution.

source

pub async fn new_i2c_without_config(i2c: I2C, address: SlaveAddr) -> Self

Create a new driver instance without talking to the LIS3DH. This can be useful when the accelerometer was already on while the microcontroller rebooted and you need continuous operation.

source

pub async fn new_i2c_with_config( i2c: I2C, address: SlaveAddr, config: Configuration ) -> Result<Self, Error<E>>

source§

impl<SPI, ESPI> Lis3dh<Lis3dhSPI<SPI>>
where SPI: SpiDevice<Error = ESPI>,

source

pub async fn new_spi(spi: SPI) -> Result<Self, Error<ESPI>>

Create a new LIS3DH driver from the given SPI peripheral.

source

pub async fn new_spi_without_config(spi: SPI) -> Self

Create a new driver instance without talking to the LIS3DH. This can be useful when the accelerometer was already on while the microcontroller rebooted and you need continuous operation.

source

pub async fn new_spi_with_config( spi: SPI, config: Configuration ) -> Result<Self, Error<ESPI>>

source§

impl<CORE> Lis3dh<CORE>
where CORE: Lis3dhCore,

source

pub async fn configure( &mut self, conf: Configuration ) -> Result<(), Error<CORE::BusError>>

Configure the device

source

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

WHO_AM_I register.

source

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

Operating mode selection. CTRL_REG1: LPen bit, CTRL_REG4: HR bit. You need to wait for stabilization after setting. In future this function will be deprecated and instead take a Delay to do this for you.

FromToWait for
HighResolutionLowPower1/datarate
HighResolutionNormal1/datarate
NormalLowPower1/datarate
NormalHighResolution7/datarate
LowPowerNormal1/datarate
LowPowerHighResolution7/datarate
source

pub async fn get_mode(&mut self) -> Result<Mode, Error<CORE::BusError>>

Read the current operating mode.

source

pub async fn set_datarate( &mut self, datarate: DataRate ) -> Result<(), Error<CORE::BusError>>

Data rate selection.

source

pub async fn get_datarate(&mut self) -> Result<DataRate, Error<CORE::BusError>>

Read the current data selection rate.

source

pub async fn set_range( &mut self, range: Range ) -> Result<(), Error<CORE::BusError>>

Full-scale selection.

source

pub async fn get_range(&mut self) -> Result<Range, Error<CORE::BusError>>

Read the current full-scale.

source

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

Set REFERENCE register.

source

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

Read the REFERENCE register.

source

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

Accelerometer data-available status.

source

pub async fn is_data_ready(&mut self) -> Result<bool, Error<CORE::BusError>>

Convenience function for STATUS_REG to confirm all three X, Y and Z-axis have new data available for reading by accel_raw and associated function calls.

source

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

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

source

pub async fn get_temp_out(&mut self) -> Result<i16, Error<CORE::BusError>>

Raw temperature sensor data as i16. The temperature sensor must be enabled via enable_temp prior to reading.

source

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

Temperature sensor data converted to f32. Output is in degree celsius. The temperature sensor must be enabled via enable_temp prior to reading.

source

pub async fn register_clear_bits( &mut self, reg: Register, bits: u8 ) -> Result<(), Error<CORE::BusError>>

Clear the given bits in the given register. For example:

lis3dh.register_clear_bits(0b0110)

This call clears (sets to 0) the bits at index 1 and 2. Other bits of the register are not touched.

source

pub async fn register_set_bits( &mut self, reg: Register, bits: u8 ) -> Result<(), Error<CORE::BusError>>

Set the given bits in the given register. For example:

lis3dh.register_set_bits(0b0110)

This call sets to 1 the bits at index 1 and 2. Other bits of the register are not touched.

source

pub async fn configure_interrupt_pin<P: IrqPin>( &mut self, pin: P ) -> Result<(), Error<CORE::BusError>>

Configure one of the interrupt pins

lis3dh.configure_interrupt_pin(IrqPin1Config {
    // Raise if interrupt 1 is raised
    ia1_en: true,
    // Disable for all other interrupts
    ..IrqPin1Config::default()
})?;
source

pub async fn configure_irq_src<I: Interrupt>( &mut self, int: I, interrupt_mode: InterruptMode, interrupt_config: InterruptConfig ) -> Result<(), Error<CORE::BusError>>

Configure an IRQ source

Example: configure interrupt 1 to fire when there is movement along any of the axes.

lis3dh.configure_irq_src(
    lis3dh::Interrupt1,
    lis3dh::InterruptMode::Movement,
    lis3dh::InterruptConfig::high_and_low(),
)?;
source

pub async fn configure_irq_src_and_control<I: Interrupt>( &mut self, _int: I, interrupt_mode: InterruptMode, interrupt_config: InterruptConfig, latch_interrupt_request: LatchInterruptRequest, detect_4d: Detect4D ) -> Result<(), Error<CORE::BusError>>

Configure an IRQ source.

LIS (latch interrupt request) will latch (keep active) the interrupt until the Lis3dh::get_irq_src is read.

4D detection is a subset of the 6D detection where detection on the Z axis is disabled. This setting only has effect when the interrupt mode is either Movement or Position.

Example: configure interrupt 1 to fire when there is movement along any of the axes.

lis3dh.configure_irq_src(
    lis3dh::Interrupt1,
    lis3dh::InterruptMode::Movement,
    lis3dh::InterruptConfig::high_and_low(),
    lis3dh::LatchInterruptRequest::Enable,
    lis3dh::Detect4D::Enable,
)?;
source

pub async fn configure_irq_duration<I: Interrupt>( &mut self, _int: I, duration: Duration ) -> Result<(), Error<CORE::BusError>>

Set the minimum duration for the Interrupt event to be recognized.

Example: the event has to last at least 25 miliseconds to be recognized.

// let mut lis3dh = ...
let duration = Duration::miliseconds(DataRate::Hz_400, 25.0);
lis3dh.configure_irq_duration(duration);
source

pub async fn configure_irq_threshold<I: Interrupt>( &mut self, _int: I, threshold: Threshold ) -> Result<(), Error<CORE::BusError>>

Set the minimum magnitude for the Interrupt event to be recognized.

Example: the event has to have a magnitude of at least 1.1g to be recognized.

// let mut lis3dh = ...
let threshold = Threshold::g(Range::G2, 1.1);
lis3dh.configure_irq_threshold(threshold);
source

pub async fn get_irq_src<I: Interrupt>( &mut self, _int: I ) -> Result<InterruptSource, Error<CORE::BusError>>

Get interrupt source. The interrupt_active field is true when an interrupt is active. The other fields specify what measurement caused the interrupt.

source

pub async fn configure_switch_to_low_power( &mut self, threshold: Threshold, duration: Duration ) -> Result<(), Error<CORE::BusError>>

Configure ‘Sleep to wake’ and ‘Return to sleep’ threshold and duration.

The LIS3DH can be programmed to automatically switch to low-power mode upon recognition of a determined event.
Once the event condition is over, the device returns back to the preset normal or highresolution mode.

Example: enter low-power mode. When a measurement above 1.1g is registered, then wake up for 25ms to send the data.

// let mut lis3dh = ...

let range = Range::default();
let data_rate = DataRate::Hz_400;

let threshold = Threshold::g(range, 1.1);
let duration = Duration::miliseconds(data_rate, 25.0);

lis3dh.configure_switch_to_low_power(threshold, duration)?;

lis3dh.set_datarate(data_rate)?;
source

pub async fn reboot_memory_content( &mut self ) -> Result<(), Error<CORE::BusError>>

Reboot memory content

source

pub async fn enable_fifo( &mut self, mode: FifoMode, threshold: u8 ) -> Result<(), Error<CORE::BusError>>

Configures FIFO and then enables it

source

pub async fn disable_fifo(&mut self) -> Result<(), Error<CORE::BusError>>

Disable FIFO. This resets the FIFO state

source

pub async fn get_fifo_status( &mut self ) -> Result<FifoStatus, Error<CORE::BusError>>

Get the status of the FIFO

source

pub async fn accel_norm(&mut self) -> Result<F32x3, Error<CORE::BusError>>

Get normalized ±g reading from the accelerometer. You should be reading based on data ready interrupt or if reading in a tight loop you should waiting for is_data_ready.

source

pub async fn sample_rate(&mut self) -> Result<f32, Error<CORE::BusError>>

Get the sample rate of the accelerometer data.

source

pub async fn accel_raw(&mut self) -> Result<I16x3, Error<CORE::BusError>>

Get raw acceleration data from the accelerometer. You should be reading based on data ready interrupt or if reading in a tight loop you should waiting for is_data_ready.

Trait Implementations§

source§

impl<CORE> Lis3dhCore for Lis3dh<CORE>
where CORE: Lis3dhCore,

§

type BusError = <CORE as Lis3dhCore>::BusError

source§

async fn write_register( &mut self, register: Register, value: u8 ) -> Result<(), Error<Self::BusError>>

source§

async fn read_register( &mut self, register: Register ) -> Result<u8, Error<Self::BusError>>

source§

async fn read_accel_bytes(&mut self) -> Result<[u8; 6], Error<Self::BusError>>

Auto Trait Implementations§

§

impl<CORE> RefUnwindSafe for Lis3dh<CORE>
where CORE: RefUnwindSafe,

§

impl<CORE> Send for Lis3dh<CORE>
where CORE: Send,

§

impl<CORE> Sync for Lis3dh<CORE>
where CORE: Sync,

§

impl<CORE> Unpin for Lis3dh<CORE>
where CORE: Unpin,

§

impl<CORE> UnwindSafe for Lis3dh<CORE>
where CORE: 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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.