WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
frc::SPI Class Reference

SPI bus interface class. More...

#include <SPI.h>

Inheritance diagram for frc::SPI:
frc::SensorBase frc::ErrorBase

Public Types

enum  Port {
  kOnboardCS0 = 0, kOnboardCS1, kOnboardCS2, kOnboardCS3,
  kMXP
}
 

Public Member Functions

 SPI (Port port)
 Constructor. More...
 
virtual ~SPI ()
 Destructor.
 
 SPI (const SPI &)=delete
 
SPIoperator= (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 int Write (uint8_t *data, int size)
 Write data to the slave device. More...
 
virtual int Read (bool initiate, uint8_t *dataReceived, int size)
 Read a word from the receive FIFO. More...
 
virtual int Transaction (uint8_t *dataToSend, uint8_t *dataReceived, int size)
 Perform a simultaneous read/write transaction with the device. More...
 
void InitAccumulator (double period, int cmd, int xfer_size, int valid_mask, int valid_value, int data_shift, int 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 (int center)
 Set the center value of the accumulator. More...
 
void SetAccumulatorDeadband (int deadband)
 Set the accumulator's deadband.
 
int GetAccumulatorLastValue () const
 Read the last value read by the accumulator engine.
 
int64_t GetAccumulatorValue () const
 Read the accumulated value. More...
 
int64_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, int64_t &count) const
 Read the accumulated value and the number of accumulated values atomically. More...
 
- Public Member Functions inherited from frc::SensorBase
 SensorBase (const SensorBase &)=delete
 
SensorBaseoperator= (const SensorBase &)=delete
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int 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, int 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, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int 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, int 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

HAL_SPIPort m_port
 
bool m_msbFirst = false
 
bool m_sampleOnTrailing = false
 
bool m_clk_idle_high = false
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::SensorBase
static int GetDefaultSolenoidModule ()
 
static bool CheckSolenoidModule (int moduleNumber)
 Check that the solenoid module number is valid. More...
 
static bool CheckDigitalChannel (int channel)
 Check that the digital channel number is valid. More...
 
static bool CheckRelayChannel (int channel)
 Check that the relay channel number is valid. More...
 
static bool CheckPWMChannel (int channel)
 Check that the digital channel number is valid. More...
 
static bool CheckAnalogInputChannel (int channel)
 Check that the analog input number is value. More...
 
static bool CheckAnalogOutputChannel (int channel)
 Check that the analog output number is valid. More...
 
static bool CheckSolenoidChannel (int channel)
 Verify that the solenoid channel number is within limits. More...
 
static bool CheckPDPChannel (int channel)
 Verify that the power distribution channel number is within limits. More...
 
- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Static Public Attributes inherited from frc::SensorBase
static const int kDigitalChannels = HAL_GetNumDigitalChannels()
 
static const int kAnalogInputs = HAL_GetNumAnalogInputs()
 
static const int kAnalogOutputs
 
static const int kSolenoidChannels = HAL_GetNumSolenoidChannels()
 
static const int kSolenoidModules = HAL_GetNumPCMModules()
 
static const int kPwmChannels = HAL_GetNumPWMChannels()
 
static const int kRelayChannels = HAL_GetNumRelayHeaders()
 
static const int kPDPChannels = HAL_GetNumPDPChannels()
 
- Static Protected Attributes inherited from frc::ErrorBase
static hal::priority_mutex _globalErrorMutex
 
static Error _globalError
 

Detailed Description

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.

Constructor & Destructor Documentation

SPI::SPI ( Port  port)
explicit

Constructor.

Parameters
portthe physical SPI port

Member Function Documentation

double SPI::GetAccumulatorAverage ( ) const

Read the average of the accumulated value.

Returns
The accumulated average value (value / count).
int64_t SPI::GetAccumulatorCount ( ) const

Read the number of accumulated values.

Read the count of the accumulated values since the accumulator was last Reset().

Returns
The number of times samples from the channel were accumulated.
void SPI::GetAccumulatorOutput ( int64_t &  value,
int64_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.

Parameters
valuePointer to the 64-bit accumulated output.
countPointer to the number of accumulation cycles.
int64_t SPI::GetAccumulatorValue ( ) const

Read the accumulated value.

Returns
The 64-bit value accumulated since the last Reset().
void SPI::InitAccumulator ( double  period,
int  cmd,
int  xfer_size,
int  valid_mask,
int  valid_value,
int  data_shift,
int  data_size,
bool  is_signed,
bool  big_endian 
)

Initialize the accumulator.

Parameters
periodTime between reads
cmdSPI command to send to request data
xfer_sizeSPI transfer size, in bytes
valid_maskMask to apply to received data for validity checking
valid_dataAfter valid_mask is applied, required matching value for validity checking
data_shiftBit shift to apply to received data to get actual data value
data_sizeSize (in bits) of data field
is_signedIs data field signed?
big_endianIs device big endian?
int SPI::Read ( bool  initiate,
uint8_t *  dataReceived,
int  size 
)
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.

Parameters
initiateIf 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 ( int  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.

Parameters
hzThe clock rate in Hertz.
int SPI::Transaction ( uint8_t *  dataToSend,
uint8_t *  dataReceived,
int  size 
)
virtual

Perform a simultaneous read/write transaction with the device.

Parameters
dataToSendThe data to be written out to the device
dataReceivedBuffer to receive data from the device
sizeThe length of the transaction, in bytes
int SPI::Write ( uint8_t *  data,
int  size 
)
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.


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