WICG / webusb

Connecting hardware to the web.
https://wicg.github.io/webusb/
Other
1.3k stars 126 forks source link

[question] Why descriptors fields names in returned USBDevice not like fields names from usb spec? #187

Closed kichMan closed 4 years ago

kichMan commented 4 years ago

a simple question about the reason for such a content model of the returned object. Why not used the model from usb spec?

type uint8_t     = number;
type uint16_t    = uint8_t;

declare interface Device {
    readonly bLength            : uint8_t;
    readonly bDescriptorType    : uint8_t;
    readonly bcdUSB             : uint16_t;
    readonly bDeviceClass       : uint8_t;
    readonly bDeviceSubClass    : uint8_t;
    readonly bDeviceProtocol    : uint8_t;
    readonly bMaxPacketSize     : uint8_t;
    readonly idVendor           : uint16_t;
    readonly idProduct          : uint16_t;
    readonly bcdDevice          : uint16_t;
    readonly iManufacturer      : uint8_t;
    readonly iProduct           : uint8_t;
    readonly iSerialNumber      : uint8_t;
    readonly bNumConfigurations : uint8_t;
}

declare interface Configuration {
    readonly bLength             : uint8_t;
    readonly bDescriptorType     : uint8_t;
    readonly wTotalLength        : uint16_t;
    readonly bNumInterfaces      : uint8_t;
    readonly bConfigurationValue : uint8_t;
    readonly iConfiguration      : uint8_t;
    readonly bmAttributes        : uint8_t;
    readonly bMaxPower           : uint8_t;
}

declare interface Interface {
    readonly bLength             : uint8_t;
    readonly bDescriptorType     : uint8_t;
    readonly bInterfaceNumber    : uint8_t;
    readonly bAlternateSetting   : uint8_t;
    readonly bNumEndpoints       : uint8_t;
    readonly bInterfaceClass     : uint8_t;
    readonly bInterfaceSubClass  : uint8_t;
    readonly bInterfaceProtocol  : uint8_t;
    readonly iInterface          : uint8_t;
}

declare interface Endpoint {
    readonly bLength             : uint8_t;
    readonly bDescriptorType     : uint8_t;
    readonly bEndpointAddress    : uint8_t;
    readonly bmAttributes        : uint8_t;
    readonly wMaxPacketSize      : uint16_t;
    readonly bInterval           : uint8_t;
}

declare interface String {
    readonly bLength            : uint8_t;
    readonly bDescriptorType    : uint8_t;
    readonly [index: number]    : uint16_t;
}
reillyeon commented 4 years ago

In some cases the raw descriptors contain a number of fields which are unimportant to Javascript (e.g. bLength, bDescriptorType and wTotalLength). In other cases I wanted to reduce unnecessary indirection (e.g. swapping iManufacturer for manufacturerName). Lastly I wanted to simplify interpretation in places where the standard descriptors make structure confusing (e.g. making the associated interface relationship explicit).

kichMan commented 4 years ago

@reillyeon Thanks for the answer and for the implementation of the usb service :)