WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
SPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 "SensorBase.h"
11 
12 namespace frc {
13 
14 class DigitalOutput;
15 class DigitalInput;
16 
24 class SPI : public SensorBase {
25  public:
26  enum Port { kOnboardCS0, kOnboardCS1, kOnboardCS2, kOnboardCS3, kMXP };
27  explicit SPI(Port SPIport);
28  virtual ~SPI();
29 
30  SPI(const SPI&) = delete;
31  SPI& operator=(const SPI&) = delete;
32 
33  void SetClockRate(double hz);
34 
35  void SetMSBFirst();
36  void SetLSBFirst();
37 
39  void SetSampleDataOnRising();
40 
41  void SetClockActiveLow();
42  void SetClockActiveHigh();
43 
46 
47  virtual int Write(uint8_t* data, int size);
48  virtual int Read(bool initiate, uint8_t* dataReceived, int size);
49  virtual int Transaction(uint8_t* dataToSend, uint8_t* dataReceived, int size);
50 
51  void InitAccumulator(double period, int cmd, int xfer_size, int valid_mask,
52  int valid_value, int data_shift, int data_size,
53  bool is_signed, bool big_endian);
54  void FreeAccumulator();
55  void ResetAccumulator();
56  void SetAccumulatorCenter(int center);
57  void SetAccumulatorDeadband(int deadband);
58  int GetAccumulatorLastValue() const;
59  int64_t GetAccumulatorValue() const;
60  int64_t GetAccumulatorCount() const;
61  double GetAccumulatorAverage() const;
62  void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
63 
64  protected:
65  int m_port;
66  bool m_msbFirst = false; // default little-endian
67  bool m_sampleOnTrailing = false; // default data updated on falling edge
68  bool m_clk_idle_high = false; // default clock active high
69 
70  private:
71  void Init();
72 };
73 
74 } // namespace frc
void SetAccumulatorCenter(int center)
Set the center value of the accumulator.
Definition: SPI.cpp:224
void SetAccumulatorDeadband(int deadband)
Set the accumulator's deadband.
Definition: SPI.cpp:233
Base class for all sensors.
Definition: SensorBase.h:22
void GetAccumulatorOutput(int64_t &value, int64_t &count) const
Read the accumulated value and the number of accumulated values atomically.
Definition: SPI.cpp:297
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.
Definition: SPI.cpp:188
double GetAccumulatorAverage() const
Read the average of the accumulated value.
Definition: SPI.cpp:281
void SetMSBFirst()
Configure the order that bits are sent and received on the wire to be most significant bit first...
Definition: SPI.cpp:54
void FreeAccumulator()
Frees the accumulator.
Definition: SPI.cpp:201
virtual int Write(uint8_t *data, int size)
Write data to the slave device.
Definition: SPI.cpp:129
int64_t GetAccumulatorValue() const
Read the accumulated value.
Definition: SPI.cpp:254
void SetChipSelectActiveLow()
Configure the chip select line to be active low.
Definition: SPI.cpp:116
void SetChipSelectActiveHigh()
Configure the chip select line to be active high.
Definition: SPI.cpp:107
virtual ~SPI()
Destructor.
Definition: SPI.cpp:38
SPI bus interface class.
Definition: SPI.h:24
void ResetAccumulator()
Resets the accumulator to zero.
Definition: SPI.cpp:210
void SetSampleDataOnRising()
Configure that the data is stable on the rising edge and the data changes on the falling edge...
Definition: SPI.cpp:81
SPI(Port SPIport)
Constructor.
Definition: SPI.cpp:24
virtual int Read(bool initiate, uint8_t *dataReceived, int size)
Read a word from the receive FIFO.
Definition: SPI.cpp:148
void SetClockActiveHigh()
Configure the clock output line to be active high.
Definition: SPI.cpp:99
void SetLSBFirst()
Configure the order that bits are sent and received on the wire to be least significant bit first...
Definition: SPI.cpp:63
Class to write to digital outputs.
Definition: DigitalOutput.h:26
virtual int Transaction(uint8_t *dataToSend, uint8_t *dataReceived, int size)
Perform a simultaneous read/write transaction with the device.
Definition: SPI.cpp:167
void SetClockRate(double hz)
Configure the rate of the generated clock signal.
Definition: SPI.cpp:48
Class to read a digital input.
Definition: DigitalInput.h:30
int GetAccumulatorLastValue() const
Read the last value read by the accumulator engine.
Definition: SPI.cpp:242
int64_t GetAccumulatorCount() const
Read the number of accumulated values.
Definition: SPI.cpp:269
void SetClockActiveLow()
Configure the clock output line to be active low.
Definition: SPI.cpp:90
void SetSampleDataOnFalling()
Configure that the data is stable on the falling edge and the data changes on the rising edge...
Definition: SPI.cpp:72