@@ -23,19 +23,6 @@ pub use sysfs_gpio;
2323
2424#[ cfg( feature = "gpio_cdev" ) ]
2525pub use gpio_cdev;
26-
27- use std:: io:: { self , Write } ;
28- use std:: ops;
29- use std:: path:: Path ;
30-
31- use spidev:: SpidevTransfer ;
32-
33- mod serial;
34- mod timer;
35-
36- pub use serial:: Serial ;
37- pub use timer:: SysTimer ;
38-
3926#[ cfg( feature = "gpio_sysfs" ) ]
4027/// Sysfs Pin wrapper module
4128mod sysfs_pin;
@@ -47,94 +34,19 @@ mod cdev_pin;
4734#[ cfg( feature = "gpio_cdev" ) ]
4835/// Cdev pin re-export
4936pub use cdev_pin:: CdevPin ;
37+
5038#[ cfg( feature = "gpio_sysfs" ) ]
5139/// Sysfs pin re-export
5240pub use sysfs_pin:: SysfsPin ;
5341
5442mod delay;
55- pub use crate :: delay:: Delay ;
56-
5743mod i2c;
58- pub use crate :: i2c:: I2cdev ;
59-
60- /// Newtype around [`spidev::Spidev`] that implements the `embedded-hal` traits
61- ///
62- /// [`spidev::Spidev`]: https://docs.rs/spidev/0.4.0/spidev/struct.Spidev.html
63- pub struct Spidev ( pub spidev:: Spidev ) ;
64-
65- impl Spidev {
66- /// See [`spidev::Spidev::open`][0] for details.
67- ///
68- /// [0]: https://docs.rs/spidev/0.4.0/spidev/struct.Spidev.html#method.open
69- pub fn open < P > ( path : P ) -> io:: Result < Self >
70- where
71- P : AsRef < Path > ,
72- {
73- spidev:: Spidev :: open ( path) . map ( Spidev )
74- }
75- }
76-
77- impl embedded_hal:: blocking:: spi:: Transfer < u8 > for Spidev {
78- type Error = io:: Error ;
79-
80- fn try_transfer < ' b > ( & mut self , buffer : & ' b mut [ u8 ] ) -> io:: Result < & ' b [ u8 ] > {
81- let tx = buffer. to_owned ( ) ;
82- self . 0
83- . transfer ( & mut SpidevTransfer :: read_write ( & tx, buffer) ) ?;
84- Ok ( buffer)
85- }
86- }
87-
88- impl embedded_hal:: blocking:: spi:: Write < u8 > for Spidev {
89- type Error = io:: Error ;
90-
91- fn try_write ( & mut self , buffer : & [ u8 ] ) -> io:: Result < ( ) > {
92- self . 0 . write_all ( buffer)
93- }
94- }
95-
96- pub use embedded_hal:: blocking:: spi:: Operation as SpiOperation ;
97-
98- /// Transactional implementation batches SPI operations into a single transaction
99- impl embedded_hal:: blocking:: spi:: Transactional < u8 > for Spidev {
100- type Error = io:: Error ;
101-
102- fn try_exec < ' a > ( & mut self , operations : & mut [ SpiOperation < ' a , u8 > ] ) -> Result < ( ) , Self :: Error > {
103- // Map types from generic to linux objects
104- let mut messages: Vec < _ > = operations
105- . iter_mut ( )
106- . map ( |a| {
107- match a {
108- SpiOperation :: Write ( w) => SpidevTransfer :: write ( w) ,
109- SpiOperation :: Transfer ( r) => {
110- // Clone read to write pointer
111- // SPIdev is okay with having w == r but this is tricky to achieve in safe rust
112- let w = unsafe {
113- let p = r. as_ptr ( ) ;
114- std:: slice:: from_raw_parts ( p, r. len ( ) )
115- } ;
116-
117- SpidevTransfer :: read_write ( w, r)
118- }
119- }
120- } )
121- . collect ( ) ;
122-
123- // Execute transfer
124- self . 0 . transfer_multiple ( & mut messages)
125- }
126- }
127-
128- impl ops:: Deref for Spidev {
129- type Target = spidev:: Spidev ;
130-
131- fn deref ( & self ) -> & Self :: Target {
132- & self . 0
133- }
134- }
44+ mod serial;
45+ mod spi;
46+ mod timer;
13547
136- impl ops :: DerefMut for Spidev {
137- fn deref_mut ( & mut self ) -> & mut Self :: Target {
138- & mut self . 0
139- }
140- }
48+ pub use crate :: delay :: Delay ;
49+ pub use crate :: i2c :: I2cdev ;
50+ pub use crate :: serial :: Serial ;
51+ pub use crate :: spi :: { SpiOperation , Spidev } ;
52+ pub use crate :: timer :: SysTimer ;
0 commit comments