Skip to content

Commit ef9b8ff

Browse files
authored
Additional docstrings for enums, structs, and traits (#271)
* Document enums and their variants * Document traits and their functions * Document structs and their public fields
1 parent c2a4854 commit ef9b8ff

File tree

16 files changed

+92
-3
lines changed

16 files changed

+92
-3
lines changed

espflash/src/cli/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ use serialport::UsbPortInfo;
2121
/// A configured, known serial connection
2222
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
2323
pub struct Connection {
24+
/// Name of the serial port used for communication
2425
pub serial: Option<String>,
25-
#[cfg(feature = "raspberry")]
26-
pub rts: Option<u8>,
26+
/// Data Transmit Ready pin
2727
#[cfg(feature = "raspberry")]
2828
pub dtr: Option<u8>,
29+
/// Ready To Send pin
30+
#[cfg(feature = "raspberry")]
31+
pub rts: Option<u8>,
2932
}
3033

3134
/// A configured, known USB device
3235
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
3336
pub struct UsbDevice {
37+
/// USB Vendor ID
3438
#[serde(with = "SerHex::<Compact>")]
3539
pub vid: u16,
40+
/// USB Product ID
3641
#[serde(with = "SerHex::<Compact>")]
3742
pub pid: u16,
3843
}
@@ -46,8 +51,10 @@ impl UsbDevice {
4651
/// Deserialized contents of a configuration file
4752
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
4853
pub struct Config {
54+
/// Preferred serial port connection information
4955
#[serde(default)]
5056
pub connection: Connection,
57+
/// Preferred USB devices
5158
#[serde(default)]
5259
pub usb_device: Vec<UsbDevice>,
5360
#[serde(skip)]

espflash/src/elf.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,26 @@ use crate::{
1919
targets::Chip,
2020
};
2121

22+
/// Operations for working with firmware images
2223
pub trait FirmwareImage<'a> {
24+
/// Firmware image entry point
2325
fn entry(&self) -> u32;
26+
27+
/// Firmware image segments
2428
fn segments(&'a self) -> Box<dyn Iterator<Item = CodeSegment<'a>> + 'a>;
29+
30+
/// Firmware image segments, with their associated load addresses
2531
fn segments_with_load_addresses(&'a self) -> Box<dyn Iterator<Item = CodeSegment<'a>> + 'a>;
2632

33+
/// Firmware image ROM segments
2734
fn rom_segments(&'a self, chip: Chip) -> Box<dyn Iterator<Item = CodeSegment<'a>> + 'a> {
2835
Box::new(
2936
self.segments()
3037
.filter(move |segment| chip.into_target().addr_is_flash(segment.addr)),
3138
)
3239
}
3340

41+
/// Firmware image RAM segments
3442
fn ram_segments(&'a self, chip: Chip) -> Box<dyn Iterator<Item = CodeSegment<'a>> + 'a> {
3543
Box::new(
3644
self.segments()
@@ -39,6 +47,7 @@ pub trait FirmwareImage<'a> {
3947
}
4048
}
4149

50+
/// A firmware image built from an ELF file
4251
pub struct ElfFirmwareImage<'a> {
4352
elf: ElfFile<'a>,
4453
}
@@ -108,8 +117,9 @@ impl<'a> FirmwareImage<'a> for ElfFirmwareImage<'a> {
108117
}
109118

110119
#[derive(Eq, Clone, Default)]
111-
/// A segment of code from the source elf
120+
/// A segment of code from the source ELF
112121
pub struct CodeSegment<'a> {
122+
/// Base address of the code segment
113123
pub addr: u32,
114124
data: Cow<'a, [u8]>,
115125
}
@@ -220,7 +230,9 @@ impl Ord for CodeSegment<'_> {
220230
#[derive(Clone)]
221231
/// A segment of data to write to the flash
222232
pub struct RomSegment<'a> {
233+
/// ROM address at which the segment begins
223234
pub addr: u32,
235+
/// Segment data
224236
pub data: Cow<'a, [u8]>,
225237
}
226238

espflash/src/flasher/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,37 @@ const FLASH_SECTORS_PER_BLOCK: usize = FLASH_SECTOR_SIZE / FLASH_BLOCK_SIZE;
4141
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Display, EnumVariantNames)]
4242
#[repr(u8)]
4343
pub enum FlashFrequency {
44+
/// 12 MHz
4445
#[strum(serialize = "12M")]
4546
Flash12M,
47+
/// 15 MHz
4648
#[strum(serialize = "15M")]
4749
Flash15M,
50+
/// 16 MHz
4851
#[strum(serialize = "16M")]
4952
Flash16M,
53+
/// 20 MHz
5054
#[strum(serialize = "20M")]
5155
Flash20M,
56+
/// 24 MHz
5257
#[strum(serialize = "24M")]
5358
Flash24M,
59+
/// 26 MHz
5460
#[strum(serialize = "26M")]
5561
Flash26M,
62+
/// 30 MHz
5663
#[strum(serialize = "30M")]
5764
Flash30M,
65+
/// 40 MHz
5866
#[strum(serialize = "40M")]
5967
Flash40M,
68+
/// 48 MHz
6069
#[strum(serialize = "48M")]
6170
Flash48M,
71+
/// 60 MHz
6272
#[strum(serialize = "60M")]
6373
Flash60M,
74+
/// 80 MHz
6475
#[strum(serialize = "80M")]
6576
Flash80M,
6677
}
@@ -92,9 +103,13 @@ impl FromStr for FlashFrequency {
92103
#[derive(Copy, Clone, Debug, EnumVariantNames)]
93104
#[strum(serialize_all = "lowercase")]
94105
pub enum FlashMode {
106+
/// Quad I/O (4 pins used for address & data)
95107
Qio,
108+
/// Quad Output (4 pins used for data)
96109
Qout,
110+
/// Dual I/O (2 pins used for address & data)
97111
Dio,
112+
/// Dual Output (2 pins used for data)
98113
Dout,
99114
}
100115

@@ -120,24 +135,34 @@ impl FromStr for FlashMode {
120135
#[derive(Clone, Copy, Debug, Eq, PartialEq, Display, EnumVariantNames)]
121136
#[repr(u8)]
122137
pub enum FlashSize {
138+
/// 256 KB
123139
#[strum(serialize = "256K")]
124140
Flash256Kb = 0x12,
141+
/// 512 KB
125142
#[strum(serialize = "512K")]
126143
Flash512Kb = 0x13,
144+
/// 1 MB
127145
#[strum(serialize = "1M")]
128146
Flash1Mb = 0x14,
147+
/// 2 MB
129148
#[strum(serialize = "2M")]
130149
Flash2Mb = 0x15,
150+
/// 4 MB
131151
#[strum(serialize = "4M")]
132152
Flash4Mb = 0x16,
153+
/// 8 MB
133154
#[strum(serialize = "8M")]
134155
Flash8Mb = 0x17,
156+
/// 16 MB
135157
#[strum(serialize = "16M")]
136158
Flash16Mb = 0x18,
159+
/// 32 MB
137160
#[strum(serialize = "32M")]
138161
Flash32Mb = 0x19,
162+
/// 64 MB
139163
#[strum(serialize = "64M")]
140164
Flash64Mb = 0x1a,
165+
/// 128 MB
141166
#[strum(serialize = "128M")]
142167
Flash128Mb = 0x21,
143168
}

espflash/src/image_format/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct SegmentHeader {
4141
length: u32,
4242
}
4343

44+
/// Operations for working with firmware image formats
4445
pub trait ImageFormat<'a>: Send {
4546
/// Get the rom segments needed when flashing to device
4647
fn flash_segments<'b>(&'b self) -> Box<dyn Iterator<Item = RomSegment<'b>> + 'b>
@@ -56,13 +57,16 @@ pub trait ImageFormat<'a>: Send {
5657
'a: 'b;
5758
}
5859

60+
/// All supported firmware image formats
5961
#[derive(
6062
Debug, Copy, Clone, Eq, PartialEq, Display, IntoStaticStr, EnumVariantNames, Deserialize,
6163
)]
6264
#[strum(serialize_all = "kebab-case")]
6365
#[serde(rename_all = "kebab-case")]
6466
pub enum ImageFormatKind {
67+
/// Use the second-stage bootloader from ESP-IDF
6568
EspBootloader,
69+
/// Use direct boot and do not use a second-stage bootloader at all
6670
DirectBoot,
6771
}
6872

espflash/src/interface.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ pub enum SerialConfigError {
2424
/// Wrapper around SerialPort where platform-specific modifications can be
2525
/// implemented.
2626
pub struct Interface {
27+
/// Hardware serial port used for communication
2728
pub serial_port: Box<dyn SerialPort>,
29+
/// Data Transmit Ready pin
2830
#[cfg(feature = "raspberry")]
2931
pub dtr: Option<OutputPin>,
32+
/// Ready To Send pin
3033
#[cfg(feature = "raspberry")]
3134
pub rts: Option<OutputPin>,
3235
}

espflash/src/targets/esp32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const UART_CLKDIV_MASK: u32 = 0xfffff;
3131

3232
const XTAL_CLK_DIVIDER: u32 = 1;
3333

34+
/// ESP32 Target
3435
pub struct Esp32;
3536

3637
impl Esp32 {

espflash/src/targets/esp32c2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const PARAMS: Esp32Params = Esp32Params::new(
2929
include_bytes!("../../resources/bootloaders/esp32c2-bootloader.bin"),
3030
);
3131

32+
/// ESP32-C2 Target
3233
pub struct Esp32c2;
3334

3435
impl Esp32c2 {

espflash/src/targets/esp32c3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const PARAMS: Esp32Params = Esp32Params::new(
2929
include_bytes!("../../resources/bootloaders/esp32c3-bootloader.bin"),
3030
);
3131

32+
/// ESP32-C3 Target
3233
pub struct Esp32c3;
3334

3435
impl Esp32c3 {

espflash/src/targets/esp32s2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const PARAMS: Esp32Params = Esp32Params::new(
2828
include_bytes!("../../resources/bootloaders/esp32s2-bootloader.bin"),
2929
);
3030

31+
/// ESP32-S2 Target
3132
pub struct Esp32s2;
3233

3334
impl Esp32s2 {

espflash/src/targets/esp32s3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const PARAMS: Esp32Params = Esp32Params::new(
2626
include_bytes!("../../resources/bootloaders/esp32s3-bootloader.bin"),
2727
);
2828

29+
/// ESP32-S2 Target
2930
pub struct Esp32s3;
3031

3132
impl Esp32s3 {

0 commit comments

Comments
 (0)