Rename EndpointType -> TransferType

This commit is contained in:
Kevin Mehall 2025-02-01 19:33:37 -07:00
parent fa37585510
commit 12c0b57d13
9 changed files with 53 additions and 53 deletions

View file

@ -14,7 +14,7 @@ use std::{
use log::warn;
use crate::{
transfer::{Direction, EndpointType},
transfer::{Direction, TransferType},
Error,
};
@ -640,12 +640,12 @@ impl<'a> EndpointDescriptor<'a> {
}
/// Get the endpoint's transfer type.
pub fn transfer_type(&self) -> EndpointType {
pub fn transfer_type(&self) -> TransferType {
match self.attributes() & 0x03 {
0 => EndpointType::Control,
1 => EndpointType::Isochronous,
2 => EndpointType::Bulk,
3 => EndpointType::Interrupt,
0 => TransferType::Control,
1 => TransferType::Isochronous,
2 => TransferType::Bulk,
3 => TransferType::Interrupt,
_ => unreachable!(),
}
}
@ -891,7 +891,7 @@ fn test_linux_root_hub() {
let endpoint = alt.endpoints().next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Interrupt);
assert_eq!(endpoint.transfer_type(), TransferType::Interrupt);
assert_eq!(endpoint.max_packet_size(), 4);
assert_eq!(endpoint.interval(), 12);
@ -1024,7 +1024,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x83);
assert_eq!(endpoint.transfer_type(), EndpointType::Interrupt);
assert_eq!(endpoint.transfer_type(), TransferType::Interrupt);
assert_eq!(endpoint.max_packet_size(), 16);
assert_eq!(endpoint.descriptors().next().unwrap().descriptor_type(), 0x25);
@ -1057,7 +1057,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Isochronous);
assert_eq!(endpoint.transfer_type(), TransferType::Isochronous);
assert_eq!(endpoint.max_packet_size(), 128);
assert!(endpoints.next().is_none());
@ -1073,7 +1073,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Isochronous);
assert_eq!(endpoint.transfer_type(), TransferType::Isochronous);
assert_eq!(endpoint.max_packet_size(), 256);
assert_eq!(endpoint.packets_per_microframe(), 1);
@ -1090,7 +1090,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Isochronous);
assert_eq!(endpoint.transfer_type(), TransferType::Isochronous);
assert_eq!(endpoint.max_packet_size(), 800);
assert_eq!(endpoint.packets_per_microframe(), 1);
@ -1107,7 +1107,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Isochronous);
assert_eq!(endpoint.transfer_type(), TransferType::Isochronous);
assert_eq!(endpoint.max_packet_size(), 800);
assert_eq!(endpoint.packets_per_microframe(), 2);
@ -1122,7 +1122,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Isochronous);
assert_eq!(endpoint.transfer_type(), TransferType::Isochronous);
assert_eq!(endpoint.max_packet_size(), 800);
assert_eq!(endpoint.packets_per_microframe(), 3);
@ -1137,7 +1137,7 @@ fn test_dell_webcam() {
let endpoint = endpoints.next().unwrap();
assert_eq!(endpoint.address(), 0x81);
assert_eq!(endpoint.transfer_type(), EndpointType::Isochronous);
assert_eq!(endpoint.transfer_type(), TransferType::Isochronous);
assert_eq!(endpoint.max_packet_size(), 1024);
assert_eq!(endpoint.packets_per_microframe(), 3);

View file

@ -5,8 +5,8 @@ use crate::{
},
platform,
transfer::{
Control, ControlIn, ControlOut, EndpointType, Queue, RequestBuffer, TransferError,
TransferFuture,
Control, ControlIn, ControlOut, Queue, RequestBuffer, TransferError, TransferFuture,
TransferType,
},
DeviceInfo, Error, MaybeFuture, Speed,
};
@ -462,7 +462,7 @@ impl Interface {
/// least significant byte differs from the interface number, and this may
/// become an error in the future.
pub fn control_in(&self, data: ControlIn) -> TransferFuture<ControlIn> {
let mut t = self.backend.make_transfer(0, EndpointType::Control);
let mut t = self.backend.make_transfer(0, TransferType::Control);
t.submit::<ControlIn>(data);
TransferFuture::new(t)
}
@ -498,7 +498,7 @@ impl Interface {
/// least significant byte differs from the interface number, and this may
/// become an error in the future.
pub fn control_out(&self, data: ControlOut) -> TransferFuture<ControlOut> {
let mut t = self.backend.make_transfer(0, EndpointType::Control);
let mut t = self.backend.make_transfer(0, TransferType::Control);
t.submit::<ControlOut>(data);
TransferFuture::new(t)
}
@ -508,7 +508,7 @@ impl Interface {
/// * The requested length must be a multiple of the endpoint's maximum packet size
/// * An IN endpoint address must have the top (`0x80`) bit set.
pub fn bulk_in(&self, endpoint: u8, buf: RequestBuffer) -> TransferFuture<RequestBuffer> {
let mut t = self.backend.make_transfer(endpoint, EndpointType::Bulk);
let mut t = self.backend.make_transfer(endpoint, TransferType::Bulk);
t.submit(buf);
TransferFuture::new(t)
}
@ -517,7 +517,7 @@ impl Interface {
///
/// * An OUT endpoint address must have the top (`0x80`) bit clear.
pub fn bulk_out(&self, endpoint: u8, buf: Vec<u8>) -> TransferFuture<Vec<u8>> {
let mut t = self.backend.make_transfer(endpoint, EndpointType::Bulk);
let mut t = self.backend.make_transfer(endpoint, TransferType::Bulk);
t.submit(buf);
TransferFuture::new(t)
}
@ -526,14 +526,14 @@ impl Interface {
///
/// * An IN endpoint address must have the top (`0x80`) bit set.
pub fn bulk_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer> {
Queue::new(self.backend.clone(), endpoint, EndpointType::Bulk)
Queue::new(self.backend.clone(), endpoint, TransferType::Bulk)
}
/// Create a queue for managing multiple **OUT (host-to-device)** transfers on a **bulk** endpoint.
///
/// * An OUT endpoint address must have the top (`0x80`) bit clear.
pub fn bulk_out_queue(&self, endpoint: u8) -> Queue<Vec<u8>> {
Queue::new(self.backend.clone(), endpoint, EndpointType::Bulk)
Queue::new(self.backend.clone(), endpoint, TransferType::Bulk)
}
/// Submit a single **IN (device-to-host)** transfer on the specified **interrupt** endpoint.
@ -543,7 +543,7 @@ impl Interface {
pub fn interrupt_in(&self, endpoint: u8, buf: RequestBuffer) -> TransferFuture<RequestBuffer> {
let mut t = self
.backend
.make_transfer(endpoint, EndpointType::Interrupt);
.make_transfer(endpoint, TransferType::Interrupt);
t.submit(buf);
TransferFuture::new(t)
}
@ -554,7 +554,7 @@ impl Interface {
pub fn interrupt_out(&self, endpoint: u8, buf: Vec<u8>) -> TransferFuture<Vec<u8>> {
let mut t = self
.backend
.make_transfer(endpoint, EndpointType::Interrupt);
.make_transfer(endpoint, TransferType::Interrupt);
t.submit(buf);
TransferFuture::new(t)
}
@ -563,14 +563,14 @@ impl Interface {
///
/// * An IN endpoint address must have the top (`0x80`) bit set.
pub fn interrupt_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer> {
Queue::new(self.backend.clone(), endpoint, EndpointType::Interrupt)
Queue::new(self.backend.clone(), endpoint, TransferType::Interrupt)
}
/// Create a queue for managing multiple **OUT (device-to-host)** transfers on an **interrupt** endpoint.
///
/// * An OUT endpoint address must have the top (`0x80`) bit clear.
pub fn interrupt_out_queue(&self, endpoint: u8) -> Queue<Vec<u8>> {
Queue::new(self.backend.clone(), endpoint, EndpointType::Interrupt)
Queue::new(self.backend.clone(), endpoint, TransferType::Interrupt)
}
/// Clear a bulk or interrupt endpoint's halt / stall condition.

View file

@ -32,7 +32,7 @@ use crate::transfer::{ControlType, Recipient};
use crate::{
descriptors::{parse_concatenated_config_descriptors, DESCRIPTOR_LEN_DEVICE},
transfer::{
notify_completion, Control, Direction, EndpointType, TransferError, TransferHandle,
notify_completion, Control, Direction, TransferError, TransferHandle, TransferType,
},
DeviceInfo, Error, Speed,
};
@ -276,7 +276,7 @@ impl LinuxDevice {
self.clone(),
None,
0,
EndpointType::Control,
TransferType::Control,
))
}
@ -468,7 +468,7 @@ impl LinuxInterface {
pub(crate) fn make_transfer(
self: &Arc<Self>,
endpoint: u8,
ep_type: EndpointType,
ep_type: TransferType,
) -> TransferHandle<super::TransferData> {
TransferHandle::new(super::TransferData::new(
self.device.clone(),

View file

@ -8,8 +8,8 @@ use std::{
use rustix::io::Errno;
use crate::transfer::{
Completion, ControlIn, ControlOut, EndpointType, PlatformSubmit, PlatformTransfer,
RequestBuffer, ResponseBuffer, TransferError, SETUP_PACKET_SIZE,
Completion, ControlIn, ControlOut, PlatformSubmit, PlatformTransfer, RequestBuffer,
ResponseBuffer, TransferError, TransferType, SETUP_PACKET_SIZE,
};
use super::{
@ -43,13 +43,13 @@ impl TransferData {
device: Arc<super::Device>,
interface: Option<Arc<super::Interface>>,
endpoint: u8,
ep_type: EndpointType,
ep_type: TransferType,
) -> TransferData {
let ep_type = match ep_type {
EndpointType::Control => USBDEVFS_URB_TYPE_CONTROL,
EndpointType::Interrupt => USBDEVFS_URB_TYPE_INTERRUPT,
EndpointType::Bulk => USBDEVFS_URB_TYPE_BULK,
EndpointType::Isochronous => USBDEVFS_URB_TYPE_ISO,
TransferType::Control => USBDEVFS_URB_TYPE_CONTROL,
TransferType::Interrupt => USBDEVFS_URB_TYPE_INTERRUPT,
TransferType::Bulk => USBDEVFS_URB_TYPE_BULK,
TransferType::Isochronous => USBDEVFS_URB_TYPE_ISO,
};
TransferData {

View file

@ -14,7 +14,7 @@ use log::{debug, error};
use crate::{
descriptors::DeviceDescriptor,
maybe_future::blocking::Blocking,
transfer::{Control, Direction, EndpointType, TransferError, TransferHandle},
transfer::{Control, Direction, TransferError, TransferHandle, TransferType},
DeviceInfo, Error, MaybeFuture, Speed,
};
@ -293,9 +293,9 @@ impl MacInterface {
pub(crate) fn make_transfer(
self: &Arc<Self>,
endpoint: u8,
ep_type: EndpointType,
ep_type: TransferType,
) -> TransferHandle<super::TransferData> {
if ep_type == EndpointType::Control {
if ep_type == TransferType::Control {
assert!(endpoint == 0);
TransferHandle::new(super::TransferData::new_control(self.device.clone()))
} else {

View file

@ -27,9 +27,9 @@ use crate::{
ConfigurationDescriptor, DeviceDescriptor, DESCRIPTOR_LEN_DEVICE,
DESCRIPTOR_TYPE_CONFIGURATION,
},
maybe_future::{blocking::Blocking, MaybeFuture, Ready},
transfer::{Control, Direction, EndpointType, Recipient, TransferError, TransferHandle},
DeviceInfo, Error, Speed,
maybe_future::{blocking::Blocking, Ready},
transfer::{Control, Direction, Recipient, TransferError, TransferHandle, TransferType},
DeviceInfo, Error, MaybeFuture, Speed,
};
use super::{
@ -388,7 +388,7 @@ impl WindowsInterface {
pub(crate) fn make_transfer(
self: &Arc<Self>,
endpoint: u8,
ep_type: EndpointType,
ep_type: TransferType,
) -> TransferHandle<super::TransferData> {
TransferHandle::new(super::TransferData::new(self.clone(), endpoint, ep_type))
}

View file

@ -21,8 +21,8 @@ use windows_sys::Win32::{
};
use crate::transfer::{
notify_completion, Completion, ControlIn, ControlOut, EndpointType, PlatformSubmit,
PlatformTransfer, Recipient, RequestBuffer, ResponseBuffer, TransferError,
notify_completion, Completion, ControlIn, ControlOut, PlatformSubmit, PlatformTransfer,
Recipient, RequestBuffer, ResponseBuffer, TransferError, TransferType,
};
#[repr(C)]
@ -38,7 +38,7 @@ pub struct TransferData {
buf: *mut u8,
capacity: usize,
endpoint: u8,
ep_type: EndpointType,
ep_type: TransferType,
submit_error: Option<WIN32_ERROR>,
}
@ -48,7 +48,7 @@ impl TransferData {
pub(crate) fn new(
interface: std::sync::Arc<super::Interface>,
endpoint: u8,
ep_type: EndpointType,
ep_type: TransferType,
) -> TransferData {
TransferData {
interface,
@ -225,7 +225,7 @@ impl PlatformSubmit<RequestBuffer> for TransferData {
impl PlatformSubmit<ControlIn> for TransferData {
unsafe fn submit(&mut self, data: ControlIn, user_data: *mut c_void) {
assert_eq!(self.endpoint, 0);
assert_eq!(self.ep_type, EndpointType::Control);
assert_eq!(self.ep_type, TransferType::Control);
if data.recipient == Recipient::Interface
&& data.index as u8 != self.interface.interface_number
@ -274,7 +274,7 @@ impl PlatformSubmit<ControlIn> for TransferData {
impl PlatformSubmit<ControlOut<'_>> for TransferData {
unsafe fn submit(&mut self, data: ControlOut, user_data: *mut c_void) {
assert_eq!(self.endpoint, 0);
assert_eq!(self.ep_type, EndpointType::Control);
assert_eq!(self.ep_type, TransferType::Control);
if data.recipient == Recipient::Interface
&& data.index as u8 != self.interface.interface_number

View file

@ -32,7 +32,7 @@ pub(crate) use internal::{
/// Endpoint type.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[allow(dead_code)]
pub enum EndpointType {
pub enum TransferType {
/// Control endpoint.
Control = 0,

View file

@ -8,7 +8,7 @@ use std::{
use crate::{platform, Error, MaybeFuture};
use super::{Completion, EndpointType, PlatformSubmit, TransferHandle, TransferRequest};
use super::{Completion, PlatformSubmit, TransferHandle, TransferRequest, TransferType};
/// Manages a stream of transfers on an endpoint.
///
@ -113,7 +113,7 @@ use super::{Completion, EndpointType, PlatformSubmit, TransferHandle, TransferRe
pub struct Queue<R: TransferRequest> {
interface: Arc<platform::Interface>,
endpoint: u8,
endpoint_type: EndpointType,
endpoint_type: TransferType,
/// A queue of pending transfers, expected to complete in order
pending: VecDeque<TransferHandle<platform::TransferData>>,
@ -132,7 +132,7 @@ where
pub(crate) fn new(
interface: Arc<platform::Interface>,
endpoint: u8,
endpoint_type: EndpointType,
endpoint_type: TransferType,
) -> Queue<R> {
Queue {
interface,