lis2dtw12

Struct Lis2dtw12

source
pub struct Lis2dtw12<I> { /* private fields */ }
Expand description

LIS2DTW12 driver

Implementations§

source§

impl<I: Interface> Lis2dtw12<I>

LIS2DTW12 driver

source

pub fn new(interface: I) -> Self

Create a new LIS2DTW12 driver from a given interface

source

pub fn destroy(self) -> I

Destroy the driver instance returning the interface instance

source

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

Read the WHO_AM_I register

source

pub fn get_temperature_raw(&mut self) -> Result<i16, I::Error>

Read the RAW temperature data

source

pub fn get_temperature(&mut self) -> Result<f32, I::Error>

Read the temperature data

source

pub fn set_output_data_rate( &mut self, odr: OutputDataRate, ) -> Result<(), I::Error>

Set the Output Data Rate

source

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

Set the Mode

source

pub fn set_low_power_mode( &mut self, low_power_mode: LowPowerMode, ) -> Result<(), I::Error>

Set the Low Power Mode

source

pub fn reset_settings(&mut self) -> Result<(), I::Error>

Reset all settings (CTRL registers to default)

source

pub fn disconnect_cs_pull_up( &mut self, disconnect: bool, ) -> Result<(), I::Error>

(Dis-)connect CS pull-up (only relevant when using SPI interface)

source

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

Enable or disable block data update

When enabled, the output registers are continously updated

When disabled, the output registers are updated only after MSB and LSB reading

Enabled by default

source

pub fn set_bandwidth( &mut self, bandwidth: BandwidthSelection, ) -> Result<(), I::Error>

Set the bandwidth selection

source

pub fn set_full_scale(&mut self, full_scale: FullScale) -> Result<(), I::Error>

Set the full-scale selection

source

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

Enable/Disable Filtered data type selection

disabled: low-pass filter path selected

enabled: high-pass filter path selected

Disabled by default

source

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

Enable/Disable low-noise configuration Disabled by default

source

pub fn get_status(&mut self) -> Result<Status, I::Error>

Get the status of the device

§NOTE

Status and Event Status registers are mostly the same with the exceptions:

  • Status register reports the status of the FIFO threshold

    INSTEAD

    Event Status register reports the status of the FIFO overrun

  • Status register reports the wake-up event detection status

    INSTEAD

    Event Status register reports the temperature data ready status

The rest is the same

source

pub fn get_event_status(&mut self) -> Result<EventStatus, I::Error>

Get the Event Status register

§NOTE

Status and Event Status registers are mostly the same with the exceptions:

  • Status register reports the status of the FIFO threshold

    INSTEAD

    Event Status register reports the status of the FIFO overrun

  • Status register reports the wake-up event detection status

    INSTEAD

    Event Status register reports the temperature data ready status

The rest is the same

source

pub fn get_x_accel_raw(&mut self) -> Result<i16, I::Error>

Get the X-axis RAW acceleration data

§NOTE

The data is 12/14-bit (depending on Mode and LowPowerMode) left-justified!

source

pub fn get_y_accel_raw(&mut self) -> Result<i16, I::Error>

Get the Y-axis RAW acceleration data

§NOTE

The data is 12/14-bit (depending on Mode and LowPowerMode) left-justified!

source

pub fn get_z_accel_raw(&mut self) -> Result<i16, I::Error>

Get the Z-axis RAW acceleration data

§NOTE

The data is 12/14-bit (depending on Mode and LowPowerMode) left-justified!

source

pub fn get_x_accel(&mut self) -> Result<f32, I::Error>

Get the X-axis acceleration data

§Returns
  • X-Acceleration in mg
source

pub fn get_y_accel(&mut self) -> Result<f32, I::Error>

Get the Y-axis acceleration data

§Returns
  • Y-Acceleration in mg
source

pub fn get_z_accel(&mut self) -> Result<f32, I::Error>

Get the Z-axis acceleration data

§Returns
  • Z-Acceleration in mg
source

pub fn get_accel_data_raw(&mut self) -> Result<RawAccelerationData, I::Error>

Get the RAW acceleration data

§NOTE

The data is 12/14-bit (depending on Mode and LowPowerMode) left-justified!

source

pub fn get_accel_data(&mut self) -> Result<AccelerationData, I::Error>

Get the acceleration data

§Returns
  • AccelerationData struct containing the acceleration data in mg
source

pub fn set_fifo_mode(&mut self, fifo_mode: FifoMode) -> Result<(), I::Error>

Set the FIFO mode

source

pub fn set_fifo_threshold(&mut self, threshold: u8) -> Result<(), I::Error>

Set the FIFO threshold

§NOTE

Fifo threshold is a 5-bit value (0-31).

If the given threshold value is greater than 31, it will be set to 31

source

pub fn get_fifo_samples_status(&mut self) -> Result<FifoSamplesStatus, I::Error>

Get the FIFO samples status

source

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

Enable 4D decection portrait/landscape position

Disabled by default

source

pub fn set_6d_threshold( &mut self, threshold: Threshold6D, ) -> Result<(), I::Error>

Set the 6D threshold

Thresholds for 4D/6D function @ FS = ±2g

source

pub fn set_tap_priority( &mut self, tap_priority: TapPriority, ) -> Result<(), I::Error>

Set the tap priority

Tap Priority axis selection for tap detection

source

pub fn enable_xyz_tap_detection( &mut self, x_enable: bool, y_enable: bool, z_enable: bool, ) -> Result<(), I::Error>

Enable X/Y/Z direction tap recognition

source

pub fn set_x_tap_threshold(&mut self, threshold: u8) -> Result<(), I::Error>

Set the tap Threshold for X direction

§NOTE

Threshold is a 5-bit value (0-31).

If the given threshold value is greater than 31, it will be set to 31

source

pub fn set_y_tap_threshold(&mut self, threshold: u8) -> Result<(), I::Error>

Set the tap Threshold for Y direction

§NOTE

Threshold is a 5-bit value (0-31).

If the given threshold value is greater than 31, it will be set to 31

source

pub fn set_z_tap_threshold(&mut self, threshold: u8) -> Result<(), I::Error>

Set the tap Threshold for Z direction

§NOTE

Threshold is a 5-bit value (0-31).

If the given threshold value is greater than 31, it will be set to 31

source

pub fn set_double_tap_latency(&mut self, latency: u8) -> Result<(), I::Error>

Duration of maximum time gap for double-tap recognition. When double-tap recognition is enabled, this register expresses the maximum time between two successive detected taps to determine a double-tap event.

Default value is LATENCY[3:0] = 0000 (which is 16 * 1/ODR)

1 LSB = 32 * 1/ODR

§NOTE

Latency is a 4-bit value (0-15).

If the given latency value is greater than 15, it will be set to 15

source

pub fn set_tap_quiet_time(&mut self, quiet_time: u8) -> Result<(), I::Error>

Expected quiet time after a tap detection: this register represents the time after the first detected tap in which there must not be any overthreshold event.

Default value is QUIET[1:0] = 00 (which is 2 * 1/ODR)

1 LSB = 4 * 1/ODR

§NOTE

Quiet time is a 2-bit value (0-3).

If the given quiet time value is greater than 3, it will be set to 3

source

pub fn set_tap_shock_time(&mut self, shock_time: u8) -> Result<(), I::Error>

Maximum duration of overthreshold event: this register represents the maximum time of an overthreshold signal detection to be recognized as a tap event.

Default value is SHOCK[1:0] = 00 (which is 4 * 1/ODR) 1 LSB = 8 *1/ODR

§NOTE

Shock time is a 2-bit value (0-3).

If the given shock time value is greater than 3, it will be set to 3

source

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

Enable/Disable double-tap detection

enabled: Single and double tap detection enabled

disabled: Only single tap detection enabled

Disabled by default

source

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

Enable/Disable sleep mode

enabled: Sleep mode enabled

disabled: Sleep mode disabled

Disabled by default

source

pub fn set_wake_up_threshold(&mut self, threshold: u8) -> Result<(), I::Error>

Set the wake-up threshold

Wake-up threshold, 6-bit unsigned 1 LSB = 1/64 of FS.

Default value: 000000

§NOTE

Threshold is a 6-bit value (0-63).

If the given threshold value is greater than 63, it will be set to 63

source

pub fn set_wake_up_duration(&mut self, duration: u8) -> Result<(), I::Error>

Set the wake-up duration

Wake-up duration. 1 LSB = 1 *1/ODR

§NOTE

Duration is a 2-bit value (0-3).

If the given duration value is greater than 3, it will be set to 3

source

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

Enable/Disable stationary detection / motion detection with no automatic ODR change when detecting stationary state

enabled: Stationary detection enabled

disabled: Stationary detection disabled

Disabled by default

source

pub fn set_sleep_duration(&mut self, duration: u8) -> Result<(), I::Error>

Set duration to go i nsleep mode

Default value is SLEEP_ DUR[3:0] = 0000 (which is 16 * 1/ODR).

1 LSB = 512 * 1/ODR

§NOTE

Duration is a 4-bit value (0-15).

If the given duration value is greater than 15, it will be set to 15

source

pub fn set_free_fall_duration(&mut self, duration: u8) -> Result<(), I::Error>

Set the free-fall duration

1 LSB = 1 * 1/ODR

Default value is FF_DUR[5:0] = 000000

§NOTE

Duration is a 6-bit value (0-63).

If the given duration value is greater than 63, it will be set to 63

source

pub fn set_free_fall_threshold( &mut self, threshold: FreeFallThreshold, ) -> Result<(), I::Error>

Set the free-fall threshold

Free-fall threshold @ FS = ±2 g

source

pub fn get_wake_up_source(&mut self) -> Result<WakeUpSource, I::Error>

Get the wake-up source

source

pub fn get_tap_source(&mut self) -> Result<TapSource, I::Error>

Get the tap source

source

pub fn get_6d_source(&mut self) -> Result<SixDSource, I::Error>

Get the 6D source

source

pub fn get_all_interrupt_sources( &mut self, ) -> Result<AllInterruptSources, I::Error>

Get all interrupt sources

§NOTE

Reading this register clears all interrupt function flags routed to the INT pads simultaneously!

source

pub fn set_x_offset(&mut self, offset: i8) -> Result<(), I::Error>

Set the X axis user offset value

§ARGUMENTS
  • offset: Two’s complement user offset value on X-axis data, used for wake-up function
source

pub fn set_y_offset(&mut self, offset: i8) -> Result<(), I::Error>

Set the Y axis user offset value

§ARGUMENTS
  • offset: Two’s complement user offset value on Y-axis data, used for wake-up function
source

pub fn set_z_offset(&mut self, offset: i8) -> Result<(), I::Error>

Set the Z axis user offset value

§ARGUMENTS
  • offset: Two’s complement user offset value on Z-axis data, used for wake-up function
source

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

Switch between latched and pulsed mode for data ready interrupt

§ARGUMENTS
  • enable: Enable pulsed interrupt mode (true: enabled - pulsed mode, false: disabled - latched mode)

Disabled by default

source

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

Route interrupts from INT2 pad to INT1

§ARGUMENTS
  • enabled: Enable routing (true: enabled - All signals available only on INT2 are routed to INT1, false: disabled)

Disabled by default

source

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

Enable/Disable interrupts

§ARGUMENTS
  • enable: Enable interrupts (true: enabled, false: disabled)

Disabled by default

source

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

Enable/Disable application of user offset values in accelerometer output data registers

§NOTE

enable_filtered_data_selection must be DISABLED (low-pass path selected)

§ARGUMENTS
  • enable: Enable user offset values (true: enabled, false: disabled)

Disabled by default

source

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

Enable/Disable application of user offset values to wake-up function only

§ARGUMENTS
  • enable: Enable user offset values (true: enabled, false: disabled)

Disabled by default

source

pub fn set_user_offset_weight( &mut self, high_weight: bool, ) -> Result<(), I::Error>

Set the weight of the user offset values

§ARGUMENTS
  • high_weight: true: 15.6 mg/LSB, false: 977 µg/LSB

Default value is 977 µg/LSB (false)

source

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

Enable/Disable high-pass filter reference mode

§ARGUMENTS
  • enable: Enable high-pass filter reference mode (true: enabled, false: disabled)

Disabled by default

source

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

Enable/Disable low-pass filter for 6D interrupt function

§ARGUMENTS
  • enable: Enable low-pass filter

    true: LPF2 output data sent to 6D interrupt function

    false: OD2/2 low-pass filtered data sent to 6D interrupt function

Disabled by default

Auto Trait Implementations§

§

impl<I> Freeze for Lis2dtw12<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for Lis2dtw12<I>
where I: RefUnwindSafe,

§

impl<I> Send for Lis2dtw12<I>
where I: Send,

§

impl<I> Sync for Lis2dtw12<I>
where I: Sync,

§

impl<I> Unpin for Lis2dtw12<I>
where I: Unpin,

§

impl<I> UnwindSafe for Lis2dtw12<I>
where I: 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, 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.