Skip to content

Commit 22d38e1

Browse files
committed
Move things back
1 parent 72b1713 commit 22d38e1

24 files changed

+593
-574
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Non-linux-musl: Only list the available USB Ports by default (#590)
1919
- `FlashData::new` now returns `crate::Error` (#591)
2020
- Moved `reset_after_flash` method to `reset` module (#594)
21-
- Moved `parse_partition_table, DeviceInfo, FlashSettings, FlashData, FlashDataBuilder, FlashFrequency, FlashMode, FlashSize, SpiSetParams and SpiAttachParams` to `flash_data` (#599)
22-
- Moved `ProgressCallbacks` to `progress` (#599)
21+
- The `command` module now requires `serialport`. (#599)
2322

2423
### Removed
2524

espflash/src/bin/espflash.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use espflash::{
1414
EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, ReadFlashArgs,
1515
},
1616
error::Error,
17-
flash_data::{parse_partition_table, FlashData, FlashSettings},
17+
flasher::{parse_partition_table, FlashData, FlashSettings},
1818
logging::initialize_logger,
1919
targets::{Chip, XtalFrequency},
2020
update::check_for_update,

espflash/src/cli/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ use crate::{
3030
connection::reset::{ResetAfterOperation, ResetBeforeOperation},
3131
elf::ElfFirmwareImage,
3232
error::{Error, MissingPartition, MissingPartitionTable},
33-
flash_data::{parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize},
34-
flasher::Flasher,
35-
progress::ProgressCallbacks,
33+
flasher::{
34+
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher,
35+
ProgressCallbacks,
36+
},
3637
targets::{Chip, XtalFrequency},
3738
};
3839

espflash/src/command.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::{io::Write, mem::size_of, time::Duration};
55
use bytemuck::{bytes_of, Pod, Zeroable};
66
use strum::Display;
77

8-
use crate::flash_data::{SpiAttachParams, SpiSetParams, CHECKSUM_INIT};
9-
use crate::flasher::checksum;
8+
use crate::flasher::{SpiAttachParams, SpiSetParams};
109

1110
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3);
1211
const ERASE_REGION_TIMEOUT_PER_MB: Duration = Duration::from_secs(30);
@@ -514,3 +513,13 @@ fn data_command<W: Write>(
514513
}
515514
Ok(())
516515
}
516+
517+
const CHECKSUM_INIT: u8 = 0xEF;
518+
519+
fn checksum(data: &[u8], mut checksum: u8) -> u8 {
520+
for byte in data {
521+
checksum ^= *byte;
522+
}
523+
524+
checksum
525+
}

espflash/src/connection/reset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
command::{Command, CommandType},
1616
connection::{Connection, Port, USB_SERIAL_JTAG_PID},
1717
error::Error,
18-
flash_data::FLASH_WRITE_SIZE,
18+
flasher::FLASH_WRITE_SIZE,
1919
};
2020

2121
/// Default time to wait before releasing the boot pin after a reset

espflash/src/error.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
//! Library and application errors
22
3+
#[cfg(feature = "serialport")]
34
use std::fmt::{Display, Formatter};
45

56
use miette::Diagnostic;
6-
#[cfg(feature = "serialport")]
7-
use slip_codec::SlipError;
7+
use std::io;
88
use strum::VariantNames;
99
use thiserror::Error;
1010

1111
#[cfg(feature = "cli")]
1212
use crate::cli::monitor::parser::esp_defmt::DefmtError;
1313
#[cfg(feature = "serialport")]
1414
use crate::command::CommandType;
15-
use crate::flash_data::{FlashFrequency, FlashSize};
16-
use crate::targets::Chip;
15+
use crate::{
16+
flasher::{FlashFrequency, FlashSize},
17+
targets::Chip,
18+
};
19+
#[cfg(feature = "serialport")]
20+
use slip_codec::SlipError;
1721

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

104108
#[cfg(not(feature = "serialport"))]
105109
#[error(transparent)]
106-
IoError(#[from] std::io::Error),
110+
IoError(#[from] io::Error),
107111

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

204208
#[error("Failed to open file: {0}")]
205-
FileOpenError(String, #[source] std::io::Error),
209+
FileOpenError(String, #[source] io::Error),
206210

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

211215
#[cfg(feature = "serialport")]
212-
impl From<std::io::Error> for Error {
213-
fn from(err: std::io::Error) -> Self {
216+
impl From<io::Error> for Error {
217+
fn from(err: io::Error) -> Self {
214218
Self::Connection(err.into())
215219
}
216220
}
@@ -292,8 +296,8 @@ pub enum ConnectionError {
292296
}
293297

294298
#[cfg(feature = "serialport")]
295-
impl From<std::io::Error> for ConnectionError {
296-
fn from(err: std::io::Error) -> Self {
299+
impl From<io::Error> for ConnectionError {
300+
fn from(err: io::Error) -> Self {
297301
from_error_kind(err.kind(), err)
298302
}
299303
}
@@ -520,11 +524,11 @@ impl<T> ResultExt for Result<T, Error> {
520524

521525
#[cfg(feature = "serialport")]
522526
#[cfg_attr(docsrs, doc(cfg(feature = "serialport")))]
523-
fn from_error_kind<E>(kind: std::io::ErrorKind, err: E) -> ConnectionError
527+
fn from_error_kind<E>(kind: io::ErrorKind, err: E) -> ConnectionError
524528
where
525529
E: Into<serialport::Error>,
526530
{
527-
use std::io::ErrorKind;
531+
use io::ErrorKind;
528532

529533
match kind {
530534
ErrorKind::TimedOut => ConnectionError::Timeout(TimedOutCommand::default()),

0 commit comments

Comments
 (0)