Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different lengths of buffers in hal_1 SpiBus impl #566

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wiktorwieclaw
Copy link

In SpiBus::transfer

fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error>;

From embedded-hal docs:

It is allowed for read and write to have different lengths, even zero length. The transfer runs for max(read.len(), write.len()) words. If read is shorter, incoming words after read has been filled will be discarded. If write is shorter, the value of words sent in MOSI after all write has been sent is implementation-defined, typically 0x00, 0xFF, or configurable.

Current implementation requires the lengths to be equal:
https://github.com/stm32-rs/stm32f4xx-hal/blob/master/src/spi/hal_1.rs#L88

fn transfer(&mut self, buff: &mut [W], data: &[W]) -> Result<(), Self::Error> {
    assert_eq!(data.len(), buff.len()); // precondition here!

    for (d, b) in data.iter().cloned().zip(buff.iter_mut()) {
        nb::block!(<Self as FullDuplex<W>>::write(self, d))?;
        *b = nb::block!(<Self as FullDuplex<W>>::read(self))?;
    }

    Ok(())
}

So I changed it accordingly. Please let me know if line 103 is needed.

@burrbull
Copy link
Contributor

cc @eldruin @ryankurte

@ryankurte
Copy link
Contributor

It is allowed for read and write to have different lengths, even zero length

huh, this is news to me / i thought we required these to be the same :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants