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

SPI bus interface class. More...

#include <SPI.h>

Inheritance diagram for SPI:
SensorBase ErrorBase ADXL345_SPI

Public Types

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

Public Member Functions

 SPI (Port SPIport)
 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 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...
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 Creates an instance of the sensor base and gets an FPGA handle.
 
 SensorBase (const SensorBase &)=delete
 
SensorBaseoperator= (const SensorBase &)=delete
 
- Public Member Functions inherited from 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, 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
 
- Protected Attributes inherited from ErrorBase
Error m_error
 

Additional Inherited Members

- Static Public Member Functions inherited from SensorBase
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 Public Member Functions inherited from ErrorBase
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 ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Static Public Attributes inherited from SensorBase
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
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 Add sensor to the singleton list. More...
 
- Static Protected Attributes inherited from SensorBase
static void * m_digital_ports [kDigitalChannels]
 
static void * m_relay_ports [kRelayChannels]
 
static void * m_pwm_ports [kPwmChannels]
 
- Static Protected Attributes inherited from ErrorBase
static 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  SPIport)

Constructor.

Parameters
SPIportthe physical SPI port

Member Function Documentation

double SPI::GetAccumulatorAverage ( ) const

Read the average of the accumulated value.

Returns
The accumulated average value (value / count).
uint32_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,
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.

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,
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.

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?
int32_t SPI::Read ( bool  initiate,
uint8_t *  dataReceived,
uint8_t  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 ( 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.

Parameters
hzThe clock rate in Hertz.
int32_t SPI::Transaction ( uint8_t *  dataToSend,
uint8_t *  dataReceived,
uint8_t  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
int32_t SPI::Write ( uint8_t *  data,
uint8_t  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: