14 #include <hal/SPITypes.h>
15 #include <units/units.h>
16 #include <wpi/ArrayRef.h>
17 #include <wpi/deprecated.h>
19 #include "frc/ErrorBase.h"
34 enum Port { kOnboardCS0 = 0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP };
41 explicit SPI(Port port);
46 SPI& operator=(
SPI&&) =
default;
86 WPI_DEPRECATED(
"Use SetSampleDataOnTrailingEdge in most cases.")
93 WPI_DEPRECATED(
"Use SetSampleDataOnLeadingEdge in most cases")
125 virtual int Write(uint8_t* data,
int size);
140 virtual int Read(
bool initiate, uint8_t* dataReceived,
int size);
149 virtual int Transaction(uint8_t* dataToSend, uint8_t* dataReceived,
int size);
195 WPI_DEPRECATED(
"Use StartAutoRate with unit-safety instead")
240 units::second_t timeout);
261 WPI_DEPRECATED(
"Use ReadAutoReceivedData with unit-safety instead")
283 int pow2BytesPerRead);
301 int validMask,
int validValue,
int dataShift,
302 int dataSize,
bool isSigned,
bool bigEndian);
319 WPI_DEPRECATED(
"Use InitAccumulator with unit-safety instead")
320 void InitAccumulator(
double period,
int cmd,
int xferSize,
int validMask,
321 int validValue,
int dataShift,
int dataSize,
322 bool isSigned,
bool bigEndian);
417 bool m_msbFirst =
false;
418 bool m_sampleOnTrailing =
false;
419 bool m_clockIdleHigh =
false;
425 std::unique_ptr<Accumulator> m_accum;
void SetLSBFirst()
Configure the order that bits are sent and received on the wire to be least significant bit first.
void ForceAutoRead()
Force the engine to make a single transfer.
void SetSampleDataOnTrailingEdge()
Configure that the data is stable on the trailing edge and the data changes on the leading edge.
void SetAccumulatorIntegratedCenter(double center)
Set the center value of the accumulator integrator.
void SetSampleDataOnRising()
Configure that the data is stable on the rising edge and the data changes on the falling edge.
void SetClockRate(int hz)
Configure the rate of the generated clock signal.
void FreeAccumulator()
Frees the accumulator.
void SetChipSelectActiveHigh()
Configure the chip select line to be active high.
int64_t GetAccumulatorValue() const
Read the accumulated value.
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
void SetSampleDataOnLeadingEdge()
Configure that the data is stable on the leading edge and the data changes on the trailing edge.
void SetAutoTransmitData(wpi::ArrayRef< uint8_t > dataToSend, int zeroSize)
Set the data to be transmitted by the engine.
void SetClockActiveLow()
Configure the clock output line to be active low.
void StartAutoTrigger(DigitalSource &source, bool rising, bool falling)
Start running the automatic SPI transfer engine when a trigger occurs.
void InitAuto(int bufferSize)
Initialize automatic SPI transfer engine.
virtual int Write(uint8_t *data, int size)
Write data to the slave device.
void ResetAccumulator()
Resets the accumulator to zero.
void StartAutoRate(units::second_t period)
Start running the automatic SPI transfer engine at a periodic rate.
void SetClockActiveHigh()
Configure the clock output line to be active high.
SPI bus interface class.
Definition: SPI.h:32
void InitAccumulator(units::second_t period, int cmd, int xferSize, int validMask, int validValue, int dataShift, int dataSize, bool isSigned, bool bigEndian)
Initialize the accumulator.
Base class for most objects.
Definition: ErrorBase.h:104
virtual int Read(bool initiate, uint8_t *dataReceived, int size)
Read a word from the receive FIFO.
void SetChipSelectActiveLow()
Configure the chip select line to be active low.
SPI(Port port)
Constructor.
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
double GetAccumulatorIntegratedAverage() const
Read the average of the integrated value.
void SetSampleDataOnFalling()
Configure that the data is stable on the falling edge and the data changes on the rising edge.
void StopAuto()
Stop running the automatic SPI transfer engine.
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
double GetAccumulatorAverage() const
Read the average of the accumulated value.
void ConfigureAutoStall(HAL_SPIPort port, int csToSclkTicks, int stallTicks, int pow2BytesPerRead)
Configure the Auto SPI Stall time between reads.
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
void FreeAuto()
Frees the automatic SPI transfer engine.
virtual int Transaction(uint8_t *dataToSend, uint8_t *dataReceived, int size)
Perform a simultaneous read/write transaction with the device.
int ReadAutoReceivedData(uint32_t *buffer, int numToRead, units::second_t timeout)
Read data that has been transferred by the automatic SPI transfer engine.
double GetAccumulatorIntegratedValue() const
Read the integrated value.
int GetAccumulatorLastValue() const
Read the last value read by the accumulator engine.
DigitalSource Interface.
Definition: DigitalSource.h:25
void SetMSBFirst()
Configure the order that bits are sent and received on the wire to be most significant bit first.
int GetAutoDroppedCount()
Get the number of bytes dropped by the automatic SPI transfer engine due to the receive buffer being ...
void SetAccumulatorDeadband(int deadband)
Set the accumulator's deadband.