Struct lsm6dsox::Lsm6dsox

source ·
pub struct Lsm6dsox<I2C, Delay>
where I2C: Write + WriteRead, Delay: DelayMs<u32>,
{ /* private fields */ }
Expand description

Representation of a LSM6DSOX. Stores the address and device peripherals.

Implementations§

source§

impl<I2C, Delay> Lsm6dsox<I2C, Delay>
where I2C: Write + WriteRead, Delay: DelayMs<u32>,

source

pub fn set_accel_sample_rate( &mut self, data_rate: DataRate ) -> Result<(), Error>

Sets the measurement output rate.

source

pub fn set_accel_scale( &mut self, scale: AccelerometerScale ) -> Result<(), Error>

Sets the acceleration measurement range.

Values up to this scale will be reported correctly.

source

pub fn setup_tap_detection( &mut self, tap_cfg: TapCfg, tap_mode: TapMode, int_line: Option<InterruptLine> ) -> Result<(), Error>

Sets up double-tap recognition and enables Interrupts on INT2 pin.

Configures everything necessary to reasonable defaults. This includes setting the accelerometer scale to 2G, configuring power modes, setting values for thresholds and optionally mapping a interrupt pin, maps only single-tap or double-tap to the pin.

source

pub fn check_tap(&mut self) -> Result<BitFlags<TapSource>, Error>

Checks the tap source register.

  • The Register will be cleared according to the LIR setting.
  • The interrupt flag will be cleared after this check, or according to the LIR mode.
  • If LIR is set to False the interrupt will be set for the quiet-time window and clears automatically after that.
source

pub fn set_tap_threshold(&mut self, x: u8, y: u8, z: u8) -> Result<(), Error>

Sets the tap Threshold for each individual axis.

[…] [These registers] are used to select the unsigned threshold value used to detect the tap event on the respective axis. The value of 1 LSB of these 5 bits depends on the selected accelerometer full scale: 1 LSB = (FS_XL)/(2⁵). The unsigned threshold is applied to both positive and negative slope data.1


  1. Definition from the LSM6DSOX Application Note 

source

pub fn set_tap_duration(&mut self, dur: u8) -> Result<(), Error>

Sets the duration of maximum time gap for double tap recognition. Default value: 0b0000

In the double-tap case, the Duration time window defines the maximum time between two consecutive detected taps. The Duration time period starts just after the completion of the Quiet time of the first tap. The DUR[3:0] bits of the INT_DUR2 register are used to set the Duration time window value: the default value of these bits is 0000b and corresponds to 16/ODR_XL time, where ODR_XL is the accelerometer output data rate. If the DUR[3:0] bits are set to a different value, 1 LSB corresponds to 32/ODR_XL time.1


  1. Definition from the LSM6DSOX Application Note 

source

pub fn set_tap_quiet(&mut self, quiet: u8) -> Result<(), Error>

Sets the expected quiet time after a tap detection. Default value: 0b00

In the double-tap case, the Quiet time window defines the time after the first tap recognition in which there must not be any overcoming threshold event. When latched mode is disabled (LIR bit of TAP_CFG is set to 0), the Quiet time also defines the length of the interrupt pulse (in both single and double-tap case).1

The QUIET[1:0] bits of the INT_DUR2 register are used to set the Quiet time window value: the default value of these bits is 00b and corresponds to 2/ODR_XL time, where ODR_XL is the accelerometer output data rate. If the QUIET[1:0] bits are set to a different value, 1 LSB corresponds to 4/ODR_XL time.1


  1. Definition from the LSM6DSOX Application Note 

source

pub fn set_tap_shock(&mut self, shock: u8) -> Result<(), Error>

Sets the maximum duration of the over-threshold event. Default value: 0b00

The Shock time window defines the maximum duration of the overcoming threshold event: the acceleration must return below the threshold before the Shock window has expired, otherwise the tap event is not detected. The SHOCK[1:0] bits of the INT_DUR2 register are used to set the Shock time window value: the default value of these bits is 00b and corresponds to 4/ODR_XL time, where ODR_XL is the accelerometer output data rate. If the SHOCK[1:0] bits are set to a different value, 1 LSB corresponds to 8/ODR_XL time.1


  1. Definition from the LSM6DSOX Application Note 

source§

impl<I2C, Delay> Lsm6dsox<I2C, Delay>
where I2C: Write + WriteRead, Delay: DelayMs<u32>,

source

pub fn set_gyro_sample_rate(&mut self, data_rate: DataRate) -> Result<(), Error>

Sets the measurement output rate.

Note: DataRate::Freq1Hz6 is not supported by the gyroscope and will yield an Error::InvalidData.

source

pub fn set_gyro_scale(&mut self, scale: GyroscopeScale) -> Result<(), Error>

Sets the gyroscope measurement range.

Values up to this scale will be reported correctly.

source

pub fn angular_rate(&mut self) -> Result<AngularRate, Error>

Get a angular rate reading.

If no data is ready returns the appropriate Error.

source

pub fn angular_rate_raw(&mut self) -> Result<RawAngularRate, Error>

Get a raw angular rate reading.

If no data is ready returns the appropriate Error.

source§

impl<I2C, Delay> Lsm6dsox<I2C, Delay>
where I2C: Write + WriteRead, Delay: DelayMs<u32>,

source

pub fn new(i2c: I2C, address: SlaveAddress, delay: Delay) -> Self

Create a new instance of this sensor.

source

pub fn destroy(self) -> (I2C, Delay)

Destroy the sensor and return the hardware peripherals

source

pub fn check_id(&mut self) -> Result<u8, Option<u8>>

Check whether the configured Sensor returns its correct id.

Returns Ok(id) if id matches the Standard LSM6DSOX id, Err(Some(id)) or Err(None) if id doesn’t match or couldn’t be read.

source

pub fn setup(&mut self) -> Result<(), Error>

Initializes the sensor.

A software reset is performed and common settings are applied. The accelerometer and gyroscope are initialized with DataRate::PowerDown.

source

pub fn check_interrupt_sources( &mut self ) -> Result<BitFlags<InterruptCause>, Error>

Checks the interrupt status of all possible sources.

The interrupt flags will be cleared after this check, or according to the LIR mode of the specific source.

source

pub fn power_down_mode(&mut self) -> Result<(), Error>

Sets both Accelerometer and Gyroscope in power-down mode.

source

pub fn map_interrupt( &mut self, int_src: InterruptSource, int_line: InterruptLine, active: bool ) -> Result<(), Error>

Maps an available interrupt source to a available interrupt line.

Toggles whether a interrupt source will generate interrupts on the specified line.

Note: Interrupt sources SHUB and Timestamp are not available on both interrupt lines.

Interrupts need to be enabled globally for a mapping to take effect. See Lsm6dsox::enable_interrupts().

source

pub fn enable_interrupts(&mut self, enabled: bool) -> Result<(), Error>

Enable basic interrupts

Enables/disables interrupts for 6D/4D, free-fall, wake-up, tap, inactivity.

source

pub unsafe fn register_access(&mut self) -> &mut RegisterAccess<I2C>

Gives direct access to the internal sensor registers

§Safety

Directly accessing the internal registers may misconfigure the sensor or invalidate some of the assumptions made in the driver implementation. It is mainly provided to allow configuring the machine learning core with a configuration generated from an external tool but it may also be useful for testing, debugging, prototyping or to use features which have not been implemented on a higher level.

Trait Implementations§

source§

impl<I2C, Delay> Accelerometer for Lsm6dsox<I2C, Delay>
where I2C: Write + WriteRead, Delay: DelayMs<u32>,

§

type Error = Error

Error type
source§

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

Get normalized ±g reading from the accelerometer. Read more
source§

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

Get sample rate of accelerometer data. Read more
source§

impl<I2C, Delay> RawAccelerometer<I16x3> for Lsm6dsox<I2C, Delay>
where I2C: Write + WriteRead, Delay: DelayMs<u32>,

§

type Error = Error

Error type
source§

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

Get raw acceleration data from the accelerometer

Auto Trait Implementations§

§

impl<I2C, Delay> RefUnwindSafe for Lsm6dsox<I2C, Delay>
where Delay: RefUnwindSafe, I2C: RefUnwindSafe,

§

impl<I2C, Delay> Send for Lsm6dsox<I2C, Delay>
where Delay: Send, I2C: Send,

§

impl<I2C, Delay> Sync for Lsm6dsox<I2C, Delay>
where Delay: Sync, I2C: Sync,

§

impl<I2C, Delay> Unpin for Lsm6dsox<I2C, Delay>
where Delay: Unpin, I2C: Unpin,

§

impl<I2C, Delay> UnwindSafe for Lsm6dsox<I2C, Delay>
where Delay: UnwindSafe, 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

§

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.