Skip to content

Commit 4286006

Browse files
committed
Move board_info into Flasher where it's usable by both applications
1 parent e67cd28 commit 4286006

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

cargo-espflash/src/main.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ fn main() -> Result<()> {
141141
None
142142
};
143143

144-
// Connect the Flasher to the target device. If the '--board-info' flag has been
145-
// provided, display the board info and terminate the application.
144+
// Connect the Flasher to the target device and print the board information
145+
// upon connection. If the '--board-info' flag has been provided, we have
146+
// nothing left to do so exit early.
146147
let mut flasher = Flasher::connect(serial, speed)?;
148+
flasher.board_info()?;
149+
147150
if matches.is_present("board_info") {
148-
board_info(&mut flasher)?;
149151
return Ok(());
150152
}
151153

@@ -193,6 +195,7 @@ fn main() -> Result<()> {
193195
} else {
194196
flasher.load_elf_to_flash(&elf_data, bootloader, partition_table)?;
195197
}
198+
println!("\nFlashing has completed!");
196199

197200
if matches.is_present("monitor") {
198201
monitor(flasher.into_serial()).into_diagnostic()?;
@@ -202,25 +205,6 @@ fn main() -> Result<()> {
202205
Ok(())
203206
}
204207

205-
fn board_info(flasher: &mut Flasher) -> Result<()> {
206-
let chip = flasher.chip();
207-
let revision = chip.chip_revision(flasher.connection())?;
208-
let freq = chip.crystal_freq(flasher.connection())?;
209-
210-
// Print the detected chip type, and if available the silicon revision.
211-
print!("Chip type: {}", chip);
212-
if let Some(revision) = revision {
213-
println!(" (revision {})", revision);
214-
} else {
215-
println!();
216-
}
217-
218-
println!("Crystal frequency: {}MHz", freq);
219-
println!("Flash size: {}", flasher.flash_size());
220-
221-
Ok(())
222-
}
223-
224208
fn build(
225209
release: bool,
226210
example: Option<&str>,

espflash/src/flasher.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,24 @@ impl Flasher {
459459
self.flash_size
460460
}
461461

462+
/// Read and print any information we can about the connected board
463+
pub fn board_info(&mut self) -> Result<(), Error> {
464+
let chip = self.chip();
465+
let maybe_revision = chip.chip_revision(self.connection())?;
466+
let freq = chip.crystal_freq(self.connection())?;
467+
let size = self.flash_size();
468+
469+
print!("Chip type: {}", chip);
470+
match maybe_revision {
471+
Some(revision) => println!(" (revision {})", revision),
472+
None => println!(),
473+
}
474+
println!("Crystal frequency: {}MHz", freq);
475+
println!("Flash size: {}", size);
476+
477+
Ok(())
478+
}
479+
462480
/// Load an elf image to ram and execute it
463481
///
464482
/// Note that this will not touch the flash on the device

espflash/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ fn main() -> Result<()> {
5656
let mut flasher = Flasher::connect(serial, None)?;
5757

5858
if board_info {
59-
println!("Chip type: {}", flasher.chip());
60-
println!("Flash size: {}", flasher.flash_size());
59+
flasher.board_info()?;
6160

6261
return Ok(());
6362
}

0 commit comments

Comments
 (0)