From c9692e190d82fb46b6b77eb97eedfee78c854871 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Tue, 4 Feb 2025 18:34:23 +0530 Subject: [PATCH 1/3] Add serial feature - No need to pull serialport-rs and embedded-hal-nb in projects that do not need serial functionality. Signed-off-by: Ayush Singh --- Cargo.toml | 7 ++++--- src/lib.rs | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 590aa91..8e67e7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,18 +18,19 @@ gpio_cdev = ["gpio-cdev"] async-tokio = ["gpio-cdev/async-tokio", "dep:embedded-hal-async", "tokio/time"] i2c = ["i2cdev"] spi = ["spidev"] +serial = ["serialport", "embedded-hal-nb"] -default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ] +default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi", "serial" ] [dependencies] embedded-hal = "1" -embedded-hal-nb = "1" +embedded-hal-nb = { version = "1", optional = true } embedded-hal-async = { version = "1", optional = true } gpio-cdev = { version = "0.6.0", optional = true } sysfs_gpio = { version = "0.6.1", optional = true } i2cdev = { version = "0.6.0", optional = true } nb = "1" -serialport = { version = "4.2.0", default-features = false } +serialport = { version = "4.2.0", default-features = false, optional = true } spidev = { version = "0.6.0", optional = true } nix = "0.27.1" tokio = { version = "1", default-features = false, optional = true } diff --git a/src/lib.rs b/src/lib.rs index ee52767..b6c1397 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ #[cfg(feature = "i2c")] pub use i2cdev; pub use nb; +#[cfg(feature = "serial")] pub use serialport; #[cfg(feature = "spi")] pub use spidev; @@ -43,6 +44,7 @@ pub use sysfs_pin::{SysfsPin, SysfsPinError}; mod delay; #[cfg(feature = "i2c")] mod i2c; +#[cfg(feature = "serial")] mod serial; #[cfg(feature = "spi")] mod spi; @@ -51,6 +53,7 @@ mod timer; pub use crate::delay::Delay; #[cfg(feature = "i2c")] pub use crate::i2c::{I2CError, I2cdev}; +#[cfg(feature = "serial")] pub use crate::serial::{Serial, SerialError}; #[cfg(feature = "spi")] pub use crate::spi::{SPIError, SpidevBus, SpidevDevice}; From fb2db219976e9bb9995195da767d27225ccd1c9b Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Tue, 4 Feb 2025 18:36:09 +0530 Subject: [PATCH 2/3] Make nix optional - nix dependency is only directly used for i2c in this crate. Signed-off-by: Ayush Singh --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8e67e7d..6371f30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" gpio_sysfs = ["sysfs_gpio"] gpio_cdev = ["gpio-cdev"] async-tokio = ["gpio-cdev/async-tokio", "dep:embedded-hal-async", "tokio/time"] -i2c = ["i2cdev"] +i2c = ["i2cdev", "nix"] spi = ["spidev"] serial = ["serialport", "embedded-hal-nb"] @@ -32,7 +32,7 @@ i2cdev = { version = "0.6.0", optional = true } nb = "1" serialport = { version = "4.2.0", default-features = false, optional = true } spidev = { version = "0.6.0", optional = true } -nix = "0.27.1" +nix = { version = "0.27.1", optional = true } tokio = { version = "1", default-features = false, optional = true } [dev-dependencies] From 17b2457a15eb8548e575a53678c13cc3b29bc266 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Fri, 7 Feb 2025 14:44:13 +0530 Subject: [PATCH 3/3] Add Changelong entry for #118 Signed-off-by: Ayush Singh --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06cdae9..dbcc339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Added async `DelayNs` implementation for `tokio`. +- Added feature flag for `serial`. ## [v0.4.0] - 2024-01-10