1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#[derive(Copy, Clone, Debug)]
pub struct FlashID {
pub manufacturer_bank: u8,
pub manufacturer_id: u8,
pub device_id_long: u16,
pub device_id_short: u8,
pub unique_id: u64,
}
impl FlashID {
pub fn manufacturer_name(&self) -> Option<&'static str> {
let (bank, id) = (self.manufacturer_bank, self.manufacturer_id & 0x7F);
match jep106::JEP106Code::new(bank, id).get() {
Some(mfn) if mfn == "NEXCOM" => Some("Winbond/NEXCOM"),
Some(mfn) => Some(mfn),
None => None,
}
}
}
impl std::fmt::Display for FlashID {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mfn = match self.manufacturer_name() {
Some(mfn) => format!(" ({})", mfn),
None => "".to_string(),
};
let unique_id = match self.unique_id {
0x0000_0000_0000_0000 | 0xFFFF_FFFF_FFFF_FFFF => "".to_string(),
id => format!(", Unique ID: {:016X}", id),
};
write!(f, "Manufacturer 0x{:02X}{}, Device 0x{:02X}/0x{:04X}{}",
self.manufacturer_id, mfn, self.device_id_short,
self.device_id_long, unique_id)
}
}