Skip to content

Commit 5cada25

Browse files
committed
Fix SPI comunication
This fixes VersBinarii#25. Any try to call the `init` function will fail with an `UnsupportedChip` error without this (using the defautl `sync` feature). Previous attempts were made to fix this (VersBinarii#28 and VersBinarii#38) but these where made before `embedded-hal` `1.0.0` and currently have conflicts preventing their merge (and can't directly be used in a project using `embedded-hal` `1.0.0` closes VersBinarii#28
1 parent f243937 commit 5cada25

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/spi.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use core::future::Future;
55
#[cfg(feature = "sync")]
66
use embedded_hal::delay::DelayNs;
7+
use embedded_hal::spi::Operation;
78
#[cfg(feature = "sync")]
89
use embedded_hal::spi::SpiDevice;
910
#[cfg(feature = "async")]
@@ -157,9 +158,9 @@ where
157158

158159
fn write_register(&mut self, register: u8, payload: u8) -> Result<(), Error<Self::Error>> {
159160
// If the first bit is 0, the register is written.
160-
let transfer = [register & 0x7f, payload];
161+
let data = [register & 0x7f, payload];
161162
self.spi
162-
.transfer(&mut [], &transfer)
163+
.write(&data)
163164
.map_err(|e| Error::Bus(SPIError::SPI(e)))?;
164165
Ok(())
165166
}
@@ -251,8 +252,11 @@ where
251252
register: u8,
252253
data: &mut [u8],
253254
) -> Result<(), Error<SPIError<SPI::Error>>> {
254-
self.spi
255-
.transfer(data, &[register])
255+
self.spi
256+
.transaction(&mut [
257+
Operation::Write(&[register]),
258+
Operation::Read(data)
259+
])
256260
.await
257261
.map_err(|e| Error::Bus(SPIError::SPI(e)))?;
258262
Ok(())

0 commit comments

Comments
 (0)