Skip to content

Commit

Permalink
Pass in progress callbacks by value
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Jan 11, 2023
1 parent 3d61fce commit c7fc4b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
print_board_info(&mut flasher)?;

if args.flash_args.ram {
flasher.load_elf_to_ram(&elf_data, Some(&mut EspflashProgress::default()))?;
flasher.load_elf_to_ram(&elf_data, EspflashProgress::default())?;
} else {
let bootloader = args
.flash_args
Expand Down
4 changes: 2 additions & 2 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
let elf_data = fs::read(&args.image).into_diagnostic()?;

if args.flash_args.ram {
flasher.load_elf_to_ram(&elf_data, &mut EspflashProgress::default())?;
flasher.load_elf_to_ram(&elf_data, EspflashProgress::default())?;
} else {
let bootloader = args.flash_args.bootloader.as_deref();
let partition_table = args.flash_args.partition_table.as_deref();
Expand Down Expand Up @@ -233,7 +233,7 @@ fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
let mut buffer = Vec::with_capacity(size.try_into().into_diagnostic()?);
f.read_to_end(&mut buffer).into_diagnostic()?;

flasher.write_bin_to_flash(args.addr, &buffer, &mut EspflashProgress::default())?;
flasher.write_bin_to_flash(args.addr, &buffer, EspflashProgress::default())?;

Ok(())
}
2 changes: 1 addition & 1 deletion espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ pub fn flash_elf_image(
flash_mode,
flash_size,
flash_freq,
&mut EspflashProgress::default(),
EspflashProgress::default(),
)?;
info!("Flashing has completed!");

Expand Down
14 changes: 7 additions & 7 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl Flasher {
pub fn load_elf_to_ram(
&mut self,
elf_data: &[u8],
progress: &mut dyn ProgressCallbacks,
mut progress: impl ProgressCallbacks,
) -> Result<(), Error> {
let image = ElfFirmwareImage::try_from(elf_data)?;
if image.rom_segments(self.chip).next().is_some() {
Expand All @@ -646,7 +646,7 @@ impl Flasher {

for segment in image.ram_segments(self.chip) {
target
.write_segment(&mut self.connection, segment.into(), progress)
.write_segment(&mut self.connection, segment.into(), &mut progress)
.flashing()?;
}

Expand All @@ -663,7 +663,7 @@ impl Flasher {
flash_mode: Option<FlashMode>,
flash_size: Option<FlashSize>,
flash_freq: Option<FlashFrequency>,
progress: &mut dyn ProgressCallbacks,
mut progress: impl ProgressCallbacks,
) -> Result<(), Error> {
let image = ElfFirmwareImage::try_from(elf_data)?;

Expand Down Expand Up @@ -691,7 +691,7 @@ impl Flasher {

for segment in image.flash_segments() {
target
.write_segment(&mut self.connection, segment, progress)
.write_segment(&mut self.connection, segment, &mut progress)
.flashing()?;
}

Expand All @@ -705,7 +705,7 @@ impl Flasher {
&mut self,
addr: u32,
data: &[u8],
progress: &mut dyn ProgressCallbacks,
mut progress: impl ProgressCallbacks,
) -> Result<(), Error> {
let segment = RomSegment {
addr,
Expand All @@ -714,7 +714,7 @@ impl Flasher {

let mut target = self.chip.flash_target(self.spi_params, self.use_stub);
target.begin(&mut self.connection).flashing()?;
target.write_segment(&mut self.connection, segment, progress)?;
target.write_segment(&mut self.connection, segment, &mut progress)?;
target.finish(&mut self.connection, true).flashing()?;

Ok(())
Expand All @@ -729,7 +729,7 @@ impl Flasher {
flash_mode: Option<FlashMode>,
flash_size: Option<FlashSize>,
flash_freq: Option<FlashFrequency>,
progress: &mut dyn ProgressCallbacks,
progress: impl ProgressCallbacks,
) -> Result<(), Error> {
self.load_elf_to_flash_with_format(
elf_data,
Expand Down

0 comments on commit c7fc4b9

Please sign in to comment.