Documentation
¶
Overview ¶
Package d2xx is a cgo wrapper for the FTDI d2xx drive.
The supported devices (ft232h/ft232r) implement support for various protocols like the GPIO, I²C, SPI, UART, JTAG.
More details ¶
See https://periph.io/device/ftdi/ for more details, and how to configure the host to be able to use this driver.
Datasheets ¶
http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232R.pdf
http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232H.pdf
Example ¶
package main import ( "fmt" "log" "github.com/zrnsm/extra/hostextra/d2xx" "periph.io/x/periph/host" ) func main() { if _, err := host.Init(); err != nil { log.Fatal(err) } for _, d := range d2xx.All() { fmt.Printf("%s\n", d) } }
Output:
Index ¶
- func Version() (uint8, uint8, uint8)
- type Dev
- type FT232H
- func (f *FT232H) CBus(direction, value byte) error
- func (f *FT232H) CBusRead() (byte, error)
- func (f *FT232H) Close() error
- func (f *FT232H) DBus(direction, value byte) error
- func (f *FT232H) DBusRead() (byte, error)
- func (f *FT232H) EEPROM(ee *ftdi.EEPROM) error
- func (f *FT232H) EraseEEPROM() error
- func (f *FT232H) Halt() error
- func (f *FT232H) Header() []gpio.PinIO
- func (f *FT232H) I2C(pull gpio.Pull) (i2c.BusCloser, error)
- func (f *FT232H) Info(i *Info)
- func (f *FT232H) Reset() error
- func (f *FT232H) SPI() (spi.PortCloser, error)
- func (f *FT232H) SetSpeed(freq physic.Frequency) error
- func (f *FT232H) String() string
- func (f *FT232H) UserArea() ([]byte, error)
- func (f *FT232H) WriteEEPROM(ee *ftdi.EEPROM) error
- func (f *FT232H) WriteUserArea(ua []byte) error
- type FT232R
- func (f *FT232R) Close() error
- func (f *FT232R) EEPROM(ee *ftdi.EEPROM) error
- func (f *FT232R) EraseEEPROM() error
- func (f *FT232R) Halt() error
- func (f *FT232R) Header() []gpio.PinIO
- func (f *FT232R) Info(i *Info)
- func (f *FT232R) Reset() error
- func (f *FT232R) SPI() (spi.PortCloser, error)
- func (f *FT232R) SetDBusMask(mask uint8) error
- func (f *FT232R) SetSpeed(freq physic.Frequency) error
- func (f *FT232R) String() string
- func (f *FT232R) Tx(w, r []byte) error
- func (f *FT232R) UserArea() ([]byte, error)
- func (f *FT232R) WriteEEPROM(ee *ftdi.EEPROM) error
- func (f *FT232R) WriteUserArea(ua []byte) error
- type Info
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Version ¶
Version returns the version number of the D2xx driver currently used.
Example ¶
package main import ( "fmt" "github.com/zrnsm/extra/hostextra/d2xx" ) func main() { // Print the d2xx driver version. It will be 0.0.0 if not found. major, minor, build := d2xx.Version() fmt.Printf("Using library %d.%d.%d\n", major, minor, build) }
Output:
Types ¶
type Dev ¶
type Dev interface { // conn.Resource String() string Halt() error // Info returns information about an opened device. Info(i *Info) // Header returns the GPIO pins exposed on the chip. Header() []gpio.PinIO // SetSpeed sets the base clock for all I/O transactions. // // The device defaults to its fastest speed. SetSpeed(f physic.Frequency) error // EEPROM returns the EEPROM content. EEPROM(ee *ftdi.EEPROM) error // WriteEEPROM updates the EEPROM. Must be used carefully. WriteEEPROM(ee *ftdi.EEPROM) error // EraseEEPROM erases the EEPROM. Must be used carefully. EraseEEPROM() error // UserArea reads and return the EEPROM part that can be used to stored user // defined values. UserArea() ([]byte, error) // WriteUserArea updates the user area in the EEPROM. // // If the length of ua is less than the available space, is it zero extended. WriteUserArea(ua []byte) error }
Dev represents one FTDI device.
There can be multiple FTDI devices connected to a host.
The device may also export one or multiple of I²C, SPI buses. You need to either cast into the right hardware, but more simply use the i2creg / spireg bus/port registries.
type FT232H ¶
type FT232H struct { D0 gpio.PinIO // Clock output D1 gpio.PinIO // Data out D2 gpio.PinIO // Data in D3 gpio.PinIO // Chip select D4 gpio.PinIO D5 gpio.PinIO D6 gpio.PinIO D7 gpio.PinIO C0 gpio.PinIO C1 gpio.PinIO C2 gpio.PinIO C3 gpio.PinIO C4 gpio.PinIO C5 gpio.PinIO C6 gpio.PinIO C7 gpio.PinIO C8 gpio.PinIO // Not implemented C9 gpio.PinIO // Not implemented // contains filtered or unexported fields }
FT232H represents a FT232H device.
It implements Dev.
The FT232H has 1024 bytes output buffer and 1024 bytes input buffer. It supports 512 bytes USB packets.
The device can be used in a few different modes, two modes are supported:
- D0~D3 as a serial protocol (MPSEE), supporting I²C and SPI (and eventually UART), In this mode, D4~D7 and C0~C7 can be used as synchronized GPIO.
- D0~D7 as a synchronous 8 bits bit-bang port. In this mode, only a few pins on CBus are usable in slow mode.
Each group of pins D0~D7 and C0~C7 can be changed at once in one pass via DBus() or CBus().
This enables usage as an 8 bit parallel port.
Pins C8 and C9 can only be used in 'slow' mode via EEPROM and are currently not implemented.
Datasheet ¶
http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232H.pdf
func (*FT232H) CBus ¶
CBus sets the values of C0 to C7 in the specified direction and value.
0 direction means input, 1 means output.
func (*FT232H) DBus ¶
DBus sets the values of D0 to d7 in the specified direction and value.
0 direction means input, 1 means output.
This function must be used to set Clock idle level.
func (*FT232H) EraseEEPROM ¶
func (f *FT232H) EraseEEPROM() error
func (*FT232H) Halt ¶
func (f *FT232H) Halt() error
Halt implements conn.Resource.
This halts all operations going through this device.
func (*FT232H) I2C ¶
I2C returns an I²C bus over the AD bus.
pull can be either gpio.PullUp or gpio.Float. The recommended pull up resistors are 10kΩ for 100kHz and 2kΩ for 400kHz when using Float. The GPIO's pull up is 75kΩ, which may require using a lower speed for signal reliability. Optimal pull up resistor calculation depends on the capacitance.
It uses D0, D1 and D2.
D0 is SCL. It must to be pulled up externally.
D1 and D2 are used for SDA. D1 is the output using open drain, D2 is the input. D1 and D2 must be wired together and must be pulled up externally.
It is recommended to set the mode to ‘245 FIFO’ in the EEPROM of the FT232H.
The FIFO mode is recommended because it allows the ADbus lines to start as tristate. If the chip starts in the default UART mode, then the ADbus lines will be in the default UART idle states until the application opens the port and configures it as MPSSE. Care should also be taken that the RD# input on ACBUS is not asserted in this initial state as this can cause the FIFO lines to drive out.
func (*FT232H) Info ¶
func (f *FT232H) Info(i *Info)
Info returns information about an opened device.
func (*FT232H) SPI ¶
func (f *FT232H) SPI() (spi.PortCloser, error)
SPI returns a SPI port over the AD bus.
It uses D0, D1, D2 and D3. D0 is the clock, D1 the output (MOSI), D2 is the input (MISO) and D3 is CS line.
func (*FT232H) WriteEEPROM ¶
func (*FT232H) WriteUserArea ¶
type FT232R ¶
type FT232R struct { // Pin and their alias to the Dn pins for user convenience. Each pair points // to the exact same pin. D0, TX gpio.PinIO // Transmit; SPI_MOSI D1, RX gpio.PinIO // Receive; SPI_MISO D2, RTS gpio.PinIO // Request To Send Control Output / Handshake signal; SPI_CLK D3, CTS gpio.PinIO // Clear to Send Control input / Handshake signal; SPI_CS D4, DTR gpio.PinIO // Data Terminal Ready Control Output / Handshake signal D5, DSR gpio.PinIO // Data Set Ready Control Input / Handshake signal D6, DCD gpio.PinIO // Data Carrier Detect Control input D7, RI gpio.PinIO // Ring Indicator Control Input. When remote wake up is enabled in the internal EEPROM taking RI# low can be used to resume the PC USB host controller from suspend. // The CBus pins are slower to use, but can drive an high load, like a LED. C0 gpio.PinIO C1 gpio.PinIO C2 gpio.PinIO C3 gpio.PinIO // contains filtered or unexported fields }
FT232R represents a FT232RL/FT232RQ device.
It implements Dev.
Not all pins may be physically connected on the header!
Adafruit's version only has the following pins connected: RX, TX, RTS and CTS.
SparkFun's version exports all pins *except* (inexplicably) the CBus ones.
The FT232R has 128 bytes output buffer and 256 bytes input buffer.
Pin C4 can only be used in 'slow' mode via EEPROM and is currently not implemented.
Datasheet ¶
http://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT232R.pdf
func (*FT232R) EraseEEPROM ¶
func (f *FT232R) EraseEEPROM() error
func (*FT232R) Halt ¶
func (f *FT232R) Halt() error
Halt implements conn.Resource.
This halts all operations going through this device.
func (*FT232R) Info ¶
func (f *FT232R) Info(i *Info)
Info returns information about an opened device.
func (*FT232R) SPI ¶
func (f *FT232R) SPI() (spi.PortCloser, error)
SPI returns a SPI port over the first 4 pins.
It uses D0(TX), D1(RX), D2(RTS) and D3(CTS). D2(RTS) is the clock, D0(TX) the output (MOSI), D1(RX) is the input (MISO) and D3(CTS) is CS line.
func (*FT232R) SetDBusMask ¶
SetDBusMask sets all D0~D7 input or output mode at once.
mask is the input/output pins to use. A bit value of 0 sets the corresponding pin to an input, a bit value of 1 sets the corresponding pin to an output.
It should be called before calling Tx().
func (*FT232R) Tx ¶
Tx does synchronized read-then-write on all the D0~D7 GPIOs.
SetSpeed() determines the pace at which the I/O is done.
SetDBusMask() determines which bits are interpreted in the w and r byte slice. w has its significant value masked by 'mask' and r has its significant value masked by '^mask'.
Input sample is done *before* updating outputs. So r[0] is sampled before w[0] is used. The last w byte should be duplicated if an addition read is desired.
On the Adafruit cable, only the first 4 bits D0(TX), D1(RX), D2(RTS) and D3(CTS) are connected. This is just enough to create a full duplex SPI bus!
func (*FT232R) WriteEEPROM ¶
func (*FT232R) WriteUserArea ¶
type Info ¶
type Info struct { // Opened is true if the device was successfully opened. Opened bool // Type is the FTDI device type. // // The value can be "FT232H", "FT232R", etc. // // An empty string means the type is unknown. Type string // VenID is the vendor ID from the USB descriptor information. It is expected // to be 0x0403 (FTDI). VenID uint16 // DevID is the product ID from the USB descriptor information. It is // expected to be one of 0x6001, 0x6006, 0x6010, 0x6014. DevID uint16 }
Info is the information gathered about the connected FTDI device.
The data is gathered from the USB descriptor.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package d2xxsmoketest is leveraged by extra-smoketest to verify that a FT232H/FT232R is working as expectd.
|
Package d2xxsmoketest is leveraged by extra-smoketest to verify that a FT232H/FT232R is working as expectd. |
Package ftdi constains the low level common FTDI device information independent of the driver used, mostly EEPROM definitions.
|
Package ftdi constains the low level common FTDI device information independent of the driver used, mostly EEPROM definitions. |