1313#![ deny( missing_docs) ]
1414
1515extern crate cast;
16+ extern crate core;
1617extern crate embedded_hal as hal;
18+ pub extern crate gpio_cdev;
1719pub extern crate i2cdev;
20+ pub extern crate nb;
21+ pub extern crate serial_core;
22+ pub extern crate serial_unix;
1823pub extern crate spidev;
1924pub extern crate sysfs_gpio;
20- pub extern crate serial_unix;
21- pub extern crate serial_core;
22- pub extern crate nb;
2325
2426use std:: io:: { self , Write } ;
2527use std:: path:: { Path , PathBuf } ;
@@ -33,7 +35,16 @@ use spidev::SpidevTransfer;
3335
3436mod serial;
3537
38+ /// Cdev Pin wrapper module
39+ pub mod cdev_pin;
40+ /// Sysfs Pin wrapper module
41+ pub mod sysfs_pin;
42+
43+ #[ cfg( feature = "gpio_cdev" ) ]
44+ pub use cdev_pin:: Pin ;
3645pub use serial:: Serial ;
46+ #[ cfg( not( feature = "gpio_cdev" ) ) ]
47+ pub use sysfs_pin:: Pin ;
3748
3849/// Empty struct that provides delay functionality on top of `thread::sleep`
3950pub struct Delay ;
@@ -92,72 +103,6 @@ impl hal::blocking::delay::DelayMs<u64> for Delay {
92103 }
93104}
94105
95- /// Newtype around [`sysfs_gpio::Pin`] that implements the `embedded-hal` traits
96- ///
97- /// [`sysfs_gpio::Pin`]: https://docs.rs/sysfs_gpio/0.5.1/sysfs_gpio/struct.Pin.html
98- pub struct Pin ( pub sysfs_gpio:: Pin ) ;
99-
100- impl Pin {
101- /// See [`sysfs_gpio::Pin::new`][0] for details.
102- ///
103- /// [0]: https://docs.rs/sysfs_gpio/0.5.1/sysfs_gpio/struct.Pin.html#method.new
104- pub fn new ( pin_num : u64 ) -> Pin {
105- Pin ( sysfs_gpio:: Pin :: new ( pin_num) )
106- }
107-
108- /// See [`sysfs_gpio::Pin::from_path`][0] for details.
109- ///
110- /// [0]: https://docs.rs/sysfs_gpio/0.5.1/sysfs_gpio/struct.Pin.html#method.from_path
111- pub fn from_path < P > ( path : P ) -> sysfs_gpio:: Result < Pin >
112- where
113- P : AsRef < Path > ,
114- {
115- sysfs_gpio:: Pin :: from_path ( path) . map ( Pin )
116- }
117- }
118-
119- impl hal:: digital:: v2:: OutputPin for Pin {
120- type Error = sysfs_gpio:: Error ;
121-
122- fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > {
123- self . 0 . set_value ( 0 )
124- }
125-
126- fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > {
127- self . 0 . set_value ( 1 )
128- }
129- }
130-
131- impl hal:: digital:: v2:: InputPin for Pin {
132- type Error = sysfs_gpio:: Error ;
133-
134- fn is_high ( & self ) -> Result < bool , Self :: Error > {
135- if !self . 0 . get_active_low ( ) ? {
136- self . 0 . get_value ( ) . map ( |val| val != 0 )
137- } else {
138- self . 0 . get_value ( ) . map ( |val| val == 0 )
139- }
140- }
141-
142- fn is_low ( & self ) -> Result < bool , Self :: Error > {
143- self . is_high ( ) . map ( |val| !val)
144- }
145- }
146-
147- impl ops:: Deref for Pin {
148- type Target = sysfs_gpio:: Pin ;
149-
150- fn deref ( & self ) -> & Self :: Target {
151- & self . 0
152- }
153- }
154-
155- impl ops:: DerefMut for Pin {
156- fn deref_mut ( & mut self ) -> & mut Self :: Target {
157- & mut self . 0
158- }
159- }
160-
161106/// Newtype around [`i2cdev::linux::LinuxI2CDevice`] that implements the `embedded-hal` traits
162107///
163108/// [`i2cdev::linux::LinuxI2CDevice`]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html
@@ -220,10 +165,7 @@ impl hal::blocking::i2c::WriteRead for I2cdev {
220165 buffer : & mut [ u8 ] ,
221166 ) -> Result < ( ) , Self :: Error > {
222167 self . set_address ( address) ?;
223- let mut messages = [
224- LinuxI2CMessage :: write ( bytes) ,
225- LinuxI2CMessage :: read ( buffer) ,
226- ] ;
168+ let mut messages = [ LinuxI2CMessage :: write ( bytes) , LinuxI2CMessage :: read ( buffer) ] ;
227169 self . inner . transfer ( & mut messages) . map ( drop)
228170 }
229171}
0 commit comments