AceSegment  0.8.0
A framework for rendering seven segment LED displays using the TM1637, MAX7219, HT16K33, or 74HC595 controller chips
Hc595Module.h
1 /*
2 MIT License
3 
4 Copyright (c) 2021 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef ACE_SEGMENT_HC595_MODULE_H
26 #define ACE_SEGMENT_HC595_MODULE_H
27 
28 #include "../hw/remap.h"
29 #include "../scanning/ScanningModule.h"
30 #include "../scanning/LedMatrixDualHc595.h"
31 
32 namespace ace_segment {
33 
35 const uint8_t kByteOrderDigitHighSegmentLow = kByteOrderGroupHighElementLow;
36 
38 const uint8_t kByteOrderSegmentHighDigitLow = kByteOrderElementHighGroupLow;
39 
52 extern const uint8_t kDigitRemapArray8Hc595[8];
53 
69 template <
70  typename T_SPII,
71  uint8_t T_DIGITS,
72  uint8_t T_SUBFIELDS = 1,
73  typename T_CI = ClockInterface
74 >
75 class Hc595Module : public ScanningModule<
76  LedMatrixDualHc595<T_SPII>,
77  T_DIGITS,
78  T_SUBFIELDS,
79  T_CI
80 > {
81  private:
82  using Super = ScanningModule<
84  T_DIGITS,
85  T_SUBFIELDS,
86  T_CI
87  >;
88 
89  public:
109  const T_SPII& spiInterface,
110  uint8_t segmentOnPattern,
111  uint8_t digitOnPattern,
112  uint8_t framesPerSecond,
113  uint8_t byteOrder,
114  const uint8_t* remapArray = nullptr
115  ) :
116  Super(mLedMatrix, framesPerSecond),
117  mLedMatrix(
118  spiInterface,
119  segmentOnPattern /*elementOnPattern*/,
120  digitOnPattern /*groupOnPattern*/,
121  byteOrder,
122  remapArray ? mRemapArrayInverted : nullptr
123  )
124  {
125  // LedMatrixDualHc595 needs the inverted mapping.
126  if (remapArray) {
127  internal::invertRemapArray(mRemapArrayInverted, remapArray, T_DIGITS);
128  }
129  }
130 
131  void begin() {
132  mLedMatrix.begin();
133  Super::begin();
134  }
135 
136  void end() {
137  mLedMatrix.end();
138  Super::end();
139  }
140 
141  private:
142  LedMatrixDualHc595<T_SPII> mLedMatrix;
143 
145  uint8_t mRemapArrayInverted[T_DIGITS];
146 };
147 
148 } // ace_segment
149 
150 #endif
ace_segment::LedMatrixDualHc595
An LedMatrix that whose group pins are attached to one 74HC595 shift register and the element pins ar...
Definition: LedMatrixDualHc595.h:56
ace_segment::Hc595Module
An implementation of LedModule class that supports an LED module using 2 74HC595 Shift Register chips...
Definition: Hc595Module.h:75
ace_segment::ScanningModule::end
void end()
A no-op end() function for consistency with other classes.
Definition: ScanningModule.h:128
ace_segment::ScanningModule
An implementation of LedModule for display modules which do not have hardware controller chips,...
Definition: ScanningModule.h:80
ace_segment::ScanningModule::begin
void begin()
Configure the driver with the parameters given by in the constructor.
Definition: ScanningModule.h:108
ace_segment::Hc595Module::Hc595Module
Hc595Module(const T_SPII &spiInterface, uint8_t segmentOnPattern, uint8_t digitOnPattern, uint8_t framesPerSecond, uint8_t byteOrder, const uint8_t *remapArray=nullptr)
Definition: Hc595Module.h:108