WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
SPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "HAL/HAL.hpp"
11 #include "SensorBase.h"
12 
13 class DigitalOutput;
14 class DigitalInput;
15 
23 class SPI : public SensorBase {
24  public:
25  enum Port { kOnboardCS0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP };
26  SPI(Port SPIport);
27  virtual ~SPI();
28 
29  SPI(const SPI&) = delete;
30  SPI& operator=(const SPI&) = delete;
31 
32  void SetClockRate(double hz);
33 
34  void SetMSBFirst();
35  void SetLSBFirst();
36 
38  void SetSampleDataOnRising();
39 
40  void SetClockActiveLow();
41  void SetClockActiveHigh();
42 
45 
46  virtual int32_t Write(uint8_t* data, uint8_t size);
47  virtual int32_t Read(bool initiate, uint8_t* dataReceived, uint8_t size);
48  virtual int32_t Transaction(uint8_t* dataToSend, uint8_t* dataReceived,
49  uint8_t size);
50 
51  void InitAccumulator(double period, uint32_t cmd, uint8_t xfer_size,
52  uint32_t valid_mask, uint32_t valid_value,
53  uint8_t data_shift, uint8_t data_size, bool is_signed,
54  bool big_endian);
55  void FreeAccumulator();
56  void ResetAccumulator();
57  void SetAccumulatorCenter(int32_t center);
58  void SetAccumulatorDeadband(int32_t deadband);
59  int32_t GetAccumulatorLastValue() const;
60  int64_t GetAccumulatorValue() const;
61  uint32_t GetAccumulatorCount() const;
62  double GetAccumulatorAverage() const;
63  void GetAccumulatorOutput(int64_t &value, uint32_t &count) const;
64 
65  protected:
66  uint8_t m_port;
67  bool m_msbFirst = false; // default little-endian
68  bool m_sampleOnTrailing = false; // default data updated on falling edge
69  bool m_clk_idle_high = false; // default clock active high
70 
71  private:
72  void Init();
73 };
SPI(Port SPIport)
Constructor.
Definition: SPI.cpp:20
void SetMSBFirst()
Configure the order that bits are sent and received on the wire to be most significant bit first...
Definition: SPI.cpp:50
Class to read a digital input.
Definition: DigitalInput.h:28
SPI bus interface class.
Definition: SPI.h:23
void SetChipSelectActiveLow()
Configure the chip select line to be active low.
Definition: SPI.cpp:118
void SetAccumulatorDeadband(int32_t deadband)
Set the accumulator's deadband.
Definition: SPI.cpp:236
void SetLSBFirst()
Configure the order that bits are sent and received on the wire to be least significant bit first...
Definition: SPI.cpp:60
Class to write to digital outputs.
Definition: DigitalOutput.h:22
void SetChipSelectActiveHigh()
Configure the chip select line to be active high.
Definition: SPI.cpp:109
virtual ~SPI()
Destructor.
Definition: SPI.cpp:34
void GetAccumulatorOutput(int64_t &value, uint32_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: SPI.cpp:299
int32_t GetAccumulatorLastValue() const
Read the last value read by the accumulator engine.
Definition: SPI.cpp:245
Base class for all sensors.
Definition: SensorBase.h:20
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.
Definition: SPI.cpp:191
void SetAccumulatorCenter(int32_t center)
Set the center value of the accumulator.
Definition: SPI.cpp:227
void ResetAccumulator()
Resets the accumulator to zero.
Definition: SPI.cpp:214
double GetAccumulatorAverage() const
Read the average of the accumulated value.
Definition: SPI.cpp:283
void SetSampleDataOnFalling()
Configure that the data is stable on the falling edge and the data changes on the rising edge...
Definition: SPI.cpp:70
void FreeAccumulator()
Frees the accumulator.
Definition: SPI.cpp:205
virtual int32_t Transaction(uint8_t *dataToSend, uint8_t *dataReceived, uint8_t size)
Perform a simultaneous read/write transaction with the device.
Definition: SPI.cpp:169
virtual int32_t Write(uint8_t *data, uint8_t size)
Write data to the slave device.
Definition: SPI.cpp:131
uint32_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: SPI.cpp:271
void SetClockActiveLow()
Configure the clock output line to be active low.
Definition: SPI.cpp:90
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: SPI.cpp:257
virtual int32_t Read(bool initiate, uint8_t *dataReceived, uint8_t size)
Read a word from the receive FIFO.
Definition: SPI.cpp:151
void SetClockActiveHigh()
Configure the clock output line to be active high.
Definition: SPI.cpp:100
void SetClockRate(double hz)
Configure the rate of the generated clock signal.
Definition: SPI.cpp:44
void SetSampleDataOnRising()
Configure that the data is stable on the rising edge and the data changes on the falling edge...
Definition: SPI.cpp:80