pub struct Bmi323<T> { /* private fields */ }Expand description
BMI323 driver.
Async mode (the default) exposes all methods as async fn. Add
features = ["blocking"] (with default-features = false) to get the
synchronous embedded-hal API instead. Create with Bmi323::new_i2c or
Bmi323::new_spi.
Implementations§
Source§impl<I2C: HalI2c> Bmi323<I2cTransport<I2C>>
impl<I2C: HalI2c> Bmi323<I2cTransport<I2C>>
Source§impl<SPI: HalSpiDevice<u8>> Bmi323<SpiTransport<SPI>>
impl<SPI: HalSpiDevice<u8>> Bmi323<SpiTransport<SPI>>
Source§impl<T> Bmi323<T>where
Self: Access,
impl<T> Bmi323<T>where
Self: Access,
Sourcepub async fn init<D: DelayNs>(
&mut self,
delay: &mut D,
) -> Result<DeviceState, Error<<Self as Access>::BusError>>
pub async fn init<D: DelayNs>( &mut self, delay: &mut D, ) -> Result<DeviceState, Error<<Self as Access>::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: DelayNs>(
&mut self,
delay: &mut D,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn soft_reset<D: DelayNs>( &mut self, delay: &mut D, ) -> Result<(), Error<<Self as Access>::BusError>>
Issue the BMI323 soft-reset command and wait for restart completion.
Sourcepub async fn run_self_test<D: DelayNs>(
&mut self,
delay: &mut D,
selection: SelfTestSelection,
) -> Result<SelfTestResult, Error<<Self as Access>::BusError>>
pub async fn run_self_test<D: DelayNs>( &mut self, delay: &mut D, selection: SelfTestSelection, ) -> Result<SelfTestResult, Error<<Self as Access>::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 when needed.
The self-test modifies the accel/gyro configuration registers and the
feature engine state. After this method returns, the sensor configuration
is in an undefined state. Call set_accel_config,
set_gyro_config, and any other configuration
methods needed before resuming normal sensor operation.
The returned SelfTestResult::error_status comes from
FEATURE_IO1.error_status. The normal value after the feature engine
is active is FEATURE_ENGINE_STATUS_NO_ERROR (0x05).
Sourcepub async fn status_word(
&mut self,
) -> Result<StatusWord, Error<<Self as Access>::BusError>>
pub async fn status_word( &mut self, ) -> Result<StatusWord, Error<<Self as Access>::BusError>>
Read and decode the STATUS register.
Sourcepub async fn error_word(
&mut self,
) -> Result<ErrorWord, Error<<Self as Access>::BusError>>
pub async fn error_word( &mut self, ) -> Result<ErrorWord, Error<<Self as Access>::BusError>>
Read and decode the ERR_REG register.
Sourcepub async fn set_accel_config(
&mut self,
config: AccelConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn set_accel_config( &mut self, config: AccelConfig, ) -> Result<(), Error<<Self as Access>::BusError>>
Configure the accelerometer and remember the selected range locally.
Call this after init before relying on accelerometer or
combined IMU sample reads.
If AltConfigControl::reset_on_user_config_write is set, writing to
ACC_CONF returns the accelerometer from its alternate configuration back
to the user configuration.
Sourcepub async fn set_gyro_config(
&mut self,
config: GyroConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn set_gyro_config( &mut self, config: GyroConfig, ) -> Result<(), Error<<Self as Access>::BusError>>
Configure the gyroscope and remember the selected range locally.
Call this after init before relying on gyroscope or
combined IMU sample reads.
If AltConfigControl::reset_on_user_config_write is set, writing to
GYR_CONF returns the gyroscope from its alternate configuration back
to the user configuration.
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::G2 (matches the BMI323 POR default).
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::Dps125 (matches the BMI323 POR default).
Sourcepub async fn read_accel(
&mut self,
) -> Result<AxisData, Error<<Self as Access>::BusError>>
pub async fn read_accel( &mut self, ) -> Result<AxisData, Error<<Self as Access>::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 Access>::BusError>>
pub async fn read_gyro( &mut self, ) -> Result<AxisData, Error<<Self as Access>::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 Access>::BusError>>
pub async fn read_imu_data( &mut self, ) -> Result<ImuData, Error<<Self as Access>::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 Access>::BusError>>
pub async fn read_temperature_celsius( &mut self, ) -> Result<f32, Error<<Self as Access>::BusError>>
Read the temperature sensor and convert it to degrees Celsius.
Sourcepub async fn read_sensor_time(
&mut self,
) -> Result<u32, Error<<Self as Access>::BusError>>
pub async fn read_sensor_time( &mut self, ) -> Result<u32, Error<<Self as Access>::BusError>>
Read the 24-bit sensor time counter.
Sourcepub async fn configure_interrupt_pin(
&mut self,
channel: InterruptChannel,
config: InterruptPinConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn configure_interrupt_pin( &mut self, channel: InterruptChannel, config: InterruptPinConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_interrupt_latching( &mut self, latched: bool, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn map_interrupt( &mut self, source: InterruptSource, route: InterruptRoute, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn read_interrupt_status( &mut self, channel: InterruptChannel, ) -> Result<InterruptStatus, Error<<Self as Access>::BusError>>
Read the interrupt status register for the selected output channel.
Sourcepub async fn set_fifo_config(
&mut self,
config: FifoConfig,
watermark_words: u16,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn set_fifo_config( &mut self, config: FifoConfig, watermark_words: u16, ) -> Result<(), Error<<Self as Access>::BusError>>
Configure FIFO contents and watermark level.
watermark_words is the interrupt threshold in 16-bit words. The BMI323
FIFO_WATERMARK register is 10 bits wide, so values are clamped to
0..=1023. Values above 1023 are silently truncated to 1023.
Sourcepub async fn fifo_fill_level(
&mut self,
) -> Result<u16, Error<<Self as Access>::BusError>>
pub async fn fifo_fill_level( &mut self, ) -> Result<u16, Error<<Self as Access>::BusError>>
Read the current FIFO fill level in 16-bit words.
Sourcepub async fn flush_fifo(
&mut self,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn flush_fifo( &mut self, ) -> Result<(), Error<<Self as Access>::BusError>>
Flush all currently buffered FIFO contents.
Sourcepub async fn read_fifo_words(
&mut self,
words: &mut [u16],
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn read_fifo_words( &mut self, words: &mut [u16], ) -> Result<(), Error<<Self as Access>::BusError>>
Read raw FIFO words into the provided output slice.
words.len() must not exceed [MAX_WORDS_PER_READ] due to the fixed
internal transfer buffer. Use fifo_fill_level
first and split larger reads into chunks of at most that size.
§Panics
Panics if words.len() > MAX_WORDS_PER_READ.
Sourcepub async fn enable_feature_engine<D: DelayNs>(
&mut self,
delay: &mut D,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn enable_feature_engine<D: DelayNs>( &mut self, delay: &mut D, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn configure_any_motion( &mut self, config: AnyMotionConfig, ) -> Result<(), Error<<Self as Access>::BusError>>
Configure the BMI323 any-motion feature-engine block.
Sourcepub async fn configure_no_motion(
&mut self,
config: NoMotionConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn configure_no_motion( &mut self, config: NoMotionConfig, ) -> Result<(), Error<<Self as Access>::BusError>>
Configure the BMI323 no-motion feature-engine block.
Sourcepub async fn configure_flat(
&mut self,
config: FlatConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn configure_flat( &mut self, config: FlatConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_flat_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as Access>::BusError>>
Enable or disable the flat-detection feature.
Sourcepub async fn configure_orientation(
&mut self,
config: OrientationConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn configure_orientation( &mut self, config: OrientationConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_orientation_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as Access>::BusError>>
Enable or disable the orientation-detection feature.
Sourcepub async fn configure_tap(
&mut self,
config: TapConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn configure_tap( &mut self, config: TapConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn configure_significant_motion( &mut self, config: SignificantMotionConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_significant_motion_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as Access>::BusError>>
Enable or disable the significant-motion feature.
Sourcepub async fn configure_tilt(
&mut self,
config: TiltConfig,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn configure_tilt( &mut self, config: TiltConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_tilt_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as Access>::BusError>>
Enable or disable the tilt-detection feature.
Sourcepub async fn set_step_detector_enabled(
&mut self,
enabled: bool,
) -> Result<(), Error<<Self as Access>::BusError>>
pub async fn set_step_detector_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_step_counter_enabled( &mut self, enabled: bool, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn configure_step_counter( &mut self, config: StepCounterConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn reset_step_counter( &mut self, ) -> Result<(), Error<<Self as Access>::BusError>>
Request a reset of the accumulated step count.
Sourcepub async fn read_step_count(
&mut self,
) -> Result<u32, Error<<Self as Access>::BusError>>
pub async fn read_step_count( &mut self, ) -> Result<u32, Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_alt_accel_config( &mut self, config: AltAccelConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn set_alt_gyro_config( &mut self, config: AltGyroConfig, ) -> Result<(), Error<<Self as Access>::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 Access>::BusError>>
pub async fn configure_alt_config_control( &mut self, config: AltConfigControl, ) -> Result<(), Error<<Self as Access>::BusError>>
Configure automatic switching between user and alternate sensor configurations.
Source§impl<T> Bmi323<T>where
Self: Access,
Async-only methods available when the async feature is enabled.
impl<T> Bmi323<T>where
Self: Access,
Async-only methods available when the async feature is enabled.
Sourcepub async fn wait_for_interrupt<P: Wait>(
&mut self,
pin: &mut P,
channel: InterruptChannel,
) -> Result<InterruptStatus, Error<<Self as Access>::BusError>>
pub async fn wait_for_interrupt<P: Wait>( &mut self, pin: &mut P, channel: InterruptChannel, ) -> Result<InterruptStatus, Error<<Self as Access>::BusError>>
Wait for an external GPIO interrupt line to assert, then read status.
Returns Error::GpioError if pin.wait_for_high() fails. The
underlying GPIO error value is not preserved because the GPIO error type
is independent of the bus error type.
Trait Implementations§
Source§impl<I2C: HalI2c> Access for Bmi323<I2cTransport<I2C>>
Available on non-crate feature blocking only.
impl<I2C: HalI2c> Access for Bmi323<I2cTransport<I2C>>
blocking only.Source§type BusError = <I2C as ErrorType>::Error
type BusError = <I2C as ErrorType>::Error
Source§async fn read_word(&mut self, reg: u8) -> Result<u16, Self::BusError>
async fn read_word(&mut self, reg: u8) -> Result<u16, Self::BusError>
Source§impl<SPI: HalSpiDevice<u8>> Access for Bmi323<SpiTransport<SPI>>
Available on non-crate feature blocking only.
impl<SPI: HalSpiDevice<u8>> Access for Bmi323<SpiTransport<SPI>>
blocking only.