ftdi

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Documentation

Overview

Go binding for libFTDI library http://http://www.intra2net.com/en/developer/libftdi/

Index

Constants

View Source
const (
	MPSSEWriteNeg           byte = C.MPSSE_WRITE_NEG
	MPSSEBitMode            byte = C.MPSSE_BITMODE
	MPSSEReadNeg            byte = C.MPSSE_READ_NEG
	MPSSELSB                byte = C.MPSSE_LSB
	MPSSEDoWrite            byte = C.MPSSE_DO_WRITE
	MPSSEDoRead             byte = C.MPSSE_DO_READ
	MPSSEWriteTMS           byte = C.MPSSE_WRITE_TMS
	MPSSESetBitsLow         byte = C.SET_BITS_LOW
	MPSSESetBitsHigh        byte = C.SET_BITS_HIGH
	MPSSEGetBitsLow         byte = C.GET_BITS_LOW
	MPSSELoopbackStart      byte = C.LOOPBACK_START
	MPSSELoopbackEnd        byte = C.LOOPBACK_END
	MPSSETCKDivisor         byte = C.TCK_DIVISOR
	MPSSEDisableDiv5        byte = C.DIS_DIV_5
	MPSSEEnableDiv5         byte = C.EN_DIV_5
	MPSSEEnable3Phase       byte = C.EN_3_PHASE
	MPSSEDisable3Phase      byte = C.DIS_3_PHASE
	MPSSEClockBits          byte = C.CLK_BITS
	MPSSEClockBytes         byte = C.CLK_BYTES
	MPSSEClockWaitHigh      byte = C.CLK_WAIT_HIGH
	MPSSEClockWaitLow       byte = C.CLK_WAIT_LOW
	MPSSEEnableAdaptive     byte = C.EN_ADAPTIVE
	MPSSEDisableAdaptive    byte = C.DIS_ADAPTIVE
	MPSSEClockBytesOrHigh   byte = C.CLK_BYTES_OR_HIGH
	MPSSEClockBytesOrLow    byte = C.CLK_BYTES_OR_LOW
	MPSSEDriveOpenCollector byte = C.DRIVE_OPEN_COLLECTOR
	MPSSESendImmediate      byte = C.SEND_IMMEDIATE
	MPSSEWaitOnHigh         byte = C.WAIT_ON_HIGH
	MPSSEWaitOnLow          byte = C.WAIT_ON_LOW
	MPSSEReadShort          byte = C.READ_SHORT
	MPSSEReadExtended       byte = C.READ_EXTENDED
	MPSSEWriteShort         byte = C.WRITE_SHORT
	MPSSEWriteExtended      byte = C.WRITE_EXTENDED
)

MPSSE commands See https://www.ftdichip.com/Documents/AppNotes/AN_108_Command_Processor_for_MPSSE_and_MCU_Host_Bus_Emulation_Modes.pdf for full details

Variables

This section is empty.

Functions

func MPSSEDivValue

func MPSSEDivValue(rate int, div5 bool) int

MPSSEDivValue calculates the two bytes that are required to be supplied after MPSSETCKDivisor to get the desired clock speed (in Hz). Set the dvi5 flag if MPSSEEnableDiv5 has been sent, to use a 12MHz base clock, instead of 60MHz.

Types

type Break

type Break int

Break represents the break mode

const (
	// BreakOff disables the use of a break signal
	BreakOff Break = C.BREAK_OFF
	// BreakOn enables the use of a break signal
	BreakOn Break = C.BREAK_ON
)

type CBusFunction

type CBusFunction byte
const (
	CBusTxEn CBusFunction = iota
	CBusPwrEn
	CBusRxLED
	CBusTxLED
	CBusTxRxLED
	CBusSleep
	CBusClk48
	CBusClk24
	CBusClk12
	CBusClk6
	CBusIOMode
	CBusBBWR
	CBusBBRD
)

func (CBusFunction) String

func (c CBusFunction) String() string

type Channel

type Channel uint32

Channel represents channel (interface) of FTDI device. Some devices have more than one channel (eg. FT2232 has 2 channels, FT4232 has 4 channels).

const (
	ChannelAny Channel = iota
	ChannelA
	ChannelB
	ChannelC
	ChannelD
)

type ChannelType

type ChannelType byte
const (
	ChannelUART ChannelType = iota
	ChannelFIFO
	ChannelOPTO
	ChannelCPU
	ChannelFT1284
)

func (ChannelType) String

func (ct ChannelType) String() string

type DataBits

type DataBits int

DataBits represents the number of data bits to expect

const (
	// DataBits7 indicates that 7 data bits are used
	DataBits7 DataBits = C.BITS_7
	// DataBits8 indicates that 8 data bits are used
	DataBits8 DataBits = C.BITS_8
)

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents FTDI device.

func Open

func Open(vendor, product int, description, serial string, index uint,
	c Channel) (*Device, error)

Open opens the index-th device with a given vendor id, product id, description and serial. Uses specified channel c.

func OpenBusAddr

func OpenBusAddr(bus, address int, c Channel) (*Device, error)

OpenBusAddr opens the device at a given USB bus and device address. Uses specified channel c.

func OpenFirst

func OpenFirst(vendor, product int, c Channel) (*Device, error)

OpenFirst opens the first device with a given vendor and product ids. Uses specified channel c.

func OpenString

func OpenString(description string, c Channel) (*Device, error)

OpenString opens the ftdi-device described by a description-string. Uses specified channel c.

func OpenUSBDev

func OpenUSBDev(u *USBDev, c Channel) (*Device, error)

OpenUSBDev opens channel (interface) c of USB device u. u must be FTDI device.

func (*Device) ChipID

func (d *Device) ChipID() (uint32, error)

ChipID reads FTDI Chip-ID (not all devices support this).

func (*Device) Close

func (d *Device) Close() error

Close closes device

func (*Device) EEPROM

func (d *Device) EEPROM() EEPROM

func (*Device) LatencyTimer

func (d *Device) LatencyTimer() (int, error)

LatencyTimer returns latency timer value [ms].

func (*Device) Pins

func (d *Device) Pins() (b byte, err error)

Pins returns current state of pins (circumventing the read buffer).

func (*Device) PurgeBuffers

func (d *Device) PurgeBuffers() error

PurgeBuffers clears both (Tx and Rx) buffers.

func (*Device) PurgeReadBuffer

func (d *Device) PurgeReadBuffer() error

PurgeReadBuffer clears Tx buffer (buffer for data that will be sent to USB?).

func (*Device) PurgeWriteBuffer

func (d *Device) PurgeWriteBuffer() error

PurgeWriteBuffer clears Rx buffer (buffer for data received from USB?).

func (*Device) Read

func (d *Device) Read(data []byte) (int, error)

Read reads data from device to data. It returns number of bytes read.

func (*Device) ReadByte

func (d *Device) ReadByte() (byte, error)

ReadByte reads one byte from device.

func (*Device) ReadChunkSize

func (d *Device) ReadChunkSize() (int, error)

ReadChunkSize returns current value of read buffer chunk size.

func (*Device) Reset

func (d *Device) Reset() error

Reset resets device d.

func (*Device) SetBaudrate

func (d *Device) SetBaudrate(br int) error

SetBaudrate sets the rate of data transfer.

For standard USB-UART adapter it sets UART baudrate.

For bitbang mode the clock is actually 16 times the br. From the FTDI documentation for FT232R bitbang mode: "The clock for the Asynchronous Bit Bang mode is actually 16 times the Baud rate. A value of 9600 Baud would transfer the data at (9600x16) = 153600 bytes per second, or 1 every 6.5 μS."

FT232R suports baudrates from 183.1 baud to 3 Mbaud but for real applications it should be <= 1 Mbaud: Actual baudrate is set to discrete value that satisfies the equation br = 3000000 / (n + x) where n can be an integer between 2 and 16384 and x can be a sub-integer of the value 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, or 0.875. When n == 1 then x should be 0, i.e. baud rate divisors with values between 1 and 2 are not possible.

func (*Device) SetBitmode

func (d *Device) SetBitmode(iomask byte, mode Mode) error

SetBitmode sets operation mode for device d to mode. iomask bitmask configures lines corresponding to its bits as input (bit=0) or output (bit=1).

func (*Device) SetDTR

func (d *Device) SetDTR(dtr int) error

SetDTR manually sets the DTR output line from the least significant bit of dtr.

func (*Device) SetDTRRTS

func (d *Device) SetDTRRTS(dtr, rts int) error

SetDTRRTS manually sets the DTR and RTS output lines from the least significant bit of dtr and rts.

func (*Device) SetFlowControl

func (d *Device) SetFlowControl(flowctrl FlowCtrl) error

SetFlowControl sets the flow control parameter

func (*Device) SetLatencyTimer

func (d *Device) SetLatencyTimer(lt int) error

SetLatencyTimer sets latency timer to lt (value beetwen 1 and 255). If FTDI device has fewer data to completely fill one USB packet (<62 B) it waits for lt ms before sending data to USB.

func (*Device) SetLineProperties

func (d *Device) SetLineProperties(bits DataBits, stopbits StopBits, parity Parity) error

SetLineProperties sets the uart data bit count, stop bits count, and parity mode

func (*Device) SetLineProperties2

func (d *Device) SetLineProperties2(bits DataBits, stopbits StopBits, parity Parity, breaks Break) error

SetLineProperties2 sets the uart data bit count, stop bits count, parity mode, and break usage

func (*Device) SetRTS

func (d *Device) SetRTS(rts int) error

SetRTS manually sets the RTS output line from the least significant bit of rts.

func (*Device) SetReadChunkSize

func (d *Device) SetReadChunkSize(cs int) error

SetReadChunkSize configure read chunk size for device (default is 4096B) and size of software buffer dedicated for reading data from device...

func (*Device) SetWriteChunkSize

func (d *Device) SetWriteChunkSize(cs int) error

SetWriteChunkSize configure write chunk size (default is 4096). If more than cs bytes need to be send to device, they will be split to chunks of size cs.

func (*Device) SubmitRead

func (d *Device) SubmitRead(data []byte) (*Transfer, error)

func (*Device) SubmitWrite

func (d *Device) SubmitWrite(data []byte) (*Transfer, error)

func (*Device) Type

func (d *Device) Type() Type

Type returns type of device d.

func (*Device) Write

func (d *Device) Write(data []byte) (int, error)

Write writes data from buf to device. It retruns number of bytes written.

func (*Device) WriteByte

func (d *Device) WriteByte(b byte) error

WriteByte writes one byte to device.

func (*Device) WriteChunkSize

func (d *Device) WriteChunkSize() (int, error)

WriteChunkSize returns current value of write chunk size.

func (*Device) WriteString

func (d *Device) WriteString(s string) (int, error)

WriteString writes bytes from string s to device. It retruns number of bytes written.

type EEPROM

type EEPROM struct {
	// contains filtered or unexported fields
}

func (EEPROM) Build

func (e EEPROM) Build() error

func (EEPROM) CBusFunction

func (e EEPROM) CBusFunction(n int) CBusFunction

func (EEPROM) ChannelDriver

func (e EEPROM) ChannelDriver(c Channel) bool

ChannelDriver returns true if c channel has a driver. c can be from range: ChannelA - ChannelD

func (EEPROM) ChannelRS485

func (e EEPROM) ChannelRS485(c Channel) bool

ChannelDriver returns true if c is RS485 channel. c can be from range: ChannelA - ChannelD

func (EEPROM) ChannelType

func (e EEPROM) ChannelType(c Channel) ChannelType

ChannelType returns type of c channel. c can be: ChannelA, ChannelB

func (EEPROM) ChipSize

func (e EEPROM) ChipSize() int

func (EEPROM) ChipType

func (e EEPROM) ChipType() byte

func (EEPROM) Decode

func (e EEPROM) Decode() error

func (EEPROM) HighCurrent

func (e EEPROM) HighCurrent(c Channel) bool

ChannelDriver returns true if c channel is in high current mode . c can be from range: ChannAny - ChannelD (use ChannAny for TypeR device).

func (EEPROM) Invert

func (e EEPROM) Invert() int

func (EEPROM) IsNotPNP

func (e EEPROM) IsNotPNP() bool

func (EEPROM) IsochronousInp

func (e EEPROM) IsochronousInp() bool

func (EEPROM) IsochronousOut

func (e EEPROM) IsochronousOut() bool

func (EEPROM) ManufacturerString

func (e EEPROM) ManufacturerString() string

func (EEPROM) MaxPower

func (e EEPROM) MaxPower() int

MaxPower returns maximum power consumption (max. current) from USB in mA

func (EEPROM) ProductId

func (e EEPROM) ProductId() uint16

func (EEPROM) ProductString

func (e EEPROM) ProductString() string

func (EEPROM) Read

func (e EEPROM) Read() error

func (EEPROM) ReleaseNumber

func (e EEPROM) ReleaseNumber() uint16

func (EEPROM) RemoteWakeup

func (e EEPROM) RemoteWakeup() bool

func (EEPROM) SelfPowered

func (e EEPROM) SelfPowered() bool

func (EEPROM) SerialString

func (e EEPROM) SerialString() string

func (EEPROM) SetCBusFunction

func (e EEPROM) SetCBusFunction(n int, v CBusFunction)

func (EEPROM) SetChannelDriver

func (e EEPROM) SetChannelDriver(c Channel, v bool)

func (EEPROM) SetChannelRS485

func (e EEPROM) SetChannelRS485(c Channel, v bool)

func (EEPROM) SetChannelType

func (e EEPROM) SetChannelType(c Channel, v ChannelType)

func (EEPROM) SetChipType

func (e EEPROM) SetChipType(v byte)

func (EEPROM) SetHighCurrent

func (e EEPROM) SetHighCurrent(c Channel, v bool)

func (EEPROM) SetInvert

func (e EEPROM) SetInvert(v int)

func (EEPROM) SetIsNotPNP

func (e EEPROM) SetIsNotPNP(v bool)

func (EEPROM) SetIsochronousInp

func (e EEPROM) SetIsochronousInp(v bool)

func (EEPROM) SetIsochronousOut

func (e EEPROM) SetIsochronousOut(v bool)

func (EEPROM) SetManufacturerString

func (e EEPROM) SetManufacturerString(s string)

func (EEPROM) SetMaxPower

func (e EEPROM) SetMaxPower(v int)

SetMaxPower sets maximum power consumption (max. current) from USB in mA

func (EEPROM) SetProductId

func (e EEPROM) SetProductId(v uint16)

func (EEPROM) SetProductString

func (e EEPROM) SetProductString(s string)

func (EEPROM) SetReleaseNumber

func (e EEPROM) SetReleaseNumber(v uint16)

func (EEPROM) SetRemoteWakeup

func (e EEPROM) SetRemoteWakeup(v bool)

func (EEPROM) SetSelfPowered

func (e EEPROM) SetSelfPowered(v bool)

func (EEPROM) SetSerialString

func (e EEPROM) SetSerialString(s string)

func (EEPROM) SetSuspendDBus7

func (e EEPROM) SetSuspendDBus7(v bool)

func (EEPROM) SetSuspendPullDowns

func (e EEPROM) SetSuspendPullDowns(v bool)

func (EEPROM) SetUSBVersion

func (e EEPROM) SetUSBVersion(v uint16)

func (EEPROM) SetUseSerial

func (e EEPROM) SetUseSerial(v bool)

func (EEPROM) SetUseUSBVersion

func (e EEPROM) SetUseUSBVersion(v bool)

func (EEPROM) SetVendorId

func (e EEPROM) SetVendorId(v uint16)

func (EEPROM) String

func (e EEPROM) String() string

func (EEPROM) SuspendDBus7

func (e EEPROM) SuspendDBus7() bool

func (EEPROM) SuspendPullDowns

func (e EEPROM) SuspendPullDowns() bool

func (EEPROM) USBVersion

func (e EEPROM) USBVersion() uint16

func (EEPROM) UseSerial

func (e EEPROM) UseSerial() bool

func (EEPROM) UseUSBVersion

func (e EEPROM) UseUSBVersion() bool

func (EEPROM) VendorId

func (e EEPROM) VendorId() uint16

func (EEPROM) Write

func (e EEPROM) Write() error

type Error

type Error struct {
	// contains filtered or unexported fields
}

func (*Error) Code

func (e *Error) Code() int

func (*Error) Error

func (e *Error) Error() string

type FlowCtrl

type FlowCtrl int
const (
	// FlowCtrlDisable disables all automatic flow control.
	FlowCtrlDisable FlowCtrl = (1 << iota) >> 1
	// FlowCtrlRTSCTS enables RTS CTS flow control.
	FlowCtrlRTSCTS
	// FlowCtrlDTRDSR enables DTR DSR flow control.
	FlowCtrlDTRDSR
	// FlowCtrlXONXOFF enables XON XOF flow control.
	FlowCtrlXONXOFF
)

type Mode

type Mode byte

Mode represents operation mode that FTDI device can work.

const (
	ModeReset Mode = (1 << iota) >> 1
	ModeBitbang
	ModeMPSSE
	ModeSyncBB
	ModeMCU
	ModeOpto
	ModeCBUS
	ModeSyncFF
	ModeFT1284
)

type Parity

type Parity int

Parity represents the parity mode

const (
	// ParityNone indicates no parity bit is used
	ParityNone Parity = C.NONE
	// ParityOdd indicates an odd parity bit is used
	ParityOdd Parity = C.ODD
	// ParityEven indicates an even parity bit is used
	ParityEven Parity = C.EVEN
	// ParityMark indicates that the parity bit should be a 1
	ParityMark Parity = C.MARK
	// ParitySpace indicates that the parity bit should be a 0
	ParitySpace Parity = C.SPACE
)

type StopBits

type StopBits int

StopBits represents the number of stop bits to expect

const (
	// StopBits1 indicates only one stop bit is expected
	StopBits1 StopBits = C.STOP_BIT_1
	// StopBits15 indicates one and a half stop bits are expected
	StopBits15 StopBits = C.STOP_BIT_15
	// StopBits2 indicates two stop bits are expected
	StopBits2 StopBits = C.STOP_BIT_2
)

type Transfer

type Transfer struct {
	// contains filtered or unexported fields
}

func (*Transfer) Done

func (t *Transfer) Done() (int, error)

type Type

type Type uint32

Type is numeric type id of FTDI device.

const (
	TypeAM Type = iota
	TypeBM
	Type2232C
	TypeR
	Type2232H
	Type4232H
	Type232H
	Type230x
)

func (Type) String

func (t Type) String() string

String returns text name that describes type id.

type USBDev

type USBDev struct {
	Manufacturer, Description, Serial string
	// contains filtered or unexported fields
}

func FindAll

func FindAll(vendor, product int) ([]*USBDev, error)

FindAll search for all USB devices with specified vendor and product id. It returns slice od found devices.

func (*USBDev) Close

func (u *USBDev) Close()

type USBError

type USBError int

func (USBError) Error

func (e USBError) Error() string

Directories

Path Synopsis
examples
ftn

Jump to

Keyboard shortcuts

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