Skip to content

SPI implementation panics if read and write buffers in a transfer are not the same length #97

Closed
@adamgreig

Description

@adamgreig

In embedded-hal SPI transfers, the read and write buffers may be different lengths:

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.

In spidev read_write, it is not:

Note that the tx_buf and rx_buf must be the same length.

However currently we implement transfer by calling read_write directly:

SpiOperation::Transfer(read, write) => SpidevTransfer::read_write(write, read),

leading to panics when the buffer lengths differ. We should adjust the buffers passed to read_write, or split the transfer into a read_write and a write or something, to accommodate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions