Skip to content

Commit 4d801ed

Browse files
committed
fix cdev/sysfs pin selection
1 parent c921d3f commit 4d801ed

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ repository = "https://github.com/japaric/linux-embedded-hal"
99
version = "0.3.0"
1010

1111
[features]
12-
default = []
1312
gpio_sysfs = ["sysfs_gpio"]
1413
gpio_cdev = ["gpio-cdev"]
1514

15+
default = [ "gpio_cdev", "gpio_sysfs" ]
16+
1617
[dependencies]
1718
embedded-hal = { version = "0.2.3", features = ["unproven"] }
1819
gpio-cdev = { version = "0.2", optional = true }

src/cdev_pin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::ops;
1+
//! Linux CDev pin type
22
33
/// Newtype around [`gpio_cdev::LineHandle`] that implements the `embedded-hal` traits
44
///
@@ -43,15 +43,15 @@ impl hal::digital::v2::InputPin for CdevPin {
4343
}
4444
}
4545

46-
impl ops::Deref for CdevPin {
46+
impl core::ops::Deref for CdevPin {
4747
type Target = gpio_cdev::LineHandle;
4848

4949
fn deref(&self) -> &Self::Target {
5050
&self.0
5151
}
5252
}
5353

54-
impl ops::DerefMut for CdevPin {
54+
impl core::ops::DerefMut for CdevPin {
5555
fn deref_mut(&mut self) -> &mut Self::Target {
5656
&mut self.0
5757
}

src/lib.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515
extern crate cast;
1616
extern crate core;
1717
extern crate embedded_hal as hal;
18-
#[cfg(feature = "gpio_cdev")]
19-
pub extern crate gpio_cdev;
2018
pub extern crate i2cdev;
21-
pub extern crate nb;
22-
pub extern crate serial_core;
23-
pub extern crate serial_unix;
2419
pub extern crate spidev;
20+
pub extern crate serial_unix;
21+
pub extern crate serial_core;
22+
pub extern crate nb;
23+
24+
2525
#[cfg(feature = "gpio_sysfs")]
2626
pub extern crate sysfs_gpio;
2727

28+
#[cfg(feature = "gpio_cdev")]
29+
pub extern crate gpio_cdev;
30+
31+
2832
use std::io::{self, Write};
2933
use std::path::{Path, PathBuf};
3034
use std::time::Duration;
@@ -37,19 +41,24 @@ use spidev::SpidevTransfer;
3741

3842
mod serial;
3943

40-
#[cfg(feature = "gpio_cdev")]
41-
/// Cdev Pin wrapper module
42-
mod cdev_pin;
44+
pub use serial::Serial;
45+
4346
#[cfg(feature = "gpio_sysfs")]
4447
/// Sysfs Pin wrapper module
4548
mod sysfs_pin;
4649

4750
#[cfg(feature = "gpio_cdev")]
51+
/// Cdev Pin wrapper module
52+
mod cdev_pin;
53+
54+
#[cfg(feature = "gpio_cdev")]
55+
/// Cdev pin re-export
4856
pub use cdev_pin::CdevPin;
49-
pub use serial::Serial;
5057
#[cfg(feature = "gpio_sysfs")]
58+
/// Sysfs pin re-export
5159
pub use sysfs_pin::SysfsPin;
5260

61+
5362
/// Empty struct that provides delay functionality on top of `thread::sleep`
5463
pub struct Delay;
5564

@@ -107,6 +116,22 @@ impl hal::blocking::delay::DelayMs<u64> for Delay {
107116
}
108117
}
109118

119+
120+
#[cfg(all(feature = "gpio_sysfs", feature = "gpio_cdev"))]
121+
/// Re-export of `sysfs_pin::SysfsPin` when both pin types are enabled
122+
/// This exists to maintain backwards compatibility with existing users
123+
pub type Pin = sysfs_pin::SysfsPin;
124+
125+
#[cfg(all(feature = "gpio_sysfs", not(feature = "gpio_cdev")))]
126+
/// Re-export of `sysfs_pin::SysfsPin` pin type when `gpio_sysfs` feature is selected
127+
pub type Pin = sysfs_pin::SysfsPin;
128+
129+
#[cfg(all(feature = "gpio_cdev", not(feature = "gpio_sysfs")))]
130+
/// Re-export of `cdev_pin::CdevPin` pin type when `gpio_cdev` feature is selected
131+
pub type Pin = cdev_pin::CdevPin;
132+
133+
134+
110135
/// Newtype around [`i2cdev::linux::LinuxI2CDevice`] that implements the `embedded-hal` traits
111136
///
112137
/// [`i2cdev::linux::LinuxI2CDevice`]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html

src/sysfs_pin.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::ops;
1+
//! Linux Sysfs pin type
2+
23
use std::path::Path;
34

45
/// Newtype around [`sysfs_gpio::Pin`] that implements the `embedded-hal` traits
@@ -53,15 +54,15 @@ impl hal::digital::v2::InputPin for SysfsPin {
5354
}
5455
}
5556

56-
impl ops::Deref for SysfsPin {
57+
impl core::ops::Deref for SysfsPin {
5758
type Target = sysfs_gpio::Pin;
5859

5960
fn deref(&self) -> &Self::Target {
6061
&self.0
6162
}
6263
}
6364

64-
impl ops::DerefMut for SysfsPin {
65+
impl core::ops::DerefMut for SysfsPin {
6566
fn deref_mut(&mut self) -> &mut Self::Target {
6667
&mut self.0
6768
}

0 commit comments

Comments
 (0)