Skip to content

Commit 7dba060

Browse files
jannicsirhcel
authored andcommitted
Implement a read_write_in_place method for in-place transfers
1 parent 82afaaf commit 7dba060

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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/include/linux/spi/spi.h?id=211ddde0823f1442e4ad052a2f30f050145ccada#n1073
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)