25 #ifndef ACE_SEGMENT_TM1638_ANODE_MODULE_H
26 #define ACE_SEGMENT_TM1638_ANODE_MODULE_H
31 #include "../LedModule.h"
33 class Tm1638ModuleTest_flushIncremental;
34 class Tm1638ModuleTest_flush;
36 namespace ace_segment {
47 template <
typename T_TMII, u
int8_t T_DIGITS>
59 const T_TMII& tmiInterface
62 mTmiInterface(tmiInterface)
76 memset(mPatterns, 0, T_DIGITS);
125 mTmiInterface.beginTransaction();
126 mTmiInterface.write(kDataCmdAutoAddress);
127 mTmiInterface.endTransaction();
135 const uint8_t NUM_SEGMENTS = 8;
136 mTmiInterface.beginTransaction();
137 mTmiInterface.write(kAddressCmd);
138 uint8_t digitMask = 0x1;
139 for (uint8_t grid = 0; grid < NUM_SEGMENTS; ++grid) {
140 uint8_t gridPattern = 0x0;
141 uint8_t gridMask = 0x80;
142 for (uint8_t digit = 0; digit < T_DIGITS; ++digit) {
143 uint8_t digitPattern = mPatterns[digit];
144 if (digitPattern & digitMask) {
145 gridPattern |= gridMask;
150 mTmiInterface.write(gridPattern);
151 mTmiInterface.write(0x00);
153 mTmiInterface.endTransaction();
159 mTmiInterface.beginTransaction();
160 mTmiInterface.write(kBrightnessCmd
161 | (mDisplayOn ? kBrightnessLevelOn : 0x0)
163 mTmiInterface.endTransaction();
180 mTmiInterface.beginTransaction();
181 mTmiInterface.write(kDataCmdReadKeys);
187 delayMicroseconds(3);
189 uint8_t byte1 = mTmiInterface.read();
190 uint8_t byte2 = mTmiInterface.read();
191 uint8_t byte3 = mTmiInterface.read();
192 uint8_t byte4 = mTmiInterface.read();
193 mTmiInterface.endTransaction();
195 uint32_t data = ((uint32_t) byte4 << 24)
196 | ((uint32_t) byte3 << 16)
197 | ((uint32_t) byte2 << 8)
204 friend class ::Tm1638ModuleTest_flush;
207 static uint8_t
const kDataCmdWriteDisplay = 0b01000000;
208 static uint8_t
const kDataCmdReadKeys = 0b01000010;
209 static uint8_t
const kDataCmdAutoAddress = 0b01000000;
210 static uint8_t
const kDataCmdFixedAddress = 0b01000100;
211 static uint8_t
const kAddressCmd = 0b11000000;
212 static uint8_t
const kBrightnessCmd = 0b10000000;
213 static uint8_t
const kBrightnessLevelOn = 0b00001000;
220 const T_TMII mTmiInterface;
222 uint8_t mPatterns[T_DIGITS];