Lis3mdl

Struct Lis3mdl 

Source
pub struct Lis3mdl<I2C> { /* private fields */ }
Expand description

LIS3MDL driver

Implementations§

Source§

impl<I2C, E> Lis3mdl<I2C>
where I2C: WriteRead<Error = E> + Write<Error = E>,

Source

pub fn new(i2c: I2C, addr: Address) -> Result<Self, Error>

Create a new driver from an I2C peripheral and configures default settings:

  • Full Scale Range: 12G
  • Measurement Mode: Continuous Measurement
  • Operating Mode: Ultra High Performance
  • Enable the temperature sensor
  • Set data rate to fast
  • Enables Block Data Update

These defaults may be changed after initialization with set_full_scale, set_measurement_mode, set_operating_mode set_temperature_sensor, set_data_rate, and set_block_data_update, respectively.

Source

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

Reads the WHO_AM_I register; should return 0x3D

Source

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

Reads the XYZ components values of the magnetic field and returns the raw signed 16-bit integer value of each axis. This will return whatever is present in the data registers for each axis, so it is recommend to ensure that you are in the proper measurement mode and either synchronizing the read with interrupt/xyz_data_available or using set_block_data_update.

To obtain the value in Gauss or milliGauss either use get_mag_axes_mgauss or divide by column 2 in the table below (obtained from Table 2 in AN4602 Rev 1):

Full-scale (G)Gain@16-bit (LSB/Gauss)
46842
83421
122281
161711
Source

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

True if the XYZ data is available to be read

Source

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

Provide the magnetic field strength in each axis in milliGauss. Uses get_raw_mag_axes to obtain the value.

Source

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

Set the Full Scale from between 4 Gauss and 16 Gauss to adjust the input dynamic range, based on the magnetic field to be measured. This will affect the output of get_raw_mag_axes so use get_mag_axes_mgauss unless you intend to adjust the values yourself.

Source

pub fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error>

Adjust the operating mode. This will have an impact on current consumption, the max data rate, and the output noise with Ultra High Performance (UHP) being the slowest and highest current consumption with the lowest noise, and Low Power (LP) being the highest level of noise, but offering up to 1000 Hz data rate and lowest current consumption. See AN4602 for more details.

Source

pub fn set_measurement_mode( &mut self, mode: MeasurementMode, ) -> Result<(), Error>

Select between 3 measurement modes: Idle, Single Measurement, and Continuous. Configure to Idle if not being used, Single Measurement if only one measurement is desired, and Continuous if a constant stream of data is needed.

Source

pub fn set_data_rate(&mut self, rate: DataRate) -> Result<(), Error>

Set the output data rate. Specific data rates from 0.625 Hz to 80 Hz can be configured for any given operating mode, and Fast will be the highest achievable data rate for the given operating mode at 1000 Hz for Low Power and 155 Hz for Ultra High Performance. See AN4602 for more details.

Source

pub fn set_block_data_update(&mut self, block: bool) -> Result<(), Error>

Blocks the refresh of data for a given axis until the initiated read for that axis completes. Strongly recommended if the reading of the magnetic data cannot be synchronized with the XYZDA in the status register. Ensures that data registers for each channel always contain the most recent magnetic data.

Source

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

Enables the temperature sensor

Auto Trait Implementations§

§

impl<I2C> Freeze for Lis3mdl<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Lis3mdl<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Lis3mdl<I2C>
where I2C: Send,

§

impl<I2C> Sync for Lis3mdl<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Lis3mdl<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Lis3mdl<I2C>
where 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, 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.