firmware  v0.1.2
Chromation Spectrometer Dev-Kit
Typedefs | Enumerations | Functions | Variables
Usb.h File Reference

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.

Typedefs

typedef uint8_t volatile *const usb_reg
 
typedef uint8_t const usb_pin
 

Enumerations

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 }
 

Functions

void _FtClockDatabus (uint8_t direction)
 
void _FtReadDatabus (uint8_t *pbyte)
 
void _FtWriteDatabus (uint8_t byte)
 
void _FtDatabusPinDirection (uint8_t pin_direction)
 
void FtSelectFT221X (void)
 
void FtUnselectFT221X (void)
 
void FtBusTurnaround (void)
 
bool FtIsOk (void)
 
void FtRead (uint8_t *pbyte)
 
void FtWrite (uint8_t byte)
 
bool UsbRxbufferIsEmpty (void)
 
bool UsbTxbufferIsFull (void)
 
uint8_t UsbReadByte (uint8_t *pbyte)
 
uint8_t UsbWriteByte (uint8_t byte)
 

Variables

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
 

Detailed Description

usb-bridge communicates over USB via FTDI USB Bridge IC FT221X

Flow from USB host to usb-bridge microcontroller:

Flow from usb-bridge microcontroller to USB host:

Definition in file Usb.h.

Function Documentation

◆ _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()

bool FtIsOk ( void  )
inline

The FT221X indicates data transfer status on Pin MISO while FT1248 communication is active.
LOW on pin MISO means FT221X status is OK.

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:

  • drives FtChipSelect LOW

Definition at line 118 of file Usb.h.

◆ FtUnselectFT221X()

void FtUnselectFT221X ( void  )
inline

FtUnselectFT221X behavior:

  • drives FtChipSelect HIGH

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.