| 1 | ## | 
|---|
| 2 | ## | 
|---|
| 3 | ## USB DESCRIPTORS | 
|---|
| 4 | ## | 
|---|
| 5 | ## | 
|---|
| 6 |  | 
|---|
| 7 | # Originally by Vojtech Horky. | 
|---|
| 8 |  | 
|---|
| 9 | # Block prefixed with a byte length | 
|---|
| 10 | transform block = (in.data) <- struct { | 
|---|
| 11 | .bLength <- uint8; | 
|---|
| 12 | .data <- known_length(.bLength - 1); | 
|---|
| 13 | }; | 
|---|
| 14 |  | 
|---|
| 15 | # USB configuration descriptor | 
|---|
| 16 | # This is not the full configuration descriptor (i.e. with interface | 
|---|
| 17 | # and endpoint descriptors included) but only the header. | 
|---|
| 18 | transform usb_configuration_descriptor_bare = struct { | 
|---|
| 19 | .wTotalLength <- uint16le; | 
|---|
| 20 | .bNumInterfaces <- uint8; | 
|---|
| 21 | .bConfigurationValue <- uint8; | 
|---|
| 22 | .iConfiguration <- uint8; | 
|---|
| 23 | .bmAttributes <- uint8; | 
|---|
| 24 | .MaxPower <- uint8; | 
|---|
| 25 | }; | 
|---|
| 26 |  | 
|---|
| 27 | # USB interface descriptor | 
|---|
| 28 | transform usb_interface_descriptor = struct { | 
|---|
| 29 | .bInterfaceNumber <- uint8; | 
|---|
| 30 | .bAlternateSetting <- uint8; | 
|---|
| 31 | .bNumEndpoints <- uint8; | 
|---|
| 32 | .bInterfaceClass <- uint8; | 
|---|
| 33 | .bInterfaceSubClass <- uint8; | 
|---|
| 34 | .bInterfaceProtocol <- uint8; | 
|---|
| 35 | .iInterface <- uint8; | 
|---|
| 36 | }; | 
|---|
| 37 |  | 
|---|
| 38 | # USB endpoint descriptor | 
|---|
| 39 | transform usb_endpoint_descriptor = struct { | 
|---|
| 40 | .bEndpointAddress  <- uint8; | 
|---|
| 41 | .bmAttributes <- uint8; | 
|---|
| 42 | .wMaxPacketSize <- uint16le; | 
|---|
| 43 | .bInterval <- uint8; | 
|---|
| 44 | }; | 
|---|
| 45 |  | 
|---|
| 46 | # USB HID descriptor | 
|---|
| 47 | transform usb_hid_descriptor = struct { | 
|---|
| 48 | .bcdHID <- uint16le; | 
|---|
| 49 | .bCountryCode <- uint8; | 
|---|
| 50 | .bNumDescriptors <- uint8; | 
|---|
| 51 | <- repeat(.bNumDescriptors) { struct { | 
|---|
| 52 | .bDescriptorType <- uint8; | 
|---|
| 53 | .wDescriptorLength <- uint16le; | 
|---|
| 54 | } }; | 
|---|
| 55 | }; | 
|---|
| 56 |  | 
|---|
| 57 | # USB descriptor | 
|---|
| 58 | transform usb_descriptor = struct { | 
|---|
| 59 | .bDescriptorType <- uint8; | 
|---|
| 60 | <- switch (.bDescriptorType) { | 
|---|
| 61 | 2: usb_configuration_descriptor_bare; | 
|---|
| 62 | 4: usb_interface_descriptor; | 
|---|
| 63 | 5: usb_endpoint_descriptor; | 
|---|
| 64 | 33: usb_hid_descriptor; | 
|---|
| 65 | }; | 
|---|
| 66 | } <- block; | 
|---|
| 67 |  | 
|---|
| 68 | transform main = repeat { usb_descriptor }; | 
|---|