Documentation ¶
Overview ¶
Package ftdi implements support for popular FTDI devices.
The supported devices (FT232h/FT232r) implement support for various protocols like the GPIO, I²C, SPI, UART, JTAG.
Use build tag periph_host_ftdi_debug to enable verbose debugging.
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 ¶
if _, err := host.Init(); err != nil { log.Fatal(err) } for _, d := range ftdi.All() { fmt.Printf("%s\n", d) }
Output:
Index ¶
- type Dev
- type DevType
- type EEPROM
- type EEPROMFT2232H
- type EEPROMFT232H
- type EEPROMFT232R
- type EEPROMHeader
- type FT232H
- func (f *FT232H) CBus(direction, value byte) error
- func (f *FT232H) CBusRead() (byte, error)
- func (f *FT232H) DBus(direction, value byte) error
- func (f *FT232H) DBusRead() (byte, error)
- func (f *FT232H) EEPROM(ee *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) 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 *EEPROM) error
- func (f *FT232H) WriteUserArea(ua []byte) error
- type FT232R
- func (f *FT232R) EEPROM(ee *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) 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 *EEPROM) error
- func (f *FT232R) WriteUserArea(ua []byte) error
- type FT232hCBusMux
- type FT232rCBusMux
- type Info
- type PinStreamOut
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 *EEPROM) error // WriteEEPROM updates the EEPROM. Must be used carefully. WriteEEPROM(ee *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 DevType ¶
type DevType uint32
DevType is the FTDI device type.
const ( DevTypeFTBM DevType = iota // 0 DevTypeFTAM DevTypeFT100AX DevTypeUnknown // 3 DevTypeFT2232C DevTypeFT232R // 5 DevTypeFT2232H DevTypeFT4232H DevTypeFT232H // 8 DevTypeFTXSeries DevTypeFT4222H0 DevTypeFT4222H1_2 DevTypeFT4222H3 DevTypeFT4222Prog DevTypeFT900 DevTypeFT930 DevTypeFTUMFTPD3A )
func (DevType) EEPROMSize ¶
EEPROMSize returns the size of the EEPROM for this device.
type EEPROM ¶
type EEPROM struct { // Raw is the raw EEPROM content. It excludes the strings. Raw []byte // The following condition must be true: len(Manufacturer) + len(Desc) <= 40. Manufacturer string ManufacturerID string Desc string Serial string }
EEPROM is the unprocessed EEPROM content.
The EEPROM is in 3 parts: the defined struct, the 4 strings and the rest which is used as an 'user area'. The size of the user area depends on the length of the strings. The user area content is not included in this struct.
func (*EEPROM) AsFT2232H ¶
func (e *EEPROM) AsFT2232H() *EEPROMFT2232H
AsFT2232H returns the Raw data aliased as EEPROMFT2232H.
func (*EEPROM) AsFT232H ¶
func (e *EEPROM) AsFT232H() *EEPROMFT232H
AsFT232H returns the Raw data aliased as EEPROMFT232H.
func (*EEPROM) AsFT232R ¶
func (e *EEPROM) AsFT232R() *EEPROMFT232R
AsFT232R returns the Raw data aliased as EEPROMFT232R.
func (*EEPROM) AsHeader ¶
func (e *EEPROM) AsHeader() *EEPROMHeader
type EEPROMFT2232H ¶
type EEPROMFT2232H struct { EEPROMHeader // FT232H specific. ALSlowSlew uint8 // 0x10 bool non-zero if AL pins have slow slew ALSchmittInput uint8 // 0x11 bool non-zero if AL pins are Schmitt input ALDriveCurrent uint8 // 0x12 Valid values are 4mA, 8mA, 12mA, 16mA in 2mA units AHSlowSlew uint8 // 0x13 bool non-zero if AH pins have slow slew AHSchmittInput uint8 // 0x14 bool non-zero if AH pins are Schmitt input AHDriveCurrent uint8 // 0x15 Valid values are 4mA, 8mA, 12mA, 16mA in 2mA units BLSlowSlew uint8 // 0x16 bool non-zero if BL pins have slow slew BLSchmittInput uint8 // 0x17 bool non-zero if BL pins are Schmitt input BLDriveCurrent uint8 // 0x18 Valid values are 4mA, 8mA, 12mA, 16mA in 2mA units BHSlowSlew uint8 // 0x19 bool non-zero if BH pins have slow slew BHSchmittInput uint8 // 0x1A bool non-zero if BH pins are Schmitt input BHDriveCurrent uint8 // 0x1B Valid values are 4mA, 8mA, 12mA, 16mA in 2mA units AIsFifo uint8 // 0x1C bool non-zero if interface is 245 FIFO AIsFifoTar uint8 // 0x1D bool non-zero if interface is 245 FIFO CPU target AIsFastSer uint8 // 0x1E bool non-zero if interface is Fast serial BIsFifo uint8 // 0x1F bool non-zero if interface is 245 FIFO BIsFifoTar uint8 // 0x20 bool non-zero if interface is 245 FIFO CPU target BIsFastSer uint8 // 0x21 bool non-zero if interface is Fast serial PowerSaveEnable uint8 // 0x22 bool non-zero if using BCBUS7 to save power for self-powered designs ADriverType uint8 // 0x23 bool BDriverType uint8 // 0x24 bool Unused2 uint8 // 0x25 Unused3 uint16 // 0x26 }
EEPROMFT2232H is the EEPROM layout of a FT2232H device.
It is 40 bytes long.
type EEPROMFT232H ¶
type EEPROMFT232H struct { EEPROMHeader // FT232H specific. ACSlowSlew uint8 // 0x10 bool Non-zero if AC bus pins have slow slew ACSchmittInput uint8 // 0x11 bool Non-zero if AC bus pins are Schmitt input ACDriveCurrent uint8 // 0x12 Valid values are 4mA, 8mA, 12mA, 16mA in 2mA units ADSlowSlew uint8 // 0x13 bool Non-zero if AD bus pins have slow slew ADSchmittInput uint8 // 0x14 bool Non-zero if AD bus pins are Schmitt input ADDriveCurrent uint8 // 0x15 Valid values are 4mA, 8mA, 12mA, 16mA in 2mA units Cbus0 FT232hCBusMux // 0x16 Cbus1 FT232hCBusMux // 0x17 Cbus2 FT232hCBusMux // 0x18 Cbus3 FT232hCBusMux // 0x19 Cbus4 FT232hCBusMux // 0x1A Cbus5 FT232hCBusMux // 0x1B Cbus6 FT232hCBusMux // 0x1C Cbus7 FT232hCBusMux // 0x1D C7 is limited a sit can only do 'suspend on C7 low'. Defaults pull down. Cbus8 FT232hCBusMux // 0x1E Cbus9 FT232hCBusMux // 0x1F FT1248Cpol uint8 // 0x20 bool FT1248 clock polarity - clock idle high (true) or clock idle low (false) FT1248Lsb uint8 // 0x21 bool FT1248 data is LSB (true), or MSB (false) FT1248FlowControl uint8 // 0x22 bool FT1248 flow control enable IsFifo uint8 // 0x23 bool Non-zero if Interface is 245 FIFO IsFifoTar uint8 // 0x24 bool Non-zero if Interface is 245 FIFO CPU target IsFastSer uint8 // 0x25 bool Non-zero if Interface is Fast serial IsFT1248 uint8 // 0x26 bool Non-zero if Interface is FT1248 PowerSaveEnable uint8 // 0x27 bool Suspect on ACBus7 low. DriverType uint8 // 0x28 bool 0 is D2XX, 1 is VCP Unused2 uint8 // 0x29 Unused3 uint16 // 0x30 }
EEPROMFT232H is the EEPROM layout of a FT232H device.
It is 44 bytes long.
func (*EEPROMFT232H) Defaults ¶
func (e *EEPROMFT232H) Defaults()
type EEPROMFT232R ¶
type EEPROMFT232R struct { EEPROMHeader // FT232R specific. IsHighCurrent uint8 // 0x10 bool High Drive I/Os; 3mA instead of 1mA (@3.3V) UseExtOsc uint8 // 0x11 bool Use external oscillator InvertTXD uint8 // 0x12 bool InvertRXD uint8 // 0x13 bool InvertRTS uint8 // 0x14 bool InvertCTS uint8 // 0x15 bool InvertDTR uint8 // 0x16 bool InvertDSR uint8 // 0x17 bool InvertDCD uint8 // 0x18 bool InvertRI uint8 // 0x19 bool Cbus0 FT232rCBusMux // 0x1A Default ft232rCBusTxLED Cbus1 FT232rCBusMux // 0x1B Default ft232rCBusRxLED Cbus2 FT232rCBusMux // 0x1C Default ft232rCBusTxdEnable Cbus3 FT232rCBusMux // 0x1D Default ft232rCBusPwrEnable Cbus4 FT232rCBusMux // 0x1E Default ft232rCBusSleep DriverType uint8 // 0x1F bool 0 is D2XX, 1 is VCP }
EEPROMFT232R is the EEPROM layout of a FT232R device.
It is 32 bytes long.
func (*EEPROMFT232R) Defaults ¶
func (e *EEPROMFT232R) Defaults()
type EEPROMHeader ¶
type EEPROMHeader struct { DeviceType DevType // 0x00 FTxxxx device type to be programmed VendorID uint16 // 0x04 Defaults to 0x0403; can be changed ProductID uint16 // 0x06 Defaults to 0x6001 for FT232R, 0x6014 for FT232H, relevant value SerNumEnable uint8 // 0x07 bool Non-zero if serial number to be used Unused0 uint8 // 0x08 For alignment. MaxPower uint16 // 0x0A 0mA < MaxPower <= 500mA SelfPowered uint8 // 0x0C bool 0 = bus powered, 1 = self powered RemoteWakeup uint8 // 0x0D bool 0 = not capable, 1 = capable; RI# low will wake host in 20ms. PullDownEnable uint8 // 0x0E bool Non zero if pull down in suspend enabled Unused1 uint8 // 0x0F For alignment. }
EEPROMHeader is the common header found on FTDI devices.
It is 16 bytes long.
type FT232H ¶
type FT232H struct { D0 gpio.PinIO // Clock output D1 PinStreamOut // 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 FT232hCBusMux ¶
type FT232hCBusMux uint8
FT232hCBusMux is stored in the FT232H EEPROM to control each CBus pin.
const ( // TriSt-PU; Sets in Tristate (pull up) (C0~C6, C8, C9) on 75kΩ. FT232hCBusTristatePullUp FT232hCBusMux = 0x00 // TXLED#; Pulses low when transmitting data (C0~C6, C8, C9). FT232hCBusTxLED FT232hCBusMux = 0x01 // RXLED#; Pulses low when receiving data (C0~C6, C8, C9). FT232hCBusRxLED FT232hCBusMux = 0x02 // TX&RXLED#; Pulses low when either receiving or transmitting data (C0~C6, // C8, C9). FT232hCBusTxRxLED FT232hCBusMux = 0x03 // PWREN#; Output is low after the device has been configured by USB, then // high during USB suspend mode (C0~C6, C8, C9). // // Must be used with an external 10kΩ pull up. FT232hCBusPwrEnable FT232hCBusMux = 0x04 // SLEEP#; Goes low during USB suspend mode (C0~C6, C8, C9). FT232hCBusSleep FT232hCBusMux = 0x05 // DRIVE1; Drives pin to logic 0 (C0~C6, C8, C9). FT232hCBusDrive0 FT232hCBusMux = 0x06 // DRIVE1; Drives pin to logic 1 (C0, C5, C6, C8, C9). FT232hCBusDrive1 FT232hCBusMux = 0x07 // I/O Mode; CBus bit-bang mode option (C5, C6, C8, C9). FT232hCBusIOMode FT232hCBusMux = 0x08 // TXDEN; Tx Data Enable. Used with RS485 level converters to enable the line // driver during data transmit. It is active one bit time before the start // bit up to until the end of the stop bit (C0~C6, C8, C9). FT232hCBusTxdEnable FT232hCBusMux = 0x09 // CLK30 30MHz clock output (C0, C5, C6, C8, C9). FT232hCBusClk30 FT232hCBusMux = 0x0A // CLK15 15MHz clock output (C0, C5, C6, C8, C9). FT232hCBusClk15 FT232hCBusMux = 0x0B // CLK7.5 7.5MHz clock output (C0, C5, C6, C8, C9). FT232hCBusClk7_5 FT232hCBusMux = 0x0C )
func (FT232hCBusMux) String ¶
func (f FT232hCBusMux) String() string
type FT232rCBusMux ¶
type FT232rCBusMux uint8
FT232rCBusMux is stored in the FT232R EEPROM to control each CBus pin.
const ( // TXDEN; Tx Data Enable. Used with RS485 level converters to enable the line // driver during data transmit. It is active one bit time before the start // bit up to until the end of the stop bit (C0~C4). FT232rCBusTxdEnable FT232rCBusMux = 0x00 // PWREN#; Output is low after the device has been configured by USB, then // high during USB suspend mode (C0~C4). // // Must be used with an external 10kΩ pull up. FT232rCBusPwrEnable FT232rCBusMux = 0x01 // RXLED#; Pulses low when receiving data (C0~C4). FT232rCBusRxLED FT232rCBusMux = 0x02 // TXLED#; Pulses low when transmitting data (C0~C4). FT232rCBusTxLED FT232rCBusMux = 0x03 // TX&RXLED#; Pulses low when either receiving or transmitting data (C0~C4). FT232rCBusTxRxLED FT232rCBusMux = 0x04 // SLEEP# Goes low during USB suspend mode (C0~C4). FT232rCBusSleep FT232rCBusMux = 0x05 // CLK48 48Mhz +/-0.7% clock output (C0~C4). FT232rCBusClk48 FT232rCBusMux = 0x06 // CLK24 24Mhz clock output (C0~C4). FT232rCBusClk24 FT232rCBusMux = 0x07 // CLK12 12Mhz clock output (C0~C4). FT232rCBusClk12 FT232rCBusMux = 0x08 // CLK6 6Mhz +/-0.7% clock output (C0~C4). FT232rCBusClk6 FT232rCBusMux = 0x09 // CBitBangI/O; CBus bit-bang mode option (C0~C3). FT232rCBusIOMode FT232rCBusMux = 0x0A // BitBangWRn; CBus WR# strobe output (C0~C3). FT232rCBusBitBangWR FT232rCBusMux = 0x0B // BitBangRDn; CBus RD# strobe output (C0~C3). FT232rCBusBitBangRD FT232rCBusMux = 0x0C )
func (FT232rCBusMux) String ¶
func (f FT232rCBusMux) String() string
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.
type PinStreamOut ¶
type PinStreamOut interface { gpio.PinIO // StreamOut defines gpiostream.PinOut. StreamOut(s gpiostream.Stream) error }
PinStreamOut is a gpio pin that supports raw data stream output.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ftdismoketest is leveraged by periph-smoketest to verify that a FT232H/FT232R is working as expectd.
|
Package ftdismoketest is leveraged by periph-smoketest to verify that a FT232H/FT232R is working as expectd. |