1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Interface descriptors
use core::num::NonZeroU8;
use crate::desc;
/// Interface descriptor
///
/// See section 9.6.5 of (USB2)
pub struct Descriptor {
// pub bLength: u8,
// pub bDescriptorType: u8,
/// Interface number
pub bInterfaceNumber: u8,
/// Alternative setting
pub bAlternativeSetting: u8,
/// Number of endpoints
pub bNumEndpoints: u8,
/// Interface class
pub bInterfaceClass: u8,
/// Interface subclass
pub bInterfaceSubClass: u8,
/// Interface protocol
pub bInterfaceProtocol: u8,
/// Interface string descriptor index
pub iInterface: Option<NonZeroU8>,
}
impl Descriptor {
/// The size of this descriptor in bytes
pub const SIZE: u8 = 9;
/// Returns the byte representation of this descriptor
pub fn bytes(&self) -> [u8; Self::SIZE as usize] {
[
Self::SIZE,
desc::Type::Interface as u8,
self.bInterfaceNumber,
self.bAlternativeSetting,
self.bNumEndpoints,
self.bInterfaceClass,
self.bInterfaceSubClass,
self.bInterfaceProtocol,
self.iInterface.map(|nz| nz.get()).unwrap_or(0),
]
}
}