added sync support
This commit is contained in:
parent
24023f6e29
commit
82105eecb9
4 changed files with 132 additions and 11 deletions
97
Cargo.lock
generated
97
Cargo.lock
generated
|
@ -9,6 +9,7 @@ dependencies = [
|
|||
"embassy-embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"maybe-async-cfg",
|
||||
"nalgebra",
|
||||
]
|
||||
|
||||
|
@ -27,6 +28,12 @@ version = "1.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.22.0"
|
||||
|
@ -227,6 +234,30 @@ version = "0.4.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
|
||||
|
||||
[[package]]
|
||||
name = "manyhow"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b33efb3ca6d3b07393750d4030418d594ab1139cee518f0dc88db70fec873587"
|
||||
dependencies = [
|
||||
"manyhow-macros",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "manyhow-macros"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46fce34d199b78b6e6073abf984c9cf5fd3e9330145a93ee0738a7443e371495"
|
||||
dependencies = [
|
||||
"proc-macro-utils",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matrixmultiply"
|
||||
version = "0.3.9"
|
||||
|
@ -237,6 +268,25 @@ dependencies = [
|
|||
"rawpointer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maybe-async-cfg"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dbfaa67a76e2623580df07d6bb5e7956c0a4bae4b418314083a9c619bd66627"
|
||||
dependencies = [
|
||||
"manyhow",
|
||||
"proc-macro2",
|
||||
"pulldown-cmark",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra"
|
||||
version = "0.31.4"
|
||||
|
@ -261,7 +311,7 @@ checksum = "01fcc0b8149b4632adc89ac3b7b31a12fb6099a0317a4eb2ebff574ef7de7218"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -334,6 +384,17 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-utils"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeaf08a13de400bc215877b5bdc088f241b12eb42f0a548d3390dc1c56bb7071"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.94"
|
||||
|
@ -343,6 +404,17 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"memchr",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.39"
|
||||
|
@ -380,6 +452,12 @@ dependencies = [
|
|||
"wide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.0"
|
||||
|
@ -397,12 +475,29 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
|
|
|
@ -8,3 +8,9 @@ embedded-hal = "1.0.0"
|
|||
embedded-hal-async = "1.0.0"
|
||||
embassy-embedded-hal = {version = "0.3.0", git="https://github.com/embassy-rs/embassy", rev = "c39076724f052fed6781b056bb79c9fa576b87a3"}
|
||||
nalgebra = "0.31.4"
|
||||
maybe-async-cfg = "0.2"
|
||||
|
||||
[features]
|
||||
default = ["sync"]
|
||||
sync = []
|
||||
async = []
|
||||
|
|
14
readme.md
14
readme.md
|
@ -4,10 +4,18 @@ no_std driver for the Analog Devices [adis1647](https://www.mouser.com/new/analo
|
|||
|
||||
### Usage
|
||||
|
||||
You need an embedded_hal_async spi driver and delay implementation
|
||||
You need an embedded_hal or embedded_hal_async spi driver and delay implementation
|
||||
|
||||
```toml
|
||||
# async
|
||||
adis1647x = { git = "https://git.ank.dev/ank/adis1647x", default-features = false, features = ["async"]
|
||||
|
||||
# sync
|
||||
adis1647x = { git = "https://git.ank.dev/ank/adis1647x" }
|
||||
|
||||
```
|
||||
|
||||
```rust
|
||||
|
||||
use adis1647x::*;
|
||||
use adis1647x::delta::*;
|
||||
|
||||
|
@ -15,7 +23,7 @@ async fn main() -> Result<(), SomeSpiError> {
|
|||
let bus = some_spi();
|
||||
let delay = some_delay();
|
||||
|
||||
let imu = ADIS1647X::new(bus, delay).await?;
|
||||
let imu = ADIS1647Async::new(bus, delay).await?;
|
||||
|
||||
let mut angle: DeltaAngle = Default::default();
|
||||
|
||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -1,6 +1,12 @@
|
|||
#![no_std]
|
||||
use delta::{DeltaAngle, DeltaVelocity};
|
||||
use embedded_hal_async::{delay::DelayNs, spi::SpiDevice};
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
use embedded_hal_async::{delay::DelayNs as DelayNsAsync, spi::SpiDevice as SpiDeviceAsync};
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
use embedded_hal::{delay::DelayNs as DelayNsSync, spi::SpiDevice as SpiDeviceSync};
|
||||
|
||||
use nalgebra::Vector3;
|
||||
use registers::*;
|
||||
|
||||
|
@ -48,16 +54,24 @@ impl Model {
|
|||
/// microseconds between requests
|
||||
const STALL_TIME: u32 = 16;
|
||||
|
||||
pub struct ADIS1647X<T, D> where T: SpiDevice, D: DelayNs {
|
||||
#[maybe_async_cfg::maybe(
|
||||
idents(DelayNs, SpiDevice),
|
||||
sync(feature="sync"),
|
||||
async(feature="async")
|
||||
)]
|
||||
pub struct ADIS1647<T, D> where T: SpiDevice, D: DelayNs {
|
||||
bus: T,
|
||||
model: Model,
|
||||
delay: D,
|
||||
}
|
||||
|
||||
impl<T: SpiDevice, D: DelayNs> ADIS1647X<T, D> {
|
||||
#[maybe_async_cfg::maybe(
|
||||
idents(DelayNs, SpiDevice),
|
||||
sync(feature="sync"),
|
||||
async(feature="async")
|
||||
)]
|
||||
impl<T: SpiDevice, D: DelayNs> ADIS1647<T, D> {
|
||||
pub async fn new(bus: T, delay: D) -> Result<Self, T::Error> {
|
||||
//let bus = BlockingAsync::new(bus);
|
||||
|
||||
let mut query_imu = Self { bus, model: Model::ADIS16475_1, delay };
|
||||
let range = query_imu.read_u16(RANG_MDL).await?;
|
||||
|
||||
|
@ -68,7 +82,6 @@ impl<T: SpiDevice, D: DelayNs> ADIS1647X<T, D> {
|
|||
|
||||
/// use a known model instead of detecting it
|
||||
pub fn with_model(bus: T, model: Model, delay: D) -> Self {
|
||||
//let bus = BlockingAsync::new(bus);
|
||||
Self { bus, model, delay }
|
||||
}
|
||||
|
||||
|
@ -103,7 +116,6 @@ impl<T: SpiDevice, D: DelayNs> ADIS1647X<T, D> {
|
|||
|
||||
pub async fn write_u16(&mut self, addr: u8, data: u16) -> Result<(), T::Error> {
|
||||
let data = u16::to_le_bytes(data);
|
||||
// TODO: do some soul searching
|
||||
self.write_u8(addr, data[0]).await?; // lower byte
|
||||
self.write_u8(addr+1, data[1]).await?; // higher byte
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue