Skip to content

Commit

Permalink
Merge flashing back into serialport
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 24, 2024
1 parent 652c2af commit cbdb3a8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ jobs:
target: ${{ matrix.platform.target }}

- run: cargo check -p espflash --lib --no-default-features
- run: cargo check -p espflash --lib --no-default-features --features flashing
- run: cargo check -p espflash --lib --no-default-features --features serialport

msrv:
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add `--list-all-ports` connection argument to avoid serial port filtering (#590)
- Allow config file to live in parent folder (#595)
- Add `flashing` feature that enables stubs and commands without the serialport feature (#599)

### Fixed
- Change the `hard_reset` sequence to fix Windows issues (#594)
Expand All @@ -19,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Non-linux-musl: Only list the available USB Ports by default (#590)
- `FlashData::new` now returns `crate::Error` (#591)
- Moved `reset_after_flash` method to `reset` module (#594)
- Moved `parse_partition_table, DeviceInfo, FlashSettings, FlashData, FlashDataBuilder, FlashFrequency, FlashMode, FlashSize and SpiAttachParams` to `flash_data` (#599)
- Moved `parse_partition_table, DeviceInfo, FlashSettings, FlashData, FlashDataBuilder, FlashFrequency, FlashMode, FlashSize, SpiSetParams and SpiAttachParams` to `flash_data` (#599)
- Moved `ProgressCallbacks` to `progress` (#599)

### Removed
Expand Down
5 changes: 1 addition & 4 deletions espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,4 @@ cli = [
]

# enables connecting to a device via serial port
serialport = ["flashing", "dep:serialport", "dep:slip-codec", "dep:regex"]

# enables flash stubs and stub commands
flashing = ["dep:toml"]
serialport = ["dep:serialport", "dep:slip-codec", "dep:regex", "dep:toml"]
14 changes: 7 additions & 7 deletions espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use thiserror::Error;

#[cfg(feature = "cli")]
use crate::cli::monitor::parser::esp_defmt::DefmtError;
#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
use crate::command::CommandType;
use crate::flash_data::{FlashFrequency, FlashSize};
use crate::targets::Chip;
Expand Down Expand Up @@ -276,9 +276,9 @@ pub enum ConnectionError {
#[diagnostic(code(espflash::read_missmatch))]
ReadMissmatch(u32, u32),

#[cfg(feature = "serialport")]
#[error("Timeout while running {0}command")]
#[diagnostic(code(espflash::timeout))]
#[cfg(feature = "flashing")]
Timeout(TimedOutCommand),

#[cfg(feature = "serialport")]
Expand Down Expand Up @@ -326,12 +326,12 @@ impl From<SlipError> for ConnectionError {

/// An executed command which has timed out
#[derive(Clone, Debug, Default)]
#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
pub struct TimedOutCommand {
command: Option<CommandType>,
}

#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
impl Display for TimedOutCommand {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match &self.command {
Expand All @@ -341,7 +341,7 @@ impl Display for TimedOutCommand {
}
}

#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
impl From<CommandType> for TimedOutCommand {
fn from(ct: CommandType) -> Self {
TimedOutCommand { command: Some(ct) }
Expand Down Expand Up @@ -488,15 +488,15 @@ impl From<&'static str> for ElfError {
}
}

#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
pub(crate) trait ResultExt {
/// Mark an error as having occurred during the flashing stage
fn flashing(self) -> Self;
/// Mark the command from which this error originates
fn for_command(self, command: CommandType) -> Self;
}

#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
impl<T> ResultExt for Result<T, Error> {
fn flashing(self) -> Self {
match self {
Expand Down
4 changes: 2 additions & 2 deletions espflash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
#[cfg(feature = "cli")]
#[cfg_attr(docsrs, doc(cfg(feature = "cli")))]
pub mod cli;
#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
pub mod command;
#[cfg(feature = "serialport")]
#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))]
pub mod connection;
pub mod elf;
pub mod error;
pub mod flash_data;
#[cfg(feature = "flashing")]
#[cfg(feature = "serialport")]
pub mod flasher;
pub mod image_format;
pub mod progress;
Expand Down

0 comments on commit cbdb3a8

Please sign in to comment.