1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! # 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
//!
//! | Feature | Default | Effect |
//! |---|---|---|
//! | `async` | no | async driver [`Qmi8658Async`] over `embedded-hal-async` |
//! | `defmt` | no | `defmt::Format` implementations for public types |
//! | `log` | no | `log` 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};
//!
//! # let mut block = vec![0u8; 17];
//! # block[9..11].copy_from_slice(&8192i16.to_le_bytes()); // AZ = 1 g at ±4 g
//! # let script = [
//! # Transaction::write(0x6A, vec![0x60, 0xB0]),
//! # Transaction::write_read(0x6A, vec![0x00], vec![0x05]),
//! # Transaction::write(0x6A, vec![0x02, 0x58]),
//! # Transaction::write(0x6A, vec![0x0B, 0x01]),
//! # Transaction::write(0x6A, vec![0x0A, 0x12]),
//! # Transaction::write_read(0x6A, vec![0x2D], vec![0x80]),
//! # Transaction::write(0x6A, vec![0x0A, 0x00]),
//! # Transaction::write_read(0x6A, vec![0x2D], vec![0x00]),
//! # Transaction::write(0x6A, vec![0x08, 0x00]),
//! # Transaction::write(0x6A, vec![0x03, 0x15]),
//! # Transaction::write(0x6A, vec![0x04, 0x55]),
//! # Transaction::write(0x6A, vec![0x06, 0x00]),
//! # Transaction::write(0x6A, vec![0x08, 0x03]),
//! # Transaction::write_read(0x6A, vec![0x30], block),
//! # ];
//! // `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);
//! # let (iface, _) = imu.release();
//! # iface.release().done();
//! ```
//!
//! ## Async (Embassy-style)
//!
//! The async driver is executor-agnostic; it only needs
//! `embedded-hal-async` bus and delay implementations from your HAL.
//!
//! ```ignore
//! 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?;
//! ```
// clippy warning level lints
// clippy deny/error level lints, they always have a quick fix that should be preferred
// allowed rules
/// Typed configuration types and `const` builders.
/// Measurement output types and conversions.
/// Bus transports (I2C/SPI) and the register-access traits.
/// Register addresses, bit layouts, and field encodings.
/// Common imports for application code.
pub use Qmi8658;
pub use Qmi8658Async;
pub use Error;
pub use DeviceAddress;