Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jonas-schievink/jaylink
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a8b564ef07b15195b40667d65162e4edb9785d7f
Choose a base ref
..
head repository: jonas-schievink/jaylink
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 15001acd2f3443423ee6994e039743aa0059a061
Choose a head ref
Showing with 25 additions and 31 deletions.
  1. +1 −2 Cargo.toml
  2. +24 −29 src/lib.rs
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -57,8 +57,7 @@ jep106 = "0.2.4"
bitflags = "1.2.1"
# Private
rusb = { version = "0.9.0", optional = true }
nusb = { version = "0.1.0", git = "https://github.com/Dirbaio/nusb", rev = "781207c9202c34cdb677cc4daae7c91ad7736de3", optional = true }
#nusb = { version = "0.1.0", path = "../nusb", optional = true }
nusb = { version = "0.1.3", optional = true }
futures-lite = { version = "1.13.0", optional = true }
log = "0.4.8"
byteorder = "1.3.2"
53 changes: 24 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -454,25 +454,28 @@ impl JayLink {
fn open_usb_inner(usb_device: UsbDeviceInfo) -> Result<Self> {
use nusb::transfer::{Direction, EndpointType};

let configs: Vec<_> = usb_device
.inner
.configurations().map_err(|e| {
let inner: Box<dyn std::error::Error + Send + Sync> = if cfg!(windows) {
format!(
"{} (this error may be caused by not having the \
WinUSB driver installed; use Zadig (https://zadig.akeo.ie/) to install it \
for the J-Link device; this will replace the SEGGER J-Link driver)",
e
)
.into()
} else {
Box::new(e)
};
fn open_error(e: std::io::Error, while_: &'static str) -> Error {
let inner: Box<dyn std::error::Error + Send + Sync> = if cfg!(windows) {
format!(
"{} (this error may be caused by not having the \
WinUSB driver installed; use Zadig (https://zadig.akeo.ie/) to install it \
for the J-Link device; this will replace the SEGGER J-Link driver)",
e
)
.into()
} else {
Box::new(e)
};

Error::with_while(ErrorKind::Usb, inner, while_)
}

Error::with_while(ErrorKind::Usb, inner, "reading USB device descriptors")
let handle = usb_device
.inner
.open()
.map_err(|e| open_error(e, "opening USB device"))?;

})?
.collect();
let configs: Vec<_> = handle.configurations().collect();

if configs.len() != 1 {
warn!("device has {} configurations, expected 1", configs.len());
@@ -484,17 +487,14 @@ impl JayLink {

let mut jlink_intf = None;
for intf in conf.interfaces() {
trace!("interface #{} descriptors:", intf.number());
trace!("interface #{} descriptors:", intf.interface_number());

for descr in intf.alternate_settings() {
for descr in intf.alt_settings() {
trace!("{:#x?}", descr);

// We detect the proprietary J-Link interface using the vendor-specific class codes
// and the endpoint properties
if descr.class_code() == 0xff
&& descr.sub_class_code() == 0xff
&& descr.protocol_code() == 0xff
{
if descr.class() == 0xff && descr.subclass() == 0xff && descr.protocol() == 0xff {
if let Some((intf, _, _)) = jlink_intf {
return Err(format!(
"found multiple matching USB interfaces ({} and {})",
@@ -540,14 +540,9 @@ impl JayLink {
return Err("device is not a J-Link device".to_string()).jaylink_err();
};

let handle = usb_device
.inner
.open()
.jaylink_err_while("opening USB device")?;

let handle = handle
.claim_interface(intf)
.jaylink_err_while("taking control over USB device")?;
.map_err(|e| open_error(e, "taking control over USB device"))?;

let mut this = Self {
manufacturer: usb_device