Commit graph

247 commits

Author SHA1 Message Date
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
kirisauce
5a7a4be0cf Linux: Support getting device speed from the kernel
This is done through an ioctl `USBDEVFS_GET_SPEED`. Judging from
the kernel souce code, it just returns a cached value, and should
not make any request to the device.
2025-01-13 22:58:12 +08:00
kirisauce
2c6a6d3758 Linux: Support getting DeviceDescriptor and DeviceInfo from a opened device 2025-01-08 13:13:19 +08:00
kirisauce
91fe523d76 Add DeviceDescriptor type for parsing device descriptors 2025-01-08 13:13:19 +08:00
Kevin Mehall
0dc8aa5fe8
Merge pull request #105 from kevinmehall/windows-hotplug-send-sync
impl Send + Sync for HotplugWatch
2025-01-05 23:17:49 -07:00
Kevin Mehall
c59e0fe7ec macos: impl Sync for HotplugWatch 2025-01-05 23:13:19 -07:00
Kevin Mehall
2f7336ed2d windows: impl Send + Sync for HotplugWatch 2025-01-05 23:13:00 -07:00
Kevin Mehall
b167c7e744 Breaking changes on main, set version to 0.2.0-beta 2024-12-27 12:47:00 -07:00
Kevin Mehall
3c8ba0a1aa Fix race condition that could lose a transfer completion wakup
If `poll_completion_generic` runs between `notify_completion`'s
`waker.take()` and `state.swap(STATE_COMPLETED, ...)`, it could see the
transfer as pending and register its waker, but that waker would never
be called.

This adds an Arc because once the transfer is set to `STATE_COMPLETED`,
the other thread might free it, so we need to ensure the AtomicWaker
stays alive while we use it. That's what the `take()` was intended
to work around, but reading the waker before writing the status
introduces the race.
2024-11-19 22:29:06 -07:00
Kevin Mehall
6562dd97e9 Update docs for windows serial number fix (4ddd81b) 2024-11-16 14:43:10 -07:00
Kevin Mehall
f8f23b2b4c
Merge pull request #88 from kevinmehall/macos-fix
macOS: Fix set_configuration and reset by using USBDeviceOpen
2024-10-30 09:20:53 -06:00
Kevin Mehall
ce3a29e820 macOS: prevent reset and set_configuration while an interface is claimed 2024-10-27 22:21:14 -06:00
Kevin Mehall
2f87736856 macOS: Fix set_configuration and reset by using USBDeviceOpen 2024-10-27 22:21:00 -06:00
Kevin Mehall
3d45e26452 macos: Fix detection of TransferError::Stall 2024-10-27 22:18:53 -06:00
Kevin Mehall
b3097f552a
Merge pull request #85 from tuna-f1sh/win-hub-devices
Windows: include hub devices in list like other platforms
2024-10-19 15:06:03 -06:00
John Whittington
785e89ab21 win: include hub devices in list like other platforms 2024-10-14 09:16:40 +02:00
Kevin Mehall
809228038f
Merge pull request #77 from tuna-f1sh/root_hub
List root hubs function
2024-09-28 11:26:47 -06:00
Kevin Mehall
4774c75c2c Remove dead code 2024-09-28 11:24:40 -06:00
John Whittington
060f284255 add getters for android; note that list_buses requires root 2024-09-27 07:20:07 +02:00
John Whittington
f4f3719387 macos: tidy list_buses now passed hci_type 2024-09-27 06:27:48 +02:00