Skip to content

Commit f12ecf3

Browse files
Improve docs (#899)
* feat: Make try_from private * docs: Improve docs * feat: Make erase_parts private * docs: Improve docs * docs: Fix typos
1 parent 61e5032 commit f12ecf3

File tree

19 files changed

+179
-49
lines changed

19 files changed

+179
-49
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Add `--monitor` option to `write-bin`. (#783)
1818
- Add `watchdog-reset` strategy to `--after` subcommand (#779)
1919
- Add `ROM` version of `read-flash` command (#812)
20-
- `espflash` can detect the log format automatically from ESP-HAL metadata. Reqires `esp-println` 0.14 (presumably, yet to be released) (#809)
20+
- `espflash` can detect the log format automatically from ESP-HAL metadata. Requires `esp-println` 0.14 (presumably, yet to be released) (#809)
2121
- Add `--output-format` option to monitor (#818)
2222
- Added chip detection based on security info, where supported (#814)
23-
- `espflash` can detect the chip from ESP-HAL metadata to prevent flashing firmware built for a different device. Reqires `esp-hal` 1.0.0-beta.0 (presumably, yet to be released) (#816)
23+
- `espflash` can detect the chip from ESP-HAL metadata to prevent flashing firmware built for a different device. Requires `esp-hal` 1.0.0-beta.0 (presumably, yet to be released) (#816)
2424
- `espflash` no longer allows flashing a too-big partition table (#830)
2525
- Allow specifying a partition label for `write-bin`, add `--partition-table`. (#828)
2626
- `--mmu-page-size` parameter for `flash` and `save-image` (#835)
2727
- Run some arguments checks for monitoring flags. (#842)
2828
- Add support for the ESP32-C5 (#863)
2929
- `--after` options now work with `espflash board-info`, `espflash read-flash` and `espflash checksum-md5` (#867)
3030
- Add support for serial port configuration files. (#777, #883)
31-
- Add a `check-app-descriptor` bool option to `ImageArgs` and add the flag to `flash` commad(#872)
31+
- Add a `check-app-descriptor` bool option to `ImageArgs` and add the flag to `flash` command (#872)
3232
- `Connection::into_serial` to get the underlying port from the connection (#882)
3333
- All methods on the now removed `Target` & `ReadEFuse`, `UsbOtg` and `RtcWdtReset` traits have been implemented directly on (#891)
3434

3535
### Changed
3636

37-
- Split the baudrate for connecting and monitorinig in `flash` subcommand (#737)
37+
- Split the baudrate for connecting and monitoring in `flash` subcommand (#737)
3838
- Normalized arguments of the CLI commands (#759)
3939
- `board-info` now prints `Security information`. (#758)
4040
- The `command`, `elf` and `error` modules are no longer public (#772)
@@ -72,7 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7272
- Fix `read-flash` which didn't work with some lengths (#804)
7373
- espflash can now flash an ESP32-S2 in download mode over USB (#813)
7474
- Fixed a case where esplash transformed the firmware elf in a way that made it unbootable (#831)
75-
- The app descriptor is now correctly placed in the front of the bianry (#835)
75+
- The app descriptor is now correctly placed in the front of the binary (#835)
7676
- espflash now extracts the MMU page size from the app descriptor (#835)
7777
- `ResetBeforeOperation` & `ResetAfterOperation` are now public, to allow the creation of a `Connection` (#895)
7878

cargo-espflash/src/cargo_config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ use serde::Deserialize;
88

99
use crate::error::TomlError;
1010

11+
/// Unstable features.
1112
#[derive(Debug, Default, Deserialize)]
1213
#[serde(rename_all = "kebab-case")]
1314
pub struct Unstable {
1415
#[serde(default)]
1516
build_std: Vec<String>,
1617
}
1718

19+
/// Build configuration extracted from `.cargo/config.toml`.
1820
#[derive(Debug, Default, Deserialize)]
1921
pub struct Build {
2022
target: Option<String>,
2123
}
2224

25+
/// Representation of a Cargo configuration extracted from `.cargo/config.toml`.
2326
#[derive(Debug, Deserialize, Default)]
2427
pub struct CargoConfig {
2528
#[serde(default)]
@@ -29,6 +32,8 @@ pub struct CargoConfig {
2932
}
3033

3134
impl CargoConfig {
35+
/// Load and merge Cargo configuration from the workspace and/or package
36+
/// level.
3237
pub fn load(workspace_root: &Path, package_root: &Path) -> Self {
3338
// If there is a Cargo configuration file in the current package, we will
3439
// deserialize and return it.
@@ -44,10 +49,12 @@ impl CargoConfig {
4449
}
4550
}
4651

52+
/// Returns if the build has unstable `build-std` feature enabled.
4753
pub fn has_build_std(&self) -> bool {
4854
!self.unstable.build_std.is_empty()
4955
}
5056

57+
/// Returns the build `target` specified in the configuration, if any.
5158
pub fn target(&self) -> Option<&str> {
5259
self.build.target.as_deref()
5360
}

cargo-espflash/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use espflash::target::Chip;
77
use miette::{Diagnostic, LabeledSpan, SourceCode};
88
use thiserror::Error;
99

10+
/// Error type returned by `cargo-espflash`.
1011
#[derive(Debug, Diagnostic, Error)]
1112
#[non_exhaustive]
1213
pub enum Error {
@@ -64,6 +65,7 @@ pub struct TomlError {
6465
}
6566

6667
impl TomlError {
68+
/// Create a new [`TomlError`] from the raw `toml`.
6769
pub fn new(err: toml::de::Error, source: String) -> Self {
6870
Self { err, source }
6971
}
@@ -104,6 +106,7 @@ pub struct UnsupportedTargetError {
104106
}
105107

106108
impl UnsupportedTargetError {
109+
/// Construct a new [`UnsupportedTargetError`].
107110
pub fn new(target: &str, chip: Chip) -> Self {
108111
Self {
109112
target: target.into(),
@@ -124,6 +127,7 @@ pub struct NoTargetError {
124127
}
125128

126129
impl NoTargetError {
130+
/// Create a new [`NoTargetError`].
127131
pub fn new(chip: Option<Chip>) -> Self {
128132
Self { chip }
129133
}

cargo-espflash/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enum Commands {
9494
/// Please refer to the ESP-IDF documentation for more information on the
9595
/// binary image format:
9696
///
97-
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
97+
/// <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html>
9898
Flash(FlashArgs),
9999
/// Hold the target device in reset
100100
HoldInReset(ConnectArgs),
@@ -110,7 +110,7 @@ enum Commands {
110110
/// Uses the ESP-IDF format for partition tables; please refer to the
111111
/// ESP-IDF documentation for more information on this format:
112112
///
113-
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
113+
/// <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html>
114114
///
115115
/// Allows for conversion between formats via the '--to-csv' and
116116
/// '--to-binary' options, plus the ability to print a partition table
@@ -229,7 +229,7 @@ fn main() -> Result<()> {
229229
miette::set_panic_hook();
230230
initialize_logger(LevelFilter::Info);
231231

232-
// Attempt to parse any provided comand-line arguments, or print the help
232+
// Attempt to parse any provided command-line arguments, or print the help
233233
// message and terminate if the invocation is not correct.
234234
let cli = Cli::parse();
235235
let CargoSubcommand::Espflash {
@@ -276,7 +276,7 @@ struct BuildContext {
276276
pub partition_table_path: Option<PathBuf>,
277277
}
278278

279-
pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
279+
fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
280280
if args.connect_args.no_stub {
281281
return Err(EspflashError::StubRequired).into_diagnostic();
282282
}

cargo-espflash/src/package_metadata.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ use serde::Deserialize;
66

77
use crate::error::Error;
88

9+
/// Package metadata.
910
#[derive(Debug, Default, Clone, Deserialize)]
1011
pub struct PackageMetadata {
12+
/// Path to the root of the Cargo workspace the package belongs to.
1113
pub workspace_root: PathBuf,
14+
/// Path to the directory that contains the `Cargo.toml` for the
15+
/// selected package.
1216
pub package_root: PathBuf,
1317
}
1418

1519
impl PackageMetadata {
20+
/// Load package metadata.
1621
pub fn load(package_name: &Option<String>) -> Result<Self> {
1722
// There MUST be a cargo manifest in the executing directory, regardless of
1823
// whether or not we are in a workspace.

espflash/src/bin/espflash.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use espflash::{
2222
use log::{LevelFilter, debug, info};
2323
use miette::{IntoDiagnostic, Result, WrapErr};
2424

25+
/// Main CLI parser.
2526
#[derive(Debug, Parser)]
2627
#[command(about, max_term_width = 100, propagate_version = true, version)]
2728
pub struct Cli {
@@ -65,7 +66,7 @@ enum Commands {
6566
/// Please refer to the ESP-IDF documentation for more information on the
6667
/// binary image format:
6768
///
68-
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html
69+
/// <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/app_image_format.html>
6970
Flash(FlashArgs),
7071
/// Hold the target device in reset
7172
HoldInReset(ConnectArgs),
@@ -81,7 +82,7 @@ enum Commands {
8182
/// Uses the ESP-IDF format for partition tables; please refer to the
8283
/// ESP-IDF documentation for more information on this format:
8384
///
84-
/// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
85+
/// <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html>
8586
///
8687
/// Allows for conversion between formats via the '--to-csv' and
8788
/// '--to-binary' options, plus the ability to print a partition table
@@ -200,7 +201,7 @@ fn main() -> Result<()> {
200201
}
201202
}
202203

203-
pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
204+
fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
204205
if args.connect_args.no_stub {
205206
return Err(Error::StubRequired.into());
206207
}

espflash/src/cli/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ pub struct ChecksumMd5Args {
339339
connect_args: ConnectArgs,
340340
}
341341

342+
/// List the available serial ports.
342343
#[derive(Debug, Args)]
343344
#[non_exhaustive]
344345
pub struct ListPortsArgs {
@@ -490,6 +491,7 @@ pub fn checksum_md5(args: &ChecksumMd5Args, config: &Config) -> Result<()> {
490491
Ok(())
491492
}
492493

494+
/// List the available serial ports.
493495
pub fn list_ports(args: &ListPortsArgs, config: &PortConfig) -> Result<()> {
494496
let mut ports: Vec<SerialPortInfo> = serial::detect_usb_serial_ports(true)?
495497
.into_iter()
@@ -1141,6 +1143,7 @@ pub fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
11411143
Ok(())
11421144
}
11431145

1146+
/// Reset the target device.
11441147
pub fn reset(args: ConnectArgs, config: &Config) -> Result<()> {
11451148
let mut args = args.clone();
11461149
args.no_stub = true;
@@ -1151,13 +1154,15 @@ pub fn reset(args: ConnectArgs, config: &Config) -> Result<()> {
11511154
Ok(())
11521155
}
11531156

1157+
/// Hold the target device in reset.
11541158
pub fn hold_in_reset(args: ConnectArgs, config: &Config) -> Result<()> {
11551159
connect(&args, config, true, true)?;
11561160
info!("Holding target device in reset");
11571161

11581162
Ok(())
11591163
}
11601164

1165+
/// Ensures the chip is compatible with the ELF file.
11611166
pub fn ensure_chip_compatibility(chip: Chip, elf: Option<&[u8]>) -> Result<()> {
11621167
let metadata = Metadata::from_bytes(elf);
11631168
let Some(elf_chip) = metadata.chip_name() else {

espflash/src/cli/monitor/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ fn handle_key_event(key_event: KeyEvent) -> Option<Vec<u8>> {
262262
key_str.map(|slice| slice.into())
263263
}
264264

265+
/// Checks the monitor arguments and emits warnings if they are invalid.
265266
pub fn check_monitor_args(monitor: &bool, monitor_args: &MonitorConfigArgs) -> Result<()> {
266267
// Check if any monitor args are provided but monitor flag isn't set
267268
if !monitor

espflash/src/cli/monitor/parser/esp_defmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl DefmtData {
203203
}
204204
}
205205

206+
/// A parser for defmt-encoded data.
206207
pub struct EspDefmt {
207208
delimiter: FrameDelimiter,
208209
defmt_data: DefmtData,
@@ -215,6 +216,7 @@ impl std::fmt::Debug for EspDefmt {
215216
}
216217

217218
impl EspDefmt {
219+
/// Creates a new `EspDefmt` parser.
218220
pub fn new(elf: Option<&[u8]>, output_format: Option<String>) -> Result<Self> {
219221
DefmtData::load(elf, output_format).map(|defmt_data| Self {
220222
delimiter: FrameDelimiter::new(),

espflash/src/cli/monitor/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub mod serial;
1313

1414
/// Trait for parsing input data.
1515
pub trait InputParser {
16+
/// Feeds the parser with new data.
1617
fn feed(&mut self, bytes: &[u8], out: &mut dyn Write);
1718
}
1819

0 commit comments

Comments
 (0)