Merge pull request #24 from zagrodzki/master

Use the calculated max iso packet size.
This commit is contained in:
zagrodzki
2017-02-06 20:43:46 +01:00
committed by GitHub
2 changed files with 17 additions and 11 deletions

View File

@@ -126,15 +126,23 @@ func newConfig(dev *C.libusb_device, cfg *C.struct_libusb_config_descriptor) Con
} }
i.Endpoints = make([]EndpointInfo, 0, len(ends)) i.Endpoints = make([]EndpointInfo, 0, len(ends))
for _, end := range ends { for _, end := range ends {
i.Endpoints = append(i.Endpoints, EndpointInfo{ ei := EndpointInfo{
Address: uint8(end.bEndpointAddress), Address: uint8(end.bEndpointAddress),
Attributes: uint8(end.bmAttributes), Attributes: uint8(end.bmAttributes),
MaxPacketSize: uint16(end.wMaxPacketSize), MaxPacketSize: uint16(end.wMaxPacketSize),
//MaxIsoPacket: uint32(C.libusb_get_max_iso_packet_size(dev, C.uchar(end.bEndpointAddress))), PollInterval: uint8(end.bInterval),
PollInterval: uint8(end.bInterval), RefreshRate: uint8(end.bRefresh),
RefreshRate: uint8(end.bRefresh), SynchAddress: uint8(end.bSynchAddress),
SynchAddress: uint8(end.bSynchAddress), }
}) if TransferType(ei.Attributes)&TRANSFER_TYPE_MASK == TRANSFER_TYPE_ISOCHRONOUS {
// bits 0-10 identify the packet size, bits 11-12 are the number of additional transactions per microframe.
// Don't use libusb_get_max_iso_packet_size, as it has a bug where it returns the same value
// 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.MaxIsoPacket = uint32(end.wMaxPacketSize) & 0x07ff * (uint32(end.wMaxPacketSize)>>11&3 + 1)
}
i.Endpoints = append(i.Endpoints, ei)
} }
descs = append(descs, i) descs = append(descs, i)
} }

View File

@@ -37,10 +37,8 @@ func iso_callback(cptr unsafe.Pointer) {
} }
func (end *endpoint) allocTransfer() *Transfer { func (end *endpoint) allocTransfer() *Transfer {
// Use libusb_get_max_iso_packet_size ?
const ( const (
iso_packets = 8 // 128 // 242 iso_packets = 8 // 128 // 242
packet_size = 2 * 960 // 1760
) )
xfer := C.libusb_alloc_transfer(C.int(iso_packets)) xfer := C.libusb_alloc_transfer(C.int(iso_packets))
@@ -49,7 +47,7 @@ func (end *endpoint) allocTransfer() *Transfer {
return nil return nil
} }
buf := make([]byte, iso_packets*packet_size) buf := make([]byte, iso_packets*end.EndpointInfo.MaxIsoPacket)
done := make(chan struct{}, 1) done := make(chan struct{}, 1)
xfer.dev_handle = end.Device.handle xfer.dev_handle = end.Device.handle
@@ -60,7 +58,7 @@ func (end *endpoint) allocTransfer() *Transfer {
xfer.length = C.int(len(buf)) xfer.length = C.int(len(buf))
xfer.num_iso_packets = iso_packets xfer.num_iso_packets = iso_packets
C.libusb_set_iso_packet_lengths(xfer, packet_size) C.libusb_set_iso_packet_lengths(xfer, C.uint(end.EndpointInfo.MaxIsoPacket))
/* /*
pkts := *(*[]C.struct_libusb_packet_descriptor)(unsafe.Pointer(&reflect.SliceHeader{ pkts := *(*[]C.struct_libusb_packet_descriptor)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&xfer.iso_packet_desc)), Data: uintptr(unsafe.Pointer(&xfer.iso_packet_desc)),