Use Class for classes in usbid.

This commit is contained in:
Sebastian Zagrodzki
2017-04-09 18:29:16 +02:00
parent af00028b97
commit d3428d9b35
7 changed files with 36 additions and 23 deletions

View File

@@ -218,4 +218,14 @@ func (s DeviceSpeed) String() string {
return deviceSpeedDescription[s]
}
const (
// SelfPoweredMask is the bitmask for "self powered" field of configuration
// descriptor bmAttributes.
SelfPoweredMask = 0x40
// RemoteWakeupMask is the bitmask for "supports remote wakeup" field of
// configuration descriptor bmAttributes.
RemoteWakeupMask = 0x20
)
// Milliamperes is a unit of electric current consumption.
type Milliamperes uint

View File

@@ -29,8 +29,8 @@ type Descriptor struct {
Product ID // The Product identifier
// Protocol information
Class uint8 // The class of this device
SubClass uint8 // The sub-class (within the class) of this device
Class Class // The class of this device
SubClass Class // The sub-class (within the class) of this device
Protocol uint8 // The protocol (within the sub-class) of this device
// Configuration information

View File

@@ -213,9 +213,11 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
return nil, err
}
c := ConfigInfo{
Config: uint8(cfg.bConfigurationValue),
Attributes: uint8(cfg.bmAttributes),
MaxPower: uint8(cfg.MaxPower),
Config: uint8(cfg.bConfigurationValue),
SelfPowered: (cfg.bmAttributes & SelfPoweredMask) != 0,
RemoteWakeup: (cfg.bmAttributes & RemoteWakeupMask) != 0,
// TODO(sebek): at GenX speeds MaxPower is expressed in units of 8mA, not 2mA.
MaxPower: 2 * Milliamperes(cfg.MaxPower),
}
var ifaces []C.struct_libusb_interface
@@ -274,8 +276,8 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
Device: BCD(desc.bcdDevice),
Vendor: ID(desc.idVendor),
Product: ID(desc.idProduct),
Class: uint8(desc.bDeviceClass),
SubClass: uint8(desc.bDeviceSubClass),
Class: Class(desc.bDeviceClass),
SubClass: Class(desc.bDeviceSubClass),
Protocol: uint8(desc.bDeviceProtocol),
Configs: cfgs,
}, nil