Skip to content

Commit a0752e6

Browse files
authored
Remove chip target files (#891)
* remove the efuse trait * remove the target trait * remove the target structs, use Chip for everything * move some things around, make FlashTarget public * rename idf image format, don't rexport things we don't need to * fix compilation by removing erroneous feature gate * Add `MissingPartition` and `MissingPartitionTable` to `Error` * Address review comments * CHANGELOG * rename targets module to target
1 parent d532c03 commit a0752e6

38 files changed

+1147
-1854
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ target/
1414
.DS_Store
1515
*.swp
1616
.idea/
17+
18+
!espflash/src/target

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- Add support for serial port configuration files. (#777, #883)
3131
- Add a `check-app-descriptor` bool option to `ImageArgs` and add the flag to `flash` commad(#872)
3232
- `Connection::into_serial` to get the underlying port from the connection (#882)
33+
- All methods on the now removed `Target` & `ReadEFuse`, `UsbOtg` and `RtcWdtReset` traits have been implemented directly on (#891)
3334

3435
### Changed
3536

@@ -55,7 +56,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5556
- `Flasher::into_serial` has been replaced by `Flasher::into_connection` (#882)
5657
- Automatically migrate `espflash@3` configuration files to the new format (#883)
5758
- Update dependencies to their latest versions (#893)
58-
59+
- `ProgressCallbacks` has moved to `flasher` (#891)
60+
- `Chip::crystal_freq` has been renamed to `Chip::xtal_frequency` (#891)
61+
- `Chip::chip_revision` has been renamed to `Chip::revision` (also applies to `minor` and `major`) (#891)
62+
- Any reference to `esp_idf` or `EspIdf` has been cut to just `idf` (#891)
63+
- Renamed `targets` module to `target` (#891)
5964

6065
### Fixed
6166

@@ -76,6 +81,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7681
- Removed the `flasher::parse_partition_table` function (#798)
7782
- The `FirmwareImage` trait has been removed (#802)
7883
- The `elf` module has been removed, and its contents moved to the `image_format` module (#802)
84+
- The `Target` trait, the `ReadEFuse` trait, and `Chip::into_target` (#891)
85+
- The `UsbOtg` and `RtcWdtReset` traits have been removed, along with `Chip::into_rtc_wdt_reset` & `Chip::into_usb_otg` (#891)
7986

8087
## [3.3.0] - 2025-01-13
8188

cargo-espflash/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
iter::once,
44
};
55

6-
use espflash::targets::Chip;
6+
use espflash::target::Chip;
77
use miette::{Diagnostic, LabeledSpan, SourceCode};
88
use thiserror::Error;
99

@@ -112,7 +112,7 @@ impl UnsupportedTargetError {
112112
}
113113

114114
fn supported_targets(&self) -> String {
115-
self.chip.into_target().supported_build_targets().join(", ")
115+
self.chip.supported_build_targets().join(", ")
116116
}
117117
}
118118

@@ -139,7 +139,7 @@ impl Diagnostic for NoTargetError {
139139
Some(chip) => format!(
140140
"Specify the target in `.cargo/config.toml`, the {} support the following targets: {}",
141141
chip,
142-
chip.into_target().supported_build_targets().join(", ")
142+
chip.supported_build_targets().join(", ")
143143
),
144144
None => "Specify the target in `.cargo/config.toml`".into(),
145145
}))

cargo-espflash/src/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ use espflash::{
1818
image_format::{
1919
ImageFormat,
2020
ImageFormatKind,
21-
check_idf_bootloader,
22-
esp_idf::parse_partition_table,
21+
idf::{check_idf_bootloader, parse_partition_table},
2322
},
2423
logging::initialize_logger,
25-
targets::{Chip, XtalFrequency},
24+
target::{Chip, XtalFrequency},
2625
update::check_for_update,
2726
};
2827
use log::{LevelFilter, debug, info};
@@ -208,7 +207,7 @@ struct FlashArgs {
208207
format: ImageFormatKind,
209208
/// ESP-IDF format arguments
210209
#[clap(flatten)]
211-
esp_idf_format_args: cli::EspIdfFormatArgs,
210+
idf_format_args: cli::IdfFormatArgs,
212211
}
213212

214213
#[derive(Debug, Args)]
@@ -223,7 +222,7 @@ struct SaveImageArgs {
223222
format: ImageFormatKind,
224223
/// ESP-IDF format arguments
225224
#[clap(flatten)]
226-
esp_idf_format_args: cli::EspIdfFormatArgs,
225+
idf_format_args: cli::IdfFormatArgs,
227226
}
228227

229228
fn main() -> Result<()> {
@@ -284,7 +283,7 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
284283

285284
let partition_table = args.partition_table.as_deref().or(config
286285
.project_config
287-
.esp_idf_format_args
286+
.idf_format_args
288287
.partition_table
289288
.as_deref());
290289
let mut flasher = connect(&args.connect_args, config, false, false)?;
@@ -325,8 +324,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
325324
}
326325

327326
let chip = flasher.chip();
328-
let target = chip.into_target();
329-
let target_xtal_freq = target.crystal_freq(flasher.connection())?;
327+
let target_xtal_freq = chip.xtal_frequency(flasher.connection())?;
330328

331329
flasher.disable_watchdog()?;
332330

@@ -345,7 +343,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
345343
monitor_args.elf = Some(build_ctx.artifact_path.clone());
346344

347345
check_monitor_args(&args.flash_args.monitor, &monitor_args)?;
348-
check_esp_idf_args(
346+
check_idf_args(
349347
args.format,
350348
&args.flash_args.erase_parts,
351349
&args.flash_args.erase_data_parts,
@@ -376,7 +374,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
376374
&flash_data,
377375
args.format,
378376
config,
379-
Some(args.esp_idf_format_args),
377+
Some(args.idf_format_args),
380378
build_ctx.bootloader_path,
381379
build_ctx.partition_table_path,
382380
)?;
@@ -441,7 +439,7 @@ fn build(
441439
}
442440
let metadata = metadata_cmd.exec().into_diagnostic()?;
443441

444-
if !chip.into_target().supports_build_target(target) {
442+
if !chip.supports_build_target(target) {
445443
return Err(UnsupportedTargetError::new(target, chip).into());
446444
}
447445

@@ -627,7 +625,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
627625
let xtal_freq = args
628626
.save_image_args
629627
.xtal_freq
630-
.unwrap_or(args.save_image_args.chip.default_crystal_frequency());
628+
.unwrap_or(args.save_image_args.chip.default_xtal_frequency());
631629

632630
let flash_data = make_flash_data(
633631
args.save_image_args.image,
@@ -641,7 +639,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
641639
&flash_data,
642640
args.format,
643641
config,
644-
Some(args.esp_idf_format_args),
642+
Some(args.idf_format_args),
645643
build_ctx.bootloader_path,
646644
build_ctx.partition_table_path,
647645
)?;

espflash/src/bin/espflash.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ use espflash::{
1313
image_format::{
1414
ImageFormat,
1515
ImageFormatKind,
16-
check_idf_bootloader,
17-
esp_idf::parse_partition_table,
16+
idf::{check_idf_bootloader, parse_partition_table},
1817
},
1918
logging::initialize_logger,
20-
targets::{Chip, XtalFrequency},
19+
target::{Chip, XtalFrequency},
2120
update::check_for_update,
2221
};
2322
use log::{LevelFilter, debug, info};
@@ -138,7 +137,7 @@ struct FlashArgs {
138137
format: ImageFormatKind,
139138
/// ESP-IDF arguments
140139
#[clap(flatten)]
141-
esp_idf_format_args: cli::EspIdfFormatArgs,
140+
idf_format_args: cli::IdfFormatArgs,
142141
}
143142

144143
#[derive(Debug, Args)]
@@ -157,7 +156,7 @@ struct SaveImageArgs {
157156
format: ImageFormatKind,
158157
// ESP-IDF arguments
159158
#[clap(flatten)]
160-
esp_idf_format_args: cli::EspIdfFormatArgs,
159+
idf_format_args: cli::IdfFormatArgs,
161160
}
162161

163162
fn main() -> Result<()> {
@@ -229,7 +228,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
229228
let mut monitor_args = args.flash_args.monitor_args;
230229
monitor_args.elf = Some(args.image.clone());
231230
check_monitor_args(&args.flash_args.monitor, &monitor_args)?;
232-
check_esp_idf_args(
231+
check_idf_args(
233232
args.format,
234233
&args.flash_args.erase_parts,
235234
&args.flash_args.erase_data_parts,
@@ -252,8 +251,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
252251
}
253252

254253
let chip = flasher.chip();
255-
let target = chip.into_target();
256-
let target_xtal_freq = target.crystal_freq(flasher.connection())?;
254+
let target_xtal_freq = chip.xtal_frequency(flasher.connection())?;
257255

258256
// Read the ELF data from the build path and load it to the target.
259257
let elf_data = fs::read(&args.image).into_diagnostic()?;
@@ -288,7 +286,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
288286
&flash_data,
289287
args.format,
290288
config,
291-
Some(args.esp_idf_format_args),
289+
Some(args.idf_format_args),
292290
None,
293291
None,
294292
)?;
@@ -353,7 +351,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
353351
let xtal_freq = args
354352
.save_image_args
355353
.xtal_freq
356-
.unwrap_or(args.save_image_args.chip.default_crystal_frequency());
354+
.unwrap_or(args.save_image_args.chip.default_xtal_frequency());
357355

358356
let flash_data = make_flash_data(
359357
args.save_image_args.image,
@@ -367,7 +365,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
367365
&flash_data,
368366
args.format,
369367
config,
370-
Some(args.esp_idf_format_args),
368+
Some(args.idf_format_args),
371369
None,
372370
None,
373371
)?;

espflash/src/cli/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct ProjectConfig {
9292
pub format: ImageFormatKind,
9393
/// ESP-IDF format arguments
9494
#[serde(default)]
95-
pub esp_idf_format_args: cli::EspIdfFormatArgs,
95+
pub idf_format_args: cli::IdfFormatArgs,
9696
/// Flash settings
9797
#[serde(default)]
9898
pub flash: FlashSettings,
@@ -124,14 +124,14 @@ impl Config {
124124
ProjectConfig::default()
125125
};
126126

127-
if let Some(table) = &project_config.esp_idf_format_args.partition_table {
127+
if let Some(table) = &project_config.idf_format_args.partition_table {
128128
match table.extension() {
129129
Some(ext) if ext == "bin" || ext == "csv" => {}
130130
_ => return Err(Error::InvalidPartitionTablePath.into()),
131131
}
132132
}
133133

134-
if let Some(bootloader) = &project_config.esp_idf_format_args.bootloader {
134+
if let Some(bootloader) = &project_config.idf_format_args.bootloader {
135135
if bootloader.extension() != Some(OsStr::new("bin")) {
136136
return Err(Error::InvalidBootloaderPath.into());
137137
}

espflash/src/cli/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ use crate::{
5353
ImageFormat,
5454
ImageFormatKind,
5555
Metadata,
56-
esp_idf::{IdfBootloaderFormat, parse_partition_table},
56+
idf::{IdfBootloaderFormat, parse_partition_table},
5757
},
58-
targets::{Chip, XtalFrequency},
58+
target::{Chip, XtalFrequency},
5959
};
6060

6161
pub mod config;
@@ -266,7 +266,7 @@ pub struct ImageArgs {
266266
#[derive(Debug, Args, Clone, Deserialize, Serialize, Default)]
267267
#[non_exhaustive]
268268
#[group(skip)]
269-
pub struct EspIdfFormatArgs {
269+
pub struct IdfFormatArgs {
270270
/// Path to a binary ESP-IDF bootloader file
271271
#[arg(long, value_name = "FILE")]
272272
pub bootloader: Option<PathBuf>,
@@ -642,13 +642,11 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
642642

643643
ensure_chip_compatibility(chip, elf.as_deref())?;
644644

645-
let target = chip.into_target();
646-
647645
let mut monitor_args = args.monitor_args;
648646

649647
// The 26MHz ESP32-C2's need to be treated as a special case.
650648
if chip == Chip::Esp32c2
651-
&& target.crystal_freq(flasher.connection())? == XtalFrequency::_26Mhz
649+
&& chip.xtal_frequency(flasher.connection())? == XtalFrequency::_26Mhz
652650
&& monitor_args.monitor_baud == 115_200
653651
{
654652
// 115_200 * 26 MHz / 40 MHz = 74_880
@@ -1022,18 +1020,18 @@ pub fn make_image_format<'a>(
10221020
flash_data: &FlashData,
10231021
image_format_kind: ImageFormatKind,
10241022
config: &Config,
1025-
esp_idf_format_args: Option<EspIdfFormatArgs>,
1023+
idf_format_args: Option<IdfFormatArgs>,
10261024
build_ctx_bootloader: Option<PathBuf>,
10271025
build_ctx_partition_table: Option<PathBuf>,
10281026
) -> Result<ImageFormat<'a>, Error> {
10291027
let image_format = match image_format_kind {
10301028
ImageFormatKind::EspIdf => {
1031-
let mut args = esp_idf_format_args.unwrap_or_default();
1029+
let mut args = idf_format_args.unwrap_or_default();
10321030
// Set bootloader path with precedence
10331031
if args.bootloader.is_none() {
10341032
args.bootloader = config
10351033
.project_config
1036-
.esp_idf_format_args
1034+
.idf_format_args
10371035
.bootloader
10381036
.clone()
10391037
.or(build_ctx_bootloader);
@@ -1043,7 +1041,7 @@ pub fn make_image_format<'a>(
10431041
if args.partition_table.is_none() {
10441042
args.partition_table = config
10451043
.project_config
1046-
.esp_idf_format_args
1044+
.idf_format_args
10471045
.partition_table
10481046
.clone()
10491047
.or(build_ctx_partition_table);
@@ -1115,8 +1113,7 @@ pub fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
11151113
print_board_info(&mut flasher)?;
11161114

11171115
let chip = flasher.chip();
1118-
let target = chip.into_target();
1119-
let target_xtal_freq = target.crystal_freq(flasher.connection())?;
1116+
let target_xtal_freq = chip.xtal_frequency(flasher.connection())?;
11201117

11211118
flasher.write_bin_to_flash(
11221119
args.address,
@@ -1179,7 +1176,7 @@ pub fn ensure_chip_compatibility(chip: Chip, elf: Option<&[u8]>) -> Result<()> {
11791176
}
11801177

11811178
/// Check if the given arguments are valid for the ESP-IDF format
1182-
pub fn check_esp_idf_args(
1179+
pub fn check_idf_args(
11831180
format: ImageFormatKind,
11841181
erase_parts: &Option<Vec<String>>,
11851182
erase_data_parts: &Option<Vec<DataType>>,
@@ -1201,7 +1198,7 @@ mod test {
12011198
#[derive(Parser)]
12021199
struct TestParser {
12031200
#[clap(flatten)]
1204-
args: EspIdfFormatArgs,
1201+
args: IdfFormatArgs,
12051202
}
12061203

12071204
#[test]

0 commit comments

Comments
 (0)