WPILibC++
unspecified
|
SPI bus interface class. More...
#include <SPI.h>
Public Types | |
enum | Port { kOnboardCS0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP } |
Public Member Functions | |
SPI (Port SPIport) | |
Constructor. More... | |
virtual | ~SPI () |
Destructor. | |
SPI (const SPI &)=delete | |
SPI & | operator= (const SPI &)=delete |
void | SetClockRate (double hz) |
Configure the rate of the generated clock signal. More... | |
void | SetMSBFirst () |
Configure the order that bits are sent and received on the wire to be most significant bit first. | |
void | SetLSBFirst () |
Configure the order that bits are sent and received on the wire to be least significant bit first. | |
void | SetSampleDataOnFalling () |
Configure that the data is stable on the falling edge and the data changes on the rising edge. | |
void | SetSampleDataOnRising () |
Configure that the data is stable on the rising edge and the data changes on the falling edge. | |
void | SetClockActiveLow () |
Configure the clock output line to be active low. More... | |
void | SetClockActiveHigh () |
Configure the clock output line to be active high. More... | |
void | SetChipSelectActiveHigh () |
Configure the chip select line to be active high. | |
void | SetChipSelectActiveLow () |
Configure the chip select line to be active low. | |
virtual int32_t | Write (uint8_t *data, uint8_t size) |
Write data to the slave device. More... | |
virtual int32_t | Read (bool initiate, uint8_t *dataReceived, uint8_t size) |
Read a word from the receive FIFO. More... | |
virtual int32_t | Transaction (uint8_t *dataToSend, uint8_t *dataReceived, uint8_t size) |
Perform a simultaneous read/write transaction with the device. More... | |
void | InitAccumulator (double period, uint32_t cmd, uint8_t xfer_size, uint32_t valid_mask, uint32_t valid_value, uint8_t data_shift, uint8_t data_size, bool is_signed, bool big_endian) |
Initialize the accumulator. More... | |
void | FreeAccumulator () |
Frees the accumulator. | |
void | ResetAccumulator () |
Resets the accumulator to zero. | |
void | SetAccumulatorCenter (int32_t center) |
Set the center value of the accumulator. More... | |
void | SetAccumulatorDeadband (int32_t deadband) |
Set the accumulator's deadband. | |
int32_t | GetAccumulatorLastValue () const |
Read the last value read by the accumulator engine. | |
int64_t | GetAccumulatorValue () const |
Read the accumulated value. More... | |
uint32_t | GetAccumulatorCount () const |
Read the number of accumulated values. More... | |
double | GetAccumulatorAverage () const |
Read the average of the accumulated value. More... | |
void | GetAccumulatorOutput (int64_t &value, uint32_t &count) const |
Read the accumulated value and the number of accumulated values atomically. More... | |
![]() | |
SensorBase () | |
Creates an instance of the sensor base and gets an FPGA handle. | |
SensorBase (const SensorBase &)=delete | |
SensorBase & | operator= (const SensorBase &)=delete |
![]() | |
ErrorBase (const ErrorBase &)=delete | |
ErrorBase & | operator= (const ErrorBase &)=delete |
virtual Error & | GetError () |
Retrieve the current error. More... | |
virtual const Error & | GetError () const |
virtual void | SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (const ErrorBase &rhs) const |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Protected Attributes | |
uint8_t | m_port |
bool | m_msbFirst = false |
bool | m_sampleOnTrailing = false |
bool | m_clk_idle_high = false |
![]() | |
Error | m_error |
Additional Inherited Members | |
![]() | |
static void | DeleteSingletons () |
Delete all the singleton classes on the list. More... | |
static uint32_t | GetDefaultSolenoidModule () |
static bool | CheckSolenoidModule (uint8_t moduleNumber) |
Check that the solenoid module number is valid. More... | |
static bool | CheckDigitalChannel (uint32_t channel) |
Check that the digital channel number is valid. More... | |
static bool | CheckRelayChannel (uint32_t channel) |
Check that the digital channel number is valid. More... | |
static bool | CheckPWMChannel (uint32_t channel) |
Check that the digital channel number is valid. More... | |
static bool | CheckAnalogInput (uint32_t channel) |
Check that the analog input number is value. More... | |
static bool | CheckAnalogOutput (uint32_t channel) |
Check that the analog output number is valid. More... | |
static bool | CheckSolenoidChannel (uint32_t channel) |
Verify that the solenoid channel number is within limits. More... | |
static bool | CheckPDPChannel (uint32_t channel) |
Verify that the power distribution channel number is within limits. More... | |
![]() | |
static void | SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) |
static void | SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) |
static Error & | GetGlobalError () |
Retrieve the current global error. | |
![]() | |
static const uint32_t | kDigitalChannels = 26 |
static const uint32_t | kAnalogInputs = 8 |
static const uint32_t | kAnalogOutputs = 2 |
static const uint32_t | kSolenoidChannels = 8 |
static const uint32_t | kSolenoidModules = 2 |
static const uint32_t | kPwmChannels = 20 |
static const uint32_t | kRelayChannels = 8 |
static const uint32_t | kPDPChannels = 16 |
static const uint32_t | kChassisSlots = 8 |
![]() | |
void | AddToSingletonList () |
Add sensor to the singleton list. More... | |
![]() | |
static void * | m_digital_ports [kDigitalChannels] |
static void * | m_relay_ports [kRelayChannels] |
static void * | m_pwm_ports [kPwmChannels] |
![]() | |
static priority_mutex | _globalErrorMutex |
static Error | _globalError |
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.
SPI::SPI | ( | Port | SPIport | ) |
Constructor.
SPIport | the physical SPI port |
double SPI::GetAccumulatorAverage | ( | ) | const |
Read the average of the accumulated value.
uint32_t SPI::GetAccumulatorCount | ( | ) | const |
Read the number of accumulated values.
Read the count of the accumulated values since the accumulator was last Reset().
void SPI::GetAccumulatorOutput | ( | int64_t & | value, |
uint32_t & | count | ||
) | const |
Read the accumulated value and the number of accumulated values atomically.
This function reads the value and count atomically. This can be used for averaging.
value | Pointer to the 64-bit accumulated output. |
count | Pointer to the number of accumulation cycles. |
int64_t SPI::GetAccumulatorValue | ( | ) | const |
Read the accumulated value.
void SPI::InitAccumulator | ( | double | period, |
uint32_t | cmd, | ||
uint8_t | xfer_size, | ||
uint32_t | valid_mask, | ||
uint32_t | valid_value, | ||
uint8_t | data_shift, | ||
uint8_t | data_size, | ||
bool | is_signed, | ||
bool | big_endian | ||
) |
Initialize the accumulator.
period | Time between reads |
cmd | SPI command to send to request data |
xfer_size | SPI transfer size, in bytes |
valid_mask | Mask to apply to received data for validity checking |
valid_data | After valid_mask is applied, required matching value for validity checking |
data_shift | Bit shift to apply to received data to get actual data value |
data_size | Size (in bits) of data field |
is_signed | Is data field signed? |
big_endian | Is device big endian? |
|
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::SetAccumulatorCenter | ( | int32_t | center | ) |
Set the center value of the accumulator.
The center value is subtracted from each value before it is added to the accumulator. This is used for the center value of devices like gyros and accelerometers to make integration work and to take the device offset into account when integrating.
void SPI::SetClockActiveHigh | ( | ) |
Configure the clock output line to be active high.
This is sometimes called clock polarity low or clock idle low.
void SPI::SetClockActiveLow | ( | ) |
Configure the clock output line to be active low.
This is sometimes called clock polarity high or clock idle high.
void SPI::SetClockRate | ( | double | hz | ) |
Configure the rate of the generated clock signal.
The default value is 500,000Hz. The maximum value is 4,000,000Hz.
hz | The clock rate in Hertz. |
|
virtual |
Perform a simultaneous read/write transaction with the device.
dataToSend | The data to be written out to the device |
dataReceived | Buffer to receive data from the device |
size | The length of the transaction, in bytes |
|
virtual |
Write data 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.