| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#, timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#}; |
| 2 | |
| 3 | use logrust-analyzer cargo log 0.4.34 crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/; |
| 4 | |
| 5 | use craterust-analyzer cargo nusb 0.1.13 crate/::{ |
| 6 | descriptorsrust-analyzer cargo nusb 0.1.13 descriptors/::{ |
| 7 | decode_string_descriptorrust-analyzer cargo nusb 0.1.13 descriptors/decode_string_descriptor()., validate_string_descriptorrust-analyzer cargo nusb 0.1.13 descriptors/validate_string_descriptor()., ActiveConfigurationErrorrust-analyzer cargo nusb 0.1.13 descriptors/ActiveConfigurationError#, |
| 8 | Configurationrust-analyzer cargo nusb 0.1.13 descriptors/Configuration#, InterfaceAltSettingrust-analyzer cargo nusb 0.1.13 descriptors/InterfaceAltSetting#, DESCRIPTOR_TYPE_STRINGrust-analyzer cargo nusb 0.1.13 descriptors/DESCRIPTOR_TYPE_STRING., |
| 9 | }, |
| 10 | platformrust-analyzer cargo nusb 0.1.13 platform/, |
| 11 | transferrust-analyzer cargo nusb 0.1.13 transfer/::{ |
| 12 | Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control#, ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#, ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#, Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#, RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#, TransferErrorrust-analyzer cargo nusb 0.1.13 transfer/TransferError#, |
| 13 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#, |
| 14 | }, |
| 15 | DeviceInforust-analyzer cargo nusb 0.1.13 enumeration/DeviceInfo#, Errorrust-analyzer cargo nusb 0.1.13 Error#, |
| 16 | }; |
| 17 | |
| 18 | /// An opened USB device. |
| 19 | /// |
| 20 | /// Obtain a `Device` by calling [`DeviceInfo::open`]: |
| 21 | /// |
| 22 | /// ```no_run |
| 23 | /// use nusb; |
| 24 | /// let device_info = nusb::list_devices().unwrap() |
| 25 | /// .find(|dev| dev.vendor_id() == 0xAAAA && dev.product_id() == 0xBBBB) |
| 26 | /// .expect("device not connected"); |
| 27 | /// |
| 28 | /// let device = device_info.open().expect("failed to open device"); |
| 29 | /// let interface = device.claim_interface(0); |
| 30 | /// ``` |
| 31 | /// |
| 32 | /// This type is reference-counted with an [`Arc`] internally, and can be cloned cheaply for |
| 33 | /// use in multiple places in your program. The device is closed when all clones and all |
| 34 | /// associated [`Interface`]s are dropped. |
| 35 | /// |
| 36 | /// Use [`.claim_interface(i)`][`Device::claim_interface`] to open an interface to submit |
| 37 | /// transfers. |
| 38 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 39 | pub struct Devicerust-analyzer cargo nusb 0.1.13 device/Device# { |
| 40 | backendrust-analyzer cargo nusb 0.1.13 device/Device#backend.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<craterust-analyzer cargo nusb 0.1.13 crate/::platformrust-analyzer cargo nusb 0.1.13 platform/::Devicerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxDevice#>, |
| 41 | } |
| 42 | |
| 43 | impl Devicerust-analyzer cargo nusb 0.1.13 device/Device# { |
| 44 | pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn openrust-analyzer cargo nusb 0.1.13 device/impl#[Device]open().(d: &DeviceInforust-analyzer cargo nusb 0.1.13 enumeration/DeviceInfo#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Devicerust-analyzer cargo nusb 0.1.13 device/Device#, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 45 | let backend = platformrust-analyzer cargo nusb 0.1.13 platform/::Devicerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxDevice#::from_device_inforust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]from_device_info().(d)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 46 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Devicerust-analyzer cargo nusb 0.1.13 device/Device# { backendrust-analyzer cargo nusb 0.1.13 device/Device#backend. }) |
| 47 | } |
| 48 | |
| 49 | /// Wraps a device that is already open. |
| 50 | #[cfg(any(target_os = "android", target_os = "linux"))] |
| 51 | pub fn from_fdrust-analyzer cargo nusb 0.1.13 device/impl#[Device]from_fd().(fd: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::OwnedFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/owned/OwnedFd#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Devicerust-analyzer cargo nusb 0.1.13 device/Device#, Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 52 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Devicerust-analyzer cargo nusb 0.1.13 device/Device# { |
| 53 | backendrust-analyzer cargo nusb 0.1.13 device/Device#backend.: platformrust-analyzer cargo nusb 0.1.13 platform/::Devicerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxDevice#::from_fdrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]from_fd().(fd)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 54 | }) |
| 55 | } |
| 56 | |
| 57 | /// Open an interface of the device and claim it for exclusive use. |
| 58 | pub fn claim_interfacerust-analyzer cargo nusb 0.1.13 device/impl#[Device]claim_interface().(&self, interface: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Interfacerust-analyzer cargo nusb 0.1.13 device/Interface#, Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 59 | let backend = self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..claim_interfacerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]claim_interface().(interface)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 60 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Interfacerust-analyzer cargo nusb 0.1.13 device/Interface# { backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend. }) |
| 61 | } |
| 62 | |
| 63 | /// Detach kernel drivers and open an interface of the device and claim it for exclusive use. |
| 64 | /// |
| 65 | /// ### Platform notes |
| 66 | /// This function can only detach kernel drivers on Linux. Calling on other platforms has |
| 67 | /// the same effect as [`claim_interface`][`Device::claim_interface`]. |
| 68 | pub fn detach_and_claim_interfacerust-analyzer cargo nusb 0.1.13 device/impl#[Device]detach_and_claim_interface().(&self, interface: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Interfacerust-analyzer cargo nusb 0.1.13 device/Interface#, Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 69 | let backend = self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..detach_and_claim_interfacerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]detach_and_claim_interface().(interface)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 70 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Interfacerust-analyzer cargo nusb 0.1.13 device/Interface# { backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend. }) |
| 71 | } |
| 72 | |
| 73 | /// Detach kernel drivers for the specified interface. |
| 74 | /// |
| 75 | /// ### Platform notes |
| 76 | /// This function can only detach kernel drivers on Linux. Calling on other platforms has |
| 77 | /// no effect. |
| 78 | pub fn detach_kernel_driverrust-analyzer cargo nusb 0.1.13 device/impl#[Device]detach_kernel_driver().(&self, interface: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 79 | #[cfg(target_os = "linux")] |
| 80 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..detach_kernel_driverrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]detach_kernel_driver().(interface)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 81 | let _ = interface; |
| 82 | |
| 83 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 84 | } |
| 85 | |
| 86 | /// Attach kernel drivers for the specified interface. |
| 87 | /// |
| 88 | /// ### Platform notes |
| 89 | /// This function can only attach kernel drivers on Linux. Calling on other platforms has |
| 90 | /// no effect. |
| 91 | pub fn attach_kernel_driverrust-analyzer cargo nusb 0.1.13 device/impl#[Device]attach_kernel_driver().(&self, interface: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 92 | #[cfg(target_os = "linux")] |
| 93 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..attach_kernel_driverrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]attach_kernel_driver().(interface)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 94 | let _ = interface; |
| 95 | |
| 96 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 97 | } |
| 98 | |
| 99 | /// Get information about the active configuration. |
| 100 | /// |
| 101 | /// This returns cached data and does not perform IO. However, it can fail if the |
| 102 | /// device is unconfigured, or if it can't find a configuration descriptor for |
| 103 | /// the configuration reported as active by the OS. |
| 104 | pub fn active_configurationrust-analyzer cargo nusb 0.1.13 device/impl#[Device]active_configuration().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Configurationrust-analyzer cargo nusb 0.1.13 descriptors/Configuration#, ActiveConfigurationErrorrust-analyzer cargo nusb 0.1.13 descriptors/ActiveConfigurationError#> { |
| 105 | let active = self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..active_configuration_valuerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]active_configuration_value().(); |
| 106 | |
| 107 | self.configurationsrust-analyzer cargo nusb 0.1.13 device/impl#[Device]configurations().() |
| 108 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|c| c.configuration_valuerust-analyzer cargo nusb 0.1.13 descriptors/impl#[`Configuration<'a>`]configuration_value().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().active) |
| 109 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| ActiveConfigurationErrorrust-analyzer cargo nusb 0.1.13 descriptors/ActiveConfigurationError# { |
| 110 | configuration_valuerust-analyzer cargo nusb 0.1.13 descriptors/ActiveConfigurationError#configuration_value.: active, |
| 111 | }) |
| 112 | } |
| 113 | |
| 114 | /// Get an iterator returning information about each configuration of the device. |
| 115 | /// |
| 116 | /// This returns cached data and does not perform IO. |
| 117 | pub fn configurationsrust-analyzer cargo nusb 0.1.13 device/impl#[Device]configurations().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Configurationrust-analyzer cargo nusb 0.1.13 descriptors/Configuration#> { |
| 118 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend. |
| 119 | .configuration_descriptorsrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]configuration_descriptors().() |
| 120 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Configurationrust-analyzer cargo nusb 0.1.13 descriptors/Configuration#::newrust-analyzer cargo nusb 0.1.13 descriptors/impl#[`Configuration<'a>`]new().) |
| 121 | } |
| 122 | |
| 123 | /// Set the device configuration. |
| 124 | /// |
| 125 | /// The argument is the desired configuration's `bConfigurationValue` |
| 126 | /// descriptor field from [`Configuration::configuration_value`] or `0` to |
| 127 | /// unconfigure the device. |
| 128 | /// |
| 129 | /// ### Platform-specific notes |
| 130 | /// * Not supported on Windows |
| 131 | pub fn set_configurationrust-analyzer cargo nusb 0.1.13 device/impl#[Device]set_configuration().(&self, configuration: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 132 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..set_configurationrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]set_configuration().(configuration) |
| 133 | } |
| 134 | |
| 135 | /// Request a descriptor from the device. |
| 136 | /// |
| 137 | /// The `language_id` should be `0` unless you are requesting a string descriptor. |
| 138 | /// |
| 139 | /// ### Platform-specific details |
| 140 | /// |
| 141 | /// * On Windows, the timeout argument is ignored, and an OS-defined timeout is used. |
| 142 | /// * On Windows, this does not wake suspended devices. Reading their |
| 143 | /// descriptors will return an error. |
| 144 | pub fn get_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_descriptor().( |
| 145 | &self, |
| 146 | desc_type: u8, |
| 147 | desc_index: u8, |
| 148 | language_id: u16, |
| 149 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 150 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 151 | #[cfg(target_os = "windows")] |
| 152 | { |
| 153 | let _ = timeout; |
| 154 | self.backend |
| 155 | .get_descriptor(desc_type, desc_index, language_id) |
| 156 | } |
| 157 | |
| 158 | #[cfg(not(target_os = "windows"))] |
| 159 | { |
| 160 | const STANDARD_REQUEST_GET_DESCRIPTORrust-analyzer cargo nusb 0.1.13 device/STANDARD_REQUEST_GET_DESCRIPTOR.: u8 = 0x06; |
| 161 | use craterust-analyzer cargo nusb 0.1.13 crate/::transferrust-analyzer cargo nusb 0.1.13 transfer/::{ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#, Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#}; |
| 162 | |
| 163 | let mut buf = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 4096]; |
| 164 | let len = self.control_in_blockingrust-analyzer cargo nusb 0.1.13 device/impl#[Device]control_in_blocking().( |
| 165 | Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control# { |
| 166 | control_typerust-analyzer cargo nusb 0.1.13 transfer/control/Control#control_type.: ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#::Standardrust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#Standard#, |
| 167 | recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Control#recipient.: Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#::Devicerust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#Device#, |
| 168 | requestrust-analyzer cargo nusb 0.1.13 transfer/control/Control#request.: STANDARD_REQUEST_GET_DESCRIPTORrust-analyzer cargo nusb 0.1.13 device/STANDARD_REQUEST_GET_DESCRIPTOR., |
| 169 | valuerust-analyzer cargo nusb 0.1.13 transfer/control/Control#value.: ((desc_type as u16) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor().desc_index as u16, |
| 170 | indexrust-analyzer cargo nusb 0.1.13 transfer/control/Control#index.: language_id, |
| 171 | }, |
| 172 | &mut buf, |
| 173 | timeout, |
| 174 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 175 | |
| 176 | buf.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(len); |
| 177 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /// Request the list of supported languages for string descriptors. |
| 182 | /// |
| 183 | /// ### Platform-specific details |
| 184 | /// |
| 185 | /// See notes on [`get_descriptor`][`Self::get_descriptor`]. |
| 186 | pub fn get_string_descriptor_supported_languagesrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_string_descriptor_supported_languages().( |
| 187 | &self, |
| 188 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 189 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = u16>, Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 190 | let data = self.get_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_descriptor().(DESCRIPTOR_TYPE_STRINGrust-analyzer cargo nusb 0.1.13 descriptors/DESCRIPTOR_TYPE_STRING., 0, 0, timeout)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 191 | |
| 192 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validate_string_descriptorrust-analyzer cargo nusb 0.1.13 descriptors/validate_string_descriptor().(&data) { |
| 193 | errorrust-analyzer cargo log 0.4.34 macros/error!!("String descriptor language list read {data:?}, not a valid string descriptor"); |
| 194 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo nusb 0.1.13 Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 195 | ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#, |
| 196 | "string descriptor data was invalid", |
| 197 | )); |
| 198 | } |
| 199 | |
| 200 | //TODO: Use array_chunks once stable |
| 201 | let mut iter = data.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(2); |
| 202 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/from_fn/from_fn().(move || { |
| 203 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(u16::from_le_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_le_bytes().([iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()., iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().])) |
| 204 | })) |
| 205 | } |
| 206 | |
| 207 | /// Request a string descriptor from the device. |
| 208 | /// |
| 209 | /// Almost all devices support only the language ID [`US_ENGLISH`][`crate::descriptors::language_id::US_ENGLISH`]. |
| 210 | /// |
| 211 | /// Unpaired UTF-16 surrogates will be replaced with `�`, like [`String::from_utf16_lossy`]. |
| 212 | /// |
| 213 | /// ### Platform-specific details |
| 214 | /// |
| 215 | /// See notes on [`get_descriptor`][`Self::get_descriptor`]. |
| 216 | pub fn get_string_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_string_descriptor().( |
| 217 | &self, |
| 218 | desc_index: u8, |
| 219 | language_id: u16, |
| 220 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 221 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 222 | if desc_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 223 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo nusb 0.1.13 Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 224 | ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, |
| 225 | "string descriptor index 0 is reserved for the language table", |
| 226 | )); |
| 227 | } |
| 228 | let data = self.get_descriptorrust-analyzer cargo nusb 0.1.13 device/impl#[Device]get_descriptor().(DESCRIPTOR_TYPE_STRINGrust-analyzer cargo nusb 0.1.13 descriptors/DESCRIPTOR_TYPE_STRING., desc_index, language_id, timeout)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 229 | |
| 230 | decode_string_descriptorrust-analyzer cargo nusb 0.1.13 descriptors/decode_string_descriptor().(&data) |
| 231 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo nusb 0.1.13 Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#, "string descriptor data was invalid")) |
| 232 | } |
| 233 | |
| 234 | /// Reset the device, forcing it to re-enumerate. |
| 235 | /// |
| 236 | /// This `Device` will no longer be usable, and you should drop it and call |
| 237 | /// [`super::list_devices`] to find and re-open it again. |
| 238 | /// |
| 239 | /// ### Platform-specific notes |
| 240 | /// * Not supported on Windows |
| 241 | pub fn resetrust-analyzer cargo nusb 0.1.13 device/impl#[Device]reset().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 242 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..resetrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]reset().() |
| 243 | } |
| 244 | |
| 245 | /// Synchronously perform a single **IN (device-to-host)** transfer on the default **control** endpoint. |
| 246 | /// |
| 247 | /// ### Platform-specific notes |
| 248 | /// |
| 249 | /// * Not supported on Windows. You must [claim an interface][`Device::claim_interface`] |
| 250 | /// and use the interface handle to submit transfers. |
| 251 | /// * On Linux, this takes a device-wide lock, so if you have multiple threads, you |
| 252 | /// are better off using the async methods. |
| 253 | #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] |
| 254 | pub fn control_in_blockingrust-analyzer cargo nusb 0.1.13 device/impl#[Device]control_in_blocking().( |
| 255 | &self, |
| 256 | control: Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control#, |
| 257 | data: &mut [u8], |
| 258 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 259 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, TransferErrorrust-analyzer cargo nusb 0.1.13 transfer/TransferError#> { |
| 260 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..control_in_blockingrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]control_in_blocking().(control, data, timeout) |
| 261 | } |
| 262 | |
| 263 | /// Synchronously perform a single **OUT (host-to-device)** transfer on the default **control** endpoint. |
| 264 | /// |
| 265 | /// ### Platform-specific notes |
| 266 | /// |
| 267 | /// * Not supported on Windows. You must [claim an interface][`Device::claim_interface`] |
| 268 | /// and use the interface handle to submit transfers. |
| 269 | /// * On Linux, this takes a device-wide lock, so if you have multiple threads, you |
| 270 | /// are better off using the async methods. |
| 271 | #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] |
| 272 | pub fn control_out_blockingrust-analyzer cargo nusb 0.1.13 device/impl#[Device]control_out_blocking().( |
| 273 | &self, |
| 274 | control: Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control#, |
| 275 | data: &[u8], |
| 276 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 277 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, TransferErrorrust-analyzer cargo nusb 0.1.13 transfer/TransferError#> { |
| 278 | self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..control_out_blockingrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]control_out_blocking().(control, data, timeout) |
| 279 | } |
| 280 | |
| 281 | /// Asynchronously submit a single **IN (device-to-host)** transfer on the default **control** endpoint. |
| 282 | /// |
| 283 | /// ### Example |
| 284 | /// |
| 285 | /// ```no_run |
| 286 | /// use futures_lite::future::block_on; |
| 287 | /// use nusb::transfer::{ ControlIn, ControlType, Recipient }; |
| 288 | /// # fn main() -> Result<(), std::io::Error> { |
| 289 | /// # let di = nusb::list_devices().unwrap().next().unwrap(); |
| 290 | /// # let device = di.open().unwrap(); |
| 291 | /// |
| 292 | /// let data: Vec<u8> = block_on(device.control_in(ControlIn { |
| 293 | /// control_type: ControlType::Vendor, |
| 294 | /// recipient: Recipient::Device, |
| 295 | /// request: 0x30, |
| 296 | /// value: 0x0, |
| 297 | /// index: 0x0, |
| 298 | /// length: 64, |
| 299 | /// })).into_result()?; |
| 300 | /// # Ok(()) } |
| 301 | /// ``` |
| 302 | /// |
| 303 | /// ### Platform-specific notes |
| 304 | /// |
| 305 | /// * Not supported on Windows. You must [claim an interface][`Device::claim_interface`] |
| 306 | /// and use the interface handle to submit transfers. |
| 307 | #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] |
| 308 | pub fn control_inrust-analyzer cargo nusb 0.1.13 device/impl#[Device]control_in().(&self, data: ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#> { |
| 309 | let mut t = self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..make_control_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]make_control_transfer().(); |
| 310 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().::<ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#>(data); |
| 311 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 312 | } |
| 313 | |
| 314 | /// Submit a single **OUT (host-to-device)** transfer on the default **control** endpoint. |
| 315 | /// |
| 316 | /// ### Example |
| 317 | /// |
| 318 | /// ```no_run |
| 319 | /// use futures_lite::future::block_on; |
| 320 | /// use nusb::transfer::{ ControlOut, ControlType, Recipient }; |
| 321 | /// # fn main() -> Result<(), std::io::Error> { |
| 322 | /// # let di = nusb::list_devices().unwrap().next().unwrap(); |
| 323 | /// # let device = di.open().unwrap(); |
| 324 | /// |
| 325 | /// block_on(device.control_out(ControlOut { |
| 326 | /// control_type: ControlType::Vendor, |
| 327 | /// recipient: Recipient::Device, |
| 328 | /// request: 0x32, |
| 329 | /// value: 0x0, |
| 330 | /// index: 0x0, |
| 331 | /// data: &[0x01, 0x02, 0x03, 0x04], |
| 332 | /// })).into_result()?; |
| 333 | /// # Ok(()) } |
| 334 | /// ``` |
| 335 | /// |
| 336 | /// ### Platform-specific notes |
| 337 | /// |
| 338 | /// * Not supported on Windows. You must [claim an interface][`Device::claim_interface`] |
| 339 | /// and use the interface handle to submit transfers. |
| 340 | #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] |
| 341 | pub fn control_outrust-analyzer cargo nusb 0.1.13 device/impl#[Device]control_out().(&self, data: ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#> { |
| 342 | let mut t = self.backendrust-analyzer cargo nusb 0.1.13 device/Device#backend..make_control_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]make_control_transfer().(); |
| 343 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().::<ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#>(data); |
| 344 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /// An opened interface of a USB device. |
| 349 | /// |
| 350 | /// Obtain an `Interface` with the [`Device::claim_interface`] method. |
| 351 | /// |
| 352 | /// This type is reference-counted with an [`Arc`] internally, and can be cloned cheaply for |
| 353 | /// use in multiple places in your program. The interface is released when all clones, and all |
| 354 | /// associated [`TransferFuture`]s and [`Queue`]s are dropped. |
| 355 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 356 | pub struct Interfacerust-analyzer cargo nusb 0.1.13 device/Interface# { |
| 357 | backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<platformrust-analyzer cargo nusb 0.1.13 platform/::Interfacerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxInterface#>, |
| 358 | } |
| 359 | |
| 360 | impl Interfacerust-analyzer cargo nusb 0.1.13 device/Interface# { |
| 361 | /// Select the alternate setting of this interface. |
| 362 | /// |
| 363 | /// An alternate setting is a mode of the interface that makes particular endpoints available |
| 364 | /// and may enable or disable functionality of the device. The OS resets the device to the default |
| 365 | /// alternate setting when the interface is released or the program exits. |
| 366 | pub fn set_alt_settingrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]set_alt_setting().(&self, alt_setting: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 367 | self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..set_alt_settingrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]set_alt_setting().(alt_setting) |
| 368 | } |
| 369 | |
| 370 | /// Synchronously perform a single **IN (device-to-host)** transfer on the default **control** endpoint. |
| 371 | /// |
| 372 | /// ### Platform-specific notes |
| 373 | /// |
| 374 | /// * On Linux, this takes a device-wide lock, so if you have multiple |
| 375 | /// threads, you are better off using the async methods. |
| 376 | /// * On Windows, if the `recipient` is `Interface`, the WinUSB driver sends |
| 377 | /// the interface number in the least significant byte of `index`, |
| 378 | /// overriding any value passed. A warning is logged if the passed `index` |
| 379 | /// least significant byte differs from the interface number, and this may |
| 380 | /// become an error in the future. |
| 381 | pub fn control_in_blockingrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]control_in_blocking().( |
| 382 | &self, |
| 383 | control: Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control#, |
| 384 | data: &mut [u8], |
| 385 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 386 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, TransferErrorrust-analyzer cargo nusb 0.1.13 transfer/TransferError#> { |
| 387 | self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..control_in_blockingrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]control_in_blocking().(control, data, timeout) |
| 388 | } |
| 389 | |
| 390 | /// Synchronously perform a single **OUT (host-to-device)** transfer on the default **control** endpoint. |
| 391 | /// |
| 392 | /// ### Platform-specific notes |
| 393 | /// |
| 394 | /// * On Linux, this takes a device-wide lock, so if you have multiple |
| 395 | /// threads, you are better off using the async methods. |
| 396 | /// * On Windows, if the `recipient` is `Interface`, the WinUSB driver sends |
| 397 | /// the interface number in the least significant byte of `index`, |
| 398 | /// overriding any value passed. A warning is logged if the passed `index` |
| 399 | /// least significant byte differs from the interface number, and this may |
| 400 | /// become an error in the future. |
| 401 | pub fn control_out_blockingrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]control_out_blocking().( |
| 402 | &self, |
| 403 | control: Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control#, |
| 404 | data: &[u8], |
| 405 | timeout: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 406 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, TransferErrorrust-analyzer cargo nusb 0.1.13 transfer/TransferError#> { |
| 407 | self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..control_out_blockingrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]control_out_blocking().(control, data, timeout) |
| 408 | } |
| 409 | |
| 410 | /// Submit a single **IN (device-to-host)** transfer on the default **control** endpoint. |
| 411 | /// |
| 412 | /// ### Example |
| 413 | /// |
| 414 | /// ```no_run |
| 415 | /// use futures_lite::future::block_on; |
| 416 | /// use nusb::transfer::{ ControlIn, ControlType, Recipient }; |
| 417 | /// # fn main() -> Result<(), std::io::Error> { |
| 418 | /// # let di = nusb::list_devices().unwrap().next().unwrap(); |
| 419 | /// # let device = di.open().unwrap(); |
| 420 | /// # let interface = device.claim_interface(0).unwrap(); |
| 421 | /// |
| 422 | /// let data: Vec<u8> = block_on(interface.control_in(ControlIn { |
| 423 | /// control_type: ControlType::Vendor, |
| 424 | /// recipient: Recipient::Device, |
| 425 | /// request: 0x30, |
| 426 | /// value: 0x0, |
| 427 | /// index: 0x0, |
| 428 | /// length: 64, |
| 429 | /// })).into_result()?; |
| 430 | /// # Ok(()) } |
| 431 | /// ``` |
| 432 | /// |
| 433 | /// ### Platform-specific notes |
| 434 | /// * On Windows, if the `recipient` is `Interface`, the WinUSB driver sends |
| 435 | /// the interface number in the least significant byte of `index`, |
| 436 | /// overriding any value passed. A warning is logged if the passed `index` |
| 437 | /// least significant byte differs from the interface number, and this may |
| 438 | /// become an error in the future. |
| 439 | pub fn control_inrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]control_in().(&self, data: ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#> { |
| 440 | let mut t = self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..make_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]make_transfer().(0, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Controlrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Control#); |
| 441 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().::<ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#>(data); |
| 442 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 443 | } |
| 444 | |
| 445 | /// Submit a single **OUT (host-to-device)** transfer on the default **control** endpoint. |
| 446 | /// |
| 447 | /// ### Example |
| 448 | /// |
| 449 | /// ```no_run |
| 450 | /// use futures_lite::future::block_on; |
| 451 | /// use nusb::transfer::{ ControlOut, ControlType, Recipient }; |
| 452 | /// # fn main() -> Result<(), std::io::Error> { |
| 453 | /// # let di = nusb::list_devices().unwrap().next().unwrap(); |
| 454 | /// # let device = di.open().unwrap(); |
| 455 | /// # let interface = device.claim_interface(0).unwrap(); |
| 456 | /// |
| 457 | /// block_on(interface.control_out(ControlOut { |
| 458 | /// control_type: ControlType::Vendor, |
| 459 | /// recipient: Recipient::Device, |
| 460 | /// request: 0x32, |
| 461 | /// value: 0x0, |
| 462 | /// index: 0x0, |
| 463 | /// data: &[0x01, 0x02, 0x03, 0x04], |
| 464 | /// })).into_result()?; |
| 465 | /// # Ok(()) } |
| 466 | /// ``` |
| 467 | /// |
| 468 | /// ### Platform-specific notes |
| 469 | /// * On Windows, if the `recipient` is `Interface`, the WinUSB driver sends |
| 470 | /// the interface number in the least significant byte of `index`, |
| 471 | /// overriding any value passed. A warning is logged if the passed `index` |
| 472 | /// least significant byte differs from the interface number, and this may |
| 473 | /// become an error in the future. |
| 474 | pub fn control_outrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]control_out().(&self, data: ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#> { |
| 475 | let mut t = self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..make_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]make_transfer().(0, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Controlrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Control#); |
| 476 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().::<ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#>(data); |
| 477 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 478 | } |
| 479 | |
| 480 | /// Submit a single **IN (device-to-host)** transfer on the specified **bulk** endpoint. |
| 481 | /// |
| 482 | /// * The requested length must be a multiple of the endpoint's maximum packet size |
| 483 | /// * An IN endpoint address must have the top (`0x80`) bit set. |
| 484 | pub fn bulk_inrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]bulk_in().(&self, endpoint: u8, buf: RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#> { |
| 485 | let mut t = self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..make_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]make_transfer().(endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Bulkrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Bulk#); |
| 486 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().(buf); |
| 487 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 488 | } |
| 489 | |
| 490 | /// Submit a single **OUT (host-to-device)** transfer on the specified **bulk** endpoint. |
| 491 | /// |
| 492 | /// * An OUT endpoint address must have the top (`0x80`) bit clear. |
| 493 | pub fn bulk_outrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]bulk_out().(&self, endpoint: u8, buf: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 494 | let mut t = self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..make_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]make_transfer().(endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Bulkrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Bulk#); |
| 495 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().(buf); |
| 496 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 497 | } |
| 498 | |
| 499 | /// Create a queue for managing multiple **IN (device-to-host)** transfers on a **bulk** endpoint. |
| 500 | /// |
| 501 | /// * An IN endpoint address must have the top (`0x80`) bit set. |
| 502 | pub fn bulk_in_queuerust-analyzer cargo nusb 0.1.13 device/impl#[Interface]bulk_in_queue().(&self, endpoint: u8) -> Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#<RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#> { |
| 503 | Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#::newrust-analyzer cargo nusb 0.1.13 transfer/queue/impl#[`Queue<R>`]new().(self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Bulkrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Bulk#) |
| 504 | } |
| 505 | |
| 506 | /// Create a queue for managing multiple **OUT (host-to-device)** transfers on a **bulk** endpoint. |
| 507 | /// |
| 508 | /// * An OUT endpoint address must have the top (`0x80`) bit clear. |
| 509 | pub fn bulk_out_queuerust-analyzer cargo nusb 0.1.13 device/impl#[Interface]bulk_out_queue().(&self, endpoint: u8) -> Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 510 | Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#::newrust-analyzer cargo nusb 0.1.13 transfer/queue/impl#[`Queue<R>`]new().(self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Bulkrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Bulk#) |
| 511 | } |
| 512 | |
| 513 | /// Submit a single **IN (device-to-host)** transfer on the specified **interrupt** endpoint. |
| 514 | /// |
| 515 | /// * The requested length must be a multiple of the endpoint's maximum packet size |
| 516 | /// * An IN endpoint address must have the top (`0x80`) bit set. |
| 517 | pub fn interrupt_inrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]interrupt_in().(&self, endpoint: u8, buf: RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#> { |
| 518 | let mut t = self |
| 519 | .backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend. |
| 520 | .make_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]make_transfer().(endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Interruptrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Interrupt#); |
| 521 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().(buf); |
| 522 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 523 | } |
| 524 | |
| 525 | /// Submit a single **OUT (host-to-device)** transfer on the specified **interrupt** endpoint. |
| 526 | /// |
| 527 | /// * An OUT endpoint address must have the top (`0x80`) bit clear. |
| 528 | pub fn interrupt_outrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]interrupt_out().(&self, endpoint: u8, buf: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 529 | let mut t = self |
| 530 | .backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend. |
| 531 | .make_transferrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]make_transfer().(endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Interruptrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Interrupt#); |
| 532 | t.submitrust-analyzer cargo nusb 0.1.13 transfer/internal/impl#[`TransferHandle<P>`]submit().(buf); |
| 533 | TransferFuturerust-analyzer cargo nusb 0.1.13 transfer/TransferFuture#::newrust-analyzer cargo nusb 0.1.13 transfer/impl#[`TransferFuture<D>`]new().(t) |
| 534 | } |
| 535 | |
| 536 | /// Create a queue for managing multiple **IN (device-to-host)** transfers on an **interrupt** endpoint. |
| 537 | /// |
| 538 | /// * An IN endpoint address must have the top (`0x80`) bit set. |
| 539 | pub fn interrupt_in_queuerust-analyzer cargo nusb 0.1.13 device/impl#[Interface]interrupt_in_queue().(&self, endpoint: u8) -> Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#<RequestBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/RequestBuffer#> { |
| 540 | Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#::newrust-analyzer cargo nusb 0.1.13 transfer/queue/impl#[`Queue<R>`]new().(self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Interruptrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Interrupt#) |
| 541 | } |
| 542 | |
| 543 | /// Create a queue for managing multiple **OUT (device-to-host)** transfers on an **interrupt** endpoint. |
| 544 | /// |
| 545 | /// * An OUT endpoint address must have the top (`0x80`) bit clear. |
| 546 | pub fn interrupt_out_queuerust-analyzer cargo nusb 0.1.13 device/impl#[Interface]interrupt_out_queue().(&self, endpoint: u8) -> Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 547 | Queuerust-analyzer cargo nusb 0.1.13 transfer/queue/Queue#::newrust-analyzer cargo nusb 0.1.13 transfer/queue/impl#[`Queue<R>`]new().(self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(), endpoint, EndpointTyperust-analyzer cargo nusb 0.1.13 transfer/EndpointType#::Interruptrust-analyzer cargo nusb 0.1.13 transfer/EndpointType#Interrupt#) |
| 548 | } |
| 549 | |
| 550 | /// Clear a bulk or interrupt endpoint's halt / stall condition. |
| 551 | /// |
| 552 | /// Sends a `CLEAR_FEATURE` `ENDPOINT_HALT` control transfer to tell the |
| 553 | /// device to reset the endpoint's data toggle and clear the halt / stall |
| 554 | /// condition, and resets the host-side data toggle. |
| 555 | /// |
| 556 | /// Use this after receiving [`TransferError::Stall`] to clear the error and |
| 557 | /// resume use of the endpoint. |
| 558 | /// |
| 559 | /// This should not be called when transfers are pending on the endpoint. |
| 560 | pub fn clear_haltrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]clear_halt().(&self, endpoint: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo nusb 0.1.13 Error#> { |
| 561 | self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..clear_haltrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxInterface]clear_halt().(endpoint) |
| 562 | } |
| 563 | |
| 564 | /// Get the interface number. |
| 565 | pub fn interface_numberrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]interface_number().(&self) -> u8 { |
| 566 | self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..interface_numberrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxInterface#interface_number. |
| 567 | } |
| 568 | |
| 569 | /// Get the interface descriptors for the alternate settings of this interface. |
| 570 | /// |
| 571 | /// This returns cached data and does not perform IO. |
| 572 | pub fn descriptorsrust-analyzer cargo nusb 0.1.13 device/impl#[Interface]descriptors().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = InterfaceAltSettingrust-analyzer cargo nusb 0.1.13 descriptors/InterfaceAltSetting#> { |
| 573 | let active = self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..devicerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxInterface#device..active_configuration_valuerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]active_configuration_value().(); |
| 574 | |
| 575 | let configuration = self |
| 576 | .backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend. |
| 577 | .devicerust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxInterface#device. |
| 578 | .configuration_descriptorsrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/impl#[LinuxDevice]configuration_descriptors().() |
| 579 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Configurationrust-analyzer cargo nusb 0.1.13 descriptors/Configuration#::newrust-analyzer cargo nusb 0.1.13 descriptors/impl#[`Configuration<'a>`]new().) |
| 580 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|c| c.configuration_valuerust-analyzer cargo nusb 0.1.13 descriptors/impl#[`Configuration<'a>`]configuration_value().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().active); |
| 581 | |
| 582 | configuration |
| 583 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][IntoIterator]into_iter().() |
| 584 | .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|i| i.interface_alt_settingsrust-analyzer cargo nusb 0.1.13 descriptors/impl#[`Configuration<'a>`]interface_alt_settings().()) |
| 585 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|g| g.interface_numberrust-analyzer cargo nusb 0.1.13 descriptors/impl#[`InterfaceAltSetting<'a>`]interface_number().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().self.backendrust-analyzer cargo nusb 0.1.13 device/Interface#backend..interface_numberrust-analyzer cargo nusb 0.1.13 platform/linux_usbfs/device/LinuxInterface#interface_number.) |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 590 | fn assert_send_syncrust-analyzer cargo nusb 0.1.13 device/assert_send_sync().() { |
| 591 | fn require_send_syncrust-analyzer cargo nusb 0.1.13 device/require_send_sync().<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>() {} |
| 592 | require_send_syncrust-analyzer cargo nusb 0.1.13 device/require_send_sync().::<Interfacerust-analyzer cargo nusb 0.1.13 device/Interface#>(); |
| 593 | require_send_syncrust-analyzer cargo nusb 0.1.13 device/require_send_sync().::<Devicerust-analyzer cargo nusb 0.1.13 device/Device#>(); |
| 594 | } |