switch fast read to twos complement, as every 32bit number
appears to be twos complement
This commit is contained in:
parent
dda1e4cf28
commit
02b3a9a87c
1 changed files with 7 additions and 6 deletions
13
src/lib.rs
13
src/lib.rs
|
@ -1,6 +1,7 @@
|
|||
#![no_std]
|
||||
use embassy_embedded_hal::adapter::BlockingAsync;
|
||||
use embedded_hal_async::spi::{SpiBus, SpiDevice};
|
||||
use registers::*;
|
||||
|
||||
#[cfg(feature = "ADIS1647x-1")]
|
||||
const DELTA_ANGLE_RANGE: f32 = 360.;
|
||||
|
@ -51,8 +52,8 @@ impl<T: SpiBus> ADIS16475<T> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// efficiently reads multiple u32s by pipelining the spi bus
|
||||
async fn read_u32_multi<const N: usize>(&mut self, addr: [u8;N]) -> Result<[u32;N], T::Error> {
|
||||
/// efficiently reads multiple i32s by pipelining the spi bus
|
||||
async fn read_i32_multi<const N: usize>(&mut self, addr: [u8;N]) -> Result<[i32;N], T::Error> {
|
||||
let read = |addr :u8| [(addr & 0x7F), 0];
|
||||
|
||||
// first address
|
||||
|
@ -60,7 +61,7 @@ impl<T: SpiBus> ADIS16475<T> {
|
|||
|
||||
let mut responses = [0; N];
|
||||
|
||||
let mut partial: [u16;2] = [0;2];
|
||||
let mut partial: [i16;2] = [0;2];
|
||||
let mut partial_idx = 0;
|
||||
|
||||
let mut buf: [u8;2] = [0;2];
|
||||
|
@ -69,19 +70,19 @@ impl<T: SpiBus> ADIS16475<T> {
|
|||
let addr = addr[i/2] + (i as u8 % 2) * 2;
|
||||
self.bus.transfer(&mut buf, &read(addr)).await?;
|
||||
|
||||
partial[partial_idx] = u16::from_be_bytes(buf);
|
||||
partial[partial_idx] = i16::from_be_bytes(buf);
|
||||
partial_idx += 1;
|
||||
|
||||
if partial_idx == 2 {
|
||||
partial_idx = 0;
|
||||
|
||||
responses[i/2 -1] = (partial[1] as u32) << 16 + partial[0] as u32;
|
||||
responses[i/2 -1] = (partial[1] as i32) << 16 + partial[0] as i32;
|
||||
}
|
||||
}
|
||||
|
||||
// last address
|
||||
self.bus.read(&mut buf).await.unwrap();
|
||||
responses[addr.len() - 1] = partial[0] as u32 + (u16::from_be_bytes(buf) as u32) << 16;
|
||||
responses[addr.len() - 1] = partial[0] as i32 + (i16::from_be_bytes(buf) as i32) << 16;
|
||||
|
||||
Ok(responses)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue