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,
impl<T> Bmi323Async<T>where
Self: AsyncAccess,
Sourcepub async fn init<D: AsyncDelayNs>(
&mut self,
delay: &mut D,
) -> Result<DeviceState, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn soft_reset<D: AsyncDelayNs>(
&mut self,
delay: &mut D,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn run_self_test<D: AsyncDelayNs>(
&mut self,
delay: &mut D,
selection: SelfTestSelection,
) -> Result<SelfTestResult, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn status_word(
&mut self,
) -> Result<StatusWord, Error<<Self as AsyncAccess>::BusError>>
pub async fn status_word( &mut self, ) -> Result<StatusWord, Error<<Self as AsyncAccess>::BusError>>
Read and decode the STATUS register.
Sourcepub async fn error_word(
&mut self,
) -> Result<ErrorWord, Error<<Self as AsyncAccess>::BusError>>
pub async fn error_word( &mut self, ) -> Result<ErrorWord, Error<<Self as AsyncAccess>::BusError>>
Read and decode the ERR_REG register.
Sourcepub async fn set_accel_config(
&mut self,
config: AccelConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_gyro_config(
&mut self,
config: GyroConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub fn accel_range(&self) -> AccelRange
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.
Sourcepub fn gyro_range(&self) -> GyroRange
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.
Sourcepub async fn read_accel(
&mut self,
) -> Result<AxisData, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn read_gyro(
&mut self,
) -> Result<AxisData, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn read_imu_data(
&mut self,
) -> Result<ImuData, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn read_temperature_celsius(
&mut self,
) -> Result<f32, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn read_sensor_time(
&mut self,
) -> Result<u32, Error<<Self as AsyncAccess>::BusError>>
pub async fn read_sensor_time( &mut self, ) -> Result<u32, Error<<Self as AsyncAccess>::BusError>>
Read the 24-bit sensor time counter.
Sourcepub async fn configure_interrupt_pin(
&mut self,
channel: InterruptChannel,
config: InterruptPinConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_interrupt_latching(
&mut self,
latched: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn map_interrupt(
&mut self,
source: InterruptSource,
route: InterruptRoute,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn read_interrupt_status(
&mut self,
channel: InterruptChannel,
) -> Result<InterruptStatus, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn wait_for_interrupt<P: Wait>(
&mut self,
pin: &mut P,
channel: InterruptChannel,
) -> Result<InterruptStatus, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_fifo_config(
&mut self,
config: FifoConfig,
watermark_words: u16,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn fifo_fill_level(
&mut self,
) -> Result<u16, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn flush_fifo(
&mut self,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn flush_fifo( &mut self, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Flush all currently buffered FIFO contents.
Sourcepub async fn read_fifo_words(
&mut self,
words: &mut [u16],
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn enable_feature_engine(
&mut self,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn configure_any_motion(
&mut self,
config: AnyMotionConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn configure_any_motion( &mut self, config: AnyMotionConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Configure the BMI323 any-motion feature-engine block.
Sourcepub async fn configure_no_motion(
&mut self,
config: NoMotionConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn configure_no_motion( &mut self, config: NoMotionConfig, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Configure the BMI323 no-motion feature-engine block.
Sourcepub async fn configure_flat(
&mut self,
config: FlatConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_flat_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn set_flat_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Enable or disable the flat-detection feature.
Sourcepub async fn configure_orientation(
&mut self,
config: OrientationConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_orientation_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn set_orientation_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Enable or disable the orientation-detection feature.
Sourcepub async fn configure_tap(
&mut self,
config: TapConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn configure_significant_motion(
&mut self,
config: SignificantMotionConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_significant_motion_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn set_significant_motion_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Enable or disable the significant-motion feature.
Sourcepub async fn configure_tilt(
&mut self,
config: TiltConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_tilt_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn set_tilt_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Enable or disable the tilt-detection feature.
Sourcepub async fn set_step_detector_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_step_counter_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn configure_step_counter(
&mut self,
config: StepCounterConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn reset_step_counter(
&mut self,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
pub async fn reset_step_counter( &mut self, ) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
Request a reset of the accumulated step count.
Sourcepub async fn read_step_count(
&mut self,
) -> Result<u32, Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_alt_accel_config(
&mut self,
config: AltAccelConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn set_alt_gyro_config(
&mut self,
config: AltGyroConfig,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn configure_alt_config_control(
&mut self,
config: AltConfigControl,
) -> Result<(), Error<<Self as AsyncAccess>::BusError>>
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.
Sourcepub async fn alt_status(
&mut self,
) -> Result<AltStatus, Error<<Self as AsyncAccess>::BusError>>
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.