AceSegment  0.4.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
LedMatrixDualShiftRegister.h
1 /*
2 MIT License
3 
4 Copyright (c) 2018 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_LED_MATRIX_DUAL_SHIFT_REGISTER_H
26 #define ACE_SEGMENT_LED_MATRIX_DUAL_SHIFT_REGISTER_H
27 
28 #include "LedMatrixBase.h"
29 
30 class LedMatrixDualShiftRegisterTest_draw;
31 class LedMatrixDualShiftRegisterTest_enableGroup;
32 class LedMatrixDualShiftRegisterTest_disableGroup;
33 
34 namespace ace_segment {
35 
47 template<typename SA>
49  public:
51  const SA& spiAdapter,
52  uint8_t groupOnPattern,
53  uint8_t elementOnPattern
54  ) :
55  LedMatrixBase(groupOnPattern, elementOnPattern),
56  mSpiAdapter(spiAdapter)
57  {}
58 
59  void begin() const {}
60 
61  void end() const {}
62 
67  void draw(uint8_t group, uint8_t elementPattern) const {
68  uint8_t groupPattern = 0x1 << group; // Would a lookup table be faster?
69 
70  uint8_t actualGroupPattern = (groupPattern ^ mGroupXorMask);
71  uint8_t actualElementPattern = (elementPattern ^ mElementXorMask);
72 
73  mSpiAdapter.transfer16(
74  actualGroupPattern << 8 | actualElementPattern);
75  mPrevElementPattern = elementPattern;
76  }
77 
78  void enableGroup(uint8_t group) const {
79  draw(group, mPrevElementPattern);
80  }
81 
82  void disableGroup(uint8_t group) const {
83  (void) group;
84  clear();
85  }
86 
87  void clear() const {
88  uint8_t actualGroupPattern = 0x00 ^ mGroupXorMask;
89  uint8_t actualElementPattern = 0x00 ^ mElementXorMask;
90  mSpiAdapter.transfer16(
91  actualGroupPattern << 8 | actualElementPattern);
92  mPrevElementPattern = 0x00;
93  }
94 
95  private:
96  friend class ::LedMatrixDualShiftRegisterTest_draw;
97  friend class ::LedMatrixDualShiftRegisterTest_enableGroup;
98  friend class ::LedMatrixDualShiftRegisterTest_disableGroup;
99 
100  const SA& mSpiAdapter;
101 
106  mutable uint8_t mPrevElementPattern;
107 };
108 
109 }
110 
111 #endif
ace_segment::LedMatrixBase
Class that represents the abstraction of a particular LED display wiring, and knows how to turn off a...
Definition: LedMatrixBase.h:72
ace_segment::LedMatrixBase::LedMatrixBase
LedMatrixBase(uint8_t groupOnPattern, uint8_t elementOnPattern)
Definition: LedMatrixBase.h:85
ace_segment::LedMatrixDualShiftRegister::draw
void draw(uint8_t group, uint8_t elementPattern) const
Write out the group and element patterns in a single 16-bit stream with the group bits in the MSB and...
Definition: LedMatrixDualShiftRegister.h:67
ace_segment::LedMatrixDualShiftRegister
An LedMatrix that whose group pins are attached to one 74HC595 shift register and the element pins ar...
Definition: LedMatrixDualShiftRegister.h:48