Skip to content

Commit a07db8d

Browse files
committed
Fix asymmetric SPI transfers
1 parent fca0b1f commit a07db8d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Changed
1212
- Changed `ErrorKind::I2cNoAck` to have an inner type of `eh1::i2c::NoAcknowledgeSource`.
1313

14+
### Fixed
15+
- Fixed asymmetric SPI transfers (read size > write size) with `eh1`.
16+
1417
## [0.17.0] - 2023-08-15
1518
### Changed
1619
- Updated the alpha release of `embedded-hal` from `1.0.0-alpha.11` to `1.0.0-rc.1`.

examples/spi-eh1-loopback.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fn main() {
4444
// bytes are still in the read buffer, which breaks tests afterwards.
4545
// Spi::flush(&mut spi) doesn't help either
4646

47-
/*
4847
// --- Asymmetric transfer (Read more than we write) ---
4948
print!("Starting asymetric transfer (read > write)...");
5049
let mut read: [u8; 4] = [0x00; 4];
@@ -55,7 +54,6 @@ fn main() {
5554
assert_eq!(read[2], 0x00u8);
5655
println!(" SUCCESS");
5756
sleep(delay);
58-
*/
5957

6058
// --- Symmetric transfer with huge buffer ---
6159
// Only your RAM is the limit!

src/spi.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ where
279279
lock.ft.send(cmd.as_slice())?;
280280
lock.ft.recv(read)?;
281281

282+
let remain: usize = write.len().saturating_sub(read.len());
283+
if remain != 0 {
284+
let mut remain_buf: Vec<u8> = vec![0; remain];
285+
lock.ft.recv(&mut remain_buf)?;
286+
}
287+
282288
Ok(())
283289
}
284290
}

0 commit comments

Comments
 (0)