Skip to content

Commit 6b34f66

Browse files
committed
make the chip create the flash target
1 parent c8b4146 commit 6b34f66

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

espflash/src/chip/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::{
99

1010
use std::{io::Write, str::FromStr};
1111

12+
use crate::flasher::SpiAttachParams;
13+
use crate::flashtarget::{ChipTarget, FlashTarget, RamTarget};
1214
pub use esp32::Esp32;
1315
pub use esp32c3::Esp32c3;
1416
pub use esp8266::Esp8266;
@@ -139,6 +141,14 @@ impl Chip {
139141
Chip::Esp8266 => Esp8266::SPI_REGISTERS,
140142
}
141143
}
144+
145+
pub fn ram_target(&self) -> Box<dyn FlashTarget> {
146+
Box::new(RamTarget::new())
147+
}
148+
149+
pub fn flash_target(&self, spi_params: SpiAttachParams) -> Box<dyn FlashTarget> {
150+
Box::new(ChipTarget::new(*self, spi_params))
151+
}
142152
}
143153

144154
impl FromStr for Chip {

espflash/src/flasher.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use strum_macros::Display;
55
use std::thread::sleep;
66

77
use crate::elf::RomSegment;
8-
use crate::flashtarget::{ChipTarget, FlashTarget, RamTarget};
98
use crate::{
109
chip::Chip, connection::Connection, elf::FirmwareImage, encoder::SlipEncoder, error::RomError,
1110
Error, PartitionTable,
@@ -465,7 +464,7 @@ impl Flasher {
465464
pub fn load_elf_to_ram(&mut self, elf_data: &[u8]) -> Result<(), Error> {
466465
let image = FirmwareImage::from_data(elf_data).map_err(|_| Error::InvalidElf)?;
467466

468-
let mut target = RamTarget::new();
467+
let mut target = self.chip.ram_target();
469468
target.begin(&mut self.connection, &image)?;
470469

471470
if image.rom_segments(self.chip).next().is_some() {
@@ -495,7 +494,7 @@ impl Flasher {
495494
let mut image = FirmwareImage::from_data(elf_data).map_err(|_| Error::InvalidElf)?;
496495
image.flash_size = self.flash_size();
497496

498-
let mut target = ChipTarget::new(self.chip, self.spi_params);
497+
let mut target = self.chip.flash_target(self.spi_params);
499498
target.begin(&mut self.connection, &image)?;
500499

501500
for segment in self

0 commit comments

Comments
 (0)