Skip to content

Commit c128742

Browse files
committed
Move FlashFrequency and FlashMode enums into the flasher module, where they belong
1 parent 8f1e2cb commit c128742

File tree

14 files changed

+98
-105
lines changed

14 files changed

+98
-105
lines changed

espflash/src/chip/esp32/esp32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::Esp32Params;
44
use crate::{
55
chip::{bytes_to_mac_addr, Chip, ChipType, ReadEFuse, SpiRegisters},
66
connection::Connection,
7-
elf::{FirmwareImage, FlashFrequency, FlashMode},
7+
elf::FirmwareImage,
88
error::UnsupportedImageFormatError,
9-
flasher::FlashSize,
9+
flasher::{FlashFrequency, FlashMode, FlashSize},
1010
image_format::{Esp32BootloaderFormat, ImageFormat, ImageFormatId},
1111
Error, PartitionTable,
1212
};

espflash/src/chip/esp32/esp32c2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use super::Esp32Params;
66
use crate::{
77
chip::{ChipType, ReadEFuse, SpiRegisters},
88
connection::Connection,
9-
elf::{FirmwareImage, FlashFrequency, FlashMode},
10-
flasher::FlashSize,
9+
elf::FirmwareImage,
10+
flasher::{FlashFrequency, FlashMode, FlashSize},
1111
image_format::{Esp32BootloaderFormat, Esp32DirectBootFormat, ImageFormat, ImageFormatId},
1212
Chip, Error, PartitionTable,
1313
};

espflash/src/chip/esp32/esp32c3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::Esp32Params;
44
use crate::{
55
chip::{ChipType, ReadEFuse, SpiRegisters},
66
connection::Connection,
7-
elf::{FirmwareImage, FlashFrequency, FlashMode},
7+
elf::FirmwareImage,
88
error::UnsupportedImageFormatError,
9-
flasher::FlashSize,
9+
flasher::{FlashFrequency, FlashMode, FlashSize},
1010
image_format::{Esp32BootloaderFormat, Esp32DirectBootFormat, ImageFormat, ImageFormatId},
1111
Chip, Error, PartitionTable,
1212
};

espflash/src/chip/esp32/esp32s2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use super::Esp32Params;
44
use crate::{
55
chip::{ChipType, ReadEFuse, SpiRegisters},
66
connection::Connection,
7-
elf::{FirmwareImage, FlashFrequency, FlashMode},
7+
elf::FirmwareImage,
88
error::UnsupportedImageFormatError,
99
flash_target::MAX_RAM_BLOCK_SIZE,
10-
flasher::{FlashSize, FLASH_WRITE_SIZE},
10+
flasher::{FlashFrequency, FlashMode, FlashSize, FLASH_WRITE_SIZE},
1111
image_format::{Esp32BootloaderFormat, ImageFormat, ImageFormatId},
1212
Chip, Error, PartitionTable,
1313
};

espflash/src/chip/esp32/esp32s3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use super::Esp32Params;
44
use crate::{
55
chip::{ChipType, ReadEFuse, SpiRegisters},
66
connection::Connection,
7-
elf::{FirmwareImage, FlashFrequency, FlashMode},
8-
flasher::FlashSize,
7+
elf::FirmwareImage,
8+
flasher::{FlashFrequency, FlashMode, FlashSize},
99
image_format::{Esp32BootloaderFormat, Esp32DirectBootFormat, ImageFormat, ImageFormatId},
1010
Chip, Error, PartitionTable,
1111
};

espflash/src/chip/esp8266.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::{bytes_to_mac_addr, ChipType};
44
use crate::{
55
chip::{ReadEFuse, SpiRegisters},
66
connection::Connection,
7-
elf::{FirmwareImage, FlashFrequency, FlashMode},
7+
elf::FirmwareImage,
88
error::UnsupportedImageFormatError,
9-
flasher::FlashSize,
9+
flasher::{FlashFrequency, FlashMode, FlashSize},
1010
image_format::{Esp8266Format, ImageFormat, ImageFormatId},
1111
Chip, Error, PartitionTable,
1212
};

espflash/src/chip/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ pub use self::{
99
};
1010
use crate::{
1111
connection::Connection,
12-
elf::{FirmwareImage, FlashFrequency, FlashMode},
12+
elf::FirmwareImage,
1313
error::ChipDetectError,
1414
flash_target::{Esp32Target, Esp8266Target, FlashTarget, RamTarget, MAX_RAM_BLOCK_SIZE},
15-
flasher::{FlashSize, SpiAttachParams, FLASH_WRITE_SIZE},
15+
flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams, FLASH_WRITE_SIZE},
1616
image_format::{ImageFormat, ImageFormatId},
1717
Error, PartitionTable,
1818
};

espflash/src/cli/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use strum::VariantNames;
1616

1717
use crate::{
1818
cli::{monitor::monitor, serial::get_serial_port_info},
19-
elf::{ElfFirmwareImage, FlashFrequency, FlashMode},
19+
elf::ElfFirmwareImage,
2020
error::{Error, NoOtadataError},
21-
flasher::FlashSize,
21+
flasher::{FlashFrequency, FlashMode, FlashSize},
2222
image_format::ImageFormatType,
2323
partition_table, Chip, Flasher, ImageFormatId, InvalidPartitionTable, MissingPartitionTable,
2424
PartitionTable,

espflash/src/elf.rs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ use std::{
44
fmt::{Debug, Formatter},
55
mem::take,
66
ops::AddAssign,
7-
str::FromStr,
87
};
98

10-
use strum_macros::{Display, EnumVariantNames};
119
use xmas_elf::{
1210
program::Type,
1311
sections::{SectionData, ShType},
@@ -21,81 +19,6 @@ use crate::{
2119

2220
pub const ESP_CHECKSUM_MAGIC: u8 = 0xef;
2321

24-
#[derive(Copy, Clone, Debug, EnumVariantNames)]
25-
#[strum(serialize_all = "UPPERCASE")]
26-
pub enum FlashMode {
27-
Qio,
28-
Qout,
29-
Dio,
30-
Dout,
31-
}
32-
33-
impl FromStr for FlashMode {
34-
type Err = Error;
35-
36-
fn from_str(s: &str) -> Result<Self, Self::Err> {
37-
let mode = match s.to_uppercase().as_str() {
38-
"QIO" => FlashMode::Qio,
39-
"QOUT" => FlashMode::Qout,
40-
"DIO" => FlashMode::Dio,
41-
"DOUT" => FlashMode::Dout,
42-
_ => return Err(Error::InvalidFlashMode(s.to_string())),
43-
};
44-
45-
Ok(mode)
46-
}
47-
}
48-
49-
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Display, EnumVariantNames)]
50-
#[repr(u8)]
51-
pub enum FlashFrequency {
52-
#[strum(serialize = "12M")]
53-
Flash12M,
54-
#[strum(serialize = "15M")]
55-
Flash15M,
56-
#[strum(serialize = "16M")]
57-
Flash16M,
58-
#[strum(serialize = "20M")]
59-
Flash20M,
60-
#[strum(serialize = "24M")]
61-
Flash24M,
62-
#[strum(serialize = "26M")]
63-
Flash26M,
64-
#[strum(serialize = "30M")]
65-
Flash30M,
66-
#[strum(serialize = "40M")]
67-
Flash40M,
68-
#[strum(serialize = "48M")]
69-
Flash48M,
70-
#[strum(serialize = "60M")]
71-
Flash60M,
72-
#[strum(serialize = "80M")]
73-
Flash80M,
74-
}
75-
76-
impl FromStr for FlashFrequency {
77-
type Err = Error;
78-
79-
fn from_str(s: &str) -> Result<Self, Self::Err> {
80-
use FlashFrequency::*;
81-
82-
match s.to_uppercase().as_str() {
83-
"12M" => Ok(Flash12M),
84-
"15M" => Ok(Flash15M),
85-
"16M" => Ok(Flash16M),
86-
"20M" => Ok(Flash20M),
87-
"24M" => Ok(Flash24M),
88-
"26M" => Ok(Flash26M),
89-
"30M" => Ok(Flash30M),
90-
"40M" => Ok(Flash40M),
91-
"48M" => Ok(Flash48M),
92-
"60M" => Ok(Flash60M),
93-
"80M" => Ok(Flash80M),
94-
_ => Err(Error::InvalidFlashFrequency(s.to_string())),
95-
}
96-
}
97-
}
98-
9922
pub trait FirmwareImage<'a> {
10023
fn entry(&self) -> u32;
10124
fn segments(&'a self) -> Box<dyn Iterator<Item = CodeSegment<'a>> + 'a>;

espflash/src/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use thiserror::Error;
1010

1111
use crate::{
1212
command::CommandType,
13-
elf::{FlashFrequency, FlashMode},
14-
flasher::FlashSize,
13+
flasher::{FlashFrequency, FlashMode, FlashSize},
1514
image_format::ImageFormatId,
1615
partition_table::{CoreType, SubType, Type},
1716
Chip,

0 commit comments

Comments
 (0)