Skip to content

Updated logic around sysfs/cdev pin selection #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- Set default features to build both sysfs and cdev pin types
- Removed `Pin` export, use `CdevPin` or `SysfsPin`

## [v0.3.0] - 2019-11-25

### Added
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ repository = "https://github.com/japaric/linux-embedded-hal"
version = "0.3.0"

[features]
default = []
gpio_sysfs = ["sysfs_gpio"]
gpio_cdev = ["gpio-cdev"]

default = [ "gpio_cdev", "gpio_sysfs" ]

[dependencies]
embedded-hal = { version = "0.2.3", features = ["unproven"] }
gpio-cdev = { version = "0.2", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions src/cdev_pin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::ops;
//! Linux CDev pin type

/// Newtype around [`gpio_cdev::LineHandle`] that implements the `embedded-hal` traits
///
Expand Down Expand Up @@ -43,15 +43,15 @@ impl hal::digital::v2::InputPin for CdevPin {
}
}

impl ops::Deref for CdevPin {
impl core::ops::Deref for CdevPin {
type Target = gpio_cdev::LineHandle;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl ops::DerefMut for CdevPin {
impl core::ops::DerefMut for CdevPin {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
Expand Down
28 changes: 19 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
extern crate cast;
extern crate core;
extern crate embedded_hal as hal;
#[cfg(feature = "gpio_cdev")]
pub extern crate gpio_cdev;
pub extern crate i2cdev;
pub extern crate nb;
pub extern crate serial_core;
pub extern crate serial_unix;
pub extern crate spidev;
pub extern crate serial_unix;
pub extern crate serial_core;
pub extern crate nb;


#[cfg(feature = "gpio_sysfs")]
pub extern crate sysfs_gpio;

#[cfg(feature = "gpio_cdev")]
pub extern crate gpio_cdev;


use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand All @@ -37,19 +41,24 @@ use spidev::SpidevTransfer;

mod serial;

#[cfg(feature = "gpio_cdev")]
/// Cdev Pin wrapper module
mod cdev_pin;
pub use serial::Serial;

#[cfg(feature = "gpio_sysfs")]
/// Sysfs Pin wrapper module
mod sysfs_pin;

#[cfg(feature = "gpio_cdev")]
/// Cdev Pin wrapper module
mod cdev_pin;

#[cfg(feature = "gpio_cdev")]
/// Cdev pin re-export
pub use cdev_pin::CdevPin;
pub use serial::Serial;
#[cfg(feature = "gpio_sysfs")]
/// Sysfs pin re-export
pub use sysfs_pin::SysfsPin;


/// Empty struct that provides delay functionality on top of `thread::sleep`
pub struct Delay;

Expand Down Expand Up @@ -107,6 +116,7 @@ impl hal::blocking::delay::DelayMs<u64> for Delay {
}
}


/// Newtype around [`i2cdev::linux::LinuxI2CDevice`] that implements the `embedded-hal` traits
///
/// [`i2cdev::linux::LinuxI2CDevice`]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html
Expand Down
7 changes: 4 additions & 3 deletions src/sysfs_pin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::ops;
//! Linux Sysfs pin type

use std::path::Path;

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

impl ops::Deref for SysfsPin {
impl core::ops::Deref for SysfsPin {
type Target = sysfs_gpio::Pin;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl ops::DerefMut for SysfsPin {
impl core::ops::DerefMut for SysfsPin {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
Expand Down