arduino-emulator
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
arduino::HardwareSPI_FTDI Class Reference

Implementation of SPI communication for FTDI FT2232HL using MPSSE mode. More...

#include <HardwareSPI_FTDI.h>

Inheritance diagram for arduino::HardwareSPI_FTDI:
arduino::HardwareSPI

Public Member Functions

 HardwareSPI_FTDI (int channel=0)
 Constructor for FTDI SPI interface.
 
 ~HardwareSPI_FTDI () override
 Destructor - closes FTDI connection.
 
void attachInterrupt () override
 Attach interrupt (not implemented for FTDI).
 
void begin () override
 
bool begin (int vendor_id, int product_id, const char *description=nullptr, const char *serial=nullptr)
 Initialize the SPI interface.
 
void beginTransaction (SPISettings settings) override
 Begin an SPI transaction with specific settings.
 
void detachInterrupt () override
 Detach interrupt (not implemented for FTDI).
 
void end () override
 Close the SPI interface and cleanup resources.
 
void endTransaction (void) override
 End the current SPI transaction.
 
void notUsingInterrupt (int interruptNumber) override
 Unregister interrupt usage (not implemented for FTDI).
 
 operator bool ()
 Boolean conversion operator.
 
uint8_t transfer (uint8_t data) override
 Transfer a single byte over SPI.
 
void transfer (void *buf, size_t count) override
 Transfer a buffer of data over SPI.
 
uint16_t transfer16 (uint16_t data) override
 Transfer a 16-bit value over SPI.
 
void usingInterrupt (int interruptNumber) override
 Register interrupt usage (not implemented for FTDI).
 

Protected Member Functions

bool configureMPSSE ()
 Configure FTDI device for MPSSE mode.
 
uint8_t getMPSSECommand (bool read_enable, bool write_enable)
 Get MPSSE command byte based on current SPI settings.
 
int receiveData (uint8_t *data, size_t length)
 Receive raw data from FTDI device.
 
int sendData (const uint8_t *data, size_t length)
 Send raw data to FTDI device.
 
bool setClockFrequency (uint32_t frequency)
 Set the SPI clock frequency.
 

Protected Attributes

BitOrder current_bit_order = MSBFIRST
 
uint32_t current_clock = 1000000
 
SPIMode current_mode = SPI_MODE0
 
int ftdi_channel = 0
 
struct ftdi_context * ftdi_context = nullptr
 
bool is_open = false
 

Static Protected Attributes

static const uint8_t CMD_BITMODE = 0x02
 
static const uint8_t CMD_DO_READ = 0x20
 
static const uint8_t CMD_DO_WRITE = 0x10
 
static const uint8_t CMD_LSB = 0x08
 
static const uint8_t CMD_READ_NEG = 0x04
 
static const uint8_t CMD_WRITE_NEG = 0x01
 
static const uint8_t CMD_WRITE_TMS = 0x40
 

Detailed Description

Implementation of SPI communication for FTDI FT2232HL using MPSSE mode.

This class provides an interface to the SPI bus on FTDI FT2232HL devices using the Multi-Protocol Synchronous Serial Engine (MPSSE) mode. The FT2232HL can operate both channels in MPSSE mode, allowing for high-speed SPI communication.

Pin mapping for SPI on FT2232HL (Channel A):

The class inherits from HardwareSPI and implements all required methods for SPI communication, including data transfer, transaction management, and configuration.

Note
This class is only available when USE_FTDI is defined.
Requires libftdi1 development library to be installed.

Constructor & Destructor Documentation

◆ HardwareSPI_FTDI()

arduino::HardwareSPI_FTDI::HardwareSPI_FTDI ( int  channel = 0)

Constructor for FTDI SPI interface.

Parameters
channelFTDI channel to use (0 for Channel A, 1 for Channel B)

Member Function Documentation

◆ attachInterrupt()

void arduino::HardwareSPI_FTDI::attachInterrupt ( )
overridevirtual

Attach interrupt (not implemented for FTDI).

Implements arduino::HardwareSPI.

◆ begin() [1/2]

void arduino::HardwareSPI_FTDI::begin ( )
inlineoverridevirtual

Implements arduino::HardwareSPI.

◆ begin() [2/2]

bool arduino::HardwareSPI_FTDI::begin ( int  vendor_id,
int  product_id,
const char description = nullptr,
const char serial = nullptr 
)

Initialize the SPI interface.

Parameters
vendor_idUSB vendor ID (default: 0x0403)
product_idUSB product ID (default: 0x6010 for FT2232HL)
descriptionDevice description string (optional)
serialDevice serial number (optional)
Returns
true if initialization successful, false otherwise

◆ beginTransaction()

void arduino::HardwareSPI_FTDI::beginTransaction ( SPISettings  settings)
overridevirtual

Begin an SPI transaction with specific settings.

Parameters
settingsSPI settings (clock, bit order, mode)

Implements arduino::HardwareSPI.

◆ configureMPSSE()

bool arduino::HardwareSPI_FTDI::configureMPSSE ( )
protected

Configure FTDI device for MPSSE mode.

Returns
true if successful, false on error

◆ detachInterrupt()

void arduino::HardwareSPI_FTDI::detachInterrupt ( )
overridevirtual

Detach interrupt (not implemented for FTDI).

Implements arduino::HardwareSPI.

◆ end()

void arduino::HardwareSPI_FTDI::end ( )
overridevirtual

Close the SPI interface and cleanup resources.

Implements arduino::HardwareSPI.

◆ endTransaction()

void arduino::HardwareSPI_FTDI::endTransaction ( void  )
overridevirtual

End the current SPI transaction.

Implements arduino::HardwareSPI.

◆ getMPSSECommand()

uint8_t arduino::HardwareSPI_FTDI::getMPSSECommand ( bool  read_enable,
bool  write_enable 
)
protected

Get MPSSE command byte based on current SPI settings.

Parameters
read_enableEnable reading data
write_enableEnable writing data
Returns
MPSSE command byte

◆ notUsingInterrupt()

void arduino::HardwareSPI_FTDI::notUsingInterrupt ( int  interruptNumber)
overridevirtual

Unregister interrupt usage (not implemented for FTDI).

Parameters
interruptNumberInterrupt number (ignored)

Implements arduino::HardwareSPI.

◆ operator bool()

arduino::HardwareSPI_FTDI::operator bool ( )
inline

Boolean conversion operator.

Returns
true if the FTDI SPI interface is open and initialized, false otherwise.

◆ receiveData()

int arduino::HardwareSPI_FTDI::receiveData ( uint8_t data,
size_t  length 
)
protected

Receive raw data from FTDI device.

Parameters
dataPointer to receive buffer
lengthNumber of bytes to receive
Returns
Number of bytes actually received, or negative on error

◆ sendData()

int arduino::HardwareSPI_FTDI::sendData ( const uint8_t data,
size_t  length 
)
protected

Send raw data to FTDI device.

Parameters
dataPointer to data buffer
lengthNumber of bytes to send
Returns
Number of bytes actually sent, or negative on error

◆ setClockFrequency()

bool arduino::HardwareSPI_FTDI::setClockFrequency ( uint32_t  frequency)
protected

Set the SPI clock frequency.

Parameters
frequencyClock frequency in Hz
Returns
true if successful, false on error

◆ transfer() [1/2]

uint8_t arduino::HardwareSPI_FTDI::transfer ( uint8_t  data)
overridevirtual

Transfer a single byte over SPI.

Parameters
dataByte to send
Returns
Received byte

Implements arduino::HardwareSPI.

◆ transfer() [2/2]

void arduino::HardwareSPI_FTDI::transfer ( void buf,
size_t  count 
)
overridevirtual

Transfer a buffer of data over SPI.

Parameters
bufBuffer containing data to send (will be overwritten with received data)
countNumber of bytes to transfer

Implements arduino::HardwareSPI.

◆ transfer16()

uint16_t arduino::HardwareSPI_FTDI::transfer16 ( uint16_t  data)
overridevirtual

Transfer a 16-bit value over SPI.

Parameters
data16-bit value to send
Returns
Received 16-bit value

Implements arduino::HardwareSPI.

◆ usingInterrupt()

void arduino::HardwareSPI_FTDI::usingInterrupt ( int  interruptNumber)
overridevirtual

Register interrupt usage (not implemented for FTDI).

Parameters
interruptNumberInterrupt number (ignored)

Implements arduino::HardwareSPI.


The documentation for this class was generated from the following files: