From bc935143f51d6dcac57522000551f9a90a93f756 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Arcos Date: Thu, 11 Jan 2024 09:54:47 +0100 Subject: [PATCH] Add serialport feature (#535) * feat: Add serialport feature * docs: Update changelog --- CHANGELOG.md | 1 + espflash/Cargo.toml | 8 +++++--- espflash/src/error.rs | 7 +++++++ espflash/src/lib.rs | 6 ++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e725567d..86872a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `checksum-md5` command (#536) - Add verify and skipping of unchanged flash regions - add `--no-verify` and `--no-skip` (#538) - Add --min-chip-rev argument to specify minimum chip revision (#252) +- Add `serialport` feature. (#535) ### Fixed diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index a920c6ca..e206a2f8 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -20,7 +20,7 @@ rustdoc-args = ["--cfg", "docsrs"] [[bin]] name = "espflash" path = "./src/bin/espflash.rs" -required-features = ["cli"] +required-features = ["cli, serialport"] [dependencies] addr2line = { version = "0.21.0", optional = true } @@ -49,7 +49,7 @@ parse_int = { version = "0.6.0", optional = true } regex = { version = "1.9.6", optional = true } rppal = { version = "0.14.1", optional = true } serde = { version = "1.0.188", features = ["derive"] } -serialport = "4.2.2" +serialport = { version = "4.2.2", optional = true } sha2 = "0.10.8" slip-codec = "0.3.4" strum = { version = "0.25.0", features = ["derive"] } @@ -62,7 +62,7 @@ xmas-elf = "0.9.0" libc = "0.2.101" [features] -default = ["cli"] +default = ["cli", "serialport"] cli = [ "dep:addr2line", "dep:clap", @@ -80,7 +80,9 @@ cli = [ "dep:lazy_static", "dep:parse_int", "dep:regex", + "dep:serialport", "dep:update-informer", ] +serialport = ["dep:serialport"] raspberry = ["dep:rppal"] diff --git a/espflash/src/error.rs b/espflash/src/error.rs index c06fe64f..3d866463 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -194,6 +194,8 @@ impl From for Error { } } +#[cfg(feature = "serialport")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))] impl From for Error { fn from(err: serialport::Error) -> Self { Self::Connection(err.into()) @@ -251,6 +253,7 @@ pub enum ConnectionError { #[diagnostic(code(espflash::timeout))] Timeout(TimedOutCommand), + #[cfg(feature = "serialport")] #[error("IO error while using serial port: {0}")] #[diagnostic(code(espflash::serial_error))] Serial(#[source] serialport::Error), @@ -262,6 +265,8 @@ impl From for ConnectionError { } } +#[cfg(feature = "serialport")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))] impl From for ConnectionError { fn from(err: serialport::Error) -> Self { use serialport::ErrorKind; @@ -544,6 +549,8 @@ impl ResultExt for Result { } } +#[cfg(feature = "serialport")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))] fn from_error_kind(kind: io::ErrorKind, err: E) -> ConnectionError where E: Into, diff --git a/espflash/src/lib.rs b/espflash/src/lib.rs index 1585c876..0d7ca9cb 100644 --- a/espflash/src/lib.rs +++ b/espflash/src/lib.rs @@ -51,11 +51,17 @@ #[cfg_attr(docsrs, doc(cfg(feature = "cli")))] pub mod cli; pub mod command; +#[cfg(feature = "serialport")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))] pub mod connection; pub mod elf; pub mod error; +#[cfg(feature = "serialport")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))] pub mod flasher; pub mod image_format; +#[cfg(feature = "serialport")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))] pub mod interface; pub mod targets;