MA FTDI utilities  v1.0
 All Data Structures Files Functions Pages
Macros | Functions | Variables
ftdi_api.h File Reference

FTDI APIs. More...

#include <stdio.h>
#include <stdlib.h>
#include "ftd2xx.h"
#include "libMPSSE_spi.h"
Include dependency graph for ftdi_api.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUG   0
 
#define DEBUG_CODE(code)   if ((gp_debug) || (DEBUG)) { code }
 
#define APP_CHECK_STATUS(exp)   {if(exp!=FT_OK){printf("%s:%d:%s(): status(0x%x) \!= FT_OK\n",__FILE__, __LINE__, __FUNCTION__,exp);exit(1);}else{;}};
 
#define CHECK_NULL(exp)   {if(exp==NULL){printf("%s:%d:%s(): NULL expression \encountered \n",__FILE__, __LINE__, __FUNCTION__);exit(1);}else{;}};
 

Functions

int ftdi_init (uint32 clock_rate, uint8 latency, int spi_mode, int cs_pin, int ss_default)
 FTDI interface initialisation. More...
 
int ftdi_kill ()
 FTDI destructor. More...
 
int ftdi_print_channel_info ()
 Prints FTDI channel information. More...
 
int ftdi_open_channel (int channel_id)
 FTDI open channel. More...
 
int ftdi_init_channel ()
 Initialise opened channel. More...
 
int ftdi_close_channel ()
 Closes FTDI channel. More...
 
int ftdi_read_stream (uint8 *buffer, int bytes)
 Read data stream from FTDI. More...
 
int ftdi_write_stream (uint8 *buffer, int bytes)
 Write data stream to FTDI. More...
 
int ftdi_readwrite (uint8 *inbuffer, uint8 *outbuffer, int bytes)
 Write and read data stream simultaneously. More...
 

Variables

int gp_debug
 

Detailed Description

FTDI APIs.

Author
Benjamin Zhai (benja.nosp@m.min..nosp@m.zhai@.nosp@m.sens.nosp@m.ima.c.nosp@m.om)
Version
1.1
Date
20131218 Copyright © 2013-2014 Sensima Technology SA
Company Confidential
Project: MA-FTDI USB
Module: MA sensor communication utility using FTDI USB
Revision History:
0.1 - rev 9 - 20131025 - Initial version
0.2 - rev - 2013xxxx - Updated to use D2XX instead of MPSSE
0.9 - rev 123 - 20131211 - Merged pre-release
1.0 - rev 136 - 20131212 - Release
1.06 - rev 150 - 20131216 - Corrected bitfield write
Todo:

Function Documentation

int ftdi_close_channel ( )

Closes FTDI channel.

This function closes the channel previously opened by ftdi_open_channel() Should always be uses in pairs with ftdi_open_channel() to release unused resources

Parameters
none
Returns
Returns 0 for success Example Usage:
See Also
Note
Warning
int ftdi_init ( uint32  clock_rate,
uint8  latency,
int  spi_mode,
int  cs_pin,
int  ss_default 
)

FTDI interface initialisation.

This function initialises FTDI interface with the following parameters

Parameters
[in]clock_rateClock rate of SPI interface
[in]latencyLatency in ms, typically 1ms for FT232H/FT2232H
[in]spi_modeSPI mode 0 to 3. SPI mode defined by (CPOL,CPHA)
[in]cs_pinSS pin on DBUSx
[in]ss_defaultSS default value
Returns
Returns 0 for success Example Usage:
* ftdi_init(25000000,1,3,3,1); // 25MHz, 1ms latency, SPI mode 3, SS=DBUS3 SS default high
*
See Also
Note
Warning
int ftdi_init_channel ( )

Initialise opened channel.

This function initialises the channel opened by ftdi_open_channel() This function should be called immediately after ftdi_open_channel() and before any other channel operation takes place

Parameters
none
Returns
Returns 0 for success Example Usage:
See Also
Note
Warning
int ftdi_kill ( )

FTDI destructor.

This function is the destructor of ftdi_init()

Parameters
none
Returns
Returns 0 for success Example Usage:
*
See Also
Note
Warning
int ftdi_open_channel ( int  channel_id)

FTDI open channel.

This function opens a channel for communications Only one channel should be opened at a time with this library

Parameters
[in]channel_idThe ID of the channel to open
Returns
Returns 0 for success Example Usage:
* ftdi_open_channel(1); // opens channel 1 for communication
*
See Also
Note
Warning
int ftdi_print_channel_info ( )

Prints FTDI channel information.

This function prints FTDI channel information to screen for user to select the correct channel to communicate with

Parameters
none
Returns
Returns 0 for success Example Usage:
See Also
Note
Warning
int ftdi_read_stream ( uint8 *  buffer,
int  bytes 
)

Read data stream from FTDI.

This function reads a data stream from FTDI

Parameters
[out]*bufferBuffer to store received data
[in]bytesNumber of bytes to be read
Returns
Returns the size transferred Example Usage:
* uint8 *buffer;
* buffer = (uint8 *) malloc(25);
* ftdi_read_stream(buffer,25);
* free(buffer);
*
See Also
Note
Warning
int ftdi_readwrite ( uint8 *  inbuffer,
uint8 *  outbuffer,
int  bytes 
)

Write and read data stream simultaneously.

This function writes a data stream to FTDI and reads from it simultaneously

Parameters
[in]*inbufferBuffer from which data will be read
[out]*outbufferBuffer to store data to write
[in]bytesNumber of bytes
Returns
Returns the size transferred Example Usage:
* uint8 *inbuffer;
* uint8 *outbuffer;
* inbuffer = (uint8 *) malloc(25);
* outbuffer = (uint8 *) malloc(25);
* ftdi_readwrite(inbuffer,outbuffer,25);
* free(inbuffer);
* free(outbuffer);
*
See Also
Note
Does not work in certain SPI modes
Warning
DO NOT USE this function without complete testing
int ftdi_write_stream ( uint8 *  buffer,
int  bytes 
)

Write data stream to FTDI.

This function writes a data stream to FTDI

Parameters
[in]*bufferBuffer from which data will be read
[in]bytesNumber of bytes to be read
Returns
Returns the size transferred Example Usage:
* uint8 *buffer;
* buffer = (uint8 *) malloc(25);
* ftdi_write_stream(buffer,25);
* free(buffer);
*
See Also
Note
Warning