Arduino Helpers master
Utility library for Arduino
SPIShiftRegisterOut.ipp
Go to the documentation of this file.
1#ifdef ARDUINO // TODO: I'm too lazy to mock the SPI library
2
5
7#include <SPI.h>
9
11
12template <uint16_t N, class SPIDriver>
13SPIShiftRegisterOut<N, SPIDriver>::SPIShiftRegisterOut(SPIDriver spi,
14 pin_t latchPin,
15 BitOrder_t bitOrder)
16 : ShiftRegisterOutBase<N>(latchPin, bitOrder),
17 spi(std::forward<SPIDriver>(spi)) {}
18
19template <uint16_t N, class SPIDriver>
21 ExtIO::pinMode(this->latchPin, OUTPUT);
22 spi.begin();
23 updateBufferedOutputs();
24}
25
26template <uint16_t N, class SPIDriver>
28 if (!this->dirty)
29 return;
30 spi.beginTransaction(settings);
31 ExtIO::digitalWrite(this->latchPin, LOW);
32 const uint16_t bufferLength = this->buffer.getBufferLength();
33 if (this->bitOrder == LSBFIRST)
34 for (uint16_t i = 0; i < bufferLength; i++)
35 spi.transfer(this->buffer.getByte(i));
36 else
37 for (uint16_t i = bufferLength; i-->0;)
38 spi.transfer(this->buffer.getByte(i));
39 ExtIO::digitalWrite(this->latchPin, HIGH);
40 spi.endTransaction();
41 this->dirty = false;
42}
43
45
46#endif
constexpr PinStatus_t LOW
uint8_t BitOrder_t
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_EXTERNAL_HEADER()
Definition: Warnings.hpp:51
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:50
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
void updateBufferedOutputs() override
Write the state buffer to the physical outputs.
void begin() override
Initialize the shift register.
A class for serial-in/parallel-out shift registers, like the 74HC595.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
Definition: vector.cpp:5