WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <SPI.h>
Public Types | |
enum | tFrameMode { kChipSelect, kPreLatchPulse, kPostLatchPulse, kPreAndPostLatchPulse } |
enum | tSPIConstants { kReceiveFIFODepth = 512, kTransmitFIFODepth = 512 } |
Public Member Functions | |
SPI (DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso) | |
SPI (DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso) | |
SPI (DigitalOutput &clk, DigitalOutput &mosi) | |
SPI (DigitalOutput *clk, DigitalOutput *mosi) | |
SPI (DigitalOutput &clk, DigitalInput &miso) | |
SPI (DigitalOutput *clk, DigitalInput *miso) | |
virtual | ~SPI () |
void | SetBitsPerWord (UINT32 bits) |
UINT32 | GetBitsPerWord () |
void | SetClockRate (double hz) |
void | SetMSBFirst () |
void | SetLSBFirst () |
void | SetSampleDataOnFalling () |
void | SetSampleDataOnRising () |
void | SetSlaveSelect (DigitalOutput *ss, tFrameMode mode=kChipSelect, bool activeLow=false) |
void | SetSlaveSelect (DigitalOutput &ss, tFrameMode mode=kChipSelect, bool activeLow=false) |
DigitalOutput * | GetSlaveSelect (tFrameMode *mode=NULL, bool *activeLow=NULL) |
void | SetClockActiveLow () |
void | SetClockActiveHigh () |
virtual void | ApplyConfig () |
virtual UINT16 | GetOutputFIFOAvailable () |
virtual UINT16 | GetNumReceived () |
virtual bool | IsDone () |
bool | HadReceiveOverflow () |
virtual void | Write (UINT32 data) |
virtual UINT32 | Read (bool initiate=false) |
virtual void | Reset () |
virtual void | ClearReceivedData () |
Protected Attributes | |
tSPI * | m_spi |
tSPI::tConfig | m_config |
tSPI::tChannels | m_channels |
DigitalOutput * | m_ss |
Static Protected Attributes | |
static SEM_ID | m_semaphore = NULL |
SPI bus interface class.
This class is intended to be used by sensor (and other SPI device) drivers. It probably should not be used directly.
The FPGA only supports a single SPI interface.
SPI::SPI | ( | DigitalOutput & | clk, |
DigitalOutput & | mosi, | ||
DigitalInput & | miso | ||
) |
Constructor for input and output.
clk | The digital output for the clock signal. |
mosi | The digital output for the written data to the slave (master-out slave-in). |
miso | The digital input for the input data from the slave (master-in slave-out). |
SPI::SPI | ( | DigitalOutput * | clk, |
DigitalOutput * | mosi, | ||
DigitalInput * | miso | ||
) |
Constructor for input and output.
clk | The digital output for the clock signal. |
mosi | The digital output for the written data to the slave (master-out slave-in). |
miso | The digital input for the input data from the slave (master-in slave-out). |
SPI::SPI | ( | DigitalOutput & | clk, |
DigitalOutput & | mosi | ||
) |
Constructor for output only.
clk | The digital output for the clock signal. |
mosi | The digital output for the written data to the slave (master-out slave-in). |
SPI::SPI | ( | DigitalOutput * | clk, |
DigitalOutput * | mosi | ||
) |
Constructor for output only.
clk | The digital output for the clock signal. |
mosi | The digital output for the written data to the slave (master-out slave-in). |
SPI::SPI | ( | DigitalOutput & | clk, |
DigitalInput & | miso | ||
) |
Constructor for input only.
clk | The digital output for the clock signal. |
miso | The digital input for the input data from the slave (master-in slave-out). |
SPI::SPI | ( | DigitalOutput * | clk, |
DigitalInput * | miso | ||
) |
Constructor for input only.
clk | The digital output for the clock signal. |
miso | The digital input for the input data from the slave (master-in slave-out). |
SPI::~SPI | ( | ) | [virtual] |
Destructor.
void SPI::ApplyConfig | ( | ) | [virtual] |
Apply configuration settings and reset the SPI logic.
void SPI::ClearReceivedData | ( | ) | [virtual] |
Empty the receive FIFO.
UINT32 SPI::GetBitsPerWord | ( | ) |
Get the number of bits from each word that the slave transmits or receives.
UINT16 SPI::GetNumReceived | ( | ) | [virtual] |
Get the number of words received and currently available to be read from the receive FIFO.
UINT16 SPI::GetOutputFIFOAvailable | ( | ) | [virtual] |
Get the number of words that can currently be stored before being transmitted to the device.
DigitalOutput * SPI::GetSlaveSelect | ( | tFrameMode * | mode = NULL , |
bool * | activeLow = NULL |
||
) |
Get the slave select line behavior.
mode | Frame mode: kChipSelect: active for the duration of the frame. kPreLatchPulse: pulses before the transfer of each frame. kPostLatchPulse: pulses after the transfer of each frame. kPreAndPostLatchPulse: pulses before and after each frame. |
activeLow | True if slave select line is active low. |
bool SPI::HadReceiveOverflow | ( | ) |
Determine if the receive FIFO was full when attempting to add new data at end of a transfer.
bool SPI::IsDone | ( | ) | [virtual] |
Have all pending transfers completed?
UINT32 SPI::Read | ( | bool | initiate = false | ) | [virtual] |
Read a word from the receive FIFO.
Waits for the current transfer to complete if the receive FIFO is empty.
If the receive FIFO is empty, there is no active transfer, and initiate is false, errors.
initiate | If true, this function pushes "0" into the transmit buffer and initiates a transfer. If false, this function assumes that data is already in the receive FIFO from a previous write. |
void SPI::Reset | ( | ) | [virtual] |
Stop any transfer in progress and empty the transmit FIFO.
void SPI::SetBitsPerWord | ( | UINT32 | bits | ) |
Configure the number of bits from each word that the slave transmits or receives.
bits | The number of bits in one frame (1 to 32 bits). |
void SPI::SetClockActiveHigh | ( | ) |
Configure the clock output line to be active high. This is sometimes called clock polarity low.
void SPI::SetClockActiveLow | ( | ) |
Configure the clock output line to be active low. This is sometimes called clock polarity high.
void SPI::SetClockRate | ( | double | hz | ) |
Configure the rate of the generated clock signal. The default and maximum value is 76,628.4 Hz.
hz | The clock rate in Hertz. |
void SPI::SetLSBFirst | ( | ) |
Configure the order that bits are sent and received on the wire to be least significant bit first.
void SPI::SetMSBFirst | ( | ) |
Configure the order that bits are sent and received on the wire to be most significant bit first.
void SPI::SetSampleDataOnFalling | ( | ) |
Configure that the data is stable on the falling edge and the data changes on the rising edge.
void SPI::SetSampleDataOnRising | ( | ) |
Configure that the data is stable on the rising edge and the data changes on the falling edge.
void SPI::SetSlaveSelect | ( | DigitalOutput * | ss, |
tFrameMode | mode = kChipSelect , |
||
bool | activeLow = false |
||
) |
Configure the slave select line behavior.
ss | slave select digital output. |
mode | Frame mode: kChipSelect: active for the duration of the frame. kPreLatchPulse: pulses before the transfer of each frame. kPostLatchPulse: pulses after the transfer of each frame. kPreAndPostLatchPulse: pulses before and after each frame. |
activeLow | True if slave select line is active low. |
void SPI::SetSlaveSelect | ( | DigitalOutput & | ss, |
tFrameMode | mode = kChipSelect , |
||
bool | activeLow = false |
||
) |
Configure the slave select line behavior.
ss | slave select digital output. |
mode | Frame mode: kChipSelect: active for the duration of the frame. kPreLatchPulse: pulses before the transfer of each frame. kPostLatchPulse: pulses after the transfer of each frame. kPreAndPostLatchPulse: pulses before and after each frame. |
activeLow | True if slave select line is active low. |
void SPI::Write | ( | UINT32 | data | ) | [virtual] |
Write a word to the slave device. Blocks until there is space in the output FIFO.
If not running in output only mode, also saves the data received on the MISO input during the transfer into the receive FIFO.