Skip to content

Commit 008c8da

Browse files
authored
Merge pull request #49 from jannic-dev-forks/transfer-in-place
Implement a read_write_in_place method for in-place transfers
2 parents 9884fe3 + 87d01e0 commit 008c8da

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

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

7+
- Implement a `read_write_in_place` method for in-place transfers.
8+
79
## 0.7.0 / 2025-03-04
810

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

src/spidevioctl.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ impl<'a, 'b> spi_ioc_transfer<'a, 'b> {
108108
}
109109
}
110110

111+
/// Create a read/write transfer using the same buffer for reading
112+
/// and writing (in-place transfer).
113+
pub fn read_write_in_place(buf: &'a mut [u8]) -> Self {
114+
// This is allowed according to a comment in the linux source tree:
115+
// https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/spi/spidev.rst?id=211ddde0823f1442e4ad052a2f30f050145ccada#n191
116+
spi_ioc_transfer {
117+
rx_buf: buf.as_ptr() as *const () as usize as u64,
118+
tx_buf: buf.as_ptr() as *const () as usize as u64,
119+
len: buf.len() as u32,
120+
..Default::default()
121+
}
122+
}
123+
111124
/// Create a delay transfer of a number of microseconds
112125
pub fn delay(microseconds: u16) -> Self {
113126
spi_ioc_transfer {

0 commit comments

Comments
 (0)