Skip to content

Commit e5abf43

Browse files
Solve some weirdness with response length pointers
1 parent e886a59 commit e5abf43

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

usb/src/device/tusb/tusbaudio.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type VendorRequestIn =
4747
unsafe extern "C" fn(u32, u32, u32, u32, u32, u16, u16, *mut u8, *mut u8, u32) -> u32;
4848
type RegisterDeviceNotification = unsafe extern "C" fn(u32, u32, HANDLE, u32) -> u32;
4949
type RegisterPnpNotification = unsafe extern "C" fn(HANDLE, HANDLE, u32, u32, u32) -> u32;
50-
type ReadDeviceNotification = unsafe extern "C" fn(u32, &u32, *mut u8, u32, &u32) -> u32;
50+
type ReadDeviceNotification = unsafe extern "C" fn(u32, *const u32, *mut u8, u32, *mut u32) -> u32;
5151
type StatusCodeString = unsafe extern "C" fn(u32) -> *const i8;
5252
type CloseDevice = unsafe extern "C" fn(u32) -> u32;
5353

@@ -429,10 +429,14 @@ impl TUSBAudio<'_> {
429429
}
430430

431431
// Assign useful variables for later :p
432-
let mut buffer: Vec<u8> = Vec::with_capacity(1024);
433-
let buffer_ptr = buffer.as_mut_ptr();
434-
let a: u32 = 0;
435-
let response_len: u32 = 0;
432+
let buffer = vec![0_u8; 1024];
433+
let buffer_ptr = &buffer as *const _ as *mut u8;
434+
435+
let mut response_len: u32 = 0;
436+
let len_ptr: *mut u32 = &mut response_len;
437+
438+
// Honestly don't know what this variable does, but 0 seems to work.
439+
let a = 0;
436440

437441
if callbacks.ready_notifier.send(true).is_err() {
438442
warn!("Error Sending Ready Notification..");
@@ -447,7 +451,7 @@ impl TUSBAudio<'_> {
447451
// Check the Queued Events :)
448452
loop {
449453
let event_result = unsafe {
450-
(self.read_device_notification)(handle, &a, buffer_ptr, 1024, &response_len)
454+
(self.read_device_notification)(handle, &a, buffer_ptr, 1024, len_ptr)
451455
};
452456
if event_result != 0 {
453457
// We've either hit the end of the list, or something's gone wrong, break

0 commit comments

Comments
 (0)