Commit graph

316 commits

Author SHA1 Message Date
Kevin Mehall
4a3b5ddf9f Simplify actual_len vs requested_len 2025-05-03 14:10:37 -06:00
Kevin Mehall
6027b5c069 Include error code in TransferError::Unknown 2025-05-03 10:19:44 -06:00
Kevin Mehall
1e3ae0f9be Rename Completion::data -> buffer 2025-04-27 21:54:50 -06:00
Kevin Mehall
6501af522f Move Completion to nusb::transfer 2025-04-27 13:52:20 -06:00
Kevin Mehall
3af56dd8f1 Endpoint::wait_next_complete for blocking wait 2025-04-20 17:02:04 -06:00
Kevin Mehall
2929a10b76 Linux zero-copy 2025-04-20 17:01:40 -06:00
Kevin Mehall
992fd16078 Expose buffer instead of transfer 2025-04-20 17:01:36 -06:00
Kevin Mehall
ba3f7d65cf impl Error for ClaimEndpointError 2025-04-12 13:47:19 -06:00
Kevin Mehall
2aee309cc3 Use TransferError for control transfers 2025-04-12 13:47:19 -06:00
Kevin Mehall
47a1896653 windows: Enable RAW_IO when creating an IN endpoint 2025-04-12 13:47:19 -06:00
Kevin Mehall
ef82f2c7f1 Redesign transfer / endpoint API 2025-04-12 13:47:19 -06:00
Kevin Mehall
3091921075
Merge pull request #125 from kevinmehall/async-rt
Add cargo features for `smol` and `tokio` runtimes
2025-04-12 13:45:47 -06:00
Kevin Mehall
38189baf5c cargo features for smol and tokio blocking executors 2025-04-12 13:29:17 -06:00
Kevin Mehall
413093e181 Bump MSRV to 1.79
The associated type bounds feature, stabilized in 1.79 allows adding
an implied Send bound on all IntoFuture types used with MaybeFuture,
so every function doesn't have to be marked as Send.

This is going to be especially useful with wasm, because it allows the
Send bound to be turned on and off in one place.
2025-04-09 08:23:09 -06:00
Kevin Mehall
25556d7f6b Prepare for not requiring Send on wasm 2025-04-09 08:23:09 -06:00
Kevin Mehall
bd3ba8283d Make MaybeFuture Send 2025-04-02 08:14:26 -06:00
Paweł Gorgoń
873f96b8e1
fix(macos): claiming incorrect interface (#124)
* fix(macos): claiming interface on macOS treats interface number as index

Bug is exposed when connected device has not continuous interface numbers. Then getting nth interface is not the same as getting interface of specific number.

This commit fixes it by getting and comparing bInterfaceNumber instead of using `nth(interface_number)` function on iterator.

* refactor: reformatted find closure in claim_interface

Extracted `get_integer_property` usage into a local variable for clarity and improved readability. This refactor maintains existing functionality while simplifying the comparison logic.

* feat: Add debug logging for interface discovery in macOS IOKit

This change introduces a debug log to provide more visibility during the interface discovery process. It logs the target interface number and the current interface being examined, noting whether a match was found. This aids debugging and troubleshooting in device enumeration scenarios.

* refactor: Rephrase debug log for interface claim process.
2025-04-02 08:11:37 -06:00
Kevin Mehall
2801deedce linux: Clean up version parsing 2025-04-01 20:13:39 -06:00
pgorgon-hem
f10a5f2c22
Add usb version to device info (#123)
Introduced a new `usb_version` field to represent the encoded USB specification version (`bcdUSB`) in DeviceInfo struct. This change includes updates to data structure, a new accessor method, and enhanced debug formatting to display the `usb_version` field.
2025-04-01 19:32:10 -06:00
Kevin Mehall
a243514f58
Merge pull request #114 from kevinmehall/rustix
Update Rustix to 1.0, use it for udev netlink
2025-03-08 14:31:03 -07:00
Kevin Mehall
f0a2e8c5a7 linux: use ioctl numbers from linux_raw_sys 2025-03-08 12:11:09 -07:00
Kevin Mehall
0e145f89a6 Switch to rustix for netlink bind/recvfrom 2025-03-07 22:42:44 -07:00
Kevin Mehall
53a3fe41fc linux: Use MaybeUninit buffer for epoll 2025-03-07 22:39:46 -07:00
Kevin Mehall
d49490ce6a Update Rustix to 1.0 2025-03-07 22:39:46 -07:00
Kevin Mehall
c3ad79ceac
Merge pull request #116 from kevinmehall/refactor
Refactor
2025-02-23 17:49:16 -07:00
Kevin Mehall
5e866af4e4 Add MaybeFuture::map 2025-02-22 15:17:58 -07:00
Kevin Mehall
8dfb3e5f1d linux: Refactor events slab 2025-02-22 12:04:24 -07:00
Kevin Mehall
99eaf768fd Refactor Direction 2025-02-22 12:04:24 -07:00
Kevin Mehall
1508051e1a Track interface alt setting 2025-02-22 11:45:39 -07:00
Kevin Mehall
12c0b57d13 Rename EndpointType -> TransferType 2025-02-19 21:10:19 -07:00
Kevin Mehall
fa37585510 Rename Descriptors -> DescriptorIter, don't include the parent descriptor 2025-02-19 21:10:19 -07:00
Kevin Mehall
e8b271d874 Return option instead of panic in descriptor constructors 2025-02-19 21:10:12 -07:00
Kevin Mehall
b526f6a6a3 Use NonZeroU8 for string descriptor indexes 2025-02-16 15:55:32 -07:00
Kevin Mehall
dad53d268d
Merge pull request #115 from kevinmehall/descriptor-api
Descriptor API changes
2025-02-15 19:27:00 -07:00
Kevin Mehall
093fc04da0 Rename descriptor types 2025-02-15 19:22:09 -07:00
Kevin Mehall
663b2684d5 Extend lifetimes on descriptors 2025-02-15 14:58:21 -07:00
Kevin Mehall
bccef50354
Merge pull request #113 from kevinmehall/windows-fix
Error instead of panic on invalid device descriptor from hub handle, update windows-sys
2025-02-15 14:55:03 -07:00
Kevin Mehall
03ffa4b36c Update windows-sys
Co-authored-by: Erkki Silvola <eki833@gmail.com>
2025-02-15 14:47:30 -07:00
Kevin Mehall
587da14a25 windows: Error instead of panic on invalid device descriptor from hub handle
https://github.com/kevinmehall/nusb/pull/111

Co-authored-by: Erkki Silvola <eki833@gmail.com>
2025-02-15 14:23:57 -07:00
Kevin Mehall
14a8f171e5
Make blocking APIs optionally async (#100)
* Make blocking APIs optionally async

`DeviceInfo::open`, `Device::from_fd`, `Device::set_configuration`,
`Device::reset`, `Interface::set_alt_setting`, `Interface::clear_halt`
all perform IO but are currently blocking because the underlying OS APIs
are blocking.

`list_devices`,`list_buses`, `Device::claim_interface`
`Device::detach_and_claim_interface` theoretically don't perform IO, but
are also included here because they need to be async on WebUSB.

The `MaybeFuture` trait allows deferring these actions to the thread pool
from the `blocking` crate when used asynchronously with `.await` /
`IntoFuture`, or directly runs the blocking syscall synchronously with a
`.wait()` method.
2025-02-11 18:53:07 -07:00
erkki-silvola
ae59ebfebf
macOS: use kUSBProductString and kUSBSerialNumberString as primary (#109) 2025-01-25 09:57:56 -07:00
Kevin Mehall
a34c4497b7
Merge pull request #102 from kirisauce/dev
Add support for getting device descriptor and speed from opened device
2025-01-19 23:10:31 -07:00
Kevin Mehall
4871f227a0 Fix existing warnings 2025-01-19 22:09:39 -07:00
Kevin Mehall
0e8c9f59f4 Add DeviceDescriptor::as_bytes 2025-01-19 21:04:16 -08:00
Kevin Mehall
8e4caaa5b2 Use Device::device_descriptor in string_descriptors example 2025-01-19 21:00:03 -08:00
Kevin Mehall
9a93ca796d Wrap DeviceDescriptor string index fields in Option 2025-01-19 20:59:05 -08:00
Kevin Mehall
9c98f2bd32 Implement Device::{device_descriptor, speed} on macOS 2025-01-19 20:47:37 -08:00
Kevin Mehall
55072d40e7 Implement Device::{device_descriptor, speed} on Windows 2025-01-19 19:32:25 -07:00
Kevin Mehall
de5771030c Simplify Device::speed API
We'll log if the ioctl failed, but there's probably not a use case to
determine why it failed to justify Result<Option<>>. It'll be
infallible (besides unknown values) on other platforms.
2025-01-19 19:03:06 -07:00
Kevin Mehall
c6f2812671 Make DeviceDescriptor contain a fixed size array
Unlike the Configuration descriptor, it does not contain nested
descriptors.

It's also made infallible, because the kernel wouldn't enumerate
the device without it.
2025-01-19 19:01:15 -07:00