Move files from gousb/usb to gousb
This commit is contained in:
258
constants.go
Normal file
258
constants.go
Normal file
@@ -0,0 +1,258 @@
|
||||
// Copyright 2013 Google Inc. All rights reserved.
|
||||
// Copyright 2016 the gousb Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package gousb
|
||||
|
||||
// #include <libusb.h>
|
||||
import "C"
|
||||
import "strconv"
|
||||
|
||||
// Class represents a USB-IF class or subclass code.
|
||||
type Class uint8
|
||||
|
||||
// Standard classes defined by USB spec.
|
||||
const (
|
||||
ClassPerInterface Class = C.LIBUSB_CLASS_PER_INTERFACE
|
||||
ClassAudio Class = C.LIBUSB_CLASS_AUDIO
|
||||
ClassComm Class = C.LIBUSB_CLASS_COMM
|
||||
ClassHID Class = C.LIBUSB_CLASS_HID
|
||||
ClassPrinter Class = C.LIBUSB_CLASS_PRINTER
|
||||
ClassPTP Class = C.LIBUSB_CLASS_PTP
|
||||
ClassMassStorage Class = C.LIBUSB_CLASS_MASS_STORAGE
|
||||
ClassHub Class = C.LIBUSB_CLASS_HUB
|
||||
ClassData Class = C.LIBUSB_CLASS_DATA
|
||||
ClassWireless Class = C.LIBUSB_CLASS_WIRELESS
|
||||
ClassApplication Class = C.LIBUSB_CLASS_APPLICATION
|
||||
ClassVendorSpec Class = C.LIBUSB_CLASS_VENDOR_SPEC
|
||||
)
|
||||
|
||||
var classDescription = map[Class]string{
|
||||
ClassPerInterface: "per-interface",
|
||||
ClassAudio: "audio",
|
||||
ClassComm: "communications",
|
||||
ClassHID: "human interface device",
|
||||
ClassPrinter: "printer dclass",
|
||||
ClassPTP: "picture transfer protocol",
|
||||
ClassMassStorage: "mass storage",
|
||||
ClassHub: "hub",
|
||||
ClassData: "data",
|
||||
ClassWireless: "wireless",
|
||||
ClassApplication: "application",
|
||||
ClassVendorSpec: "vendor-specific",
|
||||
}
|
||||
|
||||
func (c Class) String() string {
|
||||
if d, ok := classDescription[c]; ok {
|
||||
return d
|
||||
}
|
||||
return strconv.Itoa(int(c))
|
||||
}
|
||||
|
||||
// Protocol is the interface class protocol, qualified by the values
|
||||
// of interface class and subclass.
|
||||
type Protocol uint8
|
||||
|
||||
func (p Protocol) String() string {
|
||||
return strconv.Itoa(int(p))
|
||||
}
|
||||
|
||||
// DescriptorType identifies the type of a USB descriptor.
|
||||
type DescriptorType uint8
|
||||
|
||||
// Descriptor types defined by the USB spec.
|
||||
const (
|
||||
DescriptorTypeDevice DescriptorType = C.LIBUSB_DT_DEVICE
|
||||
DescriptorTypeConfig DescriptorType = C.LIBUSB_DT_CONFIG
|
||||
DescriptorTypeString DescriptorType = C.LIBUSB_DT_STRING
|
||||
DescriptorTypeInterface DescriptorType = C.LIBUSB_DT_INTERFACE
|
||||
DescriptorTypeEndpoint DescriptorType = C.LIBUSB_DT_ENDPOINT
|
||||
DescriptorTypeHID DescriptorType = C.LIBUSB_DT_HID
|
||||
DescriptorTypeReport DescriptorType = C.LIBUSB_DT_REPORT
|
||||
DescriptorTypePhysical DescriptorType = C.LIBUSB_DT_PHYSICAL
|
||||
DescriptorTypeHub DescriptorType = C.LIBUSB_DT_HUB
|
||||
)
|
||||
|
||||
var descriptorTypeDescription = map[DescriptorType]string{
|
||||
DescriptorTypeDevice: "device",
|
||||
DescriptorTypeConfig: "configuration",
|
||||
DescriptorTypeString: "string",
|
||||
DescriptorTypeInterface: "interface",
|
||||
DescriptorTypeEndpoint: "endpoint",
|
||||
DescriptorTypeHID: "HID",
|
||||
DescriptorTypeReport: "HID report",
|
||||
DescriptorTypePhysical: "physical",
|
||||
DescriptorTypeHub: "hub",
|
||||
}
|
||||
|
||||
func (dt DescriptorType) String() string {
|
||||
return descriptorTypeDescription[dt]
|
||||
}
|
||||
|
||||
// EndpointDirection defines the direction of data flow - IN (device to host)
|
||||
// or OUT (host to device).
|
||||
type EndpointDirection bool
|
||||
|
||||
const (
|
||||
endpointNumMask = 0x0f
|
||||
endpointDirectionMask = 0x80
|
||||
// EndpointDirectionIn marks data flowing from device to host.
|
||||
EndpointDirectionIn EndpointDirection = true
|
||||
// EndpointDirectionOut marks data flowing from host to device.
|
||||
EndpointDirectionOut EndpointDirection = false
|
||||
)
|
||||
|
||||
var endpointDirectionDescription = map[EndpointDirection]string{
|
||||
EndpointDirectionIn: "IN",
|
||||
EndpointDirectionOut: "OUT",
|
||||
}
|
||||
|
||||
func (ed EndpointDirection) String() string {
|
||||
return endpointDirectionDescription[ed]
|
||||
}
|
||||
|
||||
// TransferType defines the endpoint transfer type.
|
||||
type TransferType uint8
|
||||
|
||||
// Transfer types defined by the USB spec.
|
||||
const (
|
||||
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{
|
||||
TransferTypeControl: "control",
|
||||
TransferTypeIsochronous: "isochronous",
|
||||
TransferTypeBulk: "bulk",
|
||||
TransferTypeInterrupt: "interrupt",
|
||||
}
|
||||
|
||||
// String returns a human-readable name of the endpoint transfer type.
|
||||
func (tt TransferType) String() string {
|
||||
return transferTypeDescription[tt]
|
||||
}
|
||||
|
||||
// IsoSyncType defines the isochronous transfer synchronization type.
|
||||
type IsoSyncType uint8
|
||||
|
||||
// Synchronization types defined by the USB spec.
|
||||
const (
|
||||
IsoSyncTypeNone IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_NONE << 2
|
||||
IsoSyncTypeAsync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC << 2
|
||||
IsoSyncTypeAdaptive IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE << 2
|
||||
IsoSyncTypeSync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_SYNC << 2
|
||||
isoSyncTypeMask = 0x0C
|
||||
)
|
||||
|
||||
var isoSyncTypeDescription = map[IsoSyncType]string{
|
||||
IsoSyncTypeNone: "unsynchronized",
|
||||
IsoSyncTypeAsync: "asynchronous",
|
||||
IsoSyncTypeAdaptive: "adaptive",
|
||||
IsoSyncTypeSync: "synchronous",
|
||||
}
|
||||
|
||||
// String returns a human-readable description of the synchronization type.
|
||||
func (ist IsoSyncType) String() string {
|
||||
return isoSyncTypeDescription[ist]
|
||||
}
|
||||
|
||||
// UsageType defines the transfer usage type for isochronous and interrupt
|
||||
// transfers.
|
||||
type UsageType uint8
|
||||
|
||||
// Usage types for iso and interrupt transfers, defined by the USB spec.
|
||||
const (
|
||||
// Note: USB3.0 defines usage type for both isochronous and interrupt
|
||||
// endpoints, with the same constants representing different usage types.
|
||||
// UsageType constants do not correspond to bmAttribute values.
|
||||
UsageTypeUndefined UsageType = iota
|
||||
IsoUsageTypeData
|
||||
IsoUsageTypeFeedback
|
||||
IsoUsageTypeImplicit
|
||||
InterruptUsageTypePeriodic
|
||||
InterruptUsageTypeNotification
|
||||
usageTypeMask = 0x30
|
||||
)
|
||||
|
||||
var usageTypeDescription = map[UsageType]string{
|
||||
UsageTypeUndefined: "undefined usage",
|
||||
IsoUsageTypeData: "data",
|
||||
IsoUsageTypeFeedback: "feedback",
|
||||
IsoUsageTypeImplicit: "implicit data",
|
||||
InterruptUsageTypePeriodic: "periodic",
|
||||
InterruptUsageTypeNotification: "notification",
|
||||
}
|
||||
|
||||
func (ut UsageType) String() string {
|
||||
return usageTypeDescription[ut]
|
||||
}
|
||||
|
||||
// RequestType identifies a control transfer request type.
|
||||
type RequestType uint8
|
||||
|
||||
// Control request types defined in the USB spec.
|
||||
const (
|
||||
RequestTypeStandard = C.LIBUSB_REQUEST_TYPE_STANDARD
|
||||
RequestTypeClass = C.LIBUSB_REQUEST_TYPE_CLASS
|
||||
RequestTypeVendor = C.LIBUSB_REQUEST_TYPE_VENDOR
|
||||
RequestTypeReserved = C.LIBUSB_REQUEST_TYPE_RESERVED
|
||||
)
|
||||
|
||||
var requestTypeDescription = map[RequestType]string{
|
||||
RequestTypeStandard: "standard",
|
||||
RequestTypeClass: "class",
|
||||
RequestTypeVendor: "vendor",
|
||||
RequestTypeReserved: "reserved",
|
||||
}
|
||||
|
||||
// String returns a human-readable name of the control transfer request type.
|
||||
func (rt RequestType) String() string {
|
||||
return requestTypeDescription[rt]
|
||||
}
|
||||
|
||||
// Speed identifies the speed of the device.
|
||||
type Speed int
|
||||
|
||||
// Device speeds as defined in the USB spec.
|
||||
const (
|
||||
SpeedUnknown Speed = C.LIBUSB_SPEED_UNKNOWN
|
||||
SpeedLow Speed = C.LIBUSB_SPEED_LOW
|
||||
SpeedFull Speed = C.LIBUSB_SPEED_FULL
|
||||
SpeedHigh Speed = C.LIBUSB_SPEED_HIGH
|
||||
SpeedSuper Speed = C.LIBUSB_SPEED_SUPER
|
||||
)
|
||||
|
||||
var deviceSpeedDescription = map[Speed]string{
|
||||
SpeedUnknown: "unknown",
|
||||
SpeedLow: "low",
|
||||
SpeedFull: "full",
|
||||
SpeedHigh: "high",
|
||||
SpeedSuper: "super",
|
||||
}
|
||||
|
||||
// String returns a human-readable name of the device speed.
|
||||
func (s Speed) String() string {
|
||||
return deviceSpeedDescription[s]
|
||||
}
|
||||
|
||||
const (
|
||||
selfPoweredMask = 0x40
|
||||
remoteWakeupMask = 0x20
|
||||
)
|
||||
|
||||
// Milliamperes is a unit of electric current consumption.
|
||||
type Milliamperes uint
|
Reference in New Issue
Block a user