Struct lsm303agr::Lsm303agr

source ·
pub struct Lsm303agr<DI, MODE> { /* private fields */ }
Expand description

LSM303AGR device driver

Implementations§

source§

impl<DI, CommE, MODE> Lsm303agr<DI, MODE>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

pub fn set_accel_mode_and_odr<D: DelayNs>( &mut self, delay: &mut D, mode: AccelMode, odr: impl Into<Option<AccelOutputDataRate>> ) -> Result<(), Error<CommE>>

Set accelerometer power/resolution mode and output data rate.

Returns Error::InvalidInputData if the mode is incompatible with the given output data rate.

The given delay is used to wait for the sensor to turn on or change modes, according to the times specified in Table 14 and Table 15 in the datasheet. You can opt out of this by using a no-op delay implementation, see embedded_hal_mock::delay::MockNoop for an example of such an implementation.

source

pub fn get_accel_mode(&mut self) -> AccelMode

Get the accelerometer mode

source

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

Set accelerometer scaling factor

This changes the scale at which the acceleration is read. AccelScale::G2 for example can return values between -2g and +2g where g is the gravity of the earth (~9.82 m/s²).

source

pub fn get_accel_scale(&self) -> AccelScale

Get accelerometer scaling factor

source§

impl<I2C> Lsm303agr<I2cInterface<I2C>, MagOneShot>

source

pub fn new_with_i2c(i2c: I2C) -> Self

Create new instance of the LSM303AGR device communicating through I2C.

source§

impl<I2C, MODE> Lsm303agr<I2cInterface<I2C>, MODE>

source

pub fn destroy(self) -> I2C

Destroy driver instance, return I2C bus.

source§

impl<SPIXL, SPIMAG> Lsm303agr<SpiInterface<SPIXL, SPIMAG>, MagOneShot>

source

pub fn new_with_spi(spi_accel: SPIXL, spi_mag: SPIMAG) -> Self

Create new instance of the LSM303AGR device communicating through SPI.

source§

impl<SPIXL, SPIMAG, MODE> Lsm303agr<SpiInterface<SPIXL, SPIMAG>, MODE>

source

pub fn destroy(self) -> (SPIXL, SPIMAG)

Destroy driver instance, return SPI bus instance and chip select pin.

source§

impl<DI, CommE, MODE> Lsm303agr<DI, MODE>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

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

Initialize registers

source

pub fn acc_set_fifo_mode( &mut self, mode: FifoMode, fth: u8 ) -> Result<(), Error<CommE>>

Set the accelerometer FIFO mode and full threshold.

The threshold is clamped to [0, 31].

source

pub fn acc_enable_interrupt( &mut self, interrupt: Interrupt ) -> Result<(), Error<CommE>>

Enable accelerometer interrupt.

source

pub fn acc_disable_interrupt( &mut self, interrupt: Interrupt ) -> Result<(), Error<CommE>>

Disable accelerometer interrupt.

source

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

Configure the DRDY pin as a digital output.

source

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

Enable magnetometer low-pass filter.

source

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

Disable magnetometer low-pass filter.

source

pub fn accel_status(&mut self) -> Result<Status, Error<CommE>>

Accelerometer status

source

pub fn acceleration(&mut self) -> Result<Acceleration, Error<CommE>>

Get measured acceleration.

source

pub fn mag_status(&mut self) -> Result<Status, Error<CommE>>

Magnetometer status

source

pub fn accelerometer_id(&mut self) -> Result<AccelerometerId, Error<CommE>>

Get the accelerometer device ID.

source

pub fn magnetometer_id(&mut self) -> Result<MagnetometerId, Error<CommE>>

Get the magnetometer device ID.

source

pub fn temperature(&mut self) -> Result<Temperature, Error<CommE>>

Get measured temperature.

source

pub fn temperature_status(&mut self) -> Result<TemperatureStatus, Error<CommE>>

Temperature sensor status

source§

impl<DI, CommE> Lsm303agr<DI, MagOneShot>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

pub fn into_mag_continuous( self ) -> Result<Lsm303agr<DI, MagContinuous>, ModeChangeError<CommE, Self>>

Change the magnetometer to continuous measurement mode

source§

impl<DI, CommE> Lsm303agr<DI, MagContinuous>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

pub fn into_mag_one_shot( self ) -> Result<Lsm303agr<DI, MagOneShot>, ModeChangeError<CommE, Self>>

Change the magnetometer to one-shot mode

After this the magnetometer is in idle mode until a one-shot measurement is started.

source§

impl<DI, CommE, MODE> Lsm303agr<DI, MODE>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

pub fn set_mag_mode_and_odr<D: DelayNs>( &mut self, delay: &mut D, mode: MagMode, odr: MagOutputDataRate ) -> Result<(), Error<CommE>>

Set magnetometer power/resolution mode and output data rate.

The given delay is used to wait for the sensor to turn on or change modes, according to the times specified in Table 14 and Table 15 in the datasheet. You can opt out of this by using a no-op delay implementation, see embedded_hal_mock::delay::MockNoop for an example of such an implementation.

source

pub fn get_mag_mode(&self) -> MagMode

Get magnetometer power/resolution mode.

source§

impl<DI, CommE> Lsm303agr<DI, MagContinuous>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

pub fn magnetic_field(&mut self) -> Result<MagneticField, Error<CommE>>

Get the measured magnetic field.

source

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

Enable the magnetometer’s built in offset cancellation.

Offset cancellation is automatically managed by the device in continuous mode.

To later disable offset cancellation, use the disable_mag_offset_cancellation function

source

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

Disable the magnetometer’s built in offset cancellation.

source§

impl<DI, CommE> Lsm303agr<DI, MagOneShot>
where DI: ReadData<Error = Error<CommE>> + WriteData<Error = Error<CommE>>,

source

pub fn magnetic_field(&mut self) -> Result<MagneticField, Error<CommE>>

Get the measured magnetic field.

source

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

Enable the magnetometer’s built in offset cancellation.

Offset cancellation has to be managed by the user in single measurement (OneShot) mode averaging two consecutive measurements Hn and Hn-1.

To later disable offset cancellation, use the disable_mag_offset_cancellation function

source

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

Disable the magnetometer’s built in offset cancellation.

Trait Implementations§

source§

impl<DI: Debug, MODE: Debug> Debug for Lsm303agr<DI, MODE>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<DI, MODE> RefUnwindSafe for Lsm303agr<DI, MODE>
where DI: RefUnwindSafe, MODE: RefUnwindSafe,

§

impl<DI, MODE> Send for Lsm303agr<DI, MODE>
where DI: Send, MODE: Send,

§

impl<DI, MODE> Sync for Lsm303agr<DI, MODE>
where DI: Sync, MODE: Sync,

§

impl<DI, MODE> Unpin for Lsm303agr<DI, MODE>
where DI: Unpin, MODE: Unpin,

§

impl<DI, MODE> UnwindSafe for Lsm303agr<DI, MODE>
where DI: UnwindSafe, MODE: 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>,

§

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.