Skip to main content

Crate qmi8658

Crate qmi8658 

Source
Expand description

§QMI8658 6-axis IMU driver

A no_std driver for the QST QMI8658 inertial measurement unit, built on embedded-hal 1.0 (blocking, Qmi8658) and, behind the async feature, embedded-hal-async 1.0 (Qmi8658Async). Both drivers work over I2C and SPI (4-wire) and share one typed configuration and data model.

§Features

FeatureDefaultEffect
asyncnoasync driver Qmi8658Async over embedded-hal-async
defmtnodefmt::Format implementations for public types
lognolog diagnostics from init, Ctrl9 timeouts, self-tests

The blocking driver is always available.

§Wiring notes

  • I2C address is selected by the SA0 pin: high or floating gives DeviceAddress::Primary (0x6A), low gives DeviceAddress::Secondary (0x6B).
  • SPI: the sensor auto-detects Mode 0/3; configure the host for Mode 0, MSB first, at most 15 MHz, 4-wire.
  • Wait at least 15 ms after power-up before init; gyroscope data is valid ≈150 ms + 3/ODR after the gyro is enabled.
  • While the FIFO is being drained its filling is paused, so read it promptly.

§Silicon variants

Pedometer and Wake-on-Motion are documented as C-variant features; the ±2048 dps gyro range and the CTRL1 interrupt-pin enable bits as A/B-variant features. All features are exposed unconditionally; commands the silicon does not implement fail with Error::CommandTimeout. The revision ID is reported verbatim, never asserted. Hardware-verified example: the part on the ESP32-S3 reference board reports revision 0x7C yet accepts and runs the pedometer configuration, so do not gate features on the revision byte.

SPI support is verified by transaction-level mock tests; the reference board used for hardware testing wires the sensor over I2C.

§Quickstart (blocking, I2C)

Shown against a mock bus so the example runs as a doctest; on hardware, pass your HAL’s I2C and delay types instead.

use embedded_hal_mock::eh1::{delay::NoopDelay, i2c::{Mock, Transaction}};
use qmi8658::{DeviceAddress, Qmi8658, config::Config};

// `script` holds the mock I2C transaction script (elided here).
let mut imu = Qmi8658::new_i2c(Mock::new(&script), DeviceAddress::Primary, NoopDelay {});
imu.init(Config::default()).unwrap();
let sample = imu.read_sample().unwrap();
assert!((sample.accel_g[2] - 1.0).abs() < 1e-6);

§Async (Embassy-style)

The async driver is executor-agnostic; it only needs embedded-hal-async bus and delay implementations from your HAL.

ⓘ
use qmi8658::{DeviceAddress, Qmi8658Async, config::Config};

// `i2c` and `delay` are your HAL's async types (for example an
// Embassy-time-backed delay and an async I2C peripheral).
let mut imu = Qmi8658Async::new_i2c(i2c, DeviceAddress::Primary, delay);
imu.init(Config::default()).await?;
let sample = imu.read_sample().await?;

Re-exports§

pub use interface::DeviceAddress;

Modules§

config
Typed configuration types and const builders. Typed, const-friendly configuration for the QMI8658.
data
Measurement output types and conversions. Measurement output types and pure raw-to-physical conversions.
interface
Bus transports (I2C/SPI) and the register-access traits. Bus transports: how register reads and writes reach the sensor.
prelude
Common imports for application code. Common imports for application code: use qmi8658::prelude::*;
registers
Register addresses, bit layouts, and field encodings. Register addresses, bit layouts, and field encodings of the QMI8658.

Structs§

Qmi8658
Blocking QMI8658 driver.
Qmi8658Async
Async QMI8658 driver. See crate::Qmi8658 for the semantics of each operation; only the bus and delay access differs (awaited).

Enums§

Error
Errors returned by every driver operation.