Control Surface  1.1.0
MIDI Control Surface library for Arduino
SPIShiftRegisterOut.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7 
8 #include "ShiftRegisterOutBase.hpp"
10 
12 #include <Arduino.h> // MSBFIRST, SS
14 
16 
17 /**
18  * @brief A class for serial-in/parallel-out shift registers,
19  * like the 74HC595 that are connected to the SPI bus.
20  *
21  * @tparam N
22  * The number of bits in total. Usually, shift registers (e.g. the
23  * 74HC595) have eight bits per chip, so `length = 8 * k` where `k`
24  * is the number of cascaded chips.
25  *
26  * @ingroup AH_ExtIO
27  */
28 template <uint8_t N>
30  public:
32 
33  /**
34  * @brief Create a new SPIShiftRegisterOut object with a given bit order,
35  * and a given number of outputs.
36  *
37  * Multiple shift registers can be cascaded by connecting the serial output
38  * of the first one to the input of the second one:
39  *
40  * ```
41  * SCK >───────────┬──────────────────────┬───────── ⋯
42  * ┏━━━━━━━┷━━━━━━━┓ ┏━━━━━━━┷━━━━━━━┓
43  * ┃ SH_CP ┃ ┃ SH_CP ┃
44  * MOSI >───┨ DS Q7S ┠──────┨ DS Q7S ┠─ ⋯
45  * ┃ ST_CP ┃ ┃ ST_CP ┃
46  * ┗━━━━━━━┯━━━━━━━┛ ┗━━━━━━━┯━━━━━━━┛
47  * CS >───────────┴──────────────────────┴───────── ⋯
48  * ```
49  *
50  * @param latchPin
51  * The digital output pin connected to the latch pin (ST_CP or
52  * RCLK) of the shift register.
53  * @param bitOrder
54  * Either `MSBFIRST` (most significant bit first) or `LSBFIRST`
55  * (least significant bit first).
56  */
57  SPIShiftRegisterOut(pin_t latchPin = SS, BitOrder_t bitOrder = MSBFIRST);
58 
59  /**
60  * @brief Initialize the shift register.
61  * Setup the SPI interface, set the CS pin to output mode,
62  * and set all shift register outputs to `LOW`.
63  */
64  void begin() override;
65 
66  /**
67  * @brief Write the state buffer to the physical outputs.
68  */
69  void update() override;
70 };
71 
73 
74 #include "SPIShiftRegisterOut.ipp"
75 
Warnings.hpp
AH::ShiftRegisterOutBase
A class for serial-in/parallel-out shift registers, like the 74HC595.
Definition: ShiftRegisterOutBase.hpp:25
SPIShiftRegisterOut.ipp
BitArray.hpp
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH_DIAGNOSTIC_EXTERNAL_HEADER
#define AH_DIAGNOSTIC_EXTERNAL_HEADER()
Definition: Warnings.hpp:18
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
AH::ShiftRegisterOutBase::BitOrder_t
uint8_t BitOrder_t
Definition: ShiftRegisterOutBase.hpp:30
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:16
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10
AH::SPIShiftRegisterOut
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
Definition: SPIShiftRegisterOut.hpp:29