blfwk::BusPal Class Reference

Interface with the BusPal. More...

`#include <BusPal.h>`

## Classes

struct | BusPalConfigData
| BusPal configuration data. More...

## Public Types

enum | { kResetCount = 20, kResponseOk = 0x01, kBulkTransferMax = 4096, kMaxResponse = kBulkTransferMax }
| Constants. More...
enum | bus_pal_function_t { kBusPalFunction_None, kBusPalFunction_SPI, kBusPalFunction_I2C, kBusPalFunction_CAN, kBusPalFunction_GPIO_CONFIG, kBusPalFunction_GPIO_SET, kBusPalFunction_FPGA_CLOCK_SET }
| BusPal Transports.
enum | spi_clock_polarity_t { kSpiClockPolarity_ActiveHigh = 0, kSpiClockPolarity_ActiveLow = 1 }
| SPI clock polarity configuration. More...
enum | spi_clock_phase_t { kSpiClockPhase_FirstEdge, kSpiClockPhase_SecondEdge }
| SPI clock phase configuration. More...
enum | spi_shift_direction_t { kSpiMsbFirst = 0, kSpiLsbFirst = 1 }
| SPI data shifter direction options. More...

## Public Member Functions

| BusPal (int fileDescriptor)
| Constructor.
virtual | ~BusPal ()
| Destructor.
virtual bool | reset ()
| Reset to bit bang mode from another peripheral mode.
virtual bool | resetHardware ()
| Reset the bus pal, comes up in terminal mode.
virtual bool | enterBitBangMode ()
| Enter bit bang (binary scripting) mode. More...
virtual bool | enterSpiMode ()
| Enter Spi mode.
virtual bool | enterCanMode ()
| Enter Can mode.
virtual bool | enterI2cMode ()
| Enter I2c mode.
virtual bool | enterUartMode ()
| Enter Uart mode. Not currently supported for bus pal.
virtual bool | enter1WireMode ()
| Enter 1wire mode. Not currently supported for bus pal.
virtual bool | enterRawWireMode ()
| Enter raw wire mode. Not currently supported for bus pal.
virtual bool | rawConfigurePins (uint8_t port, uint8_t pin, uint8_t muxVal)
| Raw configure pins.
virtual bool | rawSetPins (uint8_t port, uint8_t pin, uint8_t level)
| Set GPIO pin.
virtual bool | configurePins (uint8_t config=0)
| Configure pins.
virtual uint8_t | readPins ()
| Read pins.
virtual bool | setFPGAClock (uint32_t clock)
| Sets the FPGA clock, clock is in hertz.
virtual bool | setSpiSpeed (unsigned int speed)
| Set SPI speed.
virtual bool | setSpiConfig (spi_clock_polarity_t polarity, spi_clock_phase_t phase, spi_shift_direction_t direction)
| Sets the SPI configuration.
virtual bool | setI2cAddress (uint8_t address)
| Set I2c address.
virtual bool | setI2cSpeed (uint32_t speed)
| Set I2c speed.
virtual bool | setCanSpeed (unsigned int speed)
| Set CAN speed.
virtual bool | setCanTxid (unsigned int txid)
| Set CAN txid.
virtual bool | setCanRxid (unsigned int rxid)
| Set CAN rxid.
virtual uint8_t * | response (size_t byteCount=1)
| Read response. More...
virtual bool | write (const uint8_t *data, size_t byteCount=1)
| writes the data over the previously selected interface
virtual int | read (uint8_t *data, size_t byteCount)
| Read data.

## Static Public Member Functions

static bool | parse (const string_vector_t &params, BusPal::BusPalConfigData &config)
| parse the passed in options into the config structure.

## Static Public Attributes

static const uint8_t | kBusPalDefaultI2cSlaveAddress = 0x10
| I2C default address.

## Protected Types

enum | bus_pal_mode_t { kBusPalModeBitBang, kBusPalModeSpi, kBusPalModeI2c, kBusPalModeCan }

## Protected Member Functions

virtual bool | writeCommand (uint8_t commandByte, const char *expectedResponse)
| Write command, check string response.
virtual uint8_t | writeCommand (uint8_t commandByte)
| Write command, return 1 byte response.
virtual uint8_t | writeCommand (uint8_t *command, unsigned int length)
| write multi-byte command, return 1 byte response.
virtual bool | writeSpi (const uint8_t *data, size_t byteCount=1)
| write via Spi
virtual bool | writeI2c (const uint8_t *data, size_t byteCount=1)
| write via I2c
virtual bool | writeCan (const uint8_t *data, size_t byteCount=1)
| write via Can
virtual int | readSpi (uint8_t *data, size_t byteCount)
| read via Spi
virtual int | readCan (uint8_t *data, size_t byteCount)
| read via Can
int | readSpiActual (uint8_t *data, size_t byteCount)
| worker function to actually read SPI data
virtual int | readI2c (uint8_t *data, size_t byteCount)
| read via I2c
int | buspal_serial_read (uint8_t *buf, int size, bool isCommandData=false)
| Overriden serial_read for logging.
int | buspal_serial_write (uint8_t *buf, int size, bool isCommandData=false)
| Overriden serial_write for logging.
void | flushRX ()
| Flushes the serial port of any RX data.

## Protected Attributes

int | m_fileDescriptor
| PC COM port file descriptor.
uint8_t | m_responseBuffer [kMaxResponse]
| Command response buffer.
bus_pal_mode_t | m_mode
unsigned int | m_spiWriteByteCount
unsigned int | m_canWriteByteCount
unsigned int | m_canFirstReadDelay

## Detailed Description

Interface with the BusPal.

For hardware documentation, see http://dangerousprototypes.com/docs/Bus_Pirate. This class is based on the pyBusPirateLite python package, see http://dangerousprototypes.com/docs/Bus_Pirate_Scripting_in_Python.

## Member Enumeration Documentation

anonymous enum

Constants.

Enumerator
kResetCount | Max number of nulls to send to enter BBIO mode.
kResponseOk | Successful command response.
kBulkTransferMax | Max number of bytes per bulk transfer.
kMaxResponse | Max number of bytes in command response, including bulk transfer response, plus some padding

enum blfwk::BusPal::spi_clock_phase_t

SPI clock phase configuration.

Enumerator
kSpiClockPhase_FirstEdge | First edge on SPSCK occurs at the middle of the first cycle of a data transfer.
kSpiClockPhase_SecondEdge | First edge on SPSCK occurs at the start of the first cycle of a data transfer.

enum blfwk::BusPal::spi_clock_polarity_t

SPI clock polarity configuration.

Enumerator
kSpiClockPolarity_ActiveHigh | Active-high SPI clock (idles low).
kSpiClockPolarity_ActiveLow | Active-low SPI clock (idles high).

enum blfwk::BusPal::spi_shift_direction_t

SPI data shifter direction options.

Enumerator
kSpiMsbFirst | Data transfers start with most significant bit.
kSpiLsbFirst | Data transfers start with least significant bit.

## Member Function Documentation

bool BusPal::enterBitBangMode | ( |  | ) |

virtual

Enter bit bang (binary scripting) mode.

Call this first before entering other peripheral modes.

uint8_t * BusPal::response | ( | size_t | byteCount = `1` | ) |

virtual

Read response.

Return values

  NULL | No response from device
  Non-NULL | Pointer to internal array of bytes at least size byteCount

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

- BusPal.h
- BusPal.cpp