pub struct Lsm6dsox<I2C, Delay>{ /* private fields */ }
Expand description
Representation of a LSM6DSOX. Stores the address and device peripherals.
Implementations§
source§impl<I2C, Delay> Lsm6dsox<I2C, Delay>
impl<I2C, Delay> Lsm6dsox<I2C, Delay>
sourcepub fn set_accel_sample_rate(
&mut self,
data_rate: DataRate
) -> Result<(), Error>
pub fn set_accel_sample_rate( &mut self, data_rate: DataRate ) -> Result<(), Error>
Sets the measurement output rate.
sourcepub fn set_accel_scale(
&mut self,
scale: AccelerometerScale
) -> Result<(), Error>
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.
sourcepub fn setup_tap_detection(
&mut self,
tap_cfg: TapCfg,
tap_mode: TapMode,
int_line: Option<InterruptLine>
) -> Result<(), Error>
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.
sourcepub fn check_tap(&mut self) -> Result<BitFlags<TapSource>, Error>
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.
sourcepub fn set_tap_threshold(&mut self, x: u8, y: u8, z: u8) -> Result<(), Error>
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
Definition from the LSM6DSOX Application Note ↩
sourcepub fn set_tap_duration(&mut self, dur: u8) -> Result<(), Error>
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
Definition from the LSM6DSOX Application Note ↩
sourcepub fn set_tap_quiet(&mut self, quiet: u8) -> Result<(), Error>
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
Definition from the LSM6DSOX Application Note ↩
sourcepub fn set_tap_shock(&mut self, shock: u8) -> Result<(), Error>
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
Definition from the LSM6DSOX Application Note ↩
source§impl<I2C, Delay> Lsm6dsox<I2C, Delay>
impl<I2C, Delay> Lsm6dsox<I2C, Delay>
sourcepub fn set_gyro_sample_rate(&mut self, data_rate: DataRate) -> Result<(), Error>
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.
sourcepub fn set_gyro_scale(&mut self, scale: GyroscopeScale) -> Result<(), Error>
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.
sourcepub fn angular_rate(&mut self) -> Result<AngularRate, Error>
pub fn angular_rate(&mut self) -> Result<AngularRate, Error>
Get a angular rate reading.
If no data is ready returns the appropriate Error.
sourcepub fn angular_rate_raw(&mut self) -> Result<RawAngularRate, Error>
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>
impl<I2C, Delay> Lsm6dsox<I2C, Delay>
sourcepub fn new(i2c: I2C, address: SlaveAddress, delay: Delay) -> Self
pub fn new(i2c: I2C, address: SlaveAddress, delay: Delay) -> Self
Create a new instance of this sensor.
sourcepub fn destroy(self) -> (I2C, Delay)
pub fn destroy(self) -> (I2C, Delay)
Destroy the sensor and return the hardware peripherals
sourcepub fn check_id(&mut self) -> Result<u8, Option<u8>>
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.
sourcepub fn setup(&mut self) -> Result<(), Error>
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
.
sourcepub fn check_interrupt_sources(
&mut self
) -> Result<BitFlags<InterruptCause>, Error>
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.
sourcepub fn power_down_mode(&mut self) -> Result<(), Error>
pub fn power_down_mode(&mut self) -> Result<(), Error>
Sets both Accelerometer and Gyroscope in power-down mode.
sourcepub fn map_interrupt(
&mut self,
int_src: InterruptSource,
int_line: InterruptLine,
active: bool
) -> Result<(), Error>
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()
.
sourcepub fn enable_interrupts(&mut self, enabled: bool) -> Result<(), Error>
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.
sourcepub unsafe fn register_access(&mut self) -> &mut RegisterAccess<I2C>
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.