Treehopper C++ API
ChainableShiftRegisterOutput.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "Spi.h"
6 #include "SpiDevice.h"
7 #include <vector>
8 
9 namespace Treehopper {
10  namespace Libraries {
11  namespace IO {
12  namespace PortExpander {
21 
23  public:
33  ChainableShiftRegisterOutput(Spi &spiModule, SpiChipSelectPin *latchPin, int numBytes = 1,
34  double speedMhz = 5, SpiMode mode = SpiMode::Mode00,
36 
42  ChainableShiftRegisterOutput(ChainableShiftRegisterOutput &upstreamDevice, int numBytes = 1);
43 
49  void write(uint8_t *value);
50 
56  void flush(bool force = false);
57 
58 
62  uint8_t *currentValue;
63 
65  int numBytes;
66  protected:
70  void flushIfAutoFlushEnabled();
71 
75  virtual void updateFromCurrentValue() = 0;
76 
81  static void requestWrite();
82 
83  private:
84  void setupSpi(Spi &spiModule, SpiChipSelectPin *latchPin, double speedMhz, SpiMode mode,
85  ChipSelectMode csMode);
86 
87  uint8_t *lastValues;
88  static SpiDevice *spiDevice;
89  static vector<ChainableShiftRegisterOutput *> shiftRegisters;
90  };
91  }
92  }
93  }
94 }
Represents any object that has a flushable interface.
Definition: Flushable.h:9
SpiMode
Defines the clock phase and polarity used for SPI communication.
Definition: SpiMode.h:10
An SPI port.
Definition: Spi.h:15
The SPI transaction takes place, and once finished, CS is pulsed high.
Any shift-register-like device that can be daisy-chained onto other shift registers.
Definition: ChainableShiftRegisterOutput.h:22
Clock is initially low; data is valid on the rising edge of the clock
int numBytes
The number of bytes wide this port is.
Definition: ChainableShiftRegisterOutput.h:65
uint8_t * currentValue
The current value of the port.
Definition: ChainableShiftRegisterOutput.h:62
#define LIBRARIES_API
Definition: Treehopper.Libraries.h:17
Definition: AdcPin.h:3
Definition: SpiChipSelectPin.h:7
Represents a peripheral on the SPI bus.
Definition: SpiDevice.h:12
ChipSelectMode
Definition: ChipSelectMode.h:3