1use core::num::NonZeroU8;
4
5use crate::desc;
6
7#[allow(non_snake_case)]
11#[derive(Clone, Copy)]
12pub struct Descriptor {
13 pub wTotalLength: u16,
18 pub bNumInterfaces: NonZeroU8,
20 pub bConfigurationValue: NonZeroU8,
22 pub iConfiguration: Option<NonZeroU8>,
24 pub bmAttributes: bmAttributes,
26 pub bMaxPower: u8,
28}
29
30impl Descriptor {
31 pub const SIZE: u8 = 9;
33
34 pub fn bytes(&self) -> [u8; Self::SIZE as usize] {
36 [
37 Self::SIZE,
38 desc::Type::Configuration as u8,
39 self.wTotalLength as u8,
40 (self.wTotalLength >> 8) as u8,
41 self.bNumInterfaces.get(),
42 self.bConfigurationValue.get(),
43 self.iConfiguration.map(|nz| nz.get()).unwrap_or(0),
44 (1 << 7)
45 | if self.bmAttributes.self_powered {
46 1 << 6
47 } else {
48 0
49 }
50 | if self.bmAttributes.remote_wakeup {
51 1 << 5
52 } else {
53 0
54 },
55 self.bMaxPower,
56 ]
57 }
58}
59
60#[allow(non_camel_case_types)]
62#[derive(Clone, Copy)]
63pub struct bmAttributes {
64 pub self_powered: bool,
66 pub remote_wakeup: bool,
68}