diff --git a/src/commands.rs b/src/commands.rs index 5d415c7..1b59358 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -268,19 +268,20 @@ impl fmt::Debug for ChipUID { /// Device reset (0x0b, _) #[derive(Debug)] pub enum Reset { - /// wlink_quitreset - ResetAndRun, // the most common reset + /// wlink_quitreset, reset and run + Soft, // the most common reset Normal, - Normal2, + /// wlink_chip_reset, chip reset + Chip, } impl Command for Reset { type Response = (); const COMMAND_ID: u8 = 0x0b; fn payload(&self) -> Vec { match self { - Reset::ResetAndRun => vec![0x01], + Reset::Soft => vec![0x01], Reset::Normal => vec![0x03], - Reset::Normal2 => vec![0x02], + Reset::Chip => vec![0x02], } } } diff --git a/src/commands/control.rs b/src/commands/control.rs index c173332..0c95fcd 100644 --- a/src/commands/control.rs +++ b/src/commands/control.rs @@ -72,7 +72,6 @@ pub struct AttachChipResponse { pub riscvchip: u8, pub chip_id: u32, } -impl AttachChipResponse {} impl Response for AttachChipResponse { fn from_payload(bytes: &[u8]) -> Result { if bytes.len() != 5 { @@ -198,3 +197,23 @@ impl Command for SetSDIPrint { } } } + +/// Set RST pin +#[derive(Debug)] +pub enum SetRSTPin { + Low, + High, + Floating, +} +impl Command for SetRSTPin { + type Response = (); + const COMMAND_ID: u8 = 0x0d; + fn payload(&self) -> Vec { + let subcmd = match *self { + SetRSTPin::Low => 0x13, + SetRSTPin::High => 0x14, + SetRSTPin::Floating => 0x15, + }; + vec![0x0e, subcmd] + } +} diff --git a/src/lib.rs b/src/lib.rs index 223bbce..852865b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,10 +34,9 @@ impl WchLinkVariant { pub fn try_from_u8(value: u8) -> Result { match value { 1 => Ok(Self::Ch549), - 2 => Ok(Self::ECh32v305), + 2 | 0x12 => Ok(Self::ECh32v305), 3 => Ok(Self::SCh32v203), - 5 => Ok(Self::WCh32v208), - 0x12 => Ok(Self::ECh32v305), // ?? + 5 | 0x85 => Ok(Self::WCh32v208), _ => Err(Error::UnknownLinkVariant(value)), } } @@ -181,9 +180,7 @@ impl RiscvChip { pub fn reset_command(&self) -> crate::commands::Reset { match self { - RiscvChip::CH57X | RiscvChip::CH58X | RiscvChip::CH59X => { - crate::commands::Reset::Normal2 - } + RiscvChip::CH57X | RiscvChip::CH58X | RiscvChip::CH59X => crate::commands::Reset::Chip, _ => crate::commands::Reset::Normal, } }