File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,49 @@ impl SpiDeviceId {
255
255
}
256
256
}
257
257
258
+ /// Wrapper struct around the kernel's `struct spi_transfer`.
259
+ pub struct SpiTransfer ( bindings:: spi_transfer ) ;
260
+
261
+ impl SpiTransfer {
262
+ pub fn new ( ) -> Self {
263
+ SpiTransfer ( bindings:: spi_transfer:: default ( ) )
264
+ }
265
+
266
+ pub fn with_tx_buf ( mut self , buf : & [ u8 ] ) -> Self {
267
+ // Make sure no tx_buf nor rx_buf has been provided before
268
+ // TODO: replace with a `Result`
269
+ assert ! ( self . 0 . len == 0 ) ;
270
+
271
+ self . 0 . tx_buf = buf. as_ptr ( ) as * const core:: ffi:: c_void ;
272
+ self . 0 . len = buf. len ( ) as core:: ffi:: c_uint ;
273
+
274
+ self
275
+ }
276
+
277
+ pub fn with_rx_buf ( mut self , buf : & mut [ u8 ] ) -> Self {
278
+ // Make sure no tx_buf nor rx_buf has been provided before
279
+ // TODO: replace with a `Result`
280
+ assert ! ( self . 0 . len == 0 ) ;
281
+
282
+ self . 0 . rx_buf = buf. as_mut_ptr ( ) as * mut core:: ffi:: c_void ;
283
+ self . 0 . len = buf. len ( ) as core:: ffi:: c_uint ;
284
+
285
+ self
286
+ }
287
+ }
288
+
289
+ #[ derive( Default ) ]
290
+ pub struct SpiMessage ( bindings:: spi_message ) ;
291
+
292
+ impl SpiMessage {
293
+ pub fn new ( ) -> Self {
294
+ Self :: default ( )
295
+ }
296
+ /// Equivalent of `spi_message_init`
297
+ pub fn spi_message_init ( & mut self ) {
298
+ }
299
+ }
300
+
258
301
/// High level abstraction over the kernel's SPI functions such as `spi_write_then_read`.
259
302
// TODO this should be a mod, right?
260
303
pub struct Spi ;
You can’t perform that action at this time.
0 commit comments