Skip to content

Commit

Permalink
Move things back
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 24, 2024
1 parent 72b1713 commit 988029f
Show file tree
Hide file tree
Showing 24 changed files with 594 additions and 578 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +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, SpiSetParams and SpiAttachParams` to `flash_data` (#599)
- Moved `ProgressCallbacks` to `progress` (#599)
- The `command` module now requires `serialport`. (#599)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use espflash::{
EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, ReadFlashArgs,
},
error::Error,
flash_data::{parse_partition_table, FlashData, FlashSettings},
flasher::{parse_partition_table, FlashData, FlashSettings},
logging::initialize_logger,
targets::{Chip, XtalFrequency},
update::check_for_update,
Expand Down
6 changes: 2 additions & 4 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ use crate::{
connection::reset::{ResetAfterOperation, ResetBeforeOperation},
elf::ElfFirmwareImage,
error::{Error, MissingPartition, MissingPartitionTable},
flash_data::{parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize},
flasher::Flasher,
progress::ProgressCallbacks,
targets::{Chip, XtalFrequency},
flasher::{parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher},
targets::{Chip, ProgressCallbacks, XtalFrequency},
};

pub mod config;
Expand Down
13 changes: 11 additions & 2 deletions espflash/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{io::Write, mem::size_of, time::Duration};
use bytemuck::{bytes_of, Pod, Zeroable};
use strum::Display;

use crate::flash_data::{SpiAttachParams, SpiSetParams, CHECKSUM_INIT};
use crate::flasher::checksum;
use crate::flasher::{SpiAttachParams, SpiSetParams};

const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3);
const ERASE_REGION_TIMEOUT_PER_MB: Duration = Duration::from_secs(30);
Expand Down Expand Up @@ -514,3 +513,13 @@ fn data_command<W: Write>(
}
Ok(())
}

const CHECKSUM_INIT: u8 = 0xEF;

fn checksum(data: &[u8], mut checksum: u8) -> u8 {
for byte in data {
checksum ^= *byte;
}

checksum
}
2 changes: 1 addition & 1 deletion espflash/src/connection/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
command::{Command, CommandType},
connection::{Connection, Port, USB_SERIAL_JTAG_PID},
error::Error,
flash_data::FLASH_WRITE_SIZE,
flasher::FLASH_WRITE_SIZE,
};

/// Default time to wait before releasing the boot pin after a reset
Expand Down
28 changes: 16 additions & 12 deletions espflash/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
//! Library and application errors

#[cfg(feature = "serialport")]
use std::fmt::{Display, Formatter};

use miette::Diagnostic;
#[cfg(feature = "serialport")]
use slip_codec::SlipError;
use std::io;
use strum::VariantNames;
use thiserror::Error;

#[cfg(feature = "cli")]
use crate::cli::monitor::parser::esp_defmt::DefmtError;
#[cfg(feature = "serialport")]
use crate::command::CommandType;
use crate::flash_data::{FlashFrequency, FlashSize};
use crate::targets::Chip;
use crate::{
flasher::{FlashFrequency, FlashSize},
targets::Chip,
};
#[cfg(feature = "serialport")]
use slip_codec::SlipError;

/// All possible errors returned by espflash
#[derive(Debug, Diagnostic, Error)]
Expand Down Expand Up @@ -103,7 +107,7 @@ pub enum Error {

#[cfg(not(feature = "serialport"))]
#[error(transparent)]
IoError(#[from] std::io::Error),
IoError(#[from] io::Error),

#[error("Specified partition table path is not a .bin or .csv file")]
#[diagnostic(code(espflash::invalid_partition_table_path))]
Expand Down Expand Up @@ -202,15 +206,15 @@ pub enum Error {
InternalError,

#[error("Failed to open file: {0}")]
FileOpenError(String, #[source] std::io::Error),
FileOpenError(String, #[source] io::Error),

#[error("Failed to parse partition table")]
Partition(#[from] esp_idf_part::Error),
}

#[cfg(feature = "serialport")]
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::Connection(err.into())
}
}
Expand Down Expand Up @@ -292,8 +296,8 @@ pub enum ConnectionError {
}

#[cfg(feature = "serialport")]
impl From<std::io::Error> for ConnectionError {
fn from(err: std::io::Error) -> Self {
impl From<io::Error> for ConnectionError {
fn from(err: io::Error) -> Self {
from_error_kind(err.kind(), err)
}
}
Expand Down Expand Up @@ -520,11 +524,11 @@ impl<T> ResultExt for Result<T, Error> {

#[cfg(feature = "serialport")]
#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))]
fn from_error_kind<E>(kind: std::io::ErrorKind, err: E) -> ConnectionError
fn from_error_kind<E>(kind: io::ErrorKind, err: E) -> ConnectionError
where
E: Into<serialport::Error>,
{
use std::io::ErrorKind;
use io::ErrorKind;

match kind {
ErrorKind::TimedOut => ConnectionError::Timeout(TimedOutCommand::default()),
Expand Down
Loading

0 comments on commit 988029f

Please sign in to comment.