Treehopper C++ API
SpiDevice.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Treehopper.h"
4 #include "Spi.h"
5 #include "SpiChipSelectPin.h"
6 
7 namespace Treehopper {
12  class SpiDevice {
13  public:
22  SpiDevice(Spi &spiModule, SpiChipSelectPin *chipSelect,
23  ChipSelectMode chipSelectMode = ChipSelectMode::SpiActiveLow, double speedMhz = 1,
24  SpiMode mode = SpiMode::Mode00)
25  : spi(spiModule), chipSelect(chipSelect), chipSelectMode(chipSelectMode), frequency(speedMhz),
26  mode(mode) {
27  chipSelect->makePushPullOutput();
28  spi.enabled(true);
29  }
30 
36  std::vector<uint8_t> sendReceive(std::vector<uint8_t> dataToSend, SpiBurstMode burst) {
37  return spi.sendReceive(dataToSend, chipSelect, chipSelectMode, frequency, burst, mode);
38  }
39 
40  private:
41  Spi &spi;
42  ChipSelectMode chipSelectMode;
43  SpiChipSelectPin *chipSelect;
44  double frequency;
45  SpiMode mode;
46 
47  };
48 }
virtual std::vector< uint8_t > sendReceive(std::vector< uint8_t > dataToWrite, SpiChipSelectPin *chipSelect=nullptr, ChipSelectMode chipSelectMode=ChipSelectMode::SpiActiveLow, double speed=6, SpiBurstMode burstMode=SpiBurstMode::NoBurst, SpiMode spiMode=SpiMode::Mode00)=0
Send/receive data out of this SPI port.
SpiMode
Defines the clock phase and polarity used for SPI communication.
Definition: SpiMode.h:10
SpiBurstMode
The SPI burst mode to use.
Definition: SpiBurstMode.h:7
An SPI port.
Definition: Spi.h:15
std::vector< uint8_t > sendReceive(std::vector< uint8_t > dataToSend, SpiBurstMode burst)
Starts an SPI send/receive transaction.
Definition: SpiDevice.h:36
virtual bool enabled()=0
Gets whether the port is enabled.
Clock is initially low; data is valid on the rising edge of the clock
CS is asserted low, the SPI transaction takes place, and then the signal is returned high...
Definition: AdcPin.h:3
SpiDevice(Spi &spiModule, SpiChipSelectPin *chipSelect, ChipSelectMode chipSelectMode=ChipSelectMode::SpiActiveLow, double speedMhz=1, SpiMode mode=SpiMode::Mode00)
Construct an SPI device attached to a particular module
Definition: SpiDevice.h:22
Definition: SpiChipSelectPin.h:7
Represents a peripheral on the SPI bus.
Definition: SpiDevice.h:12
virtual void makePushPullOutput()=0
Make the pin a push-pull output.
ChipSelectMode
Definition: ChipSelectMode.h:3