From 2b2ab40b798666df00dc8dafa948c7be8716808c Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 Oct 2025 19:31:04 +0000 Subject: [PATCH 1/3] Implement a read_write_in_place method for in-place transfers --- src/spidevioctl.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/spidevioctl.rs b/src/spidevioctl.rs index 1c343615c..904388a14 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/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 { From 38d26d7bad92c786b54352d58473c6862b83260e Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Tue, 21 Oct 2025 20:05:05 +0000 Subject: [PATCH 2/3] Add changelog entry. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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) From 87d01e01bc6aa81af1b52db421bce5a680e2bed0 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 22 Oct 2025 11:18:25 +0000 Subject: [PATCH 3/3] Use a better reference allowing to share rx/tx buffers --- src/spidevioctl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spidevioctl.rs b/src/spidevioctl.rs index 904388a14..1942d858d 100644 --- a/src/spidevioctl.rs +++ b/src/spidevioctl.rs @@ -112,7 +112,7 @@ impl<'a, 'b> spi_ioc_transfer<'a, 'b> { /// 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 + // 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,