This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
SPIShiftRegisterOut.ipp
Go to the documentation of this file.
1 #ifdef ARDUINO // I'm too lazy to mock the SPI library
2 
5 #include <SPI.h>
6 
8 
9 template <uint8_t N>
11  : ShiftRegisterOutBase<N>(latchPin, bitOrder) {}
12 
13 template <uint8_t N>
15  ExtIO::pinMode(this->latchPin, OUTPUT);
16  SPI.begin();
17  update();
18 }
19 
20 template <uint8_t N>
22  if (!this->dirty)
23  return;
24  SPISettings settings = {SPI_MAX_SPEED, this->bitOrder, SPI_MODE0};
25  SPI.beginTransaction(settings);
26  ExtIO::digitalWrite(this->latchPin, LOW);
27  const uint8_t bufferLength = this->buffer.getBufferLength();
28  if (this->bitOrder == LSBFIRST)
29  for (uint8_t i = 0; i < bufferLength; i++)
30  SPI.transfer(this->buffer.getByte(i));
31  else
32  for (int8_t i = bufferLength - 1; i >= 0; i--)
33  SPI.transfer(this->buffer.getByte(i));
34  ExtIO::digitalWrite(this->latchPin, HIGH);
35  SPI.endTransaction();
36  this->dirty = false;
37 }
38 
40 
41 #endif
SPIShiftRegisterOut::update
void update() override
Write the state buffer to the physical outputs.
Definition: SPIShiftRegisterOut.ipp:21
ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:34
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
SPIShiftRegisterOut.hpp
ExtendedInputOutput.hpp
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:34
ShiftRegisterOutBase
A class for serial-in/parallel-out shift registers, like the 74HC595.
Definition: ShiftRegisterOutBase.hpp:22
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
ExtIO::digitalWrite
void digitalWrite(pin_t pin, uint8_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:45
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:35
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
SPI_MAX_SPEED
constexpr static Frequency SPI_MAX_SPEED
Definition: Settings.hpp:113
SPIShiftRegisterOut::SPIShiftRegisterOut
SPIShiftRegisterOut(pin_t latchPin=SS, uint8_t bitOrder=MSBFIRST)
Create a new SPIShiftRegisterOut object with a given bit order, and a given number of outputs.
Definition: SPIShiftRegisterOut.ipp:10
SPIShiftRegisterOut::begin
void begin() override
Initialize the shift register.
Definition: SPIShiftRegisterOut.ipp:14
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:38