usb-bridge
communicates over USB via FTDI USB Bridge IC FT221X
More...
#include <stdint.h>
#include <stdbool.h>
#include "ReadWriteBits.h"
Go to the source code of this file.
|
typedef uint8_t volatile *const | usb_reg |
|
typedef uint8_t const | usb_pin |
|
|
enum | ft_cmd { FtReadCmd =0xC6
, FtWriteCmd =0x86
} |
|
enum | ft_databus_pin_direction { FtIn =0x00
, FtOut =0xFF
} |
|
enum | ft_status { FtError =0
, FtOk =1
} |
|
enum | ft_clock_edge { FtSample =0
, FtDrive =1
} |
|
|
usb_reg | FtCtrl_port |
|
usb_reg | FtCtrl_pin |
|
usb_reg | FtData_pin |
|
usb_reg | FtData_ddr |
|
usb_reg | FtData_port |
|
usb_pin | FtMiso |
|
usb_pin | FtChipSelect |
|
usb_pin | FtClock |
|
usb_pin | FtMiosio0 |
|
usb-bridge
communicates over USB via FTDI USB Bridge IC FT221X
- USB host sees
FT221X
as a USB device
- Two options for host to communicate with this USB device:
- use generic USB serial device driver, e.g.,
pyserial
- use the
D2XX
driver to access the expanded functionality of the FTDI USB API
- The
usb-bridge
microcontroller sees FT221X
as an FT1248 slave
Flow from USB host to usb-bridge
microcontroller:
- USB host writes to
FT221X
- now
FT221X
has data in its receive buffer:
- pin
FT1248 MISO
asserts LOW
- this signals to the
usb-bridge
microcontroller that data is available
usb-bridge
microcontroller reads the data
Flow from usb-bridge
microcontroller to USB host:
- Control lines
FtClock
- the clock idles
LOW
- the clock is only active during FT1248 communication
- Sending a single byte takes three clock cycles
- TODO: multi-byte communication where each additional byte only adds one clock cycle
- Databus pin direction
- databus pins are
FtMiosio0
through FtMiosio7
- the databus is bi-directional
FtRead
: the FT221X drives the databus
FtWrite
the microcontroller drives the databus
- databus pins are usually microcontroller inputs
- microcontroller only outputs to the databus during an
FtWrite
- the microcontroller pins are outputs for the interval
- starting after a clock rising edge
- ending before the next clock rising edge
- TODO: fill this in
Definition in file Usb.h.
◆ _FtClockDatabus()
void _FtClockDatabus |
( |
uint8_t |
direction | ) |
|
|
inline |
FtClockDatabus behavior:
- drives FtClock HIGH if direction is FtDrive
- drives FtClock LOW if direction is FtSample
Definition at line 84 of file Usb.h.
◆ _FtDatabusPinDirection()
void _FtDatabusPinDirection |
( |
uint8_t |
pin_direction | ) |
|
|
inline |
FtDatabusPinDirection behavior:
- makes databus pins outputs if direction is FtOut
- makes databus pins inputs if direction is FtIn
Definition at line 108 of file Usb.h.
◆ _FtReadDatabus()
void _FtReadDatabus |
( |
uint8_t * |
pbyte | ) |
|
|
inline |
FtReadDatabus behavior:
- copies databus pin values to address pbyte
Definition at line 94 of file Usb.h.
◆ _FtWriteDatabus()
void _FtWriteDatabus |
( |
uint8_t |
byte | ) |
|
|
inline |
FtWriteDatabus behavior:
- outputs byte on databus pins
Definition at line 101 of file Usb.h.
◆ FtBusTurnaround()
void FtBusTurnaround |
( |
void |
| ) |
|
|
inline |
FtBusTurnaround behavior:
- clocks one cycle to signal data drive then data sample
Definition at line 136 of file Usb.h.
◆ FtIsOk()
The FT221X indicates data transfer status on Pin MISO
while FT1248 communication is active.
LOW
on pin MISO
means FT221X status is OK.
- See the 8-bit write and 8-bit read timing diagrams:
- See ACK/NAK details in section FT1248: NAK:
Timing diagram and ACK/NAK summary:
- During the
BUS TURNAROUND
after the COMMAND PHASE
- if command is 8-bit read
LOW
indicates receive buffer has data to read
HIGH
indicates receive buffer is empty
- if command is 8-bit write
LOW
indicates transmit buffer has room to write
HIGH
indicates transmit buffer is full
- During the
DATA
phase
- after the clock rising edge
- FT221X outputs an
ACK
or NAK
on MISO
ACK
:
MISO
is LOW
- indicates a successful data transfer
NAK
:
MISO
is HIGH
- indicates a failed data transfer
- after clock falling edge:
- Microcontroller reads
MISO
LOW
indicates ACK
HIGH
indicates NAK
- Data transers fail because of either:
- a buffer full condition on writing data to the FT221X
- a buffer empty condition on reading data from the FT221X
FtIsOk behavior:
- returns true if FtMiso is LOW
- returns false if FtMiso is HIGH
Definition at line 149 of file Usb.h.
◆ FtRead()
void FtRead |
( |
uint8_t * |
pbyte | ) |
|
|
inline |
FtRead behavior:
- clocks one byte out of the FT221X
- stores the byte at address pbyte
Definition at line 197 of file Usb.h.
◆ FtSelectFT221X()
void FtSelectFT221X |
( |
void |
| ) |
|
|
inline |
FtSelectFT221X behavior:
Definition at line 118 of file Usb.h.
◆ FtUnselectFT221X()
void FtUnselectFT221X |
( |
void |
| ) |
|
|
inline |
FtUnselectFT221X behavior:
Definition at line 125 of file Usb.h.
◆ FtWrite()
void FtWrite |
( |
uint8_t |
byte | ) |
|
|
inline |
FtWrite behavior:
- signals to drive data onto the databus
- sets microcontroller databus pins as outputs
- outputs byte on databus pins
- signals FT221X to sample the databus
- sets microcontroller databus pins as inputs
Definition at line 209 of file Usb.h.
◆ UsbReadByte()
uint8_t UsbReadByte |
( |
uint8_t * |
pbyte | ) |
|
|
inline |
UsbReadByte behavior:
- selects the FT221X
- drives databus with read command
- signals FT221X to sample the databus
Definition at line 262 of file Usb.h.
◆ UsbRxbufferIsEmpty()
bool UsbRxbufferIsEmpty |
( |
void |
| ) |
|
|
inline |
UsbRxbufferIsEmpty behavior:
- returns true if pin FT1248 MISO is HIGH
- returns false if pin FT1248 MISO is LOW
Definition at line 237 of file Usb.h.
◆ UsbTxbufferIsFull()
bool UsbTxbufferIsFull |
( |
void |
| ) |
|
|
inline |
UsbTxbufferIsFull behavior:
- returns true if pin MIOSIO0 is HIGH
- returns false if pin MIOSIO0 is LOW
Definition at line 245 of file Usb.h.