Unexport bitmasks, they are only used internally. All values present

in exported structs are meaningful and the users should not need to use
bitmasks.
This commit is contained in:
Sebastian Zagrodzki
2017-04-09 18:53:49 +02:00
parent 3d62929e05
commit 13f4e95f2f
2 changed files with 16 additions and 20 deletions

View File

@@ -105,8 +105,8 @@ func (dt DescriptorType) String() string {
type EndpointDirection bool type EndpointDirection bool
const ( const (
EndpointNumMask = 0x0f endpointNumMask = 0x0f
EndpointDirectionMask = 0x80 endpointDirectionMask = 0x80
// EndpointDirectionIn marks data flowing from device to host. // EndpointDirectionIn marks data flowing from device to host.
EndpointDirectionIn EndpointDirection = true EndpointDirectionIn EndpointDirection = true
// EndpointDirectionOut marks data flowing from host to device. // EndpointDirectionOut marks data flowing from host to device.
@@ -129,7 +129,7 @@ const (
TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK
TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT
TransferTypeMask = 0x03 transferTypeMask = 0x03
) )
var transferTypeDescription = map[TransferType]string{ var transferTypeDescription = map[TransferType]string{
@@ -150,7 +150,7 @@ const (
IsoSyncTypeAsync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC << 2 IsoSyncTypeAsync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC << 2
IsoSyncTypeAdaptive IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE << 2 IsoSyncTypeAdaptive IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE << 2
IsoSyncTypeSync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_SYNC << 2 IsoSyncTypeSync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_SYNC << 2
IsoSyncTypeMask = 0x0C isoSyncTypeMask = 0x0C
) )
var isoSyncTypeDescription = map[IsoSyncType]string{ var isoSyncTypeDescription = map[IsoSyncType]string{
@@ -170,7 +170,7 @@ const (
// Note: USB3.0 defines usage type for both isochronous and interrupt // Note: USB3.0 defines usage type for both isochronous and interrupt
// endpoints, with the same constants representing different usage types. // endpoints, with the same constants representing different usage types.
// UsageType constants do not correspond to bmAttribute values. // UsageType constants do not correspond to bmAttribute values.
UsageTypeMask = 0x30 usageTypeMask = 0x30
UsageTypeUndefined UsageType = iota UsageTypeUndefined UsageType = iota
IsoUsageTypeData IsoUsageTypeData
IsoUsageTypeFeedback IsoUsageTypeFeedback
@@ -235,12 +235,8 @@ func (s DeviceSpeed) String() string {
} }
const ( const (
// SelfPoweredMask is the bitmask for "self powered" field of configuration selfPoweredMask = 0x40
// descriptor bmAttributes. remoteWakeupMask = 0x20
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. // Milliamperes is a unit of electric current consumption.

View File

@@ -40,9 +40,9 @@ type libusbEndpoint C.struct_libusb_endpoint_descriptor
func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo { func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo {
ei := EndpointInfo{ ei := EndpointInfo{
Number: uint8(ep.bEndpointAddress & EndpointNumMask), Number: uint8(ep.bEndpointAddress & endpointNumMask),
Direction: EndpointDirection((ep.bEndpointAddress & EndpointDirectionMask) != 0), Direction: EndpointDirection((ep.bEndpointAddress & endpointDirectionMask) != 0),
TransferType: TransferType(ep.bmAttributes & TransferTypeMask), TransferType: TransferType(ep.bmAttributes & transferTypeMask),
MaxPacketSize: uint32(ep.wMaxPacketSize), MaxPacketSize: uint32(ep.wMaxPacketSize),
} }
if ei.TransferType == TransferTypeIsochronous { if ei.TransferType == TransferTypeIsochronous {
@@ -52,8 +52,8 @@ func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo {
// max packet sizes. // max packet sizes.
// See http://libusb.org/ticket/77 for more background. // See http://libusb.org/ticket/77 for more background.
ei.MaxPacketSize = uint32(ep.wMaxPacketSize) & 0x07ff * (uint32(ep.wMaxPacketSize)>>11&3 + 1) ei.MaxPacketSize = uint32(ep.wMaxPacketSize) & 0x07ff * (uint32(ep.wMaxPacketSize)>>11&3 + 1)
ei.IsoSyncType = IsoSyncType(ep.bmAttributes & IsoSyncTypeMask) ei.IsoSyncType = IsoSyncType(ep.bmAttributes & isoSyncTypeMask)
switch ep.bmAttributes & UsageTypeMask { switch ep.bmAttributes & usageTypeMask {
case C.LIBUSB_ISO_USAGE_TYPE_DATA: case C.LIBUSB_ISO_USAGE_TYPE_DATA:
ei.UsageType = IsoUsageTypeData ei.UsageType = IsoUsageTypeData
case C.LIBUSB_ISO_USAGE_TYPE_FEEDBACK: case C.LIBUSB_ISO_USAGE_TYPE_FEEDBACK:
@@ -214,8 +214,8 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
} }
c := ConfigInfo{ c := ConfigInfo{
Config: uint8(cfg.bConfigurationValue), Config: uint8(cfg.bConfigurationValue),
SelfPowered: (cfg.bmAttributes & SelfPoweredMask) != 0, SelfPowered: (cfg.bmAttributes & selfPoweredMask) != 0,
RemoteWakeup: (cfg.bmAttributes & RemoteWakeupMask) != 0, RemoteWakeup: (cfg.bmAttributes & remoteWakeupMask) != 0,
// TODO(sebek): at GenX speeds MaxPower is expressed in units of 8mA, not 2mA. // TODO(sebek): at GenX speeds MaxPower is expressed in units of 8mA, not 2mA.
MaxPower: 2 * Milliamperes(cfg.MaxPower), 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) return nil, fmt.Errorf("libusb_alloc_transfer(%d) failed", isoPackets)
} }
xfer.dev_handle = (*C.libusb_device_handle)(d) xfer.dev_handle = (*C.libusb_device_handle)(d)
addr := ep.Number & EndpointNumMask addr := ep.Number & endpointNumMask
if ep.Direction == EndpointDirectionIn { if ep.Direction == EndpointDirectionIn {
addr |= EndpointDirectionMask addr |= endpointDirectionMask
} }
xfer.endpoint = C.uchar(addr) xfer.endpoint = C.uchar(addr)
xfer.timeout = C.uint(timeout / time.Millisecond) xfer.timeout = C.uint(timeout / time.Millisecond)