aboutsummaryrefslogtreecommitdiffstats
path: root/usbh/src
diff options
context:
space:
mode:
Diffstat (limited to 'usbh/src')
-rw-r--r--usbh/src/pipe.rs8
-rw-r--r--usbh/src/usbproto.rs149
2 files changed, 78 insertions, 79 deletions
diff --git a/usbh/src/pipe.rs b/usbh/src/pipe.rs
index 0a8503b..beac863 100644
--- a/usbh/src/pipe.rs
+++ b/usbh/src/pipe.rs
@@ -142,13 +142,13 @@ impl Pipe<'_, '_> {
// TODO: data stage, has up to 5,000ms (in 500ms
// per-packet chunks) to complete. cf §9.2.6.4 of USB 2.0.
match bm_request_type.direction()? {
- USBSetupDirection::DeviceToHost => {
+ RequestDirection::DeviceToHost => {
trace!("buf0: {:?}", &b);
self.in_transfer(&b, NAK_LIMIT, millis)?;
trace!("buf1: {:?}", &b);
}
- USBSetupDirection::HostToDevice => {
+ RequestDirection::HostToDevice => {
debug!("Should OUT for {}b", b.len);
}
}
@@ -166,8 +166,8 @@ impl Pipe<'_, '_> {
});
let token = match bm_request_type.direction()? {
- USBSetupDirection::DeviceToHost => USBToken::Out,
- USBSetupDirection::HostToDevice => USBToken::In,
+ RequestDirection::DeviceToHost => USBToken::Out,
+ RequestDirection::HostToDevice => USBToken::In,
};
// TODO: should probably make `pipe.send` have optional
diff --git a/usbh/src/usbproto.rs b/usbh/src/usbproto.rs
index 0b7a8eb..66b99ce 100644
--- a/usbh/src/usbproto.rs
+++ b/usbh/src/usbproto.rs
@@ -74,64 +74,6 @@ pub struct SetupPacket {
pub w_index: u16,
pub w_length: u16,
}
-// TODO: shortcuts for standard device requests §9.4 of USB standard.
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub enum USBSetupDirection {
- HostToDevice = 0x00,
- DeviceToHost = 0x80,
-}
-impl TryFrom<u8> for USBSetupDirection {
- type Error = &'static str;
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- 0x00 => Ok(Self::HostToDevice),
- 0x80 => Ok(Self::DeviceToHost),
- _ => Err("direction can only be 0x00 or 0x80"),
- }
- }
-}
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub enum USBSetupType {
- Standard = 0x00,
- Class = 0x20,
- Vendor = 0x40,
-}
-impl TryFrom<u8> for USBSetupType {
- type Error = &'static str;
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- 0x00 => Ok(Self::Standard),
- 0x20 => Ok(Self::Class),
- 0x40 => Ok(Self::Vendor),
- _ => Err("type can only be 0x00, 0x20, or 0x40"),
- }
- }
-}
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub enum USBSetupRecipient {
- Device = 0x00,
- Interface = 0x01,
- Endpoint = 0x02,
- Other = 0x03,
-}
-impl TryFrom<u8> for USBSetupRecipient {
- type Error = &'static str;
-
- fn try_from(v: u8) -> Result<Self, Self::Error> {
- match v {
- 0x00 => Ok(Self::Device),
- 0x01 => Ok(Self::Interface),
- 0x02 => Ok(Self::Endpoint),
- 0x03 => Ok(Self::Other),
- _ => Err("recipient can only be between 0 and 3"),
- }
- }
-}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[repr(C)]
@@ -140,75 +82,132 @@ impl RequestType {
// Get descriptor request type.
pub fn get_descr() -> Self {
Self::from((
- USBSetupDirection::DeviceToHost,
- USBSetupType::Standard,
- USBSetupRecipient::Device,
+ RequestDirection::DeviceToHost,
+ RequestKind::Standard,
+ RequestRecipient::Device,
))
}
// Set request type for all but 'set feature' and 'set interface'.
pub fn set() -> Self {
Self::from((
- USBSetupDirection::HostToDevice,
- USBSetupType::Standard,
- USBSetupRecipient::Device,
+ RequestDirection::HostToDevice,
+ RequestKind::Standard,
+ RequestRecipient::Device,
))
}
// Get interface request type.
pub fn cl_get_intf() -> Self {
Self::from((
- USBSetupDirection::DeviceToHost,
- USBSetupType::Class,
- USBSetupRecipient::Interface,
+ RequestDirection::DeviceToHost,
+ RequestKind::Class,
+ RequestRecipient::Interface,
))
}
- pub fn recipient(&self) -> Result<USBSetupRecipient, &'static str> {
+ pub fn recipient(&self) -> Result<RequestRecipient, &'static str> {
const POS: u8 = 0;
const MASK: u8 = 0x1f;
(self.0 & (MASK << POS)).try_into()
}
- pub fn set_recipient(&mut self, v: USBSetupRecipient) {
+ pub fn set_recipient(&mut self, v: RequestRecipient) {
const POS: u8 = 0;
const MASK: u8 = 0x1f;
self.0 &= !(MASK << POS);
self.0 |= v as u8 & MASK;
}
- pub fn typ(&self) -> Result<USBSetupType, &'static str> {
+ pub fn kind(&self) -> Result<RequestKind, &'static str> {
const POS: u8 = 5;
const MASK: u8 = 0x3;
(self.0 & (MASK << POS)).try_into()
}
- pub fn set_typ(&mut self, v: USBSetupType) {
+ pub fn set_kind(&mut self, v: RequestKind) {
const POS: u8 = 5;
const MASK: u8 = 0x3;
self.0 &= !(MASK << POS);
self.0 |= v as u8 & MASK;
}
- pub fn direction(&self) -> Result<USBSetupDirection, &'static str> {
+ pub fn direction(&self) -> Result<RequestDirection, &'static str> {
const POS: u8 = 7;
const MASK: u8 = 0x1;
(self.0 & (MASK << POS)).try_into()
}
- pub fn set_direction(&mut self, v: USBSetupDirection) {
+ pub fn set_direction(&mut self, v: RequestDirection) {
const POS: u8 = 7;
const MASK: u8 = 0x1;
self.0 &= !(MASK << POS);
self.0 |= v as u8 & MASK;
}
}
-impl From<(USBSetupDirection, USBSetupType, USBSetupRecipient)> for RequestType {
- fn from(v: (USBSetupDirection, USBSetupType, USBSetupRecipient)) -> Self {
+impl From<(RequestDirection, RequestKind, RequestRecipient)> for RequestType {
+ fn from(v: (RequestDirection, RequestKind, RequestRecipient)) -> Self {
Self(v.0 as u8 | v.1 as u8 | v.2 as u8)
}
}
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum RequestDirection {
+ HostToDevice = 0x00,
+ DeviceToHost = 0x80,
+}
+impl TryFrom<u8> for RequestDirection {
+ type Error = &'static str;
+
+ fn try_from(v: u8) -> Result<Self, Self::Error> {
+ match v {
+ 0x00 => Ok(Self::HostToDevice),
+ 0x80 => Ok(Self::DeviceToHost),
+ _ => Err("direction can only be 0x00 or 0x80"),
+ }
+ }
+}
+
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum RequestKind {
+ Standard = 0x00,
+ Class = 0x20,
+ Vendor = 0x40,
+}
+impl TryFrom<u8> for RequestKind {
+ type Error = &'static str;
+
+ fn try_from(v: u8) -> Result<Self, Self::Error> {
+ match v {
+ 0x00 => Ok(Self::Standard),
+ 0x20 => Ok(Self::Class),
+ 0x40 => Ok(Self::Vendor),
+ _ => Err("type can only be 0x00, 0x20, or 0x40"),
+ }
+ }
+}
+
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum RequestRecipient {
+ Device = 0x00,
+ Interface = 0x01,
+ Endpoint = 0x02,
+ Other = 0x03,
+}
+impl TryFrom<u8> for RequestRecipient {
+ type Error = &'static str;
+
+ fn try_from(v: u8) -> Result<Self, Self::Error> {
+ match v {
+ 0x00 => Ok(Self::Device),
+ 0x01 => Ok(Self::Interface),
+ 0x02 => Ok(Self::Endpoint),
+ 0x03 => Ok(Self::Other),
+ _ => Err("recipient can only be between 0 and 3"),
+ }
+ }
+}
+
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[repr(C)]
pub struct WValue(u16);