From 128c206986e1580fe5274c5da2b45f1192afdf21 Mon Sep 17 00:00:00 2001 From: Sebastian Zagrodzki Date: Sun, 9 Apr 2017 20:51:47 +0200 Subject: [PATCH] Move EndpointInfo to endpoint.go --- usb/config.go | 53 +------------------------------------------------ usb/endpoint.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/usb/config.go b/usb/config.go index 9cc61d7..567cab7 100644 --- a/usb/config.go +++ b/usb/config.go @@ -15,58 +15,7 @@ package usb -import ( - "fmt" - "strings" - "time" -) - -// EndpointInfo contains the information about an interface endpoint, extracted -// from the descriptor. -type EndpointInfo struct { - // Number represents the endpoint number. Note that the endpoint number is different from the - // address field in the descriptor - address 0x82 means endpoint number 2, - // with endpoint direction IN. - // The device can have up to two endpoints with the same number but with - // different directions. - Number uint8 - // 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 - // TransferType defines the endpoint type - bulk, interrupt, isochronous. - TransferType TransferType - // PollInterval is the maximum time between transfers for interrupt and isochronous transfer, - // or the NAK interval for a control transfer. See endpoint descriptor bInterval documentation - // in the USB spec for details. - PollInterval time.Duration - // IsoSyncType is the isochronous endpoint synchronization type, as defined by USB spec. - IsoSyncType IsoSyncType - // UsageType is the isochronous or interrupt endpoint usage type, as defined by USB spec. - UsageType UsageType -} - -func endpointAddr(n uint8, d EndpointDirection) uint8 { - addr := n - if d == EndpointDirectionIn { - addr |= 0x80 - } - return addr -} - -// String returns the human-readable description of the endpoint. -func (e EndpointInfo) String() string { - ret := make([]string, 0, 3) - ret = append(ret, fmt.Sprintf("Endpoint #%d %s (address 0x%02x) %s", e.Number, e.Direction, endpointAddr(e.Number, e.Direction), e.TransferType)) - switch e.TransferType { - case TransferTypeIsochronous: - ret = append(ret, fmt.Sprintf("- %s %s", e.IsoSyncType, e.UsageType)) - case TransferTypeInterrupt: - ret = append(ret, fmt.Sprintf("- %s", e.UsageType)) - } - ret = append(ret, fmt.Sprintf("[%d bytes]", e.MaxPacketSize)) - return strings.Join(ret, " ") -} +import "fmt" // InterfaceInfo contains information about a USB interface, extracted from // the descriptor. diff --git a/usb/endpoint.go b/usb/endpoint.go index b76ba6f..269bccd 100644 --- a/usb/endpoint.go +++ b/usb/endpoint.go @@ -17,9 +17,57 @@ package usb import ( "fmt" + "strings" "time" ) +// EndpointInfo contains the information about an interface endpoint, extracted +// from the descriptor. +type EndpointInfo struct { + // Number represents the endpoint number. Note that the endpoint number is different from the + // address field in the descriptor - address 0x82 means endpoint number 2, + // with endpoint direction IN. + // The device can have up to two endpoints with the same number but with + // different directions. + Number uint8 + // 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 + // TransferType defines the endpoint type - bulk, interrupt, isochronous. + TransferType TransferType + // PollInterval is the maximum time between transfers for interrupt and isochronous transfer, + // or the NAK interval for a control transfer. See endpoint descriptor bInterval documentation + // in the USB spec for details. + PollInterval time.Duration + // IsoSyncType is the isochronous endpoint synchronization type, as defined by USB spec. + IsoSyncType IsoSyncType + // UsageType is the isochronous or interrupt endpoint usage type, as defined by USB spec. + UsageType UsageType +} + +func endpointAddr(n uint8, d EndpointDirection) uint8 { + addr := n + if d == EndpointDirectionIn { + addr |= 0x80 + } + return addr +} + +// String returns the human-readable description of the endpoint. +func (e EndpointInfo) String() string { + ret := make([]string, 0, 3) + ret = append(ret, fmt.Sprintf("Endpoint #%d %s (address 0x%02x) %s", e.Number, e.Direction, endpointAddr(e.Number, e.Direction), e.TransferType)) + switch e.TransferType { + case TransferTypeIsochronous: + ret = append(ret, fmt.Sprintf("- %s %s", e.IsoSyncType, e.UsageType)) + case TransferTypeInterrupt: + ret = append(ret, fmt.Sprintf("- %s", e.UsageType)) + } + ret = append(ret, fmt.Sprintf("[%d bytes]", e.MaxPacketSize)) + return strings.Join(ret, " ") +} + // Endpoint identifies a USB endpoint opened for transfer. type Endpoint struct { h *libusbDevHandle