WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
SPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef __SPI_H__
8 #define __SPI_H__
9 
10 #include "ChipObject.h"
11 #include "SensorBase.h"
12 
13 class DigitalOutput;
14 class DigitalInput;
15 
24 class SPI : public SensorBase
25 {
26 public:
27  enum tFrameMode {kChipSelect, kPreLatchPulse, kPostLatchPulse, kPreAndPostLatchPulse};
28  enum tSPIConstants {kReceiveFIFODepth=512, kTransmitFIFODepth=512};
29 
30  SPI(DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso);
31  SPI(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso);
32  SPI(DigitalOutput &clk, DigitalOutput &mosi);
33  SPI(DigitalOutput *clk, DigitalOutput *mosi);
34  SPI(DigitalOutput &clk, DigitalInput &miso);
35  SPI(DigitalOutput *clk, DigitalInput *miso);
36  virtual ~SPI();
37 
38  void SetBitsPerWord(uint32_t bits);
39  uint32_t GetBitsPerWord();
40  void SetClockRate(double hz);
41 
42  void SetMSBFirst();
43  void SetLSBFirst();
44 
46  void SetSampleDataOnRising();
47 
48  void SetSlaveSelect(DigitalOutput *ss, tFrameMode mode=kChipSelect, bool activeLow=false);
49  void SetSlaveSelect(DigitalOutput &ss, tFrameMode mode=kChipSelect, bool activeLow=false);
50  DigitalOutput *GetSlaveSelect(tFrameMode *mode=NULL, bool *activeLow=NULL);
51 
52  void SetClockActiveLow();
53  void SetClockActiveHigh();
54 
55  virtual void ApplyConfig();
56 
57  virtual uint16_t GetOutputFIFOAvailable();
58  virtual uint16_t GetNumReceived();
59 
60  virtual bool IsDone();
61  bool HadReceiveOverflow();
62 
63  virtual void Write(uint32_t data);
64  virtual uint32_t Read(bool initiate = false);
65 
66  virtual void Reset();
67  virtual void ClearReceivedData();
68 
69 protected:
70  static SEM_ID m_semaphore;
71 
72  tSPI* m_spi;
73  tSPI::tConfig m_config;
74  tSPI::tChannels m_channels;
75  DigitalOutput *m_ss;
76 
77 private:
78  void Init(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso);
79 
80  DISALLOW_COPY_AND_ASSIGN(SPI);
81 };
82 
83 #endif
void SetMSBFirst()
Definition: SPI.cpp:220
Definition: DigitalInput.h:22
virtual void ApplyConfig()
Definition: SPI.cpp:361
void SetBitsPerWord(uint32_t bits)
Definition: SPI.cpp:176
DigitalOutput * GetSlaveSelect(tFrameMode *mode=NULL, bool *activeLow=NULL)
Definition: SPI.cpp:327
Definition: SPI.h:24
void SetLSBFirst()
Definition: SPI.cpp:229
virtual void ClearReceivedData()
Definition: SPI.cpp:521
bool HadReceiveOverflow()
Definition: SPI.cpp:419
Definition: DigitalOutput.h:21
virtual ~SPI()
Definition: SPI.cpp:101
virtual bool IsDone()
Definition: SPI.cpp:405
Definition: SensorBase.h:20
virtual void Write(uint32_t data)
Definition: SPI.cpp:434
virtual void Reset()
Definition: SPI.cpp:511
virtual uint16_t GetOutputFIFOAvailable()
Definition: SPI.cpp:378
uint32_t GetBitsPerWord()
Definition: SPI.cpp:187
virtual uint32_t Read(bool initiate=false)
Definition: SPI.cpp:466
void SetSampleDataOnFalling()
Definition: SPI.cpp:238
SPI(DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso)
Definition: SPI.cpp:31
virtual uint16_t GetNumReceived()
Definition: SPI.cpp:392
void SetClockActiveLow()
Definition: SPI.cpp:344
void SetSlaveSelect(DigitalOutput *ss, tFrameMode mode=kChipSelect, bool activeLow=false)
Definition: SPI.cpp:263
void SetClockActiveHigh()
Definition: SPI.cpp:353
void SetClockRate(double hz)
Definition: SPI.cpp:198
void SetSampleDataOnRising()
Definition: SPI.cpp:247