Skip to content

Commit be1ff81

Browse files
authored
Refactor: make more modules private (#772)
* Move `command` module into `connection` module * Make the `elf` and `error` modules private * Don't document the modules/types behind the `cli` feature * Clean up some imports * Remove unused code * Miscellaneous cleanup * Update `CHANGELOG.md`
1 parent 7495637 commit be1ff81

File tree

25 files changed

+89
-163
lines changed

25 files changed

+89
-163
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
1112
- Add `non-interactive` flag to `flash` subcommand (#737)
1213
- Add `no-reset` flag to `monitor` subcommands (#737)
1314
- Add an environment variable to set monitoring baudrate (`MONITOR_BAUD`) (#737)
14-
Add list-ports command to list available serial ports.
15-
- Add list-ports command to list available serial ports.
15+
- Add list-ports command to list available serial ports. (#761)
1616

1717
### Changed
18+
1819
- Split the baudrate for connecting and monitorinig in `flash` subcommand (#737)
1920
- Normalized arguments of the CLI commands (#759)
2021
- `board-info` now prints `Security information`. (#758)
22+
- The `command`, `elf` and `error` modules are no longer public (#772)
2123

2224
### Fixed
2325

cargo-espflash/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use cargo_metadata::{Message, MetadataCommand};
88
use clap::{Args, CommandFactory, Parser, Subcommand};
99
use espflash::{
1010
cli::{self, config::Config, monitor::monitor, *},
11-
error::Error as EspflashError,
1211
flasher::parse_partition_table,
1312
logging::initialize_logger,
1413
targets::{Chip, XtalFrequency},
1514
update::check_for_update,
15+
Error as EspflashError,
1616
};
1717
use log::{debug, info, LevelFilter};
1818
use miette::{IntoDiagnostic, Result, WrapErr};

espflash/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ bin-dir = "{ bin }{ binary-ext }"
1515
pkg-fmt = "zip"
1616

1717
[package.metadata.docs.rs]
18-
rustdoc-args = ["--cfg", "docsrs"]
18+
features = ["serialport"]
19+
no-default-features = true
20+
rustdoc-args = ["--cfg", "docsrs"]
1921

2022
[[bin]]
2123
name = "espflash"
@@ -73,11 +75,10 @@ cli = [
7375
"dep:directories",
7476
"dep:env_logger",
7577
"dep:indicatif",
76-
"dep:toml",
7778
"dep:update-informer",
7879
"miette/fancy",
7980
"serialport",
8081
]
8182

82-
# enables connecting to a device via serial port
83+
# Enables connecting to a device via serial port
8384
serialport = ["dep:regex", "dep:serialport", "dep:slip-codec", "dep:toml"]

espflash/src/bin/espflash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use std::{
77
use clap::{Args, CommandFactory, Parser, Subcommand};
88
use espflash::{
99
cli::{self, config::Config, monitor::monitor, *},
10-
error::Error,
1110
flasher::parse_partition_table,
1211
logging::initialize_logger,
1312
targets::{Chip, XtalFrequency},
1413
update::check_for_update,
14+
Error,
1515
};
1616
use log::{debug, info, LevelFilter};
1717
use miette::{IntoDiagnostic, Result, WrapErr};

espflash/src/cli/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use miette::{IntoDiagnostic, Result, WrapErr};
1919
use serde::{Deserialize, Serialize};
2020
use serialport::UsbPortInfo;
2121

22-
use crate::{error::Error, flasher::FlashSettings};
22+
use crate::{flasher::FlashSettings, Error};
2323

2424
/// A configured, known serial connection
2525
#[derive(Debug, Deserialize, Serialize, Default, Clone)]

espflash/src/cli/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serialport::{available_ports, SerialPortInfo, SerialPortType};
99

1010
use crate::{
1111
cli::{config::UsbDevice, Config, ConnectArgs},
12-
error::Error,
12+
Error,
1313
};
1414

1515
/// Return the information of a serial port taking into account the different
File renamed without changes.

espflash/src/connection/mod.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,24 @@ use slip_codec::SlipDecoder;
1919
#[cfg(unix)]
2020
use self::reset::UnixTightReset;
2121
use self::{
22+
command::{Command, CommandType},
2223
encoder::SlipEncoder,
2324
reset::{
2425
construct_reset_strategy_sequence,
2526
hard_reset,
2627
reset_after_flash,
28+
soft_reset,
2729
ClassicReset,
2830
ResetAfterOperation,
2931
ResetBeforeOperation,
3032
ResetStrategy,
3133
UsbJtagSerialReset,
3234
},
3335
};
34-
use crate::{
35-
command::{Command, CommandType},
36-
connection::reset::soft_reset,
37-
error::{ConnectionError, Error, ResultExt, RomError, RomErrorKind},
38-
};
36+
use crate::error::{ConnectionError, Error, ResultExt, RomError, RomErrorKind};
3937

40-
pub mod reset;
38+
pub(crate) mod command;
39+
pub(crate) mod reset;
4140

4241
const MAX_CONNECT_ATTEMPTS: usize = 7;
4342
const MAX_SYNC_ATTEMPTS: usize = 5;
@@ -56,36 +55,36 @@ pub enum CommandResponseValue {
5655
}
5756

5857
impl TryInto<u32> for CommandResponseValue {
59-
type Error = crate::error::Error;
58+
type Error = Error;
6059

6160
fn try_into(self) -> Result<u32, Self::Error> {
6261
match self {
6362
CommandResponseValue::ValueU32(value) => Ok(value),
64-
CommandResponseValue::ValueU128(_) => Err(crate::error::Error::InternalError),
65-
CommandResponseValue::Vector(_) => Err(crate::error::Error::InternalError),
63+
CommandResponseValue::ValueU128(_) => Err(Error::InternalError),
64+
CommandResponseValue::Vector(_) => Err(Error::InternalError),
6665
}
6766
}
6867
}
6968

7069
impl TryInto<u128> for CommandResponseValue {
71-
type Error = crate::error::Error;
70+
type Error = Error;
7271

7372
fn try_into(self) -> Result<u128, Self::Error> {
7473
match self {
75-
CommandResponseValue::ValueU32(_) => Err(crate::error::Error::InternalError),
74+
CommandResponseValue::ValueU32(_) => Err(Error::InternalError),
7675
CommandResponseValue::ValueU128(value) => Ok(value),
77-
CommandResponseValue::Vector(_) => Err(crate::error::Error::InternalError),
76+
CommandResponseValue::Vector(_) => Err(Error::InternalError),
7877
}
7978
}
8079
}
8180

8281
impl TryInto<Vec<u8>> for CommandResponseValue {
83-
type Error = crate::error::Error;
82+
type Error = Error;
8483

8584
fn try_into(self) -> Result<Vec<u8>, Self::Error> {
8685
match self {
87-
CommandResponseValue::ValueU32(_) => Err(crate::error::Error::InternalError),
88-
CommandResponseValue::ValueU128(_) => Err(crate::error::Error::InternalError),
86+
CommandResponseValue::ValueU32(_) => Err(Error::InternalError),
87+
CommandResponseValue::ValueU128(_) => Err(Error::InternalError),
8988
CommandResponseValue::Vector(value) => Ok(value),
9089
}
9190
}

espflash/src/connection/reset.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! Most of this module is copied from `esptool.py` (https://github.com/espressif/esptool/blob/a8586d02b1305ebc687d31783437a7f4d4dbb70f/esptool/reset.py)
1+
// Most of this module is copied from `esptool.py`:
2+
// https://github.com/espressif/esptool/blob/a8586d0/esptool/reset.py
23

34
#[cfg(unix)]
45
use std::{io, os::fd::AsRawFd};
@@ -10,12 +11,13 @@ use log::debug;
1011
use serialport::SerialPort;
1112
use strum::{Display, EnumIter, EnumString, VariantNames};
1213

13-
use crate::{
14+
use super::{
1415
command::{Command, CommandType},
15-
connection::{Connection, Port, USB_SERIAL_JTAG_PID},
16-
error::Error,
17-
flasher::FLASH_WRITE_SIZE,
16+
Connection,
17+
Port,
18+
USB_SERIAL_JTAG_PID,
1819
};
20+
use crate::{flasher::FLASH_WRITE_SIZE, Error};
1921

2022
/// Default time to wait before releasing the boot pin after a reset
2123
const DEFAULT_RESET_DELAY: u64 = 50; // ms

espflash/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use thiserror::Error;
1313
#[cfg(feature = "cli")]
1414
use crate::cli::monitor::parser::esp_defmt::DefmtError;
1515
#[cfg(feature = "serialport")]
16-
use crate::command::CommandType;
16+
use crate::connection::command::CommandType;
1717
use crate::{
1818
flasher::{FlashFrequency, FlashSize},
1919
targets::Chip,

0 commit comments

Comments
 (0)