replace uint32 in MaxPacketSize with int

This commit is contained in:
Sebastian Zagrodzki
2017-04-26 22:27:12 +02:00
parent 22ff844a3d
commit 93355e7490
4 changed files with 9 additions and 10 deletions

View File

@@ -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,

View File

@@ -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:

View File

@@ -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{

View File

@@ -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