diff --git a/CHANGELOG.md b/CHANGELOG.md index 507d78bef..3b0018105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/spidevioctl.rs b/src/spidevioctl.rs index 1c343615c..1942d858d 100644 --- a/src/spidevioctl.rs +++ b/src/spidevioctl.rs @@ -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/Documentation/spi/spidev.rst?id=211ddde0823f1442e4ad052a2f30f050145ccada#n191 + 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 {