Skip to content

Commit 12847c4

Browse files
Merge #81
81: Add features for spi and i2c r=eldruin a=zuckschwerdt Adds the features `i2c` and `spi` for an optional dependency on `i2cdev` and `spidev`. Discussion in #80. Closes #80 Co-authored-by: Christian W. Zuckschwerdt <[email protected]>
2 parents 245b250 + ff5b588 commit 12847c4

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added feature flag for `spi` and `i2c`
13+
1014
## [v0.4.0-alpha.2] - 2022-02-15
1115

1216
### Added

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ edition = "2018"
1616
gpio_sysfs = ["sysfs_gpio"]
1717
gpio_cdev = ["gpio-cdev"]
1818
async-tokio = ["gpio-cdev/async-tokio"]
19+
i2c = ["i2cdev"]
20+
spi = ["spidev"]
1921

20-
default = [ "gpio_cdev", "gpio_sysfs" ]
22+
default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ]
2123

2224
[dependencies]
2325
embedded-hal = "=1.0.0-alpha.7"
2426
gpio-cdev = { version = "0.5.1", optional = true }
2527
sysfs_gpio = { version = "0.6.1", optional = true }
26-
i2cdev = "0.5.1"
28+
i2cdev = { version = "0.5.1", optional = true }
2729
nb = "1"
2830
serial-core = "0.4.0"
2931
serial-unix = "0.4.0"
30-
spidev = "0.5.1"
32+
spidev = { version = "0.5.1", optional = true }
3133
nix = "0.23.1"
3234

3335
[dev-dependencies]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ linux-embedded-hal = { version = "0.3", features = ["gpio_cdev"] }
2525

2626
`SysfsPin` can be still used with feature flag `gpio_sysfs`.
2727

28+
With `default-features = false` you can enable the features `gpio_cdev`, `gpio_sysfs`, `i2c`, and `spi` as needed.
29+
2830
## Minimum Supported Rust Version (MSRV)
2931

3032
This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might*

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
1313
#![deny(missing_docs)]
1414

15+
#[cfg(feature = "i2c")]
1516
pub use i2cdev;
1617
pub use nb;
1718
pub use serial_core;
1819
pub use serial_unix;
20+
#[cfg(feature = "spi")]
1921
pub use spidev;
2022

2123
#[cfg(feature = "gpio_sysfs")]
@@ -40,13 +42,17 @@ pub use cdev_pin::CdevPin;
4042
pub use sysfs_pin::SysfsPin;
4143

4244
mod delay;
45+
#[cfg(feature = "i2c")]
4346
mod i2c;
4447
mod serial;
48+
#[cfg(feature = "spi")]
4549
mod spi;
4650
mod timer;
4751

4852
pub use crate::delay::Delay;
53+
#[cfg(feature = "i2c")]
4954
pub use crate::i2c::{I2CError, I2cdev};
5055
pub use crate::serial::{Serial, SerialError};
56+
#[cfg(feature = "spi")]
5157
pub use crate::spi::{SPIError, Spidev};
5258
pub use crate::timer::{CountDown, Periodic, SysTimer};

0 commit comments

Comments
 (0)