Skip to content

Commit

Permalink
fix: probe detect; chore: add new commands
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Nov 7, 2023
1 parent 3601495 commit 921876b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
match self {
Reset::ResetAndRun => vec![0x01],
Reset::Soft => vec![0x01],
Reset::Normal => vec![0x03],
Reset::Normal2 => vec![0x02],
Reset::Chip => vec![0x02],
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/commands/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
if bytes.len() != 5 {
Expand Down Expand Up @@ -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<u8> {
let subcmd = match *self {
SetRSTPin::Low => 0x13,
SetRSTPin::High => 0x14,
SetRSTPin::Floating => 0x15,
};
vec![0x0e, subcmd]
}
}
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ impl WchLinkVariant {
pub fn try_from_u8(value: u8) -> Result<Self> {
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)),
}
}
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 921876b

Please sign in to comment.