1
- use std:: { borrow:: Cow , thread:: sleep} ;
1
+ use std:: { borrow:: Cow , str :: FromStr , thread:: sleep} ;
2
2
3
3
use bytemuck:: { Pod , Zeroable , __core:: time:: Duration } ;
4
4
use serialport:: { SerialPort , UsbPortInfo } ;
5
- use strum_macros:: Display ;
5
+ use strum_macros:: { Display , EnumVariantNames } ;
6
6
7
7
use crate :: {
8
8
chip:: Chip ,
@@ -25,7 +25,7 @@ const FLASH_SECTORS_PER_BLOCK: usize = FLASH_SECTOR_SIZE / FLASH_BLOCK_SIZE;
25
25
// register used for chip detect
26
26
const CHIP_DETECT_MAGIC_REG_ADDR : u32 = 0x40001000 ;
27
27
28
- #[ derive( Clone , Copy , Debug , Eq , PartialEq , Display ) ]
28
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Display , EnumVariantNames ) ]
29
29
#[ repr( u8 ) ]
30
30
pub enum FlashSize {
31
31
#[ strum( serialize = "256KB" ) ]
@@ -62,11 +62,34 @@ impl FlashSize {
62
62
0x18 => Ok ( FlashSize :: Flash16Mb ) ,
63
63
0x19 => Ok ( FlashSize :: Flash32Mb ) ,
64
64
0x1a => Ok ( FlashSize :: Flash64Mb ) ,
65
+ 0x21 => Ok ( FlashSize :: Flash128Mb ) ,
65
66
_ => Err ( Error :: UnsupportedFlash ( FlashDetectError :: from ( value) ) ) ,
66
67
}
67
68
}
68
69
}
69
70
71
+ impl FromStr for FlashSize {
72
+ type Err = Error ;
73
+
74
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
75
+ let size = match s. to_uppercase ( ) . as_str ( ) {
76
+ "256KB" => FlashSize :: Flash256Kb ,
77
+ "512KB" => FlashSize :: Flash512Kb ,
78
+ "1MB" => FlashSize :: Flash1Mb ,
79
+ "2MB" => FlashSize :: Flash2Mb ,
80
+ "4MB" => FlashSize :: Flash4Mb ,
81
+ "8MB" => FlashSize :: Flash8Mb ,
82
+ "16MB" => FlashSize :: Flash16Mb ,
83
+ "32MB" => FlashSize :: Flash32Mb ,
84
+ "64MB" => FlashSize :: Flash64Mb ,
85
+ "128MB" => FlashSize :: Flash128Mb ,
86
+ _ => return Err ( Error :: InvalidFlashSize ( s. to_string ( ) ) ) ,
87
+ } ;
88
+
89
+ Ok ( size)
90
+ }
91
+ }
92
+
70
93
#[ derive( Copy , Clone , Debug ) ]
71
94
#[ repr( C ) ]
72
95
pub struct SpiAttachParams {
0 commit comments