Skip to content

Commit 8a15817

Browse files
Switch to using rusb crate instead of libusb
libusb is no longer supported on newer versions of rust
1 parent 6ae6171 commit 8a15817

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ categories = ["command-line-utilities"]
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
libusb = "0.3.0"
16+
rusb = "=0.9.4"

rust/src/main.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ fn main() {
33
.nth(1)
44
.expect("No firmware filename received");
55

6-
let mut libusb_context: libusb::Context = libusb::Context::new().unwrap();
7-
8-
libusb_context.set_log_level(libusb::LogLevel::Warning);
96

107
// See `libusb` output in documentation for where these come from
118
const USB_VENDOR_ID: u16 = 0x05a9;
129
const USB_PRODUCT_ID: u16 = 0x0580;
1310

14-
let mut libusb_dev_handle: libusb::DeviceHandle = libusb_context
15-
.open_device_with_vid_pid(USB_VENDOR_ID, USB_PRODUCT_ID)
11+
let libusb_dev_handle = rusb::open_device_with_vid_pid(USB_VENDOR_ID, USB_PRODUCT_ID)
1612
.unwrap();
1713

1814
// Device only has one USB 'endpoint'/interface (see `lsusb` output)
@@ -68,9 +64,10 @@ fn main() {
6864
let upper_transaction_idx = 0x15; // 21d
6965

7066
/* Goes from 0 to 65536, incrementing by 512. Then, starts over at 0, and continues incrementing.
71-
This is again something that was taken from OrbisEyeCam */
72-
let mut wValue = std::num::Wrapping(std::u16::MAX);
73-
wValue.0 = 0;
67+
This is again something that was taken from OrbisEyeCam
68+
Corresponds to 'wValue' in standard USB semantics */
69+
let mut w_value = std::num::Wrapping(std::u16::MAX);
70+
w_value.0 = 0;
7471

7572
while file_byte_idx < firmware_file_len {
7673
let pkt_size = std::cmp::min(
@@ -86,21 +83,21 @@ fn main() {
8683
upper_transaction_idx
8784
};
8885

89-
let bytes_transferred = libusb_dev_handle
86+
let _bytes_transferred = libusb_dev_handle
9087
.write_control(
9188
USB_OUTGOING_PACKET_BM_REQUEST_TYPE,
9289
0x0,
93-
wValue.0,
90+
w_value.0,
9491
cur_transaction_idx,
9592
&firmware_file_as_bytes[file_byte_idx as usize..pkt_end_idx],
9693
std::time::Duration::ZERO,
9794
)
9895
.unwrap();
9996

10097
// Careful with this log statement. Logging in between USB transactions can slow things down enough to where it no longer works
101-
//println!("Transferred {} bytes [{} , {}], value= {}, index= {}", bytes_transferred, file_byte_idx, pkt_end_idx, wValue.0, transaction_idx);
98+
//println!("Transferred {} bytes [{} , {}], value= {}, index= {}", bytes_transferred, file_byte_idx, pkt_end_idx, w_value.0, transaction_idx);
10299

103-
wValue += pkt_size as u16;
100+
w_value += pkt_size as u16;
104101
file_byte_idx += pkt_size as usize;
105102
}
106103

0 commit comments

Comments
 (0)