Skip to main content

Bmi323Async

Struct Bmi323Async 

Source
pub struct Bmi323Async<T> { /* private fields */ }
Expand description

Async BMI323 driver.

Create this with Bmi323Async::new_i2c or Bmi323Async::new_spi.

Implementations§

Source§

impl<T> Bmi323Async<T>
where Self: AsyncAccess,

Source

pub async fn init<D: AsyncDelayNs>( &mut self, delay: &mut D, ) -> Result<DeviceState, Error<<Self as AsyncAccess>::BusError>>

Reset the sensor and verify communication, chip ID, and error state.

This method performs a soft reset on every call so startup begins from a known device state. After init, configure the accelerometer and gyroscope explicitly with set_accel_config and set_gyro_config before depending on sample reads in application code.

Source

pub async fn soft_reset<D: AsyncDelayNs>( &mut self, delay: &mut D, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Issue the BMI323 soft-reset command and wait for restart completion.

Source

pub async fn run_self_test<D: AsyncDelayNs>( &mut self, delay: &mut D, selection: SelfTestSelection, ) -> Result<SelfTestResult, Error<<Self as AsyncAccess>::BusError>>

Run the BMI323 built-in self-test and return the detailed result.

For gyroscope self-test, the BMI323 requires the accelerometer to be in high-performance mode with an output data rate between 12.5 Hz and 200 Hz. This method enforces that prerequisite temporarily when needed and restores the previous accel/gyro and alternate-configuration registers afterwards.

The returned SelfTestResult::error_status comes from FEATURE_IO1.error_status. On the BMI323, 0x5 is the normal “no error” value after the feature engine is active.

Source

pub async fn status_word( &mut self, ) -> Result<StatusWord, Error<<Self as AsyncAccess>::BusError>>

Read and decode the STATUS register.

Source

pub async fn error_word( &mut self, ) -> Result<ErrorWord, Error<<Self as AsyncAccess>::BusError>>

Read and decode the ERR_REG register.

Source

pub async fn set_accel_config( &mut self, config: AccelConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the accelerometer and remember the selected range locally.

Call this after init before relying on accelerometer or combined IMU sample reads.

Source

pub async fn set_gyro_config( &mut self, config: GyroConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the gyroscope and remember the selected range locally.

Call this after init before relying on gyroscope or combined IMU sample reads.

Source

pub fn accel_range(&self) -> AccelRange

Return the last accelerometer range configured through this driver.

Before any explicit accelerometer configuration, this returns the driver’s local startup value of AccelRange::G8.

Source

pub fn gyro_range(&self) -> GyroRange

Return the last gyroscope range configured through this driver.

Before any explicit gyroscope configuration, this returns the driver’s local startup value of GyroRange::Dps2000.

Source

pub async fn read_accel( &mut self, ) -> Result<AxisData, Error<<Self as AsyncAccess>::BusError>>

Read a single accelerometer sample.

For predictable results, configure the accelerometer first with set_accel_config.

Source

pub async fn read_gyro( &mut self, ) -> Result<AxisData, Error<<Self as AsyncAccess>::BusError>>

Read a single gyroscope sample.

For predictable results, configure the gyroscope first with set_gyro_config.

Source

pub async fn read_imu_data( &mut self, ) -> Result<ImuData, Error<<Self as AsyncAccess>::BusError>>

Read accelerometer and gyroscope data in one burst transaction.

For predictable results, configure both sensors first with set_accel_config and set_gyro_config.

Source

pub async fn read_temperature_celsius( &mut self, ) -> Result<f32, Error<<Self as AsyncAccess>::BusError>>

Read the temperature sensor and convert it to degrees Celsius.

Source

pub async fn read_sensor_time( &mut self, ) -> Result<u32, Error<<Self as AsyncAccess>::BusError>>

Read the 24-bit sensor time counter.

Source

pub async fn configure_interrupt_pin( &mut self, channel: InterruptChannel, config: InterruptPinConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the electrical behavior of INT1 or INT2.

Passing InterruptChannel::Ibi is a no-op: I3C in-band interrupts have no pin electrical configuration in the BMI323.

Source

pub async fn set_interrupt_latching( &mut self, latched: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable latched interrupt behavior inside the sensor.

Source

pub async fn map_interrupt( &mut self, source: InterruptSource, route: InterruptRoute, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Route an interrupt source to INT1, INT2, or I3C IBI.

Source

pub async fn read_interrupt_status( &mut self, channel: InterruptChannel, ) -> Result<InterruptStatus, Error<<Self as AsyncAccess>::BusError>>

Read the interrupt status register for the selected output channel.

Source

pub async fn wait_for_interrupt<P: Wait>( &mut self, pin: &mut P, channel: InterruptChannel, ) -> Result<InterruptStatus, Error<<Self as AsyncAccess>::BusError>>

Wait for an external GPIO interrupt line to assert, then read status.

Any error from pin.wait_for_high() is silently discarded. The interrupt status register is read regardless, so if the pin wait fails the status read still proceeds. If you need to handle GPIO errors, call pin.wait_for_high() yourself and then call read_interrupt_status directly.

Source

pub async fn set_fifo_config( &mut self, config: FifoConfig, watermark_words: u16, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure FIFO contents and watermark level.

Source

pub async fn fifo_fill_level( &mut self, ) -> Result<u16, Error<<Self as AsyncAccess>::BusError>>

Read the current FIFO fill level in 16-bit words.

Source

pub async fn flush_fifo( &mut self, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Flush all currently buffered FIFO contents.

Source

pub async fn read_fifo_words( &mut self, words: &mut [u16], ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Read raw FIFO words into the provided output slice.

words.len() must not exceed 64 due to the fixed internal transfer buffer. Use fifo_fill_level first and split larger reads into chunks of at most 64 words.

§Panics

Panics if words.len() > 64.

Source

pub async fn enable_feature_engine( &mut self, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable the BMI323 feature engine required by advanced motion features.

This method temporarily disables the accelerometer and gyroscope by writing to ACC_CONF and GYR_CONF as part of the enable sequence. After calling this method, re-configure the sensors with set_accel_config and set_gyro_config before reading samples.

Source

pub async fn configure_any_motion( &mut self, config: AnyMotionConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 any-motion feature-engine block.

Source

pub async fn configure_no_motion( &mut self, config: NoMotionConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 no-motion feature-engine block.

Source

pub async fn configure_flat( &mut self, config: FlatConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 flat-detection feature-engine block and enable the flat detector.

Source

pub async fn set_flat_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable the flat-detection feature.

Source

pub async fn configure_orientation( &mut self, config: OrientationConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 orientation-detection feature-engine block and enable the orientation detector.

Source

pub async fn set_orientation_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable the orientation-detection feature.

Source

pub async fn configure_tap( &mut self, config: TapConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 tap-detection feature-engine block.

The interrupt status register exposes a single tap bit, even when single-, double-, and triple-tap detection are enabled together.

Source

pub async fn configure_significant_motion( &mut self, config: SignificantMotionConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 significant-motion feature-engine block and enable the significant-motion detector.

Source

pub async fn set_significant_motion_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable the significant-motion feature.

Source

pub async fn configure_tilt( &mut self, config: TiltConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 tilt-detection feature-engine block and enable the tilt detector.

Source

pub async fn set_tilt_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable the tilt-detection feature.

Source

pub async fn set_step_detector_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable the feature-engine step detector.

When enabled, the BMI323 can assert the InterruptSource::StepDetector interrupt source after the feature engine has been enabled with enable_feature_engine.

Source

pub async fn set_step_counter_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Enable or disable the feature-engine step counter.

This controls the BMI323 step-count accumulation path and the InterruptSource::StepCounter interrupt source. The feature engine must already be enabled with enable_feature_engine.

Source

pub async fn configure_step_counter( &mut self, config: StepCounterConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure the BMI323 step-counter watermark and optional reset request.

A watermark of 0 disables the step-counter interrupt source while still allowing the accumulated step count to be read.

Source

pub async fn reset_step_counter( &mut self, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Request a reset of the accumulated step count.

Source

pub async fn read_step_count( &mut self, ) -> Result<u32, Error<<Self as AsyncAccess>::BusError>>

Read the 32-bit accumulated step count from the feature engine.

Source

pub async fn set_alt_accel_config( &mut self, config: AltAccelConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Program the alternate accelerometer configuration in ALT_ACC_CONF.

Source

pub async fn set_alt_gyro_config( &mut self, config: AltGyroConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Program the alternate gyroscope configuration in ALT_GYR_CONF.

Source

pub async fn configure_alt_config_control( &mut self, config: AltConfigControl, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>

Configure automatic switching between user and alternate sensor configurations.

Source

pub async fn alt_status( &mut self, ) -> Result<AltStatus, Error<<Self as AsyncAccess>::BusError>>

Read which configuration set is currently active for accel and gyro.

Source§

impl<I2C> Bmi323Async<AsyncI2cTransport<I2C>>
where I2C: AsyncI2c,

Source

pub fn new_i2c(i2c: I2C, address: u8) -> Self

Create an async BMI323 driver over an I2C bus.

address is the 7-bit BMI323 I2C address selected by hardware.

Source

pub fn destroy(self) -> I2C

Consume the driver and return ownership of the underlying I2C bus.

Source§

impl<SPI> Bmi323Async<AsyncSpiTransport<SPI>>
where SPI: AsyncSpiDevice<u8>,

Source

pub fn new_spi(spi: SPI) -> Self

Create an async BMI323 driver over an SPI device.

Source

pub fn destroy(self) -> SPI

Consume the driver and return ownership of the underlying SPI device.

Trait Implementations§

Source§

impl<I2C> AsyncAccess for Bmi323Async<AsyncI2cTransport<I2C>>
where I2C: AsyncI2c,

Source§

type BusError = <I2C as ErrorType>::Error

Underlying bus error type returned by the transport.
Source§

async fn read_word(&mut self, reg: u8) -> Result<u16, Self::BusError>

Read a single 16-bit register payload from the BMI323.
Source§

async fn write_word(&mut self, reg: u8, word: u16) -> Result<(), Self::BusError>

Write a single 16-bit register payload to the BMI323.
Source§

async fn read_words( &mut self, reg: u8, words: &mut [u16], ) -> Result<(), Self::BusError>

Read multiple consecutive 16-bit register payloads starting at reg.
Source§

impl<SPI> AsyncAccess for Bmi323Async<AsyncSpiTransport<SPI>>
where SPI: AsyncSpiDevice<u8>,

Source§

type BusError = <SPI as ErrorType>::Error

Underlying bus error type returned by the transport.
Source§

async fn read_word(&mut self, reg: u8) -> Result<u16, Self::BusError>

Read a single 16-bit register payload from the BMI323.
Source§

async fn write_word(&mut self, reg: u8, word: u16) -> Result<(), Self::BusError>

Write a single 16-bit register payload to the BMI323.
Source§

async fn read_words( &mut self, reg: u8, words: &mut [u16], ) -> Result<(), Self::BusError>

Read multiple consecutive 16-bit register payloads starting at reg.

Auto Trait Implementations§

§

impl<T> Freeze for Bmi323Async<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Bmi323Async<T>
where T: RefUnwindSafe,

§

impl<T> Send for Bmi323Async<T>
where T: Send,

§

impl<T> Sync for Bmi323Async<T>
where T: Sync,

§

impl<T> Unpin for Bmi323Async<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Bmi323Async<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Bmi323Async<T>
where T: 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.