WIP: update for SPI transfer impl #1

Draft
muellerr wants to merge 1 commits from update-spi-impl into main
3 changed files with 18 additions and 7 deletions

View File

@ -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.

View File

@ -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};

View File

@ -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;
}
}