diff --git a/usb/endpoint.go b/usb/endpoint.go index a68d231..d2bf047 100644 --- a/usb/endpoint.go +++ b/usb/endpoint.go @@ -33,7 +33,7 @@ type EndpointInfo struct { // Direction defines whether the data is flowing IN or OUT from the host perspective. Direction EndpointDirection // MaxPacketSize is the maximum USB packet size for a single frame/microframe. - MaxPacketSize uint32 + MaxPacketSize int // TransferType defines the endpoint type - bulk, interrupt, isochronous. TransferType TransferType // PollInterval is the maximum time between transfers for interrupt and isochronous transfer, diff --git a/usb/libusb.go b/usb/libusb.go index 93ac407..d6d6136 100644 --- a/usb/libusb.go +++ b/usb/libusb.go @@ -44,7 +44,7 @@ func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo { Number: int(ep.bEndpointAddress & endpointNumMask), Direction: EndpointDirection((ep.bEndpointAddress & endpointDirectionMask) != 0), TransferType: TransferType(ep.bmAttributes & transferTypeMask), - MaxPacketSize: uint32(ep.wMaxPacketSize), + MaxPacketSize: int(ep.wMaxPacketSize), } if ei.TransferType == TransferTypeIsochronous { // bits 0-10 identify the packet size, bits 11-12 are the number of additional transactions per microframe. @@ -52,7 +52,7 @@ func (ep libusbEndpoint) endpointInfo(dev *Descriptor) EndpointInfo { // regardless of alternative setting used, where different alternative settings might define different // 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.MaxPacketSize = int(ep.wMaxPacketSize) & 0x07ff * (int(ep.wMaxPacketSize)>>11&3 + 1) ei.IsoSyncType = IsoSyncType(ep.bmAttributes & isoSyncTypeMask) switch ep.bmAttributes & usageTypeMask { case C.LIBUSB_ISO_USAGE_TYPE_DATA: diff --git a/usb/transfer.go b/usb/transfer.go index bcd6b14..be9286c 100644 --- a/usb/transfer.go +++ b/usb/transfer.go @@ -112,14 +112,13 @@ func (t *usbTransfer) data() []byte { // newUSBTransfer allocates a new transfer structure for communication with a // given device/endpoint, with buf as the underlying transfer buffer. func newUSBTransfer(dev *libusbDevHandle, ei *EndpointInfo, buf []byte, timeout time.Duration) (*usbTransfer, error) { - var isoPackets int - var isoPktSize uint32 + var isoPackets, isoPktSize int if ei.TransferType == TransferTypeIsochronous { isoPktSize = ei.MaxPacketSize - if len(buf) < int(isoPktSize) { - isoPktSize = uint32(len(buf)) + if len(buf) < isoPktSize { + isoPktSize = len(buf) } - isoPackets = len(buf) / int(isoPktSize) + isoPackets = len(buf) / isoPktSize debug.Printf("New isochronous transfer - buffer length %d, using %d packets of %d bytes each", len(buf), isoPackets, isoPktSize) } @@ -130,7 +129,7 @@ func newUSBTransfer(dev *libusbDevHandle, ei *EndpointInfo, buf []byte, timeout } if ei.TransferType == TransferTypeIsochronous { - libusb.setIsoPacketLengths(xfer, isoPktSize) + libusb.setIsoPacketLengths(xfer, uint32(isoPktSize)) } t := &usbTransfer{ diff --git a/usb/transfer_test.go b/usb/transfer_test.go index a59897a..d07a51b 100644 --- a/usb/transfer_test.go +++ b/usb/transfer_test.go @@ -27,7 +27,7 @@ func TestNewTransfer(t *testing.T) { desc string dir EndpointDirection tt TransferType - maxPkt uint32 + maxPkt int buf int timeout time.Duration wantIso int