25 #ifndef ACE_SEGMENT_LED_MATRIX_SINGLE_HC595_H
26 #define ACE_SEGMENT_LED_MATRIX_SINGLE_HC595_H
29 #include "../hw/GpioInterface.h"
30 #include "LedMatrixBase.h"
32 class LedMatrixSingleHc595Test_drawElements;
34 namespace ace_segment {
52 template <
typename T_SPII,
typename T_GPIOI = GpioInterface>
64 const T_SPII& spiInterface,
65 uint8_t elementOnPattern,
66 uint8_t groupOnPattern,
68 const uint8_t* groupPins
71 mSpiInterface(spiInterface),
72 mGroupPins(groupPins),
78 uint8_t output = (0x00 ^ mGroupXorMask) & 0x1;
79 for (uint8_t group = 0; group < mNumGroups; group++) {
80 uint8_t pin = mGroupPins[group];
81 T_GPIOI::pinMode(pin, OUTPUT);
82 T_GPIOI::digitalWrite(pin, output);
88 for (uint8_t group = 0; group < mNumGroups; group++) {
89 uint8_t pin = mGroupPins[group];
90 T_GPIOI::pinMode(pin, INPUT);
94 void draw(uint8_t group, uint8_t elementPattern)
const {
95 if (group != mPrevGroup) {
96 disableGroup(mPrevGroup);
99 drawElements(elementPattern);
104 void enableGroup(uint8_t group)
const {
105 writeGroupPin(group, 0x1);
109 void disableGroup(uint8_t group)
const {
110 writeGroupPin(group, 0x0);
115 for (uint8_t group = 0; group < mNumGroups; group++) {
122 friend class ::LedMatrixSingleHc595Test_drawElements;
125 void drawElements(uint8_t pattern)
const {
126 uint8_t actualPattern = pattern ^ mElementXorMask;
127 mSpiInterface.send8(actualPattern);
131 void writeGroupPin(uint8_t group, uint8_t output)
const {
132 uint8_t groupPin = mGroupPins[group];
133 T_GPIOI::digitalWrite(groupPin, (output ^ mGroupXorMask) & 0x1);
141 const T_SPII mSpiInterface;
143 const uint8_t*
const mGroupPins;
145 uint8_t
const mNumGroups;
148 mutable uint8_t mPrevGroup = 0;