#![deny(
missing_docs,
missing_copy_implementations,
unstable_features,
unused_import_braces,
unused_qualifications
)]
pub use libusb1_sys::{self as ffi, constants};
#[cfg(unix)]
pub use crate::options::disable_device_discovery;
pub use crate::{
config_descriptor::{ConfigDescriptor, Interfaces},
context::{Context, LogLevel},
device::Device,
device_descriptor::DeviceDescriptor,
device_handle::DeviceHandle,
device_list::{DeviceList, Devices},
endpoint_descriptor::EndpointDescriptor,
error::{Error, Result},
fields::{
request_type, Direction, IsoSyncType, IsoUsageType, Port, Recipient, RequestType, Speed,
TransferType, Version,
},
hotplug::{Hotplug, HotplugBuilder, Registration},
interface_descriptor::{
EndpointDescriptors, Interface, InterfaceDescriptor, InterfaceDescriptors,
},
language::{Language, PrimaryLanguage, SubLanguage},
options::UsbOption,
version::{version, LibraryVersion},
};
#[cfg(test)]
#[macro_use]
mod test_helpers;
#[macro_use]
mod error;
mod version;
mod context;
mod device;
mod device_handle;
mod device_list;
mod config_descriptor;
mod device_descriptor;
mod endpoint_descriptor;
mod fields;
mod hotplug;
mod interface_descriptor;
mod language;
mod options;
pub fn has_capability() -> bool {
Context::global().as_raw();
unsafe { ffi::libusb_has_capability(constants::LIBUSB_CAP_HAS_CAPABILITY) != 0 }
}
pub fn has_hotplug() -> bool {
Context::global().as_raw();
unsafe { ffi::libusb_has_capability(constants::LIBUSB_CAP_HAS_HOTPLUG) != 0 }
}
pub fn has_hid_access() -> bool {
Context::global().as_raw();
unsafe { ffi::libusb_has_capability(constants::LIBUSB_CAP_HAS_HID_ACCESS) != 0 }
}
pub fn supports_detach_kernel_driver() -> bool {
Context::global().as_raw();
unsafe { ffi::libusb_has_capability(constants::LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER) != 0 }
}
pub fn devices() -> Result<DeviceList> {
Context::global().devices()
}
pub fn set_log_level(level: LogLevel) {
unsafe {
ffi::libusb_set_debug(Context::global().as_raw(), level.as_c_int());
}
}
pub fn open_device_with_vid_pid(vid: u16, pid: u16) -> Option<DeviceHandle> {
let handle =
unsafe { ffi::libusb_open_device_with_vid_pid(Context::global().as_raw(), vid, pid) };
if handle.is_null() {
None
} else {
Some(unsafe {
DeviceHandle::from_libusb(Context::global(), std::ptr::NonNull::new_unchecked(handle))
})
}
}