diff --git a/usb/constants.go b/usb/constants.go index aec3a0d..9a8f69a 100644 --- a/usb/constants.go +++ b/usb/constants.go @@ -105,8 +105,8 @@ func (dt DescriptorType) String() string { type EndpointDirection bool const ( - EndpointNumMask = 0x0f - EndpointDirectionMask = 0x80 + endpointNumMask = 0x0f + endpointDirectionMask = 0x80 // EndpointDirectionIn marks data flowing from device to host. EndpointDirectionIn EndpointDirection = true // EndpointDirectionOut marks data flowing from host to device. @@ -129,7 +129,7 @@ const ( TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT - TransferTypeMask = 0x03 + transferTypeMask = 0x03 ) var transferTypeDescription = map[TransferType]string{ @@ -150,7 +150,7 @@ const ( IsoSyncTypeAsync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC << 2 IsoSyncTypeAdaptive IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE << 2 IsoSyncTypeSync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_SYNC << 2 - IsoSyncTypeMask = 0x0C + isoSyncTypeMask = 0x0C ) var isoSyncTypeDescription = map[IsoSyncType]string{ @@ -170,7 +170,7 @@ const ( // Note: USB3.0 defines usage type for both isochronous and interrupt // endpoints, with the same constants representing different usage types. // UsageType constants do not correspond to bmAttribute values. - UsageTypeMask = 0x30 + usageTypeMask = 0x30 UsageTypeUndefined UsageType = iota IsoUsageTypeData IsoUsageTypeFeedback @@ -235,12 +235,8 @@ func (s DeviceSpeed) String() string { } 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 + selfPoweredMask = 0x40 + remoteWakeupMask = 0x20 ) // Milliamperes is a unit of electric current consumption. diff --git a/usb/libusb.go b/usb/libusb.go index db6f8e3..e51f496 100644 --- a/usb/libusb.go +++ b/usb/libusb.go @@ -40,9 +40,9 @@ type libusbEndpoint C.struct_libusb_endpoint_descriptor func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo { ei := EndpointInfo{ - Number: uint8(ep.bEndpointAddress & EndpointNumMask), - Direction: EndpointDirection((ep.bEndpointAddress & EndpointDirectionMask) != 0), - TransferType: TransferType(ep.bmAttributes & TransferTypeMask), + Number: uint8(ep.bEndpointAddress & endpointNumMask), + Direction: EndpointDirection((ep.bEndpointAddress & endpointDirectionMask) != 0), + TransferType: TransferType(ep.bmAttributes & transferTypeMask), MaxPacketSize: uint32(ep.wMaxPacketSize), } if ei.TransferType == TransferTypeIsochronous { @@ -52,8 +52,8 @@ func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo { // max packet sizes. // See http://libusb.org/ticket/77 for more background. ei.MaxPacketSize = uint32(ep.wMaxPacketSize) & 0x07ff * (uint32(ep.wMaxPacketSize)>>11&3 + 1) - ei.IsoSyncType = IsoSyncType(ep.bmAttributes & IsoSyncTypeMask) - switch ep.bmAttributes & UsageTypeMask { + ei.IsoSyncType = IsoSyncType(ep.bmAttributes & isoSyncTypeMask) + switch ep.bmAttributes & usageTypeMask { case C.LIBUSB_ISO_USAGE_TYPE_DATA: ei.UsageType = IsoUsageTypeData case C.LIBUSB_ISO_USAGE_TYPE_FEEDBACK: @@ -214,8 +214,8 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) { } c := ConfigInfo{ Config: uint8(cfg.bConfigurationValue), - SelfPowered: (cfg.bmAttributes & SelfPoweredMask) != 0, - RemoteWakeup: (cfg.bmAttributes & RemoteWakeupMask) != 0, + 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), } @@ -374,9 +374,9 @@ func (libusbImpl) alloc(d *libusbDevHandle, ep *EndpointInfo, timeout time.Durat return nil, fmt.Errorf("libusb_alloc_transfer(%d) failed", isoPackets) } xfer.dev_handle = (*C.libusb_device_handle)(d) - addr := ep.Number & EndpointNumMask + addr := ep.Number & endpointNumMask if ep.Direction == EndpointDirectionIn { - addr |= EndpointDirectionMask + addr |= endpointDirectionMask } xfer.endpoint = C.uchar(addr) xfer.timeout = C.uint(timeout / time.Millisecond)