Documentation ¶
Index ¶
- Constants
- Variables
- func ClassToStr(c byte) string
- type ConfigDescriptor
- type Context
- type ControlSetup
- type Device
- func (d *Device) GetActiveConfigDescriptor() (*ConfigDescriptor, error)
- func (d *Device) GetBusNumber() uint8
- func (d *Device) GetConfigDescriptor(config byte) (*ConfigDescriptor, error)
- func (d *Device) GetConfigDescriptorByValue(value byte) (*ConfigDescriptor, error)
- func (d *Device) GetDeviceAddress() uint8
- func (d *Device) GetDeviceDescriptor() (*DeviceDescriptor, error)
- func (d *Device) GetDeviceSpeed() int
- func (d *Device) GetMaxIsoPacketSize(endpoint byte) int
- func (d *Device) GetMaxPacketSize(endpoint byte) int
- func (d *Device) Open() (*DeviceHandle, error)
- func (d *Device) Ref() *Device
- func (d *Device) Unref()
- type DeviceDescriptor
- type DeviceHandle
- func (h *DeviceHandle) AttachKernelDriver(ifaceNum byte) error
- func (h *DeviceHandle) BulkTransfer(endpoint byte, data []byte, timeout int) (actual int, err error)
- func (h *DeviceHandle) ClaimInterface(num byte) error
- func (h *DeviceHandle) ClearHalt(endpoint byte) error
- func (h *DeviceHandle) Close() error
- func (h *DeviceHandle) ControlTransfer(reqType, req byte, value, index uint16, data []byte, timeout int) error
- func (h *DeviceHandle) DetachKernelDriver(ifaceNum byte) error
- func (h *DeviceHandle) Device() *Device
- func (h *DeviceHandle) GetConfiguration() (byte, error)
- func (h *DeviceHandle) GetStringDescriptorASCII(descIndex byte) (string, error)
- func (h *DeviceHandle) InterruptTransfer(endpoint byte, data []byte, timeout int) (actual int, err error)
- func (h *DeviceHandle) KernelDriverActive(ifaceNum byte) (bool, error)
- func (h *DeviceHandle) ReleaseInterface(num byte) error
- func (h *DeviceHandle) Reset() error
- func (h *DeviceHandle) SetConfiguration(c byte) error
- func (h *DeviceHandle) SetInterfaceAltSetting(num int, alternate int) error
- type DeviceList
- type EndpointDescriptor
- type Error
- type Interface
- type InterfaceDescriptor
- type IsoPacketDescriptor
- type Transfer
Constants ¶
const CLASS_APPLICATION = 0xfe
const CLASS_AUDIO = 1
const CLASS_COMM = 2
const CLASS_CONTENT_SECURITY = 0x0d
const CLASS_DATA = 10
const CLASS_DIAGNOSTIC_DEVICE = 0xdc
const CLASS_HID = 3
const CLASS_HUB = 9
const CLASS_IMAGE = 6
const CLASS_MASS_STORAGE = 8
const CLASS_PERSONAL_HEALTHCARE = 0x0f
const CLASS_PER_INTERFACE = 0
Device and/or interface class codes.
const CLASS_PHYSICAL = 5
const CLASS_PRINTER = 7
const CLASS_SMART_CARD = 0x0b
const CLASS_VENDOR_SPEC = 0xff
const CLASS_VIDEO = 0x0e
const CLASS_WIRELESS = 0xe0
const DT_CONFIG = 0x02
const DT_DEVICE = 0x01
Descriptor types as defined by the USB specification.
const DT_ENDPOINT = 0x05
const DT_HID = 0x21
const DT_HUB = 0x29
const DT_INTERFACE = 0x04
const DT_PHYSICAL = 0x23
const DT_REPORT = 0x22
const DT_STRING = 0x03
const ENDPOINT_IN = 0x80
in: device-to-host
const ENDPOINT_OUT = 0x00
out: host-to-device
const ERROR_ACCESS = Error(-3)
const ERROR_BUSY = Error(-6)
const ERROR_INTERRUPTED = Error(-10)
const ERROR_INVALID_PARAM = Error(-2)
const ERROR_IO = Error(-1)
const ERROR_NOT_FOUND = Error(-5)
const ERROR_NOT_SUPPORTED = Error(-12)
const ERROR_NO_DEVICE = Error(-4)
const ERROR_NO_MEM = Error(-11)
const ERROR_OTHER = Error(-99)
const ERROR_OVERFLOW = Error(-8)
const ERROR_PIPE = Error(-9)
const ERROR_TIMEOUT = Error(-7)
const ISO_SYNC_TYPE_ADAPTIVE = 2
const ISO_SYNC_TYPE_ASYNC = 1
const ISO_SYNC_TYPE_NONE = 0
Synchronization types for isochronous endpoints, used in EndpointDescriptor.Attributes, bits 2:3.
const ISO_SYNC_TYPE_SYNC = 3
const ISO_USAGE_TYPE_DATA = 0
Usage types used in EndpointDescriptor.Attributes, bits 4:5.
const ISO_USAGE_TYPE_FEEDBACK = 1
const ISO_USAGE_TYPE_IMPLICIT = 2
const RECIPIENT_DEVICE = 0x00
Recipient bits for the reqType of ControlTransfer(). Values 4 - 31 are reserved.
const RECIPIENT_ENDPOINT = 0x02
const RECIPIENT_INTERFACE = 0x01
const RECIPIENT_OTHER = 0x03
const REQUEST_CLEAR_FEATURE = 0x01
const REQUEST_GET_CONFIGURATION = 0x08
Get the current device configuration value
const REQUEST_GET_DESCRIPTOR = 0x06
Get the specified descriptor
const REQUEST_GET_INTERFACE = 0x0A
Return the selected alternate setting for the specified interface.
const REQUEST_GET_STATUS = 0x00
Standard request types, as defined in table 9-3 of the USB2 specifications
const REQUEST_SET_ADDRESS = 0x05
Set device address for all future accesses
const REQUEST_SET_CONFIGURATION = 0x09
Set device configuration
const REQUEST_SET_DESCRIPTOR = 0x07
Used to update existing descriptors or add new descriptors
const REQUEST_SET_FEATURE = 0x03
Set or enable a specific feature
const REQUEST_SET_INTERFACE = 0x0B
Select an alternate interface for the specified interface
const REQUEST_SYNCH_FRAME = 0x0C
Set then report an endpoint's synchronization frame
const REQUEST_TYPE_CLASS = (0x01 << 5)
const REQUEST_TYPE_RESERVED = (0x03 << 5)
const REQUEST_TYPE_STANDARD = (0x00 << 5)
Request types to use in ControlTransfer().
const REQUEST_TYPE_VENDOR = (0x02 << 5)
const SPEED_FULL = C.LIBUSB_SPEED_FULL
const SPEED_HIGH = C.LIBUSB_SPEED_HIGH
const SPEED_LOW = C.LIBUSB_SPEED_LOW
const SPEED_SUPER = C.LIBUSB_SPEED_SUPER
const SPEED_UNKNOWN = C.LIBUSB_SPEED_UNKNOWN
const SUCCESS = Error(0)
const TRANSFER_CANCELLED = 3
const TRANSFER_COMPLETED = 0
const TRANSFER_ERROR = 1
const TRANSFER_FREE_BUFFER = 1 << 1
const TRANSFER_FREE_TRANSFER = 1 << 2
const TRANSFER_NO_DEVICE = 5
const TRANSFER_OVERFLOW = 6
const TRANSFER_SHORT_NOT_OK = 1 << 0
const TRANSFER_STALL = 4
const TRANSFER_TIMED_OUT = 2
const TRANSFER_TYPE_BULK = 2
const TRANSFER_TYPE_CONTROL = 0
Endpoint transfer types, for bits 0:1 of EndpointDescriptor.Attributes
const TRANSFER_TYPE_INTERRUPT = 3
const TRANSFER_TYPE_ISOCHRONOUS = 1
Variables ¶
var CLASS_names = map[byte]string{
0: "PER_INTERFACE",
1: "AUDIO",
2: "COMM",
3: "HID",
5: "PHYSICAL",
7: "PRINTER",
6: "IMAGE",
8: "MASS_STORAGE",
9: "HUB",
10: "DATA",
0x0b: "SMART_CARD",
0x0d: "CONTENT_SECURITY",
0x0e: "VIDEO",
0x0f: "PERSONAL_HEALTHCARE",
0xdc: "DIAGNOSTIC_DEVICE",
0xe0: "WIRELESS",
0xfe: "APPLICATION",
0xff: "VENDOR_SPEC",
}
Device and/or interface class codes.
var SPEED_names = map[byte]string{ byte(C.LIBUSB_SPEED_UNKNOWN): "UNKNOWN", byte(C.LIBUSB_SPEED_LOW): "LOW", byte(C.LIBUSB_SPEED_FULL): "FULL", byte(C.LIBUSB_SPEED_HIGH): "HIGH", byte(C.LIBUSB_SPEED_SUPER): "SUPER", }
Functions ¶
func ClassToStr ¶
Types ¶
type ConfigDescriptor ¶
type ConfigDescriptor struct { // Size of this descriptor (in bytes) Length byte // Descriptor type. Will have value DT_CONFIG LIBUSB_DT_CONFIG // in this context. DescriptorType byte // Total length of data returned for this configuration TotalLength uint16 // Identifier value for this configuration ConfigurationValue byte // Index of string descriptor describing this configuration ConfigurationIndex byte // Configuration characteristics Attributes byte // Maximum power consumption of the USB device from this bus in this // configuration when the device is fully opreation. Expressed in units // of 2 mA. MaxPower byte // Array of interfaces supported by this configuration. Interfaces []Interface // Extra descriptors. If libusb encounters unknown configuration // descriptors, it will store them here, should you wish to parse them. Extra []byte }
type Context ¶
type Context C.struct_libusb_context
func NewContext ¶
func NewContext() *Context
func (*Context) GetDeviceList ¶
func (c *Context) GetDeviceList() (DeviceList, error)
type ControlSetup ¶
type ControlSetup C.struct_libusb_control_setup
type Device ¶
type Device C.struct_libusb_device
func (*Device) GetActiveConfigDescriptor ¶
func (d *Device) GetActiveConfigDescriptor() (*ConfigDescriptor, error)
func (*Device) GetBusNumber ¶
Get the number of the bus that a device is connected to.
func (*Device) GetConfigDescriptor ¶
func (d *Device) GetConfigDescriptor(config byte) (*ConfigDescriptor, error)
func (*Device) GetConfigDescriptorByValue ¶
func (d *Device) GetConfigDescriptorByValue(value byte) (*ConfigDescriptor, error)
func (*Device) GetDeviceAddress ¶
Get the address of the device on the bus it is connected to.
func (*Device) GetDeviceDescriptor ¶
func (d *Device) GetDeviceDescriptor() (*DeviceDescriptor, error)
func (*Device) GetDeviceSpeed ¶
Get the negotiated connection speed for a device.
func (*Device) GetMaxIsoPacketSize ¶
Calculate the maximum packet size which a specific endpoint is capable is sending or receiving in the duration of 1 microframe.
func (*Device) GetMaxPacketSize ¶
Convenience function to retrieve the MaxPacketSize value for a particular endpoint in the active device configuration.
func (*Device) Open ¶
func (d *Device) Open() (*DeviceHandle, error)
Open a device and obtain a device handle.
type DeviceDescriptor ¶
type DeviceDescriptor struct { // Size of this descriptor (in bytes) Length byte // Descriptor type. DescriptorType byte // USB specification release number in binary-coded decimal. USBRelease uint16 // USB-IF class code for the device. DeviceClass byte // USB-IF subclass code for the device, qualified by the // DeviceClass value. DeviceSubClass byte // USB-IF protocol code for the device, qualified by the // DeviceClass and DeviceSubClass values. DeviceProtocol byte // Maximum packet size for endpoint 0. MaxPacketSize0 byte // USB-IF vendor ID. IdVendor uint16 // USB-IF product ID. IdProduct uint16 // Device release number in binary-coded decimal. Device uint16 // Index of string descriptor describing manufacturer. Manufacturer byte // Index of string descriptor describing product. Product byte // Index of string descriptor containing device serial number. SerialNumber byte // Number of possible configurations. NumConfigurations byte }
DeviceDescriptor is the standard USB device descriptor as documented in section 9.6.1 of the USB 2.0 specification.
type DeviceHandle ¶
type DeviceHandle C.struct_libusb_device_handle
func (*DeviceHandle) AttachKernelDriver ¶
func (h *DeviceHandle) AttachKernelDriver(ifaceNum byte) error
Re-attach an interface's kernel driver, which was previously detached using libusb_detach_kernel_driver().
func (*DeviceHandle) BulkTransfer ¶
func (*DeviceHandle) ClaimInterface ¶
func (h *DeviceHandle) ClaimInterface(num byte) error
Claim an interface on a given device handle.
func (*DeviceHandle) ClearHalt ¶
func (h *DeviceHandle) ClearHalt(endpoint byte) error
Clear an halt/stall for a endpoint.
func (*DeviceHandle) ControlTransfer ¶
func (*DeviceHandle) DetachKernelDriver ¶
func (h *DeviceHandle) DetachKernelDriver(ifaceNum byte) error
Detach a kernel driver from an interface.
func (*DeviceHandle) Device ¶
func (h *DeviceHandle) Device() *Device
Get the underlying device for a handle.
func (*DeviceHandle) GetConfiguration ¶
func (h *DeviceHandle) GetConfiguration() (byte, error)
Determine the ConfigurationValue of the currently active configuration.
func (*DeviceHandle) GetStringDescriptorASCII ¶
func (h *DeviceHandle) GetStringDescriptorASCII(descIndex byte) (string, error)
func (*DeviceHandle) InterruptTransfer ¶
func (*DeviceHandle) KernelDriverActive ¶
func (h *DeviceHandle) KernelDriverActive(ifaceNum byte) (bool, error)
Determine if a kernel driver is active on an interface.
func (*DeviceHandle) ReleaseInterface ¶
func (h *DeviceHandle) ReleaseInterface(num byte) error
Release an interface previously claimed with libusb_claim_interface().
func (*DeviceHandle) Reset ¶
func (h *DeviceHandle) Reset() error
Perform a USB port reset to reinitialize a device.
func (*DeviceHandle) SetConfiguration ¶
func (h *DeviceHandle) SetConfiguration(c byte) error
Set the active configuration for a device. The argument should be a ConfigurationValue, as given in the ConfigDescriptor.
func (*DeviceHandle) SetInterfaceAltSetting ¶
func (h *DeviceHandle) SetInterfaceAltSetting(num int, alternate int) error
Activate an alternate setting for an interface.
type EndpointDescriptor ¶
type EndpointDescriptor struct { // Size of this descriptor (in bytes) Length byte // Descriptor type. Will have value LIBUSB_DT_ENDPOINT in this // context. DescriptorType byte // The address of the endpoint described by this descriptor. Bits 0:3 are // the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction. EndpointAddress byte // Attributes which apply to the endpoint when it is configured using // the ConfigurationValue. Bits 0:1 determine the transfer type and // correspond to libusb_transfer_type. Bits 2:3 are only used for // isochronous endpoints and correspond to libusb_iso_sync_type. // Bits 4:5 are also only used for isochronous endpoints and correspond to // libusb_iso_usage_type. Bits 6:7 are reserved. Attributes byte // Maximum packet size this endpoint is capable of sending/receiving. MaxPacketSize uint16 // Interval for polling endpoint for data transfers. Interval byte // For audio devices only: the rate at which synchronization feedback // is provided. Refresh byte // For audio devices only: the address if the synch endpoint SynchAddress byte // Extra descriptors. If libusb encounters unknown endpoint // descriptors, it will store them here, should you wish to // parse them. Extra []byte }
EndpointDescriptor represents the standard USB endpoint descriptor. This descriptor is documented in section 9.6.3 of the USB 2.0 specification.
func (*EndpointDescriptor) Direction ¶
func (e *EndpointDescriptor) Direction() byte
func (*EndpointDescriptor) Number ¶
func (e *EndpointDescriptor) Number() byte
func (*EndpointDescriptor) String ¶
func (e *EndpointDescriptor) String() string
func (*EndpointDescriptor) TransferType ¶
func (e *EndpointDescriptor) TransferType() byte
type Interface ¶
type Interface struct {
AltSetting []InterfaceDescriptor
}
A collection of alternate settings for a USB interface.
type InterfaceDescriptor ¶
type InterfaceDescriptor struct { // Size of this descriptor (in bytes) Length byte // Descriptor type. Will have value DT_INTERFACE // LIBUSB_DT_INTERFACE in this context. DescriptorType byte // Number of this interface InterfaceNumber byte // Value used to select this alternate setting for this interface AlternateSetting byte // USB-IF class code for this interface. InterfaceClass byte // USB-IF subclass code for this interface, qualified by the // InterfaceClass value InterfaceSubClass byte // USB-IF protocol code for this interface, qualified by the // InterfaceClass and InterfaceSubClass values InterfaceProtocol byte // Index of string descriptor describing this interface InterfaceStringIndex byte // Array of endpoint descriptors. EndPoints []EndpointDescriptor // Extra descriptors. If libusb encounters unknown interface // descriptors, it will store them here, should you wish to // parse them. Extra []byte }
InterfaceDescriptor contains the standard USB interface descriptor, according to section 9.6.5 of the USB 2.0 specification.
type IsoPacketDescriptor ¶
type Transfer ¶
type Transfer C.struct_libusb_transfer