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 {
50 template <
typename T_SPII,
typename T_GPIOI = GpioInterface>
54 const T_SPII& spiInterface,
55 uint8_t elementOnPattern,
56 uint8_t groupOnPattern,
58 const uint8_t* groupPins
61 mSpiInterface(spiInterface),
62 mGroupPins(groupPins),
68 uint8_t output = (0x00 ^ mGroupXorMask) & 0x1;
69 for (uint8_t group = 0; group < mNumGroups; group++) {
70 uint8_t pin = mGroupPins[group];
71 T_GPIOI::pinMode(pin, OUTPUT);
72 T_GPIOI::digitalWrite(pin, output);
78 for (uint8_t group = 0; group < mNumGroups; group++) {
79 uint8_t pin = mGroupPins[group];
80 T_GPIOI::pinMode(pin, INPUT);
84 void draw(uint8_t group, uint8_t elementPattern)
const {
85 if (group != mPrevGroup) {
86 disableGroup(mPrevGroup);
89 drawElements(elementPattern);
94 void enableGroup(uint8_t group)
const {
95 writeGroupPin(group, 0x1);
99 void disableGroup(uint8_t group)
const {
100 writeGroupPin(group, 0x0);
105 for (uint8_t group = 0; group < mNumGroups; group++) {
112 friend class ::LedMatrixSingleHc595Test_drawElements;
115 void drawElements(uint8_t pattern)
const {
116 uint8_t actualPattern = pattern ^ mElementXorMask;
117 mSpiInterface.send8(actualPattern);
121 void writeGroupPin(uint8_t group, uint8_t output)
const {
122 uint8_t groupPin = mGroupPins[group];
123 T_GPIOI::digitalWrite(groupPin, (output ^ mGroupXorMask) & 0x1);
127 const T_SPII& mSpiInterface;
128 const uint8_t*
const mGroupPins;
129 uint8_t
const mNumGroups;
132 mutable uint8_t mPrevGroup = 0;