usb

package
v0.0.0-...-cc768dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2019 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Abstraction module for gousb library.

Index

Constants

View Source
const (
	BASE_CONFIGURE = 0x01
	SET_CLEAR_OUT  = 0x08
	CONFIGURE      = 0x10
	READ_EEPROM    = 0x20
	WRITE_EEPROM   = 0x40
	READ_ALL       = 0x80
)

define command opcodes for MCP2200

Variables

This section is empty.

Functions

func NewContext

func NewContext() *gousb.Context

Initializes a new USB context object.

Types

type AltOpts

type AltOpts struct {
	HW_Flow string
	Invert  string
	LEDX    string
	TxTGL   string
	RxTGL   string
}

Represents Config_Alt_Options bitmap.

type AltPins

type AltPins struct {
	SSPND  string
	USBCFG string
	RxLED  string
	TxLED  string
}

Represents Config_Alt_Pins bitmap.

type Data

type Data struct {
	OpCmd       uint8
	EEP_Addr    uint8
	Reserved1   uint8
	EEP_Val     uint8
	IO_Bmap     uint8
	Alt_Pins    uint8
	IO_Default  uint8
	Alt_Opts    uint8
	Baud_Rate_H uint8
	Baud_Rate_L uint8
	IO_Port_Val uint8
}

Represents configuration data from READ_ALL and CONFIGURE opcode commands.

type ID

type ID = gousb.ID

define alias for gousb.ID

type MCP

type MCP struct {
	Context   *gousb.Context
	Device    *gousb.Device
	Conf      *gousb.Config
	Interface *gousb.Interface
	InEP      *gousb.InEndpoint
	OutEP     *gousb.OutEndpoint
	VendID    ID
	ProdID    ID
	*Data
}

MCP struct represents all the data structures to interact with the USB device.

func (*MCP) AutoDetach

func (micro *MCP) AutoDetach()

Enables/disables automatic kernel driver detachment.

func (*MCP) CalcHLBytes

func (micro *MCP) CalcHLBytes(baud string) (high, low uint8)

Calculates high/low byte values.

func (*MCP) ClaimHIDInterface

func (micro *MCP) ClaimHIDInterface() *gousb.Interface

Claims the specified HID interface using a convenience function. The default interface is always #0 alt #0 in the currently active config.

func (*MCP) ConfigCmd

func (micro *MCP) ConfigCmd() int

Sends the CONFIGURE command to MCP2200.

func (*MCP) GetBaudRate

func (micro *MCP) GetBaudRate(high, low uint8) int

Gets baud rate value.

func (*MCP) GetBaudRateIndex

func (micro *MCP) GetBaudRateIndex(input string) int

Returns active baud rate index

func (*MCP) InEndpoint

func (micro *MCP) InEndpoint() *gousb.InEndpoint

Prepares an IN endpoint for transfer.

func (*MCP) NewReqData

func (micro *MCP) NewReqData() []byte

Creates new request data for CONFIGURE command.

func (*MCP) OpenDevice

func (micro *MCP) OpenDevice(VendID, ProdID ID) *gousb.Device

Opens any device with a given VID/PID using a convenience function.

func (*MCP) OutEndpoint

func (micro *MCP) OutEndpoint() *gousb.OutEndpoint

Prepares an OUT endpoint for transfer.

func (*MCP) ParseAltOpts

func (micro *MCP) ParseAltOpts(bitmap uint8) *AltOpts

Parses Alt_Opts bitmap.

func (*MCP) ParseAltPins

func (micro *MCP) ParseAltPins(bitmap uint8) *AltPins

Parses Alt_Pins bitmap.

func (*MCP) ParseResponse

func (micro *MCP) ParseResponse() *Data

Parses READ_ALL command response.

func (*MCP) ReadAllCmd

func (micro *MCP) ReadAllCmd() int

Sends READ_ALL command to MCP2200.

func (*MCP) ReadManufacturer

func (micro *MCP) ReadManufacturer() string

Reads device manufacturer information.

func (*MCP) ReadProduct

func (micro *MCP) ReadProduct() string

Reads device's product name.

func (*MCP) ReadSerial

func (micro *MCP) ReadSerial() string

Reads device's serial number.

func (*MCP) Reload

func (micro *MCP) Reload() bool

Reload performs a USB port reset to reinitialize a device.

func (*MCP) SelectConfig

func (micro *MCP) SelectConfig() *gousb.Config

Select the device configuration number 0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL