Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[Full Changelog](https://github.com/rust-embedded/rust-spidev/compare/0.7.0...HEAD)

- Implement a `read_write_in_place` method for in-place transfers.

## 0.7.0 / 2025-03-04

[Full Changelog](https://github.com/rust-embedded/rust-spidev/compare/0.6.0...0.7.0)
Expand Down
13 changes: 13 additions & 0 deletions src/spidevioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ impl<'a, 'b> spi_ioc_transfer<'a, 'b> {
}
}

/// Create a read/write transfer using the same buffer for reading
/// and writing (in-place transfer).
pub fn read_write_in_place(buf: &'a mut [u8]) -> Self {
// This is allowed according to a comment in the linux source tree:
// https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/spi/spi.h?id=211ddde0823f1442e4ad052a2f30f050145ccada#n1073
spi_ioc_transfer {
rx_buf: buf.as_ptr() as *const () as usize as u64,
tx_buf: buf.as_ptr() as *const () as usize as u64,
len: buf.len() as u32,
..Default::default()
}
}

/// Create a delay transfer of a number of microseconds
pub fn delay(microseconds: u16) -> Self {
spi_ioc_transfer {
Expand Down