diff --git a/usb/config.go b/usb/config.go index b492e26..41142ac 100644 --- a/usb/config.go +++ b/usb/config.go @@ -44,14 +44,18 @@ type EndpointInfo struct { UsageType UsageType } -// String returns the human-readable description of the endpoint. -func (e EndpointInfo) String() string { +func (e EndpointInfo) addr() uint8 { addr := e.Number if e.Direction == EndpointDirectionIn { addr |= 0x80 } + return addr +} + +// String returns the human-readable description of the endpoint. +func (e EndpointInfo) String() string { ret := make([]string, 0, 3) - ret = append(ret, fmt.Sprintf("Endpoint #%d %s (address 0x%02x) %s", e.Number, e.Direction, addr, e.TransferType)) + ret = append(ret, fmt.Sprintf("Endpoint #%d %s (address 0x%02x) %s", e.Number, e.Direction, e.addr(), e.TransferType)) switch e.TransferType { case TransferTypeIsochronous: ret = append(ret, fmt.Sprintf("- %s %s", e.IsoSyncType, e.UsageType)) diff --git a/usb/libusb.go b/usb/libusb.go index e51f496..142f0b8 100644 --- a/usb/libusb.go +++ b/usb/libusb.go @@ -374,11 +374,7 @@ 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 - if ep.Direction == EndpointDirectionIn { - addr |= endpointDirectionMask - } - xfer.endpoint = C.uchar(addr) + xfer.endpoint = C.uchar(ep.addr()) xfer.timeout = C.uint(timeout / time.Millisecond) xfer._type = C.uchar(ep.TransferType) xfer.num_iso_packets = C.int(isoPackets)