Skip to content

Commit

Permalink
Switch to using rusb crate instead of libusb
Browse files Browse the repository at this point in the history
libusb is no longer supported on newer versions of rust
  • Loading branch information
raleighlittles committed Aug 10, 2024
1 parent 6ae6171 commit 8a15817
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ categories = ["command-line-utilities"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libusb = "0.3.0"
rusb = "=0.9.4"
21 changes: 9 additions & 12 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ fn main() {
.nth(1)
.expect("No firmware filename received");

let mut libusb_context: libusb::Context = libusb::Context::new().unwrap();

libusb_context.set_log_level(libusb::LogLevel::Warning);

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

let mut libusb_dev_handle: libusb::DeviceHandle = libusb_context
.open_device_with_vid_pid(USB_VENDOR_ID, USB_PRODUCT_ID)
let libusb_dev_handle = rusb::open_device_with_vid_pid(USB_VENDOR_ID, USB_PRODUCT_ID)
.unwrap();

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

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

while file_byte_idx < firmware_file_len {
let pkt_size = std::cmp::min(
Expand All @@ -86,21 +83,21 @@ fn main() {
upper_transaction_idx
};

let bytes_transferred = libusb_dev_handle
let _bytes_transferred = libusb_dev_handle
.write_control(
USB_OUTGOING_PACKET_BM_REQUEST_TYPE,
0x0,
wValue.0,
w_value.0,
cur_transaction_idx,
&firmware_file_as_bytes[file_byte_idx as usize..pkt_end_idx],
std::time::Duration::ZERO,
)
.unwrap();

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

wValue += pkt_size as u16;
w_value += pkt_size as u16;
file_byte_idx += pkt_size as usize;
}

Expand Down

1 comment on commit 8a15817

@raleighlittles
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #11

Please sign in to comment.