source: mainline/uspace/dist/src/bithenge/usbdesc.bh@ cf13b17

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cf13b17 was 71450c8, checked in by Sean Bartell <wingedtachikoma@…>, 13 years ago

Bithenge: add member expressions and improve USB example

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[ff788c3]1##
2##
3## USB DESCRIPTORS
4##
5##
6
7# Originally by Vojtech Horky.
8
[71450c8]9# Block prefixed with a byte length
10transform block = (in.data) <- struct {
11 .bLength <- uint8;
12 .data <- known_length(.bLength - 1);
13};
14
[ff788c3]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.
18transform 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
28transform 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
39transform usb_endpoint_descriptor = struct {
40 .bEndpointAddress <- uint8;
41 .bmAttributes <- uint8;
42 .wMaxPacketSize <- uint16le;
43 .bInterval <- uint8;
44};
45
46# USB HID descriptor
47transform usb_hid_descriptor = struct {
48 .bcdHID <- uint16le;
49 .bCountryCode <- uint8;
50 .bNumDescriptors <- uint8;
[71450c8]51 <- repeat(.bNumDescriptors) { struct {
52 .bDescriptorType <- uint8;
53 .wDescriptorLength <- uint16le;
54 } };
[ff788c3]55};
56
[71450c8]57# USB descriptor
58transform 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;
[ff788c3]67
[71450c8]68transform main = repeat { usb_descriptor };
Note: See TracBrowser for help on using the repository browser.