pub struct Lis3dh<CORE> { /* private fields */ }
Expand description
LIS3DH
driver.
Implementations§
Source§impl<I2C, E> Lis3dh<Lis3dhI2C<I2C>>where
I2C: I2c<Error = E>,
impl<I2C, E> Lis3dh<Lis3dhI2C<I2C>>where
I2C: I2c<Error = E>,
Sourcepub async fn new_i2c(i2c: I2C, address: SlaveAddr) -> Result<Self, Error<E>>
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.
Sourcepub async fn new_i2c_without_config(i2c: I2C, address: SlaveAddr) -> Self
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.
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>,
impl<SPI, ESPI> Lis3dh<Lis3dhSPI<SPI>>where
SPI: SpiDevice<Error = ESPI>,
Sourcepub async fn new_spi(spi: SPI) -> Result<Self, Error<ESPI>>
pub async fn new_spi(spi: SPI) -> Result<Self, Error<ESPI>>
Create a new LIS3DH driver from the given SPI peripheral.
Sourcepub async fn new_spi_without_config(spi: SPI) -> Self
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.
pub async fn new_spi_with_config( spi: SPI, config: Configuration, ) -> Result<Self, Error<ESPI>>
Source§impl<CORE> Lis3dh<CORE>where
CORE: Lis3dhCore,
impl<CORE> Lis3dh<CORE>where
CORE: Lis3dhCore,
Sourcepub async fn configure(
&mut self,
conf: Configuration,
) -> Result<(), Error<CORE::BusError>>
pub async fn configure( &mut self, conf: Configuration, ) -> Result<(), Error<CORE::BusError>>
Configure the device
Sourcepub async fn set_mode(
&mut self,
mode: Mode,
) -> Result<(), Error<CORE::BusError>>
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.
From | To | Wait for |
---|---|---|
HighResolution | LowPower | 1/datarate |
HighResolution | Normal | 1/datarate |
Normal | LowPower | 1/datarate |
Normal | HighResolution | 7/datarate |
LowPower | Normal | 1/datarate |
LowPower | HighResolution | 7/datarate |
Sourcepub async fn get_mode(&mut self) -> Result<Mode, Error<CORE::BusError>>
pub async fn get_mode(&mut self) -> Result<Mode, Error<CORE::BusError>>
Read the current operating mode.
Sourcepub async fn set_datarate(
&mut self,
datarate: DataRate,
) -> Result<(), Error<CORE::BusError>>
pub async fn set_datarate( &mut self, datarate: DataRate, ) -> Result<(), Error<CORE::BusError>>
Data rate selection.
Sourcepub async fn get_datarate(&mut self) -> Result<DataRate, Error<CORE::BusError>>
pub async fn get_datarate(&mut self) -> Result<DataRate, Error<CORE::BusError>>
Read the current data selection rate.
Sourcepub async fn set_range(
&mut self,
range: Range,
) -> Result<(), Error<CORE::BusError>>
pub async fn set_range( &mut self, range: Range, ) -> Result<(), Error<CORE::BusError>>
Full-scale selection.
Sourcepub async fn get_range(&mut self) -> Result<Range, Error<CORE::BusError>>
pub async fn get_range(&mut self) -> Result<Range, Error<CORE::BusError>>
Read the current full-scale.
Sourcepub async fn set_ref(
&mut self,
reference: u8,
) -> Result<(), Error<CORE::BusError>>
pub async fn set_ref( &mut self, reference: u8, ) -> Result<(), Error<CORE::BusError>>
Set REFERENCE
register.
Sourcepub async fn get_ref(&mut self) -> Result<u8, Error<CORE::BusError>>
pub async fn get_ref(&mut self) -> Result<u8, Error<CORE::BusError>>
Read the REFERENCE
register.
Sourcepub async fn get_status(&mut self) -> Result<DataStatus, Error<CORE::BusError>>
pub async fn get_status(&mut self) -> Result<DataStatus, Error<CORE::BusError>>
Accelerometer data-available status.
Sourcepub async fn is_data_ready(&mut self) -> Result<bool, Error<CORE::BusError>>
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.
Sourcepub async fn enable_temp(
&mut self,
enable: bool,
) -> Result<(), Error<CORE::BusError>>
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.
Sourcepub async fn get_temp_out(&mut self) -> Result<i16, Error<CORE::BusError>>
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.
Sourcepub async fn get_temp_outf(&mut self) -> Result<f32, Error<CORE::BusError>>
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.
Sourcepub async fn register_clear_bits(
&mut self,
reg: Register,
bits: u8,
) -> Result<(), Error<CORE::BusError>>
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.
Sourcepub async fn register_set_bits(
&mut self,
reg: Register,
bits: u8,
) -> Result<(), Error<CORE::BusError>>
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.
Sourcepub async fn configure_interrupt_pin<P: IrqPin>(
&mut self,
pin: P,
) -> Result<(), Error<CORE::BusError>>
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()
})?;
Sourcepub async fn configure_irq_src<I: Interrupt>(
&mut self,
int: I,
interrupt_mode: InterruptMode,
interrupt_config: InterruptConfig,
) -> Result<(), Error<CORE::BusError>>
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(),
)?;
Sourcepub 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>>
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,
)?;
Sourcepub async fn configure_irq_duration<I: Interrupt>(
&mut self,
_int: I,
duration: Duration,
) -> Result<(), Error<CORE::BusError>>
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);
Sourcepub async fn configure_irq_threshold<I: Interrupt>(
&mut self,
_int: I,
threshold: Threshold,
) -> Result<(), Error<CORE::BusError>>
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);
Sourcepub async fn get_irq_src<I: Interrupt>(
&mut self,
_int: I,
) -> Result<InterruptSource, Error<CORE::BusError>>
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.
Sourcepub async fn configure_switch_to_low_power(
&mut self,
threshold: Threshold,
duration: Duration,
) -> Result<(), Error<CORE::BusError>>
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)?;
Sourcepub async fn reboot_memory_content(
&mut self,
) -> Result<(), Error<CORE::BusError>>
pub async fn reboot_memory_content( &mut self, ) -> Result<(), Error<CORE::BusError>>
Reboot memory content
Sourcepub async fn enable_fifo(
&mut self,
mode: FifoMode,
threshold: u8,
) -> Result<(), Error<CORE::BusError>>
pub async fn enable_fifo( &mut self, mode: FifoMode, threshold: u8, ) -> Result<(), Error<CORE::BusError>>
Configures FIFO and then enables it
Sourcepub async fn disable_fifo(&mut self) -> Result<(), Error<CORE::BusError>>
pub async fn disable_fifo(&mut self) -> Result<(), Error<CORE::BusError>>
Disable FIFO. This resets the FIFO state
Sourcepub async fn get_fifo_status(
&mut self,
) -> Result<FifoStatus, Error<CORE::BusError>>
pub async fn get_fifo_status( &mut self, ) -> Result<FifoStatus, Error<CORE::BusError>>
Get the status of the FIFO
Sourcepub async fn accel_norm(&mut self) -> Result<F32x3, Error<CORE::BusError>>
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
.