Skip to content

Commit ce0ad9d

Browse files
authored
Minor docs improvement (#878)
* Minor docs improvement * Add a forgotten one * add periods
1 parent 18a4e38 commit ce0ad9d

File tree

18 files changed

+152
-46
lines changed

18 files changed

+152
-46
lines changed

espflash/src/cli/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,29 +208,31 @@ pub struct ReadFlashArgs {
208208
pub max_in_flight: u32,
209209
}
210210

211-
/// Save the image to disk instead of flashing to device
211+
/// Save the image to disk instead of flashing to device.
212212
#[derive(Debug, Args)]
213213
#[non_exhaustive]
214214
#[group(skip)]
215215
pub struct SaveImageArgs {
216-
/// Chip to create an image for
216+
/// Chip to create an image for.
217217
#[arg(long, value_enum)]
218218
pub chip: Chip,
219-
/// File name to save the generated image to
219+
/// File name to save the generated image to.
220220
pub file: PathBuf,
221-
/// Boolean flag to merge binaries into single binary
221+
/// Boolean flag to merge binaries into single binary.
222222
#[arg(long)]
223223
pub merge: bool,
224-
/// Don't pad the image to the flash size
224+
/// Don't pad the image to the flash size.
225225
#[arg(long, requires = "merge")]
226226
pub skip_padding: bool,
227-
/// Cristal frequency of the target
227+
/// Crystal frequency of the target.
228228
#[arg(long, short = 'x')]
229229
pub xtal_freq: Option<XtalFrequency>,
230230
#[clap(flatten)]
231+
/// Image arguments.
231232
pub image: ImageArgs,
232233
}
233234

235+
/// Image arguments needed for image generation.
234236
#[derive(Debug, Args)]
235237
#[non_exhaustive]
236238
#[group(skip)]
@@ -258,6 +260,7 @@ pub struct ImageArgs {
258260
pub check_app_descriptor: Option<bool>,
259261
}
260262

263+
/// Arguments for connection and monitoring
261264
#[derive(Debug, Args)]
262265
#[non_exhaustive]
263266
pub struct MonitorArgs {
@@ -300,6 +303,7 @@ pub struct MonitorConfigArgs {
300303
processors: Option<String>,
301304
}
302305

306+
/// Arguments for MD5 checksum calculation
303307
#[derive(Debug, Args)]
304308
#[non_exhaustive]
305309
pub struct ChecksumMd5Args {
@@ -757,6 +761,7 @@ impl ProgressCallbacks for EspflashProgress {
757761
}
758762
}
759763

764+
/// Erase the entire flash memory of a target device
760765
pub fn erase_flash(args: EraseFlashArgs, config: &Config) -> Result<()> {
761766
if args.connect_args.no_stub {
762767
return Err(Error::StubRequired.into());
@@ -777,6 +782,7 @@ pub fn erase_flash(args: EraseFlashArgs, config: &Config) -> Result<()> {
777782
Ok(())
778783
}
779784

785+
/// Erase a specified region of flash memory
780786
pub fn erase_region(args: EraseRegionArgs, config: &Config) -> Result<()> {
781787
if args.connect_args.no_stub {
782788
return Err(Error::StubRequired).into_diagnostic();
@@ -1016,6 +1022,7 @@ fn pretty_print(table: PartitionTable) {
10161022
println!("{pretty}");
10171023
}
10181024

1025+
/// Creates `FlashData` from `ImageArgs`, `FlashConfigArgs`, and `Config`.
10191026
pub fn make_flash_data(
10201027
image_args: ImageArgs,
10211028
flash_config_args: &FlashConfigArgs,

espflash/src/cli/monitor/external_processors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use std::{
5757

5858
use miette::Diagnostic;
5959

60+
/// Represents an error associated with a specific executable.
6061
#[derive(Debug)]
6162
pub struct Error {
6263
executable: String,
@@ -80,6 +81,7 @@ struct Processor {
8081
}
8182

8283
impl Processor {
84+
/// Creates a new processor from a child process.
8385
pub fn new(child: Child) -> Self {
8486
let mut child = child;
8587
let (tx, rx) = mpsc::channel::<u8>();
@@ -103,6 +105,7 @@ impl Processor {
103105
Self { rx, stdin, child }
104106
}
105107

108+
/// Tries to receive data from the processor.
106109
pub fn try_receive(&mut self) -> Vec<u8> {
107110
let mut res = Vec::new();
108111
while let Ok(b) = self.rx.try_recv() {
@@ -111,6 +114,7 @@ impl Processor {
111114
res
112115
}
113116

117+
/// Sends data to the processor.
114118
pub fn send(&mut self, data: Vec<u8>) {
115119
let _ignored = self.stdin.write(&data).ok();
116120
}
@@ -122,12 +126,14 @@ impl Drop for Processor {
122126
}
123127
}
124128

129+
/// Represents a collection of external processors.
125130
#[derive(Debug)]
126131
pub struct ExternalProcessors {
127132
processors: Vec<Processor>,
128133
}
129134

130135
impl ExternalProcessors {
136+
/// Creates a new collection of external processors.
131137
pub fn new(processors: Option<String>, elf: Option<PathBuf>) -> Result<Self, Error> {
132138
let mut args = Vec::new();
133139

@@ -156,6 +162,8 @@ impl ExternalProcessors {
156162
})
157163
}
158164

165+
/// Processes input bytes through a series of processors, returning the
166+
/// final output.
159167
pub fn process(&mut self, read: &[u8]) -> Vec<u8> {
160168
let mut buffer = Vec::new();
161169
buffer.extend_from_slice(read);

espflash/src/cli/monitor/line_endings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ where
3535
}
3636
}
3737

38+
/// Normalize line endings to CRLF.
3839
pub(crate) fn normalized(iter: impl Iterator<Item = u8>) -> impl Iterator<Item = u8> {
3940
Normalized {
4041
iter,

espflash/src/cli/monitor/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub mod parser;
4141
mod line_endings;
4242
mod symbols;
4343

44+
/// Log format to use when parsing incoming data.
4445
#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
4546
#[derive(Debug, Clone, Copy, PartialEq, Eq, Display, EnumIter, EnumString, VariantNames)]
4647
#[non_exhaustive]
@@ -56,6 +57,7 @@ pub enum LogFormat {
5657
struct RawModeGuard;
5758

5859
impl RawModeGuard {
60+
/// Enable raw mode and return a guard that will disable it when dropped.
5961
pub fn new() -> Result<Self> {
6062
enable_raw_mode().into_diagnostic()?;
6163
Ok(RawModeGuard)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use thiserror::Error;
1212

1313
use crate::cli::monitor::parser::InputParser;
1414

15+
/// Errors that can occur when setting up the defmt logger.
1516
#[derive(Clone, Copy, Debug, Diagnostic, Error)]
1617
#[error("Could not set up defmt logger")]
1718
pub enum DefmtError {
@@ -79,6 +80,8 @@ impl FrameDelimiter {
7980
Some((&haystack[start..][..end], start + end + needle.len()))
8081
}
8182

83+
/// Feeds data into the parser, extracting and processing framed or raw
84+
/// data.
8285
pub fn feed(&mut self, buffer: &[u8], mut process: impl FnMut(FrameKind<'_>)) {
8386
self.buffer.extend_from_slice(buffer);
8487

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::cli::monitor::{line_endings::normalized, symbols::Symbols};
1111
pub mod esp_defmt;
1212
pub mod serial;
1313

14+
/// Trait for parsing input data.
1415
pub trait InputParser {
1516
fn feed(&mut self, bytes: &[u8], out: &mut dyn Write);
1617
}
@@ -102,6 +103,7 @@ impl Utf8Merger {
102103
}
103104
}
104105

106+
/// A printer that resolves symbol names and writes formatted output.
105107
#[allow(missing_debug_implementations)]
106108
pub struct ResolvingPrinter<'ctx, W: Write> {
107109
writer: W,
@@ -111,6 +113,7 @@ pub struct ResolvingPrinter<'ctx, W: Write> {
111113
}
112114

113115
impl<'ctx, W: Write> ResolvingPrinter<'ctx, W> {
116+
/// Creates a new `ResolvingPrinter` with the given ELF file and writer.
114117
pub fn new(elf: Option<&'ctx [u8]>, writer: W) -> Self {
115118
Self {
116119
writer,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::io::Write;
22

33
use crate::cli::monitor::parser::InputParser;
44

5+
/// Serial parser.
56
#[derive(Debug)]
67
pub struct Serial;
78

espflash/src/cli/monitor/symbols.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) struct Symbols<'sym> {
1515
}
1616

1717
impl<'sym> Symbols<'sym> {
18+
/// Tries to create a new `Symbols` instance from the given ELF file bytes.
1819
pub fn try_from(bytes: &'sym [u8]) -> Result<Self, Box<dyn Error>> {
1920
let object = File::parse(bytes)?;
2021
let dwarf = Dwarf::load(

0 commit comments

Comments
 (0)