AceSegment  0.7.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 
67 template <
68  typename T_SPII,
69  uint8_t T_DIGITS,
70  uint8_t T_SUBFIELDS = 1,
71  typename T_CI = ClockInterface
72 >
73 class Hc595Module : public ScanningModule<
74  LedMatrixDualHc595<T_SPII>,
75  T_DIGITS,
76  T_SUBFIELDS,
77  T_CI
78 > {
79  private:
80  using Super = ScanningModule<
82  T_DIGITS,
83  T_SUBFIELDS,
84  T_CI
85  >;
86 
87  public:
107  const T_SPII& spiInterface,
108  uint8_t segmentOnPattern,
109  uint8_t digitOnPattern,
110  uint8_t framesPerSecond,
111  uint8_t byteOrder,
112  const uint8_t* remapArray = nullptr
113  ) :
114  Super(mLedMatrix, framesPerSecond),
115  mLedMatrix(
116  spiInterface,
117  segmentOnPattern /*elementOnPattern*/,
118  digitOnPattern /*groupOnPattern*/,
119  byteOrder,
120  remapArray ? mRemapArrayInverted : nullptr
121  )
122  {
123  // LedMatrixDualHc595 needs the inverted mapping.
124  if (remapArray) {
125  internal::invertRemapArray(mRemapArrayInverted, remapArray, T_DIGITS);
126  }
127  }
128 
129  void begin() {
130  mLedMatrix.begin();
131  Super::begin();
132  }
133 
134  void end() {
135  mLedMatrix.end();
136  Super::end();
137  }
138 
139  private:
140  LedMatrixDualHc595<T_SPII> mLedMatrix;
141 
143  uint8_t mRemapArrayInverted[T_DIGITS];
144 };
145 
146 } // ace_segment
147 
148 #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:54
ace_segment::Hc595Module
An implementation of LedModule class that supports an LED module using 2 74HC595 Shift Register chips...
Definition: Hc595Module.h:73
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:106