Documentation
¶
Overview ¶
Package libusb provides Go bindings for the libusb 1.0 C library.
Index ¶
- Constants
- func BitmapRequestType(dir TransferDirection, reqType RequestType, recipient RequestRecipient) byte
- func CPUtoLE16(value int) int
- func ErrorName(err ErrorCode) string
- func HasCapability(capability int) bool
- func StrError(err ErrorCode) string
- type Config
- type ConfigDescriptor
- type Context
- func (ctx *Context) Close() error
- func (ctx *Context) DeviceList() ([]*Device, error)
- func (ctx *Context) HotplugDeregisterAllCallbacks() error
- func (ctx *Context) HotplugDeregisterCallback(vendorID, productID uint16) error
- func (ctx *Context) HotplugRegisterCallbackEvent(vendorID, productID uint16, eventType HotPlugEventType, cb HotPlugCbFunc) error
- func (ctx *Context) OpenDeviceWithVendorProduct(vendorID uint16, productID uint16) (*Device, *DeviceHandle, error)
- func (ctx *Context) SetDebug(level LogLevel)
- type Descriptor
- type Device
- func (dev *Device) ActiveConfigDescriptor() (*ConfigDescriptor, error)
- func (dev *Device) BusNumber() (int, error)
- func (dev *Device) Clone() *Device
- func (dev *Device) Close()
- func (dev *Device) ConfigDescriptor(configIndex int) (*ConfigDescriptor, error)
- func (dev *Device) ConfigDescriptorByValue(configValue int) (*ConfigDescriptor, error)
- func (dev *Device) DeviceAddress() (int, error)
- func (dev *Device) DeviceDescriptor() (*Descriptor, error)
- func (dev *Device) FindInterfacesByClass(class uint8) (InterfaceDescriptors, error)
- func (dev *Device) Identity() (*DeviceIdentity, error)
- func (dev *Device) MaxPacketSize(ep EndpointAddress) (int, error)
- func (dev *Device) Open() (*DeviceHandle, error)
- func (dev *Device) PortNumber() (int, error)
- func (dev *Device) SerialNumber() (string, error)
- func (dev *Device) Speed() (SpeedType, error)
- func (dev *Device) SysfsAttribute(name string) (string, error)
- type DeviceHandle
- func (dh *DeviceHandle) AttachKernelDriver(interfaceNum int) error
- func (dh *DeviceHandle) BulkTransfer(endpoint EndpointAddress, data []byte, length int, timeout int) (int, error)
- func (dh *DeviceHandle) BulkTransferIn(endpoint EndpointAddress, maxReceiveBytes int, timeout int) ([]byte, int, error)
- func (dh *DeviceHandle) BulkTransferOut(endpoint EndpointAddress, data []byte, timeout int) (int, error)
- func (dh *DeviceHandle) ClaimInterface(interfaceNum int) error
- func (dh *DeviceHandle) ClearHalt(endpoint EndpointAddress) error
- func (dh *DeviceHandle) Close() error
- func (dh *DeviceHandle) Configuration() (int, error)
- func (dh *DeviceHandle) ControlIn(reqType RequestType, recipient RequestRecipient, request byte, value uint16, ...) (int, error)
- func (dh *DeviceHandle) ControlOut(reqType RequestType, recipient RequestRecipient, request byte, value uint16, ...) (int, error)
- func (dh *DeviceHandle) ControlTransfer(requestType byte, request byte, value uint16, index uint16, data []byte, ...) (int, error)
- func (dh *DeviceHandle) ControlTransferWithTypes(direction TransferDirection, reqType RequestType, recipient RequestRecipient, ...) (int, error)
- func (dh *DeviceHandle) DetachKernelDriver(interfaceNum int) error
- func (dh *DeviceHandle) Device() (*Device, error)
- func (dh *DeviceHandle) InterruptTransfer(endpoint EndpointAddress, data []byte, length int, timeout int) (int, error)
- func (dh *DeviceHandle) KernelDriverActive(interfaceNum int) (bool, error)
- func (dh *DeviceHandle) NewBulkTransfer(endpoint EndpointAddress, data []byte, length int, timeout int, ...) (*Transfer, error)
- func (dh *DeviceHandle) NewBulkTransferIn(endpoint EndpointAddress, maxReceiveBytes int, timeout int, ...) (*Transfer, error)
- func (dh *DeviceHandle) NewBulkTransferOut(endpoint EndpointAddress, data []byte, timeout int, callback TransferCallback) (*Transfer, error)
- func (dh *DeviceHandle) NewControlTransfer(requestType byte, request byte, value uint16, index uint16, data []byte, ...) (*Transfer, error)
- func (dh *DeviceHandle) NewInterruptTransfer(endpoint EndpointAddress, data []byte, length int, timeout int, ...) (*Transfer, error)
- func (dh *DeviceHandle) NewInterruptTransferIn(endpoint EndpointAddress, maxReceiveBytes int, timeout int, ...) (*Transfer, error)
- func (dh *DeviceHandle) NewInterruptTransferOut(endpoint EndpointAddress, data []byte, timeout int, callback TransferCallback) (*Transfer, error)
- func (dh *DeviceHandle) ReleaseInterface(interfaceNum int) error
- func (dh *DeviceHandle) ResetDevice() error
- func (dh *DeviceHandle) SetAutoDetachKernelDriver(enable bool) error
- func (dh *DeviceHandle) SetConfiguration(configuration int) error
- func (dh *DeviceHandle) SetInterfaceAltSetting(interfaceNum int, alternateSetting int) error
- func (dh *DeviceHandle) StringDescriptor(descIndex uint8, langID uint16) (string, error)
- func (dh *DeviceHandle) StringDescriptorASCII(descIndex uint8) (string, error)
- type DeviceIdentity
- type Endpoint
- type EndpointAddress
- type EndpointDescriptor
- type EndpointDescriptors
- type EndpointDirection
- type ErrorCode
- type HotPlugCbFunc
- type HotPlugEvent
- type HotPlugEventType
- type HotplugCallbackStorage
- type InterfaceDescriptor
- type InterfaceDescriptors
- type LogLevel
- type RequestRecipient
- type RequestType
- type SpeedType
- type SupportedInterface
- type SupportedInterfaces
- type Transfer
- type TransferCallback
- type TransferDirection
- type TransferFlag
- type TransferStatus
- type TransferType
- type VersionType
Constants ¶
const ( IsoSyncTypeNone synchronizationType = C.LIBUSB_ISO_SYNC_TYPE_NONE IsoSyncTypeAsync synchronizationType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC IsoSyncTypeAdaptive synchronizationType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE IsoSynceTypeSync synchronizationType = C.LIBUSB_ISO_SYNC_TYPE_SYNC )
Synchronization type for isochronous endpoints. "Values for bits 2:3 of the bmAttributes field in libusb_endpoint_descriptor" http://bit.ly/enum_libusb_iso_sync_type
const ( // USB Interface Class Codes - useful for finding interfaces by class InterfaceClassAudio uint8 = 0x01 InterfaceClassComm uint8 = 0x02 InterfaceClassHID uint8 = 0x03 InterfaceClassPhysical uint8 = 0x05 InterfaceClassImage uint8 = 0x06 InterfaceClassPrinter uint8 = 0x07 InterfaceClassMassStorage uint8 = 0x08 InterfaceClassHub uint8 = 0x09 InterfaceClassData uint8 = 0x0A InterfaceClassSmartCard uint8 = 0x0B InterfaceClassContentSecurity uint8 = 0x0D InterfaceClassVideo uint8 = 0x0E InterfaceClassPersonalHealthcare uint8 = 0x0F InterfaceClassAudioVideo uint8 = 0x10 InterfaceClassWireless uint8 = 0xE0 InterfaceClassApplication uint8 = 0xFE InterfaceClassVendorSpec uint8 = 0xFF )
USB Interface Class Codes
Variables ¶
This section is empty.
Functions ¶
func BitmapRequestType ¶
func BitmapRequestType(dir TransferDirection, reqType RequestType, recipient RequestRecipient) byte
BitmapRequestType creates a bmRequestType byte from individual components. Bits 0:4 determine recipient, see libusb_request_recipient. Bits 5:6 determine type, see libusb_request_type. Bit 7 determines data transfer direction, see libusb_endpoint_direction.
func CPUtoLE16 ¶
CPUtoLE16 converts "a 16-bit value from host-endian to little-endian format. On little endian systems, this function does nothing. On big endian systems, the bytes are swapped.
func HasCapability ¶
HasCapability checks "at runtime if the loaded library has a given capability. This call should be performed after libusb_init(), to ensure the backend has updated its capability set." (Source: libusb docs)
Types ¶
type Config ¶
type Config struct {
*ConfigDescriptor
Device *Device
}
Config models the USB configuration.
type ConfigDescriptor ¶
type ConfigDescriptor struct {
Length int
DescriptorType descriptorType
TotalLength uint16
NumInterfaces int
ConfigurationValue uint8
ConfigurationIndex uint8
Attributes uint8
MaxPowerMilliAmperes uint
SupportedInterfaces
}
ConfigDescriptor models the descriptor for the USB configuration
type Context ¶
type Context struct {
LogLevel LogLevel
// contains filtered or unexported fields
}
Context represents a libusb session/context.
func NewContext ¶
NewContext intializes a new libusb session/context by creating a new Context and returning a pointer to that Context.
func (*Context) DeviceList ¶
DeviceList returns an array of devices for the context.
func (*Context) HotplugDeregisterAllCallbacks ¶
HotplugDeregisterAllCallbacks deregisters all hotplug callbacks for this context.
func (*Context) HotplugDeregisterCallback ¶
HotplugDeregisterCallback deregisters the callback for a vendor/product pair. The context's shared event loop remains available for other async work.
func (*Context) HotplugRegisterCallbackEvent ¶
func (ctx *Context) HotplugRegisterCallbackEvent( vendorID, productID uint16, eventType HotPlugEventType, cb HotPlugCbFunc, ) error
HotplugRegisterCallbackEvent registers a hotplug callback for the given vendor/product ID pair and event type.
func (*Context) OpenDeviceWithVendorProduct ¶
func (ctx *Context) OpenDeviceWithVendorProduct( vendorID uint16, productID uint16, ) (*Device, *DeviceHandle, error)
OpenDeviceWithVendorProduct opens a USB device using the VendorID and productID and then returns a device handle.
type Descriptor ¶
type Descriptor struct {
Length uint8
DescriptorType descriptorType
USBSpecification bcd
DeviceClass classCode
DeviceSubClass byte
DeviceProtocol byte
MaxPacketSize0 uint8
VendorID uint16
ProductID uint16
DeviceReleaseNumber bcd
ManufacturerIndex uint8
ProductIndex uint8
SerialNumberIndex uint8
NumConfigurations uint8
}
Descriptor represents a USB device descriptor as a Go struct.
type Device ¶
type Device struct {
ActiveConfiguration *ConfigDescriptor
// contains filtered or unexported fields
}
Device represents a USB device including the opaque libusb_device struct.
func (*Device) ActiveConfigDescriptor ¶
func (dev *Device) ActiveConfigDescriptor() (*ConfigDescriptor, error)
ActiveConfigDescriptor "gets the USB configuration descriptor for the currently active configuration. This is a non-blocking function which does not involve any requests being sent to the device." (Source: libusb docs)
func (*Device) BusNumber ¶
BusNumber gets "the number of the bus that a device is connected to." (Source: libusb docs)
func (*Device) Close ¶
func (dev *Device) Close()
Close decrements the reference count of the device. If the decrement operation causes the reference count to reach zero, the device shall be destroyed.
func (*Device) ConfigDescriptor ¶
func (dev *Device) ConfigDescriptor(configIndex int) (*ConfigDescriptor, error)
ConfigDescriptor "gets a USB configuration descriptor based on its index. This is a non-blocking function which does not involve any requests being sent to the device." (Source: libusb docs)
func (*Device) ConfigDescriptorByValue ¶
func (dev *Device) ConfigDescriptorByValue(configValue int) (*ConfigDescriptor, error)
ConfigDescriptorByValue gets "a USB configuration descriptor with a specific bConfigurationValue. This is a non-blocking function which does not involve any requests being sent to the device. (Source: libusb docs)
func (*Device) DeviceAddress ¶
DeviceAddress gets "the address of the device on the bus it is connected to." (Source: libusb docs)
func (*Device) DeviceDescriptor ¶
func (dev *Device) DeviceDescriptor() (*Descriptor, error)
DeviceDescriptor implements the libusb_get_device_descriptor function to update the DeviceDescriptor struct embedded in the Device. DeviceDescriptor gets "the USB device descriptor for a given device. This is a non-blocking function; the device descriptor is cached in memory. Note since libusb-1.0.16, LIBUSB_API_VERSION >= 0x01000102, this function always succeeds." (Source: libusb docs)
func (*Device) FindInterfacesByClass ¶
func (dev *Device) FindInterfacesByClass( class uint8, ) (InterfaceDescriptors, error)
FindInterfacesByClass finds all interfaces that match the given USB class code. This is particularly useful for devices where the device class is reported as LIBUSB_CLASS_PER_INTERFACE (0), where individual interfaces have their own class codes.
For example, to find all printer class interfaces:
printerInterfaces, err := device.FindInterfacesByClass(libusb.InterfaceClassPrinter)
Example of finding and printing information about a printer device:
package main
import (
"fmt"
"github.com/Tryanks/libusb"
)
func main() {
ctx, _ := libusb.NewContext()
devices, _ := ctx.DeviceList()
for _, device := range devices {
desc, _ := device.DeviceDescriptor()
// Check if this is a per-interface class device
if desc.DeviceClass == 0 {
// Find printer interfaces (class 7)
printerIfaces, _ := device.FindInterfacesByClass(libusb.InterfaceClassPrinter)
if len(printerIfaces) > 0 {
fmt.Printf("Found printer device: VID=0x%04x, PID=0x%04x\n", desc.VendorID, desc.ProductID)
}
}
}
}
func (*Device) Identity ¶
func (dev *Device) Identity() (*DeviceIdentity, error)
Identity returns the best-effort stable identity snapshot for the device.
func (*Device) MaxPacketSize ¶
func (dev *Device) MaxPacketSize(ep EndpointAddress) (int, error)
MaxPacketSize is a "convenience function to retrieve the wMaxPacketSize value for a particular endpoint in the active device configuration. This function was originally intended to be of assistance when setting up isochronous transfers, but a design mistake resulted in this function instead. It simply returns the wMaxPacketSize value without considering its contents. If you're dealing with isochronous transfers, you probably want libusb_get_max_iso_packet_size() instead." (Source: libusb docs)
func (*Device) Open ¶
func (dev *Device) Open() (*DeviceHandle, error)
Open will "open a device and obtain a device handle. A handle allows you to perform I/O on the device in question. Internally, this function adds a reference to the device and makes it available to you through libusb_get_device(). This reference is removed during libusb_close()." This is a non-blocking function; no requests are sent over the bus. (Source: libusb docs)
func (*Device) PortNumber ¶
PortNumber gets "the number of the port that a device is connected to. Unless the OS does something funky, or you are hot-plugging USB extension cards, the port number returned by this call is usually guaranteed to be uniquely tied to a physical port, meaning that different devices plugged on the same physical port should return the same port number. But outside of this, there is no guarantee that the port number returned by this call will remain the same, or even match the order in which ports have been numbered by the HUB/HCD manufacturer." (Source: libusb docs)
func (*Device) SerialNumber ¶
SerialNumber reads the device serial number through an explicit device open.
type DeviceHandle ¶
type DeviceHandle struct {
// contains filtered or unexported fields
}
DeviceHandle represents the libusb device handle.
func (*DeviceHandle) AttachKernelDriver ¶
func (dh *DeviceHandle) AttachKernelDriver(interfaceNum int) error
AttachKernelDriver implements libusb_attach_kernel_driver to re-attach an interface's kernel driver, which was previously detached using libusb_detach_kernel_driver().
func (*DeviceHandle) BulkTransfer ¶
func (dh *DeviceHandle) BulkTransfer( endpoint EndpointAddress, data []byte, length int, timeout int, ) (int, error)
BulkTransfer implements libusb_bulk_transfer to perform a USB bulk transfer.
func (*DeviceHandle) BulkTransferIn ¶
func (dh *DeviceHandle) BulkTransferIn( endpoint EndpointAddress, maxReceiveBytes int, timeout int, ) ([]byte, int, error)
BulkTransferIn is a helper method that performs a USB bulk input transfer.
func (*DeviceHandle) BulkTransferOut ¶
func (dh *DeviceHandle) BulkTransferOut( endpoint EndpointAddress, data []byte, timeout int, ) (int, error)
BulkTransferOut is a helper method that performs a USB bulk output transfer.
func (*DeviceHandle) ClaimInterface ¶
func (dh *DeviceHandle) ClaimInterface(interfaceNum int) error
ClaimInterface implements libusb_claim_interface to claim an interface on a given device handle. You must claim the interface you wish to use before you can perform I/O on any of its endpoints.
func (*DeviceHandle) ClearHalt ¶
func (dh *DeviceHandle) ClearHalt(endpoint EndpointAddress) error
ClearHalt clears a halt/stall condition for the given endpoint.
func (*DeviceHandle) Close ¶
func (dh *DeviceHandle) Close() error
Close implements libusb_close to close the device handle.
func (*DeviceHandle) Configuration ¶
func (dh *DeviceHandle) Configuration() (int, error)
Configuration implements the libusb_get_configuration function to determine the bConfigurationValue of the currently active configuration.
func (*DeviceHandle) ControlIn ¶
func (dh *DeviceHandle) ControlIn( reqType RequestType, recipient RequestRecipient, request byte, value uint16, index uint16, data []byte, maxReceiveLength int, timeout int, ) (int, error)
ControlIn is a helper method for control IN transfers (device to host)
func (*DeviceHandle) ControlOut ¶
func (dh *DeviceHandle) ControlOut( reqType RequestType, recipient RequestRecipient, request byte, value uint16, index uint16, data []byte, timeout int, ) (int, error)
ControlOut is a helper method for control OUT transfers (host to device)
func (*DeviceHandle) ControlTransfer ¶
func (dh *DeviceHandle) ControlTransfer( requestType byte, request byte, value uint16, index uint16, data []byte, length int, timeout int, ) (int, error)
ControlTransfer sends a transfer using a control endpoint for the given device handle.
func (*DeviceHandle) ControlTransferWithTypes ¶
func (dh *DeviceHandle) ControlTransferWithTypes( direction TransferDirection, reqType RequestType, recipient RequestRecipient, request byte, value uint16, index uint16, data []byte, length int, timeout int, ) (int, error)
ControlTransferWithTypes is a more type-safe version of ControlTransfer that accepts TransferDirection, RequestType, and RequestRecipient components to build the bmRequestType. This allows for more readable and maintainable code when using constant values.
func (*DeviceHandle) DetachKernelDriver ¶
func (dh *DeviceHandle) DetachKernelDriver(interfaceNum int) error
DetachKernelDriver implements libusb_detach_kernel_driver to detach a kernel driver from an interface.
func (*DeviceHandle) Device ¶
func (dh *DeviceHandle) Device() (*Device, error)
Device implements libusb_get_device to get the underlying device for a handle.
func (*DeviceHandle) InterruptTransfer ¶
func (dh *DeviceHandle) InterruptTransfer( endpoint EndpointAddress, data []byte, length int, timeout int, ) (int, error)
InterruptTransfer performs a USB interrupt transfer.
func (*DeviceHandle) KernelDriverActive ¶
func (dh *DeviceHandle) KernelDriverActive(interfaceNum int) (bool, error)
KernelDriverActive implements libusb_kernel_driver_active to determine if a kernel driver is active on an interface.
func (*DeviceHandle) NewBulkTransfer ¶
func (dh *DeviceHandle) NewBulkTransfer( endpoint EndpointAddress, data []byte, length int, timeout int, callback TransferCallback, ) (*Transfer, error)
NewBulkTransfer creates a bulk transfer that can later be submitted.
func (*DeviceHandle) NewBulkTransferIn ¶
func (dh *DeviceHandle) NewBulkTransferIn( endpoint EndpointAddress, maxReceiveBytes int, timeout int, callback TransferCallback, ) (*Transfer, error)
NewBulkTransferIn creates a bulk IN transfer with a preallocated receive buffer.
func (*DeviceHandle) NewBulkTransferOut ¶
func (dh *DeviceHandle) NewBulkTransferOut( endpoint EndpointAddress, data []byte, timeout int, callback TransferCallback, ) (*Transfer, error)
NewBulkTransferOut creates a bulk OUT transfer.
func (*DeviceHandle) NewControlTransfer ¶
func (dh *DeviceHandle) NewControlTransfer( requestType byte, request byte, value uint16, index uint16, data []byte, length int, timeout int, callback TransferCallback, ) (*Transfer, error)
NewControlTransfer creates an asynchronous control transfer.
func (*DeviceHandle) NewInterruptTransfer ¶
func (dh *DeviceHandle) NewInterruptTransfer( endpoint EndpointAddress, data []byte, length int, timeout int, callback TransferCallback, ) (*Transfer, error)
NewInterruptTransfer creates an interrupt transfer.
func (*DeviceHandle) NewInterruptTransferIn ¶
func (dh *DeviceHandle) NewInterruptTransferIn( endpoint EndpointAddress, maxReceiveBytes int, timeout int, callback TransferCallback, ) (*Transfer, error)
NewInterruptTransferIn creates an interrupt IN transfer.
func (*DeviceHandle) NewInterruptTransferOut ¶
func (dh *DeviceHandle) NewInterruptTransferOut( endpoint EndpointAddress, data []byte, timeout int, callback TransferCallback, ) (*Transfer, error)
NewInterruptTransferOut creates an interrupt OUT transfer.
func (*DeviceHandle) ReleaseInterface ¶
func (dh *DeviceHandle) ReleaseInterface(interfaceNum int) error
ReleaseInterface implements libusb_release_interface to release an interface previously claimed with libusb_claim_interface() (i.e., ClaimInterface()).
func (*DeviceHandle) ResetDevice ¶
func (dh *DeviceHandle) ResetDevice() error
ResetDevice implements libusb_reset_device to perform a USB port reset to reinitialize a device.
func (*DeviceHandle) SetAutoDetachKernelDriver ¶
func (dh *DeviceHandle) SetAutoDetachKernelDriver(enable bool) error
SetAutoDetachKernelDriver implements libusb_set_auto_detach_kernel_driver to enable/disable libusb's automatic kernel driver detachment.
func (*DeviceHandle) SetConfiguration ¶
func (dh *DeviceHandle) SetConfiguration(configuration int) error
SetConfiguration implements libusb_set_configuration to set the active configuration for the device.
func (*DeviceHandle) SetInterfaceAltSetting ¶
func (dh *DeviceHandle) SetInterfaceAltSetting( interfaceNum int, alternateSetting int, ) error
SetInterfaceAltSetting activates an alternate setting for an interface.
func (*DeviceHandle) StringDescriptor ¶
func (dh *DeviceHandle) StringDescriptor( descIndex uint8, langID uint16, ) (string, error)
StringDescriptor retrieves a descriptor from a device.
func (*DeviceHandle) StringDescriptorASCII ¶
func (dh *DeviceHandle) StringDescriptorASCII( descIndex uint8, ) (string, error)
StringDescriptorASCII retrieve(s) a string descriptor in C style ASCII. Wrapper around libusb_get_string_descriptor(). Uses the first language supported by the device. (Source: libusb docs)
type DeviceIdentity ¶
type DeviceIdentity struct {
VendorID uint16
ProductID uint16
BusNumber int
DeviceAddress int
PortNumbers []int
PortNumber int
Speed SpeedType
}
DeviceIdentity is a stable device snapshot suitable for hotplug and export tracking.
func (DeviceIdentity) BusID ¶
func (id DeviceIdentity) BusID() string
BusID formats the identity into the standard USB/IP busid form.
type Endpoint ¶
type Endpoint struct {
}
Endpoint doesn't seem to model anything. Did I replace this with EndpointDescriptor?
type EndpointAddress ¶
type EndpointAddress byte
EndpointAddress identifies a USB endpoint, including its direction bit.
func (EndpointAddress) Byte ¶
func (address EndpointAddress) Byte() byte
Byte returns the raw endpoint address byte.
func (EndpointAddress) Direction ¶
func (address EndpointAddress) Direction() EndpointDirection
Direction returns the endpoint direction encoded in the address byte.
func (EndpointAddress) IsIn ¶
func (address EndpointAddress) IsIn() bool
IsIn reports whether this is a device-to-host endpoint.
func (EndpointAddress) IsOut ¶
func (address EndpointAddress) IsOut() bool
IsOut reports whether this is a host-to-device endpoint.
func (EndpointAddress) Number ¶
func (address EndpointAddress) Number() byte
Number returns the endpoint number encoded in bits 0..3.
type EndpointDescriptor ¶
type EndpointDescriptor struct {
Length int
DescriptorType descriptorType
EndpointAddress EndpointAddress
Attributes endpointAttributes
MaxPacketSize uint16
Interval uint8
Refresh uint8
SynchAddress uint8
}
EndpointDescriptor models the descriptor for a given endpoint.
func (*EndpointDescriptor) Direction ¶
func (end *EndpointDescriptor) Direction() EndpointDirection
Direction returns the endpointDirection.
func (*EndpointDescriptor) Number ¶
func (end *EndpointDescriptor) Number() byte
Number returns the endpoint number in bits 0..3 in the endpoint address.
func (*EndpointDescriptor) TransferType ¶
func (end *EndpointDescriptor) TransferType() TransferType
TransferType returns the transfer type for an endpoint.
type EndpointDescriptors ¶
type EndpointDescriptors []*EndpointDescriptor
EndpointDescriptors contains the available endpoint descriptors.
type EndpointDirection ¶
type EndpointDirection byte
EndpointDirection provides the type for an in or out endpoint.
func (EndpointDirection) String ¶
func (endpointDirection EndpointDirection) String() string
String implements the Stringer interface for endpointDirection.
type ErrorCode ¶
type ErrorCode int
ErrorCode is the type for the libusb_error C enum.
type HotPlugCbFunc ¶
type HotPlugCbFunc func(event HotPlugEvent)
HotPlugCbFunc is the callback function signature for hotplug events.
type HotPlugEvent ¶
type HotPlugEvent struct {
VendorID uint16
ProductID uint16
Event HotPlugEventType
Identity DeviceIdentity
}
HotPlugEvent is the structured hotplug callback payload.
type HotPlugEventType ¶
type HotPlugEventType uint8
HotPlugEventType represents the type of hotplug event.
const ( HotplugUndefined HotPlugEventType = iota HotplugArrived HotplugLeft )
HotPlug Event Types
type HotplugCallbackStorage ¶
type HotplugCallbackStorage struct {
// contains filtered or unexported fields
}
HotplugCallbackStorage holds the callback map for a single context.
type InterfaceDescriptor ¶
type InterfaceDescriptor struct {
Length int
DescriptorType descriptorType
InterfaceNumber int
AlternateSetting int
NumEndpoints int
InterfaceClass uint8
InterfaceSubClass uint8
InterfaceProtocol uint8
InterfaceIndex int
EndpointDescriptors
}
InterfaceDescriptor "provides information about a function or feature that a device implements." (Source: *USB Complete* 5th edition by Jan Axelson)
type InterfaceDescriptors ¶
type InterfaceDescriptors []*InterfaceDescriptor
InterfaceDescriptors contains a slice of pointers to the available interface descriptors.
func (InterfaceDescriptors) GetInterfacesByClass ¶
func (ifaces InterfaceDescriptors) GetInterfacesByClass(class uint8) InterfaceDescriptors
GetInterfacesByClass returns all interface descriptors that match the given USB class code. This is particularly useful for devices that report bDeviceClass as LIBUSB_CLASS_PER_INTERFACE (0), where individual interfaces have their own class codes.
type LogLevel ¶
type LogLevel int
LogLevel is an enum for the C libusb log message levels.
const ( LogLevelNone LogLevel = C.LIBUSB_LOG_LEVEL_NONE LogLevelError LogLevel = C.LIBUSB_LOG_LEVEL_ERROR LogLevelWarning LogLevel = C.LIBUSB_LOG_LEVEL_WARNING LogLevelInfo LogLevel = C.LIBUSB_LOG_LEVEL_INFO LogLevelDebug LogLevel = C.LIBUSB_LOG_LEVEL_DEBUG )
Log message levels
type RequestRecipient ¶
type RequestRecipient byte
RequestRecipient represents the recipient of a control request.
const ( DeviceRecipient RequestRecipient = C.LIBUSB_RECIPIENT_DEVICE InterfaceRecipient RequestRecipient = C.LIBUSB_RECIPIENT_INTERFACE EndpointRecipient RequestRecipient = C.LIBUSB_RECIPIENT_ENDPOINT OtherRecipient RequestRecipient = C.LIBUSB_RECIPIENT_OTHER )
Constants representing the libusb recipient types.
func (RequestRecipient) String ¶
func (r RequestRecipient) String() string
type RequestType ¶
type RequestType byte
RequestType represents the type of control request.
const ( Standard RequestType = C.LIBUSB_REQUEST_TYPE_STANDARD Class RequestType = C.LIBUSB_REQUEST_TYPE_CLASS Vendor RequestType = C.LIBUSB_REQUEST_TYPE_VENDOR Reserved RequestType = C.LIBUSB_REQUEST_TYPE_RESERVED )
Constants representing the libusb request types.
func (RequestType) String ¶
func (rt RequestType) String() string
type SupportedInterface ¶
type SupportedInterface struct {
InterfaceDescriptors
NumAltSettings int
}
SupportedInterface models an supported USB interface and its associated interface descriptors.
type SupportedInterfaces ¶
type SupportedInterfaces []*SupportedInterface
SupportedInterfaces contains an array of the supported USB interfaces for a given USB device.
func (SupportedInterfaces) GetAllInterfacesByClass ¶
func (si SupportedInterfaces) GetAllInterfacesByClass(class uint8) InterfaceDescriptors
GetAllInterfacesByClass searches through all supported interfaces and their interface descriptors to find all interfaces matching the given class code. This is especially useful for printer devices (InterfaceClassPrinter) and other specialized devices.
type Transfer ¶
type Transfer struct {
TransferType TransferType
Endpoint EndpointAddress
Buffer []byte
RequestedLength int
ActualLength int
Status TransferStatus
UserData any
// contains filtered or unexported fields
}
Transfer is the asynchronous libusb transfer wrapper.
type TransferCallback ¶
type TransferCallback func(*Transfer)
TransferCallback receives transfer completion notifications.
type TransferDirection ¶
type TransferDirection byte
TransferDirection represents the direction of a control transfer.
const ( HostToDevice TransferDirection = 0x00 DeviceToHost TransferDirection = 0x80 )
Constants to set the transfer direction.
func (TransferDirection) String ¶
func (dir TransferDirection) String() string
String implements the Stringer interface for TransferDirection.
type TransferFlag ¶
type TransferFlag uint8
TransferFlag controls optional libusb transfer behaviors.
const ( TransferShortNotOK TransferFlag = C.LIBUSB_TRANSFER_SHORT_NOT_OK TransferAddZeroPacket TransferFlag = C.LIBUSB_TRANSFER_ADD_ZERO_PACKET )
type TransferStatus ¶
type TransferStatus int
TransferStatus mirrors libusb transfer completion states.
const ( TransferCompleted TransferStatus = C.LIBUSB_TRANSFER_COMPLETED TransferError TransferStatus = C.LIBUSB_TRANSFER_ERROR TransferTimedOut TransferStatus = C.LIBUSB_TRANSFER_TIMED_OUT TransferCanceled TransferStatus = C.LIBUSB_TRANSFER_CANCELLED TransferStall TransferStatus = C.LIBUSB_TRANSFER_STALL TransferNoDevice TransferStatus = C.LIBUSB_TRANSFER_NO_DEVICE TransferOverflow TransferStatus = C.LIBUSB_TRANSFER_OVERFLOW )
Transfer completion states.
func (TransferStatus) ErrorCode ¶
func (status TransferStatus) ErrorCode() error
ErrorCode returns the terminal error value associated with the transfer status. Completed transfers return nil.
func (TransferStatus) String ¶
func (status TransferStatus) String() string
String implements fmt.Stringer for transfer statuses.
type TransferType ¶
type TransferType int
TransferType provides which type of transfer.
const ( ControlTransfer TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL IsochronousTransfer TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS BulkTransfer TransferType = C.LIBUSB_TRANSFER_TYPE_BULK InterruptTransfer TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT )
Endpoint transfer type http://bit.ly/enum_libusb_transfer_type
func (TransferType) String ¶
func (transferType TransferType) String() string