From ff5b588c5fee9f84dbcbf9c1e45277c963c94e76 Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Tue, 5 Apr 2022 18:03:28 +0200 Subject: [PATCH] Add features for spi and i2c --- CHANGELOG.md | 4 ++++ Cargo.toml | 8 +++++--- README.md | 2 ++ src/lib.rs | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f0f54..036d328 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Added feature flag for `spi` and `i2c` + ## [v0.4.0-alpha.2] - 2022-02-15 ### Added diff --git a/Cargo.toml b/Cargo.toml index 947143b..a487645 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,18 +16,20 @@ edition = "2018" gpio_sysfs = ["sysfs_gpio"] gpio_cdev = ["gpio-cdev"] async-tokio = ["gpio-cdev/async-tokio"] +i2c = ["i2cdev"] +spi = ["spidev"] -default = [ "gpio_cdev", "gpio_sysfs" ] +default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ] [dependencies] embedded-hal = "=1.0.0-alpha.7" gpio-cdev = { version = "0.5.1", optional = true } sysfs_gpio = { version = "0.6.1", optional = true } -i2cdev = "0.5.1" +i2cdev = { version = "0.5.1", optional = true } nb = "1" serial-core = "0.4.0" serial-unix = "0.4.0" -spidev = "0.5.1" +spidev = { version = "0.5.1", optional = true } nix = "0.23.1" [dev-dependencies] diff --git a/README.md b/README.md index 949e3c3..671688a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ linux-embedded-hal = { version = "0.3", features = ["gpio_cdev"] } `SysfsPin` can be still used with feature flag `gpio_sysfs`. +With `default-features = false` you can enable the features `gpio_cdev`, `gpio_sysfs`, `i2c`, and `spi` as needed. + ## Minimum Supported Rust Version (MSRV) This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might* diff --git a/src/lib.rs b/src/lib.rs index 081e708..4de0d92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,10 +12,12 @@ #![deny(missing_docs)] +#[cfg(feature = "i2c")] pub use i2cdev; pub use nb; pub use serial_core; pub use serial_unix; +#[cfg(feature = "spi")] pub use spidev; #[cfg(feature = "gpio_sysfs")] @@ -40,13 +42,17 @@ pub use cdev_pin::CdevPin; pub use sysfs_pin::SysfsPin; mod delay; +#[cfg(feature = "i2c")] mod i2c; mod serial; +#[cfg(feature = "spi")] mod spi; mod timer; pub use crate::delay::Delay; +#[cfg(feature = "i2c")] pub use crate::i2c::{I2CError, I2cdev}; pub use crate::serial::{Serial, SerialError}; +#[cfg(feature = "spi")] pub use crate::spi::{SPIError, Spidev}; pub use crate::timer::{CountDown, Periodic, SysTimer};