more constants

This commit is contained in:
Sebastian Zagrodzki
2017-03-27 22:29:24 +02:00
parent b70848cf73
commit 36241e869e
7 changed files with 27 additions and 27 deletions

View File

@@ -34,7 +34,7 @@ func (e EndpointInfo) Number() int {
}
func (e EndpointInfo) TransferType() TransferType {
return TransferType(e.Attributes) & TRANSFER_TYPE_MASK
return TransferType(e.Attributes) & TransferTypeMask
}
func (e EndpointInfo) Direction() EndpointDirection {

View File

@@ -105,18 +105,18 @@ func (ed EndpointDirection) String() string {
type TransferType uint8
const (
TRANSFER_TYPE_CONTROL TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL
TRANSFER_TYPE_ISOCHRONOUS TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
TRANSFER_TYPE_BULK TransferType = C.LIBUSB_TRANSFER_TYPE_BULK
TRANSFER_TYPE_INTERRUPT TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT
TRANSFER_TYPE_MASK TransferType = 0x03
TransferTypeControl TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL
TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK
TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT
TransferTypeMask = 0x03
)
var transferTypeDescription = map[TransferType]string{
TRANSFER_TYPE_CONTROL: "control",
TRANSFER_TYPE_ISOCHRONOUS: "isochronous",
TRANSFER_TYPE_BULK: "bulk",
TRANSFER_TYPE_INTERRUPT: "interrupt",
TransferTypeControl: "control",
TransferTypeIsochronous: "isochronous",
TransferTypeBulk: "bulk",
TransferTypeInterrupt: "interrupt",
}
func (tt TransferType) String() string {

View File

@@ -17,7 +17,7 @@ package usb
// IN bulk endpoint
var testBulkInEP = EndpointInfo{
Address: 0x82,
Attributes: uint8(TRANSFER_TYPE_BULK),
Attributes: uint8(TransferTypeBulk),
MaxPacketSize: 512,
PollInterval: 1,
}
@@ -32,7 +32,7 @@ var testBulkInSetup = InterfaceSetup{
// OUT iso endpoint
var testIsoOutEP = EndpointInfo{
Address: 0x06,
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 3<<11 + 1024,
MaxIsoPacket: 3 * 1024,
PollInterval: 1,

View File

@@ -47,11 +47,11 @@ var (
IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{
Address: uint8(0x01 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_BULK),
Attributes: uint8(TransferTypeBulk),
MaxPacketSize: 512,
}, {
Address: uint8(0x02 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_BULK),
Attributes: uint8(TransferTypeBulk),
MaxPacketSize: 512,
}},
}},
@@ -88,12 +88,12 @@ var (
IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{
Address: uint8(0x05 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 2<<11 | 1024,
MaxIsoPacket: 3 * 1024,
}, {
Address: uint8(0x06 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 2<<11 | 1024,
MaxIsoPacket: 3 * 1024,
}},
@@ -103,12 +103,12 @@ var (
IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{
Address: uint8(0x05 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 1<<11 | 1024,
MaxIsoPacket: 2 * 1024,
}, {
Address: uint8(0x06 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 1<<11 | 1024,
MaxIsoPacket: 2 * 1024,
}},
@@ -118,12 +118,12 @@ var (
IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{
Address: uint8(0x05 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 1024,
MaxIsoPacket: 1024,
}, {
Address: uint8(0x06 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
Attributes: uint8(TransferTypeIsochronous),
MaxPacketSize: 1024,
MaxIsoPacket: 1024,
}},

View File

@@ -193,7 +193,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
RefreshRate: uint8(end.bRefresh),
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.
// 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
@@ -338,7 +338,7 @@ func (libusbImpl) submit(t *libusbTransfer, done chan struct{}) error {
}
func (libusbImpl) data(t *libusbTransfer) (int, TransferStatus) {
if TransferType(t._type) == TRANSFER_TYPE_ISOCHRONOUS {
if TransferType(t._type) == TransferTypeIsochronous {
var status TransferStatus
n := int(C.compact_iso_data((*C.struct_libusb_transfer)(t), (*C.uchar)(unsafe.Pointer(&status))))
return n, status

View File

@@ -115,7 +115,7 @@ func (t *usbTransfer) free() error {
func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout time.Duration) (*usbTransfer, error) {
var isoPackets int
tt := ei.TransferType()
if tt == TRANSFER_TYPE_ISOCHRONOUS {
if tt == TransferTypeIsochronous {
isoPackets = len(buf) / int(ei.MaxIsoPacket)
if int(ei.MaxIsoPacket)*isoPackets < len(buf) {
isoPackets++
@@ -127,7 +127,7 @@ func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout t
return nil, err
}
if tt == TRANSFER_TYPE_ISOCHRONOUS {
if tt == TransferTypeIsochronous {
libusb.setIsoPacketLengths(xfer, ei.MaxIsoPacket)
}

View File

@@ -38,7 +38,7 @@ func TestNewTransfer(t *testing.T) {
{
desc: "bulk in transfer, 512B packets",
dir: EndpointDirectionIn,
tt: TRANSFER_TYPE_BULK,
tt: TransferTypeBulk,
maxPkt: 512,
buf: 1024,
timeout: time.Second,
@@ -47,7 +47,7 @@ func TestNewTransfer(t *testing.T) {
{
desc: "iso out transfer, 3 * 1024B packets",
dir: EndpointDirectionOut,
tt: TRANSFER_TYPE_ISOCHRONOUS,
tt: TransferTypeIsochronous,
maxPkt: 2<<11 + 1024,
maxIso: 3 * 1024,
buf: 10000,
@@ -82,7 +82,7 @@ func TestTransferProtocol(t *testing.T) {
for i := 0; i < 2; i++ {
xfers[i], err = newUSBTransfer(nil, EndpointInfo{
Address: 0x86,
Attributes: uint8(TRANSFER_TYPE_BULK),
Attributes: uint8(TransferTypeBulk),
MaxPacketSize: 512,
PollInterval: 1,
}, make([]byte, 10240), time.Second)