diff options
Diffstat (limited to 'usbh/src/usbproto.rs')
-rw-r--r-- | usbh/src/usbproto.rs | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/usbh/src/usbproto.rs b/usbh/src/usbproto.rs index be8ebfe..690cb40 100644 --- a/usbh/src/usbproto.rs +++ b/usbh/src/usbproto.rs @@ -8,9 +8,9 @@ #[derive(Copy, Clone, Debug, Default, PartialEq)] #[repr(C, packed)] -pub struct USBDeviceDescriptor { +pub struct DeviceDescriptor { pub b_length: u8, - pub b_descriptor_type: USBDescriptor, + pub b_descriptor_type: DescriptorType, pub bcd_usb: u16, pub b_device_class: u8, pub b_device_sub_class: u8, @@ -27,9 +27,9 @@ pub struct USBDeviceDescriptor { #[derive(Copy, Clone, Debug, Default, PartialEq)] #[repr(C, packed)] -pub struct USBConfigurationDescriptor { +pub struct ConfigurationDescriptor { pub b_length: u8, - pub b_descriptor_type: USBDescriptor, + pub b_descriptor_type: DescriptorType, pub w_total_length: u16, pub b_num_interfaces: u8, pub b_configuration_value: u8, @@ -40,9 +40,9 @@ pub struct USBConfigurationDescriptor { #[derive(Copy, Clone, Debug, Default, PartialEq)] #[repr(C, packed)] -pub struct USBInterfaceDescriptor { +pub struct InterfaceDescriptor { pub b_length: u8, - pub b_descriptor_type: USBDescriptor, + pub b_descriptor_type: DescriptorType, pub b_interface_number: u8, pub b_alternate_setting: u8, pub b_num_endpoints: u8, @@ -54,9 +54,9 @@ pub struct USBInterfaceDescriptor { #[derive(Copy, Clone, Debug, Default, PartialEq)] #[repr(C, packed)] -pub struct USBEndpointDescriptor { +pub struct EndpointDescriptor { pub b_length: u8, - pub b_descriptor_type: USBDescriptor, + pub b_descriptor_type: DescriptorType, pub b_endpoint_address: u8, pub bm_attributes: u8, pub w_max_packet_size: u16, @@ -65,9 +65,9 @@ pub struct USBEndpointDescriptor { #[derive(Copy, Clone, Debug, Default, PartialEq)] #[repr(C, packed)] -pub struct USBSetupPacket { - pub bm_request_type: BMRequestType, - pub b_request: USBRequest, +pub struct SetupPacket { + pub bm_request_type: RequestType, + pub b_request: RequestCode, pub w_value: WValue, pub w_index: u16, pub w_length: u16, @@ -136,8 +136,8 @@ where #[derive(Clone, Copy, Debug, Default, PartialEq)] #[repr(C)] -pub struct BMRequestType(u8); -impl BMRequestType { +pub struct RequestType(u8); +impl RequestType { // Get descriptor request type. pub fn get_descr() -> Self { Self::from(( @@ -204,12 +204,12 @@ impl BMRequestType { self.0 |= v as u8 & MASK; } } -impl From<u8> for BMRequestType { +impl From<u8> for RequestType { fn from(v: u8) -> Self { Self(v) } } -impl From<(USBSetupDirection, USBSetupType, USBSetupRecipient)> for BMRequestType { +impl From<(USBSetupDirection, USBSetupType, USBSetupRecipient)> for RequestType { fn from(v: (USBSetupDirection, USBSetupType, USBSetupRecipient)) -> Self { Self(v.0 as u8 | v.1 as u8 | v.2 as u8) } @@ -255,7 +255,7 @@ impl From<(u8, u8)> for WValue { } #[derive(Clone, Copy, Debug, PartialEq)] -pub enum USBRequest { +pub enum RequestCode { GetStatus = 0, ClearFeature = 1, SetFeature = 3, @@ -268,7 +268,7 @@ pub enum USBRequest { SetInterface = 11, SynchFrame = 12, } -impl<T> From<T> for USBRequest +impl<T> From<T> for RequestCode where T: Into<u8>, { @@ -289,7 +289,7 @@ where } } } -impl Default for USBRequest { +impl Default for RequestCode { fn default() -> Self { Self::GetStatus } @@ -303,18 +303,18 @@ pub enum USBFeature { } #[derive(Clone, Copy, Debug, PartialEq)] -pub enum USBDescriptor { - Device = 0x01, - Configuration = 0x02, - String = 0x03, - Interface = 0x04, - Endpoint = 0x05, - DeviceQualifier = 0x06, - OtherSpeed = 0x07, - InterfacePower = 0x08, - OTG = 0x09, +pub enum DescriptorType { + Device = 1, + Configuration = 2, + String = 3, + Interface = 4, + Endpoint = 5, + DeviceQualifier = 6, + OtherSpeed = 7, + InterfacePower = 8, + OTG = 9, } -impl Default for USBDescriptor { +impl Default for DescriptorType { fn default() -> Self { Self::Device } @@ -347,9 +347,9 @@ mod test { #[test] fn dev_desc_serialize() { - let desc = USBDeviceDescriptor { + let desc = DeviceDescriptor { b_length: 18, - b_descriptor_type: USBDescriptor::Device, + b_descriptor_type: DescriptorType::Device, bcd_usb: 0x0110, b_device_class: 0x02, b_device_sub_class: 0x03, @@ -373,9 +373,9 @@ mod test { #[test] fn config_desc_serialize() { - let desc = USBConfigurationDescriptor { + let desc = ConfigurationDescriptor { b_length: 18, - b_descriptor_type: USBDescriptor::Configuration, + b_descriptor_type: DescriptorType::Configuration, w_total_length: 0x20, b_num_interfaces: 5, b_configuration_value: 10, @@ -390,9 +390,9 @@ mod test { #[test] fn interface_desc_serialize() { - let desc = USBInterfaceDescriptor { + let desc = InterfaceDescriptor { b_length: 18, - b_descriptor_type: USBDescriptor::Interface, + b_descriptor_type: DescriptorType::Interface, b_interface_number: 2, b_alternate_setting: 0xaa, b_num_endpoints: 5, @@ -408,9 +408,9 @@ mod test { #[test] fn endpoint_desc_serialize() { - let desc = USBEndpointDescriptor { + let desc = EndpointDescriptor { b_length: 18, - b_descriptor_type: USBDescriptor::Endpoint, + b_descriptor_type: DescriptorType::Endpoint, b_endpoint_address: 1, bm_attributes: 0x22, w_max_packet_size: 0xdead, @@ -423,9 +423,9 @@ mod test { #[test] fn setup_packet_serialize() { - let setup_packet = USBSetupPacket { - bm_request_type: BMRequestType::get_descr(), - b_request: USBRequest::GetDescriptor, + let setup_packet = SetupPacket { + bm_request_type: RequestType::get_descr(), + b_request: RequestCode::GetDescriptor, w_value: WValue::from((0x00, 0x01)), w_index: 0xbeef, w_length: 18, |