more constants
This commit is contained in:
@@ -34,7 +34,7 @@ func (e EndpointInfo) Number() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e EndpointInfo) TransferType() TransferType {
|
func (e EndpointInfo) TransferType() TransferType {
|
||||||
return TransferType(e.Attributes) & TRANSFER_TYPE_MASK
|
return TransferType(e.Attributes) & TransferTypeMask
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EndpointInfo) Direction() EndpointDirection {
|
func (e EndpointInfo) Direction() EndpointDirection {
|
||||||
|
@@ -105,18 +105,18 @@ func (ed EndpointDirection) String() string {
|
|||||||
type TransferType uint8
|
type TransferType uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TRANSFER_TYPE_CONTROL TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL
|
TransferTypeControl TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL
|
||||||
TRANSFER_TYPE_ISOCHRONOUS TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
|
TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
|
||||||
TRANSFER_TYPE_BULK TransferType = C.LIBUSB_TRANSFER_TYPE_BULK
|
TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK
|
||||||
TRANSFER_TYPE_INTERRUPT TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT
|
TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT
|
||||||
TRANSFER_TYPE_MASK TransferType = 0x03
|
TransferTypeMask = 0x03
|
||||||
)
|
)
|
||||||
|
|
||||||
var transferTypeDescription = map[TransferType]string{
|
var transferTypeDescription = map[TransferType]string{
|
||||||
TRANSFER_TYPE_CONTROL: "control",
|
TransferTypeControl: "control",
|
||||||
TRANSFER_TYPE_ISOCHRONOUS: "isochronous",
|
TransferTypeIsochronous: "isochronous",
|
||||||
TRANSFER_TYPE_BULK: "bulk",
|
TransferTypeBulk: "bulk",
|
||||||
TRANSFER_TYPE_INTERRUPT: "interrupt",
|
TransferTypeInterrupt: "interrupt",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tt TransferType) String() string {
|
func (tt TransferType) String() string {
|
||||||
|
@@ -17,7 +17,7 @@ package usb
|
|||||||
// IN bulk endpoint
|
// IN bulk endpoint
|
||||||
var testBulkInEP = EndpointInfo{
|
var testBulkInEP = EndpointInfo{
|
||||||
Address: 0x82,
|
Address: 0x82,
|
||||||
Attributes: uint8(TRANSFER_TYPE_BULK),
|
Attributes: uint8(TransferTypeBulk),
|
||||||
MaxPacketSize: 512,
|
MaxPacketSize: 512,
|
||||||
PollInterval: 1,
|
PollInterval: 1,
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ var testBulkInSetup = InterfaceSetup{
|
|||||||
// OUT iso endpoint
|
// OUT iso endpoint
|
||||||
var testIsoOutEP = EndpointInfo{
|
var testIsoOutEP = EndpointInfo{
|
||||||
Address: 0x06,
|
Address: 0x06,
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 3<<11 + 1024,
|
MaxPacketSize: 3<<11 + 1024,
|
||||||
MaxIsoPacket: 3 * 1024,
|
MaxIsoPacket: 3 * 1024,
|
||||||
PollInterval: 1,
|
PollInterval: 1,
|
||||||
|
@@ -47,11 +47,11 @@ var (
|
|||||||
IfClass: uint8(ClassVendorSpec),
|
IfClass: uint8(ClassVendorSpec),
|
||||||
Endpoints: []EndpointInfo{{
|
Endpoints: []EndpointInfo{{
|
||||||
Address: uint8(0x01 | EndpointDirectionOut),
|
Address: uint8(0x01 | EndpointDirectionOut),
|
||||||
Attributes: uint8(TRANSFER_TYPE_BULK),
|
Attributes: uint8(TransferTypeBulk),
|
||||||
MaxPacketSize: 512,
|
MaxPacketSize: 512,
|
||||||
}, {
|
}, {
|
||||||
Address: uint8(0x02 | EndpointDirectionIn),
|
Address: uint8(0x02 | EndpointDirectionIn),
|
||||||
Attributes: uint8(TRANSFER_TYPE_BULK),
|
Attributes: uint8(TransferTypeBulk),
|
||||||
MaxPacketSize: 512,
|
MaxPacketSize: 512,
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
@@ -88,12 +88,12 @@ var (
|
|||||||
IfClass: uint8(ClassVendorSpec),
|
IfClass: uint8(ClassVendorSpec),
|
||||||
Endpoints: []EndpointInfo{{
|
Endpoints: []EndpointInfo{{
|
||||||
Address: uint8(0x05 | EndpointDirectionOut),
|
Address: uint8(0x05 | EndpointDirectionOut),
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 2<<11 | 1024,
|
MaxPacketSize: 2<<11 | 1024,
|
||||||
MaxIsoPacket: 3 * 1024,
|
MaxIsoPacket: 3 * 1024,
|
||||||
}, {
|
}, {
|
||||||
Address: uint8(0x06 | EndpointDirectionIn),
|
Address: uint8(0x06 | EndpointDirectionIn),
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 2<<11 | 1024,
|
MaxPacketSize: 2<<11 | 1024,
|
||||||
MaxIsoPacket: 3 * 1024,
|
MaxIsoPacket: 3 * 1024,
|
||||||
}},
|
}},
|
||||||
@@ -103,12 +103,12 @@ var (
|
|||||||
IfClass: uint8(ClassVendorSpec),
|
IfClass: uint8(ClassVendorSpec),
|
||||||
Endpoints: []EndpointInfo{{
|
Endpoints: []EndpointInfo{{
|
||||||
Address: uint8(0x05 | EndpointDirectionOut),
|
Address: uint8(0x05 | EndpointDirectionOut),
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 1<<11 | 1024,
|
MaxPacketSize: 1<<11 | 1024,
|
||||||
MaxIsoPacket: 2 * 1024,
|
MaxIsoPacket: 2 * 1024,
|
||||||
}, {
|
}, {
|
||||||
Address: uint8(0x06 | EndpointDirectionIn),
|
Address: uint8(0x06 | EndpointDirectionIn),
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 1<<11 | 1024,
|
MaxPacketSize: 1<<11 | 1024,
|
||||||
MaxIsoPacket: 2 * 1024,
|
MaxIsoPacket: 2 * 1024,
|
||||||
}},
|
}},
|
||||||
@@ -118,12 +118,12 @@ var (
|
|||||||
IfClass: uint8(ClassVendorSpec),
|
IfClass: uint8(ClassVendorSpec),
|
||||||
Endpoints: []EndpointInfo{{
|
Endpoints: []EndpointInfo{{
|
||||||
Address: uint8(0x05 | EndpointDirectionOut),
|
Address: uint8(0x05 | EndpointDirectionOut),
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 1024,
|
MaxPacketSize: 1024,
|
||||||
MaxIsoPacket: 1024,
|
MaxIsoPacket: 1024,
|
||||||
}, {
|
}, {
|
||||||
Address: uint8(0x06 | EndpointDirectionIn),
|
Address: uint8(0x06 | EndpointDirectionIn),
|
||||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
Attributes: uint8(TransferTypeIsochronous),
|
||||||
MaxPacketSize: 1024,
|
MaxPacketSize: 1024,
|
||||||
MaxIsoPacket: 1024,
|
MaxIsoPacket: 1024,
|
||||||
}},
|
}},
|
||||||
|
@@ -193,7 +193,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
|||||||
RefreshRate: uint8(end.bRefresh),
|
RefreshRate: uint8(end.bRefresh),
|
||||||
SynchAddress: uint8(end.bSynchAddress),
|
SynchAddress: uint8(end.bSynchAddress),
|
||||||
}
|
}
|
||||||
if ei.TransferType() == TRANSFER_TYPE_ISOCHRONOUS {
|
if ei.TransferType() == TransferTypeIsochronous {
|
||||||
// bits 0-10 identify the packet size, bits 11-12 are the number of additional transactions per microframe.
|
// 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
|
// 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
|
// regardless of alternative setting used, where different alternative settings might define different
|
||||||
@@ -338,7 +338,7 @@ func (libusbImpl) submit(t *libusbTransfer, done chan struct{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (libusbImpl) data(t *libusbTransfer) (int, TransferStatus) {
|
func (libusbImpl) data(t *libusbTransfer) (int, TransferStatus) {
|
||||||
if TransferType(t._type) == TRANSFER_TYPE_ISOCHRONOUS {
|
if TransferType(t._type) == TransferTypeIsochronous {
|
||||||
var status TransferStatus
|
var status TransferStatus
|
||||||
n := int(C.compact_iso_data((*C.struct_libusb_transfer)(t), (*C.uchar)(unsafe.Pointer(&status))))
|
n := int(C.compact_iso_data((*C.struct_libusb_transfer)(t), (*C.uchar)(unsafe.Pointer(&status))))
|
||||||
return n, status
|
return n, status
|
||||||
|
@@ -115,7 +115,7 @@ func (t *usbTransfer) free() error {
|
|||||||
func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout time.Duration) (*usbTransfer, error) {
|
func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout time.Duration) (*usbTransfer, error) {
|
||||||
var isoPackets int
|
var isoPackets int
|
||||||
tt := ei.TransferType()
|
tt := ei.TransferType()
|
||||||
if tt == TRANSFER_TYPE_ISOCHRONOUS {
|
if tt == TransferTypeIsochronous {
|
||||||
isoPackets = len(buf) / int(ei.MaxIsoPacket)
|
isoPackets = len(buf) / int(ei.MaxIsoPacket)
|
||||||
if int(ei.MaxIsoPacket)*isoPackets < len(buf) {
|
if int(ei.MaxIsoPacket)*isoPackets < len(buf) {
|
||||||
isoPackets++
|
isoPackets++
|
||||||
@@ -127,7 +127,7 @@ func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout t
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if tt == TRANSFER_TYPE_ISOCHRONOUS {
|
if tt == TransferTypeIsochronous {
|
||||||
libusb.setIsoPacketLengths(xfer, ei.MaxIsoPacket)
|
libusb.setIsoPacketLengths(xfer, ei.MaxIsoPacket)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ func TestNewTransfer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "bulk in transfer, 512B packets",
|
desc: "bulk in transfer, 512B packets",
|
||||||
dir: EndpointDirectionIn,
|
dir: EndpointDirectionIn,
|
||||||
tt: TRANSFER_TYPE_BULK,
|
tt: TransferTypeBulk,
|
||||||
maxPkt: 512,
|
maxPkt: 512,
|
||||||
buf: 1024,
|
buf: 1024,
|
||||||
timeout: time.Second,
|
timeout: time.Second,
|
||||||
@@ -47,7 +47,7 @@ func TestNewTransfer(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "iso out transfer, 3 * 1024B packets",
|
desc: "iso out transfer, 3 * 1024B packets",
|
||||||
dir: EndpointDirectionOut,
|
dir: EndpointDirectionOut,
|
||||||
tt: TRANSFER_TYPE_ISOCHRONOUS,
|
tt: TransferTypeIsochronous,
|
||||||
maxPkt: 2<<11 + 1024,
|
maxPkt: 2<<11 + 1024,
|
||||||
maxIso: 3 * 1024,
|
maxIso: 3 * 1024,
|
||||||
buf: 10000,
|
buf: 10000,
|
||||||
@@ -82,7 +82,7 @@ func TestTransferProtocol(t *testing.T) {
|
|||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
xfers[i], err = newUSBTransfer(nil, EndpointInfo{
|
xfers[i], err = newUSBTransfer(nil, EndpointInfo{
|
||||||
Address: 0x86,
|
Address: 0x86,
|
||||||
Attributes: uint8(TRANSFER_TYPE_BULK),
|
Attributes: uint8(TransferTypeBulk),
|
||||||
MaxPacketSize: 512,
|
MaxPacketSize: 512,
|
||||||
PollInterval: 1,
|
PollInterval: 1,
|
||||||
}, make([]byte, 10240), time.Second)
|
}, make([]byte, 10240), time.Second)
|
||||||
|
Reference in New Issue
Block a user