From 811cead9c66bae6eb1a1a05cd7ca7850a1be6a7e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 12 May 2025 10:43:33 +0200 Subject: [PATCH] update for SPI `transfer` impl --- CHANGELOG.md | 4 ++++ src/gpio/mod.rs | 2 +- src/spi/mod.rs | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 445eb9d..7a6067a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] +### Changed + +- SPI `transfer` implemenation update to handle size missmatch between read and write. + ## [v0.1.0] Init commit. diff --git a/src/gpio/mod.rs b/src/gpio/mod.rs index 54ae665..3a3c051 100644 --- a/src/gpio/mod.rs +++ b/src/gpio/mod.rs @@ -1,7 +1,7 @@ //! GPIO support module. use core::convert::Infallible; -pub use crate::ioconfig::{regs::FunSel, FilterClkSel, FilterType}; +pub use crate::ioconfig::{FilterClkSel, FilterType, regs::FunSel}; pub use embedded_hal::digital::PinState; pub use ll::{InterruptEdge, InterruptLevel, PinId, Port, Pull}; diff --git a/src/spi/mod.rs b/src/spi/mod.rs index e9fcf12..16dc12b 100644 --- a/src/spi/mod.rs +++ b/src/spi/mod.rs @@ -860,21 +860,28 @@ where self.transfer_preparation(write)?; let mut current_read_idx = 0; let mut current_write_idx = self.initial_send_fifo_pumping_with_words(write); + let max_idx = core::cmp::max(read.len(), write.len()); while current_read_idx < read.len() || current_write_idx < write.len() { - if current_write_idx < write.len() { + if current_write_idx < max_idx { if current_write_idx == write.len() - 1 && self.bmstall { nb::block!( self.write_fifo(write[current_write_idx].into() | BMSTART_BMSTOP_MASK) )?; - } else { + } else if current_write_idx < write.len() { nb::block!(self.write_fifo(write[current_write_idx].into()))?; + } else { + nb::block!(self.write_fifo(0))?; } current_write_idx += 1; } - if current_read_idx < read.len() { - read[current_read_idx] = (nb::block!(self.read_fifo())? & Word::MASK) - .try_into() - .unwrap(); + if current_read_idx < max_idx { + if current_read_idx < read.len() { + read[current_read_idx] = (nb::block!(self.read_fifo())? & Word::MASK) + .try_into() + .unwrap(); + } else { + nb::block!(self.read_fifo()).unwrap(); + } current_read_idx += 1; } } -- 2.43.0