@@ -50,6 +50,8 @@ enum CmdId {
50
50
CmdJump = 0x01 ,
51
51
/// Seems to enter flashing mode
52
52
CmdFlash = 0x02 ,
53
+ /// Not quite sure what it does
54
+ Cmd0x04 = 0x04 ,
53
55
/// Some sort of mode switch
54
56
Cmd0x06 = 0x06 ,
55
57
}
@@ -87,17 +89,7 @@ enum ReportIdCmd {
87
89
fn flashing_mode ( device : & HidDevice ) {
88
90
// Probably enter flashing mode?
89
91
info ! ( "Enter flashing mode" ) ;
90
- let _ = device
91
- . write ( & [
92
- ReportIdCmd :: E1Cmd as u8 ,
93
- CmdId :: CmdFlash as u8 ,
94
- CmdParam :: Enable as u8 ,
95
- 0x00 ,
96
- 0xCC ,
97
- 0xCC ,
98
- 0xCC ,
99
- 0xCC ,
100
- ] )
92
+ let _ = send_command ( device, CmdId :: CmdFlash , CmdParam :: Enable as u8 )
101
93
. expect ( "Failed to enter flashing mode" ) ;
102
94
}
103
95
@@ -123,16 +115,7 @@ fn magic_unlock(device: &HidDevice) {
123
115
// TODO: I have a feeling the last five bytes are ignored. They're the same in all commands.
124
116
// Seems to work with all of them set to 0x00
125
117
info ! ( "Bridge Mode" ) ;
126
- let _ = device. write ( & [
127
- ReportIdCmd :: E1Cmd as u8 ,
128
- CmdId :: Cmd0x06 as u8 ,
129
- CmdParam :: BridgeMode as u8 ,
130
- 0x00 ,
131
- 0xCC ,
132
- 0xCC ,
133
- 0xCC ,
134
- 0xCC ,
135
- ] ) ;
118
+ let _ = send_command ( device, CmdId :: Cmd0x06 , CmdParam :: BridgeMode as u8 ) ;
136
119
}
137
120
138
121
fn get_fw_info ( device : & HidDevice ) -> HidFirmwareInfo {
@@ -425,33 +408,24 @@ fn flash_firmware_image(
425
408
// Not quite sure what this is. But on the first update it has
426
409
// 0x01 and on the second it has 0x02. So I think this switches the boot order?
427
410
info ! ( "Bootswitch" ) ;
428
- let _ = device
429
- . write ( & [
430
- ReportIdCmd :: E1Cmd as u8 ,
431
- 0x04 ,
432
- no,
433
- 0x00 ,
434
- 0xCC ,
435
- 0xCC ,
436
- 0xCC ,
437
- 0xCC ,
438
- ] )
439
- . unwrap ( ) ;
411
+ let _ = send_command ( device, CmdId :: Cmd0x04 , no) . unwrap ( ) ;
440
412
441
413
// Seems to reset the device, since the USB device number changes
442
414
info ! ( "Reset" ) ;
443
- let _ = device
444
- . write ( & [
445
- ReportIdCmd :: E1Cmd as u8 ,
446
- CmdId :: CmdJump as u8 ,
447
- CmdParam :: Reset as u8 ,
448
- 0x00 ,
449
- 0xCC ,
450
- 0xCC ,
451
- 0xCC ,
452
- 0xCC ,
453
- ] )
454
- . unwrap ( ) ;
415
+ let _ = send_command ( device, CmdId :: CmdJump , CmdParam :: Reset as u8 ) . unwrap ( ) ;
416
+ }
417
+
418
+ fn send_command ( device : & HidDevice , cmd_id : CmdId , cmd_param : u8 ) -> Result < usize , HidError > {
419
+ device. write ( & [
420
+ ReportIdCmd :: E1Cmd as u8 ,
421
+ cmd_id as u8 ,
422
+ cmd_param,
423
+ 0x00 ,
424
+ 0xCC ,
425
+ 0xCC ,
426
+ 0xCC ,
427
+ 0xCC ,
428
+ ] )
455
429
}
456
430
457
431
fn write_row ( device : & HidDevice , row_no : u16 , row : & [ u8 ] ) -> Result < usize , HidError > {
0 commit comments