From fc0922f6f97416b9e2276974143d33225e316b50 Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Tue, 17 Sep 2024 15:37:25 +0900 Subject: [PATCH 01/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index caee6e6..4b23aba 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Current firmware version: 2.11 (aka. v31). - [ ] [CH643] - I don't have this chip, help wanted - [ ] [CH641] - I don't have this chip, help wanted - [CH32X035] -- [ ] [CH32L103] - I don't have this chip, help wanted +- [CH32L103] - [ ] [CH8571] - No other source about this chip, help wanted - ... (Feel free to open an issue if you have tested on other chips) From 509a30bc49542c132d7f7e3f56281947526f5a6f Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 22:28:07 +0900 Subject: [PATCH 02/11] add 3.3V and 5V output control --- CHANGELOG.md | 1 + README.md | 1 + src/commands/mod.rs | 2 +- src/main.rs | 22 ++++++++++++++++++++++ src/operations.rs | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0df4be..a1d1b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Rename ChipUID response to ESignature, #58 +- Add functions to control 3.3V and 5V outputs of probe ## [0.0.8] - 2024-03-30 diff --git a/README.md b/README.md index 4b23aba..4c2fd12 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ - [x] Read chip memory(flash) - [x] Read/write chip register - very handy for debugging - [x] Code-Protect & Code-Unprotect for supported chips +- [x] Enable or Disable 3.3V, 5V output - [x] [SDI print](https://www.cnblogs.com/liaigu/p/17628184.html) support, requires 2.10+ firmware - [x] [Serial port watching](https://github.com/ch32-rs/wlink/pull/36) for a smooth development experience - [x] Windows native driver support, no need to install libusb manually (requires x86 build) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 7e300b0..d894a2b 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -425,4 +425,4 @@ impl Command for DisableDebug { // 81 0D 01 0F ClearCodeFlashB // 81 0D 02 08 xx ClearCodeFlash // 81 11 01 0D unknown in query info, before GetChipRomRamSplit -// 81 0d 02 ee 00 stop flash ? +// 81 0D 02 EE 00 stop flash ? diff --git a/src/main.rs b/src/main.rs index a5419c3..7f9d8fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,6 +148,12 @@ enum Commands { }, /// List probes List {}, + /// Enable 3.3V output + Enable3V3 {}, + /// Disable 3.3V output + Disable3V3 {}, + /// Enable 5V output + Enable5V {}, /// SDI virtual serial port, #[command(subcommand)] SdiPrint(SdiPrint), @@ -401,6 +407,22 @@ fn main() -> Result<()> { sess.dump_info()?; sess.dump_core_csrs()?; sess.dump_dmi()?; + } + Commands::Enable3V3 {} => { + log::info!("Enable 3.3V Output"); + sess.set_3v3_output_enabled(true)?; + } + Commands::Disable3V3 {} => { + log::info!("Disable 3.3V Output"); + sess.set_3v3_output_enabled(false)?; + } + Commands::Enable5V {} => { + log::info!("Enable 5V Output"); + sess.set_5v_output_enabled(true)?; + } + Commands::Disable5V {} => { + log::info!("Disable 5V Output"); + sess.set_5v_output_enabled(false)?; } Commands::SdiPrint(v) => match v { // By enabling SDI print and modifying the _write function called by printf in the mcu code, diff --git a/src/operations.rs b/src/operations.rs index d4dedef..cfaf39a 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -331,6 +331,38 @@ impl ProbeSession { Ok(mem) } + pub fn set_3v3_output_enabled(&mut self, enable: bool) -> Result<()> { + if !probe.info.variant.support_power_funcs() { + return Err(Error::Custom( + "Probe doesn't support power control".to_string(), + )); + } + + if enable { + self.send_command(control::SetPower::Enable3V3)?; + } else { + self.send_command(control::SetPower::Disable3V3)?; + } + + Ok(()) + } + + pub fn set_5v_output_enabled(&mut self, enable: bool) -> Result<()> { + if !probe.info.variant.support_power_funcs() { + return Err(Error::Custom( + "Probe doesn't support power control".to_string(), + )); + } + + if enable { + self.send_command(control::SetPower::Enable5V)?; + } else { + self.send_command(control::SetPower::Disable5V)?; + } + + Ok(()) + } + pub fn set_sdi_print_enabled(&mut self, enable: bool) -> Result<()> { if !self.probe.info.variant.support_sdi_print() { return Err(Error::Custom( From 8a52255f80c6e22113b6f537ecd1fd68d7239c66 Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 22:33:35 +0900 Subject: [PATCH 03/11] function fix --- src/operations.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operations.rs b/src/operations.rs index cfaf39a..31c893d 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -332,7 +332,7 @@ impl ProbeSession { } pub fn set_3v3_output_enabled(&mut self, enable: bool) -> Result<()> { - if !probe.info.variant.support_power_funcs() { + if !self.probe.info.variant.support_power_funcs() { return Err(Error::Custom( "Probe doesn't support power control".to_string(), )); @@ -348,7 +348,7 @@ impl ProbeSession { } pub fn set_5v_output_enabled(&mut self, enable: bool) -> Result<()> { - if !probe.info.variant.support_power_funcs() { + if !self.probe.info.variant.support_power_funcs() { return Err(Error::Custom( "Probe doesn't support power control".to_string(), )); From 4f1b85ef35738d08ee3b5cbafc98972ccd0530ec Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 22:35:14 +0900 Subject: [PATCH 04/11] commands --- src/operations.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/operations.rs b/src/operations.rs index 31c893d..6e1d88f 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -339,9 +339,9 @@ impl ProbeSession { } if enable { - self.send_command(control::SetPower::Enable3V3)?; + self.send_command(commands::control::SetPower::Enable3V3)?; } else { - self.send_command(control::SetPower::Disable3V3)?; + self.send_command(commands::control::SetPower::Disable3V3)?; } Ok(()) @@ -355,9 +355,9 @@ impl ProbeSession { } if enable { - self.send_command(control::SetPower::Enable5V)?; + self.send_command(commands::control::SetPower::Enable5V)?; } else { - self.send_command(control::SetPower::Disable5V)?; + self.send_command(commands::control::SetPower::Disable5V)?; } Ok(()) From fc63fc3bcdebe240b4e42f368f131aae218860cb Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 22:37:13 +0900 Subject: [PATCH 05/11] probe --- src/operations.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/operations.rs b/src/operations.rs index 6e1d88f..4502908 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -339,9 +339,11 @@ impl ProbeSession { } if enable { - self.send_command(commands::control::SetPower::Enable3V3)?; + self.probe + .send_command(commands::control::SetPower::Enable3V3)?; } else { - self.send_command(commands::control::SetPower::Disable3V3)?; + self.probe + .send_command(commands::control::SetPower::Disable3V3)?; } Ok(()) @@ -355,9 +357,11 @@ impl ProbeSession { } if enable { - self.send_command(commands::control::SetPower::Enable5V)?; + self.probe + .send_command(commands::control::SetPower::Enable5V)?; } else { - self.send_command(commands::control::SetPower::Disable5V)?; + self.probe + .send_command(commands::control::SetPower::Disable5V)?; } Ok(()) From d50b3c0a34da890c73a16ed2f445b363e83b38b8 Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 22:39:25 +0900 Subject: [PATCH 06/11] disable5v --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7f9d8fc..a9b28ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -154,6 +154,8 @@ enum Commands { Disable3V3 {}, /// Enable 5V output Enable5V {}, + /// Disable 5V output + Disable5V {}, /// SDI virtual serial port, #[command(subcommand)] SdiPrint(SdiPrint), From 7b5920819807cdccb2722277666abe8e45324438 Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 23:01:26 +0900 Subject: [PATCH 07/11] move logiv to probe.rs --- src/main.rs | 32 ++++++++++++++++---------------- src/operations.rs | 36 ------------------------------------ src/probe.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/main.rs b/src/main.rs index a9b28ae..18c7765 100644 --- a/src/main.rs +++ b/src/main.rs @@ -212,6 +212,22 @@ fn main() -> Result<()> { Some(Commands::List {}) => { WchLink::list_probes()?; } + Some(Commands::Enable3V3 {}) => { + log::info!("Enable 3.3V Output"); + WchLink::set_3v3_output_enabled(true)?; + } + Some(Commands::Disable3V3 {}) => { + log::info!("Disable 3.3V Output"); + WchLink::set_3v3_output_enabled(false)?; + } + Some(Commands::Enable5V {}) => { + log::info!("Enable 5V Output"); + WchLink::set_5v_output_enabled(true)?; + } + Some(Commands::Disable5V {}) => { + log::info!("Disable 5V Output"); + WchLink::set_5v_output_enabled(false)?; + } Some(Commands::Erase { method }) if method != EraseMode::Default => { // Special handling for non-default erase: bypass attach chip @@ -410,22 +426,6 @@ fn main() -> Result<()> { sess.dump_core_csrs()?; sess.dump_dmi()?; } - Commands::Enable3V3 {} => { - log::info!("Enable 3.3V Output"); - sess.set_3v3_output_enabled(true)?; - } - Commands::Disable3V3 {} => { - log::info!("Disable 3.3V Output"); - sess.set_3v3_output_enabled(false)?; - } - Commands::Enable5V {} => { - log::info!("Enable 5V Output"); - sess.set_5v_output_enabled(true)?; - } - Commands::Disable5V {} => { - log::info!("Disable 5V Output"); - sess.set_5v_output_enabled(false)?; - } Commands::SdiPrint(v) => match v { // By enabling SDI print and modifying the _write function called by printf in the mcu code, // the WCH-Link can be used to read data from the debug interface of the mcu diff --git a/src/operations.rs b/src/operations.rs index 4502908..d4dedef 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -331,42 +331,6 @@ impl ProbeSession { Ok(mem) } - pub fn set_3v3_output_enabled(&mut self, enable: bool) -> Result<()> { - if !self.probe.info.variant.support_power_funcs() { - return Err(Error::Custom( - "Probe doesn't support power control".to_string(), - )); - } - - if enable { - self.probe - .send_command(commands::control::SetPower::Enable3V3)?; - } else { - self.probe - .send_command(commands::control::SetPower::Disable3V3)?; - } - - Ok(()) - } - - pub fn set_5v_output_enabled(&mut self, enable: bool) -> Result<()> { - if !self.probe.info.variant.support_power_funcs() { - return Err(Error::Custom( - "Probe doesn't support power control".to_string(), - )); - } - - if enable { - self.probe - .send_command(commands::control::SetPower::Enable5V)?; - } else { - self.probe - .send_command(commands::control::SetPower::Disable5V)?; - } - - Ok(()) - } - pub fn set_sdi_print_enabled(&mut self, enable: bool) -> Result<()> { if !self.probe.info.variant.support_sdi_print() { return Err(Error::Custom( diff --git a/src/probe.rs b/src/probe.rs index 9a37767..6db2c03 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -173,6 +173,42 @@ impl WchLink { Ok(()) } + pub fn set_3v3_output_enabled(&mut self, enable: bool) -> Result<()> { + if !self.probe.info.variant.support_power_funcs() { + return Err(Error::Custom( + "Probe doesn't support power control".to_string(), + )); + } + + if enable { + self.probe + .send_command(commands::control::SetPower::Enable3V3)?; + } else { + self.probe + .send_command(commands::control::SetPower::Disable3V3)?; + } + + Ok(()) + } + + pub fn set_5v_output_enabled(&mut self, enable: bool) -> Result<()> { + if !self.probe.info.variant.support_power_funcs() { + return Err(Error::Custom( + "Probe doesn't support power control".to_string(), + )); + } + + if enable { + self.probe + .send_command(commands::control::SetPower::Enable5V)?; + } else { + self.probe + .send_command(commands::control::SetPower::Disable5V)?; + } + + Ok(()) + } + fn write_raw_cmd(&mut self, buf: &[u8]) -> Result<()> { log::trace!("send {} {}", hex::encode(&buf[..3]), hex::encode(&buf[3..])); self.device.write_endpoint(ENDPOINT_OUT, buf)?; From 5b6cceec0e7f81234e0e8aca5fef8736b34eb792 Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 23:06:01 +0900 Subject: [PATCH 08/11] device_index --- src/main.rs | 8 ++++---- src/probe.rs | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 18c7765..fc8ad67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,19 +214,19 @@ fn main() -> Result<()> { } Some(Commands::Enable3V3 {}) => { log::info!("Enable 3.3V Output"); - WchLink::set_3v3_output_enabled(true)?; + WchLink::set_3v3_output_enabled(device_index, true)?; } Some(Commands::Disable3V3 {}) => { log::info!("Disable 3.3V Output"); - WchLink::set_3v3_output_enabled(false)?; + WchLink::set_3v3_output_enabled(device_index, false)?; } Some(Commands::Enable5V {}) => { log::info!("Enable 5V Output"); - WchLink::set_5v_output_enabled(true)?; + WchLink::set_5v_output_enabled(device_index, true)?; } Some(Commands::Disable5V {}) => { log::info!("Disable 5V Output"); - WchLink::set_5v_output_enabled(false)?; + WchLink::set_5v_output_enabled(device_index, false)?; } Some(Commands::Erase { method }) if method != EraseMode::Default => { diff --git a/src/probe.rs b/src/probe.rs index 6db2c03..f0d6d0e 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -173,37 +173,37 @@ impl WchLink { Ok(()) } - pub fn set_3v3_output_enabled(&mut self, enable: bool) -> Result<()> { - if !self.probe.info.variant.support_power_funcs() { + pub fn set_3v3_output_enabled(nth: usize, enable: bool) -> Result<()> { + let mut probe = Self::open_nth(nth)?; + + if !probe.info.variant.support_power_funcs() { return Err(Error::Custom( "Probe doesn't support power control".to_string(), )); } if enable { - self.probe - .send_command(commands::control::SetPower::Enable3V3)?; + probe.send_command(commands::control::SetPower::Enable3V3)?; } else { - self.probe - .send_command(commands::control::SetPower::Disable3V3)?; + probe.send_command(commands::control::SetPower::Disable3V3)?; } Ok(()) } - pub fn set_5v_output_enabled(&mut self, enable: bool) -> Result<()> { - if !self.probe.info.variant.support_power_funcs() { + pub fn set_5v_output_enabled(nth: usize, enable: bool) -> Result<()> { + let mut probe = Self::open_nth(nth)?; + + if !probe.info.variant.support_power_funcs() { return Err(Error::Custom( "Probe doesn't support power control".to_string(), )); } if enable { - self.probe - .send_command(commands::control::SetPower::Enable5V)?; + probe.send_command(commands::control::SetPower::Enable5V)?; } else { - self.probe - .send_command(commands::control::SetPower::Disable5V)?; + probe.send_command(commands::control::SetPower::Disable5V)?; } Ok(()) From 50d276a1e241148a3602fc35bfffeceed7cda50e Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 23:40:14 +0900 Subject: [PATCH 09/11] fix command name and log timing --- src/main.rs | 20 ++++++++------------ src/probe.rs | 4 ++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index fc8ad67..e438a0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,13 +149,13 @@ enum Commands { /// List probes List {}, /// Enable 3.3V output - Enable3V3 {}, + Enable3v3 {}, /// Disable 3.3V output - Disable3V3 {}, + Disable3v3 {}, /// Enable 5V output - Enable5V {}, + Enable5v {}, /// Disable 5V output - Disable5V {}, + Disable5v {}, /// SDI virtual serial port, #[command(subcommand)] SdiPrint(SdiPrint), @@ -212,20 +212,16 @@ fn main() -> Result<()> { Some(Commands::List {}) => { WchLink::list_probes()?; } - Some(Commands::Enable3V3 {}) => { - log::info!("Enable 3.3V Output"); + Some(Commands::Enable3v3 {}) => { WchLink::set_3v3_output_enabled(device_index, true)?; } - Some(Commands::Disable3V3 {}) => { - log::info!("Disable 3.3V Output"); + Some(Commands::Disable3v3 {}) => { WchLink::set_3v3_output_enabled(device_index, false)?; } - Some(Commands::Enable5V {}) => { - log::info!("Enable 5V Output"); + Some(Commands::Enable5v {}) => { WchLink::set_5v_output_enabled(device_index, true)?; } - Some(Commands::Disable5V {}) => { - log::info!("Disable 5V Output"); + Some(Commands::Disable5v {}) => { WchLink::set_5v_output_enabled(device_index, false)?; } diff --git a/src/probe.rs b/src/probe.rs index f0d6d0e..3b996b9 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -183,8 +183,10 @@ impl WchLink { } if enable { + log::info!("Enable 3.3V Output"); probe.send_command(commands::control::SetPower::Enable3V3)?; } else { + log::info!("Disable 3.3V Output"); probe.send_command(commands::control::SetPower::Disable3V3)?; } @@ -201,8 +203,10 @@ impl WchLink { } if enable { + log::info!("Enable 5V Output"); probe.send_command(commands::control::SetPower::Enable5V)?; } else { + log::info!("Disable 5V Output"); probe.send_command(commands::control::SetPower::Disable5V)?; } From cdc5befb84f70a33b8f05ebefa25a5f702007f2a Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Sat, 28 Sep 2024 23:46:37 +0900 Subject: [PATCH 10/11] delete unused space --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e438a0c..922d51b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -421,7 +421,7 @@ fn main() -> Result<()> { sess.dump_info()?; sess.dump_core_csrs()?; sess.dump_dmi()?; - } + } Commands::SdiPrint(v) => match v { // By enabling SDI print and modifying the _write function called by printf in the mcu code, // the WCH-Link can be used to read data from the debug interface of the mcu From 35b37134340010d9855fac1d6d46e66134e9150a Mon Sep 17 00:00:00 2001 From: Koki Mizumoto <21km43@gmail.com> Date: Wed, 2 Oct 2024 22:54:01 +0900 Subject: [PATCH 11/11] integrate into subcommand --- src/commands/control.rs | 22 +++++++++++++--------- src/main.rs | 26 +++++++------------------- src/probe.rs | 33 +++++++-------------------------- 3 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/commands/control.rs b/src/commands/control.rs index 8f90d23..3f71b8a 100644 --- a/src/commands/control.rs +++ b/src/commands/control.rs @@ -160,22 +160,26 @@ impl Command for OptEnd { } /// Set Power, from pow3v3, pow5v fn -#[derive(Debug)] +#[derive(clap::Subcommand, PartialEq, Clone, Copy, Debug)] pub enum SetPower { - Enable3V3, - Disable3V3, - Enable5V, - Disable5V, + /// Enable 3.3V output + Enable3v3, + /// Disable 3.3V output + Disable3v3, + /// Enable 5V output + Enable5v, + /// Disable 5V output + Disable5v, } impl Command for SetPower { type Response = (); const COMMAND_ID: u8 = 0x0d; fn payload(&self) -> Vec { match self { - SetPower::Enable3V3 => vec![0x09], - SetPower::Disable3V3 => vec![0x0A], - SetPower::Enable5V => vec![0x0B], - SetPower::Disable5V => vec![0x0C], + SetPower::Enable3v3 => vec![0x09], + SetPower::Disable3v3 => vec![0x0A], + SetPower::Enable5v => vec![0x0B], + SetPower::Disable5v => vec![0x0C], } } } diff --git a/src/main.rs b/src/main.rs index 922d51b..b5cdb0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,14 +148,11 @@ enum Commands { }, /// List probes List {}, - /// Enable 3.3V output - Enable3v3 {}, - /// Disable 3.3V output - Disable3v3 {}, - /// Enable 5V output - Enable5v {}, - /// Disable 5V output - Disable5v {}, + /// Enable or disable power output + SetPower { + #[command(subcommand)] + cmd: commands::control::SetPower, + }, /// SDI virtual serial port, #[command(subcommand)] SdiPrint(SdiPrint), @@ -212,17 +209,8 @@ fn main() -> Result<()> { Some(Commands::List {}) => { WchLink::list_probes()?; } - Some(Commands::Enable3v3 {}) => { - WchLink::set_3v3_output_enabled(device_index, true)?; - } - Some(Commands::Disable3v3 {}) => { - WchLink::set_3v3_output_enabled(device_index, false)?; - } - Some(Commands::Enable5v {}) => { - WchLink::set_5v_output_enabled(device_index, true)?; - } - Some(Commands::Disable5v {}) => { - WchLink::set_5v_output_enabled(device_index, false)?; + Some(Commands::SetPower { cmd }) => { + WchLink::set_power_output_enabled(device_index, cmd)?; } Some(Commands::Erase { method }) if method != EraseMode::Default => { diff --git a/src/probe.rs b/src/probe.rs index 3b996b9..06f2043 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -173,7 +173,7 @@ impl WchLink { Ok(()) } - pub fn set_3v3_output_enabled(nth: usize, enable: bool) -> Result<()> { + pub fn set_power_output_enabled(nth: usize, cmd: commands::control::SetPower) -> Result<()> { let mut probe = Self::open_nth(nth)?; if !probe.info.variant.support_power_funcs() { @@ -182,32 +182,13 @@ impl WchLink { )); } - if enable { - log::info!("Enable 3.3V Output"); - probe.send_command(commands::control::SetPower::Enable3V3)?; - } else { - log::info!("Disable 3.3V Output"); - probe.send_command(commands::control::SetPower::Disable3V3)?; - } - - Ok(()) - } - - pub fn set_5v_output_enabled(nth: usize, enable: bool) -> Result<()> { - let mut probe = Self::open_nth(nth)?; + probe.send_command(cmd)?; - if !probe.info.variant.support_power_funcs() { - return Err(Error::Custom( - "Probe doesn't support power control".to_string(), - )); - } - - if enable { - log::info!("Enable 5V Output"); - probe.send_command(commands::control::SetPower::Enable5V)?; - } else { - log::info!("Disable 5V Output"); - probe.send_command(commands::control::SetPower::Disable5V)?; + match cmd { + commands::control::SetPower::Enable3v3 => log::info!("Enable 3.3V Output"), + commands::control::SetPower::Disable3v3 => log::info!("Disable 3.3V Output"), + commands::control::SetPower::Enable5v => log::info!("Enable 5V Output"), + commands::control::SetPower::Disable5v => log::info!("Disable 5V Output"), } Ok(())