|
@@ -28,7 +28,11 @@
|
28
|
28
|
#define OK 0x42
|
29
|
29
|
#define ERROR 0x23
|
30
|
30
|
|
31
|
|
-#define VERSION "8^3 LED-Cube v1\n"
|
|
31
|
+#ifdef DEBUG
|
|
32
|
+#define VERSION "v2 (Debug Build)\nNOT COMPATIBLE WITH CubeControl!\n"
|
|
33
|
+#else
|
|
34
|
+#define VERSION "v2\n"
|
|
35
|
+#endif
|
32
|
36
|
|
33
|
37
|
#include <avr/io.h>
|
34
|
38
|
#include <util/delay.h>
|
|
@@ -41,9 +45,22 @@
|
41
|
45
|
#include "cube.h"
|
42
|
46
|
#include "time.h"
|
43
|
47
|
#include "audio.h"
|
|
48
|
+#include "mem.h"
|
44
|
49
|
#include "memLayer.h"
|
45
|
50
|
#include "twi.h"
|
46
|
51
|
|
|
52
|
+#define NOERROR 0
|
|
53
|
+
|
|
54
|
+#define AUDIOERROR 1
|
|
55
|
+
|
|
56
|
+#define MEMORYERROR 2
|
|
57
|
+
|
|
58
|
+#define MEMORYWRITEERROR 4
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+#define ISERROR(x, e) ((x) & (e))
|
|
62
|
+
|
|
63
|
+uint8_t selfTest(void);
|
47
|
64
|
void serialHandler(char c);
|
48
|
65
|
void sendAudioData(void);
|
49
|
66
|
void recieveAnimations(void);
|
|
@@ -53,6 +70,9 @@ inline void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t **buf);
|
53
|
70
|
inline void clearPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t **buf);
|
54
|
71
|
void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t **buf);
|
55
|
72
|
void visualizeAudioData(uint8_t *audioData, uint8_t **imageData);
|
|
73
|
+#ifdef DEBUG
|
|
74
|
+void printErrors(uint8_t e);
|
|
75
|
+#endif
|
56
|
76
|
|
57
|
77
|
uint8_t refreshAnimationCount = 1;
|
58
|
78
|
uint8_t lastButtonState = 0;
|
|
@@ -76,6 +96,17 @@ int main(void) {
|
76
|
96
|
DDRC = 0xFF;
|
77
|
97
|
DDRA = 0xFF;
|
78
|
98
|
|
|
99
|
+ i = selfTest();
|
|
100
|
+ if (i) {
|
|
101
|
+
|
|
102
|
+#ifdef DEBUG
|
|
103
|
+ serialWriteString("Self-Test Error: 0b");
|
|
104
|
+ serialWriteString(itoa(i, buffer, 2));
|
|
105
|
+ serialWrite('\n');
|
|
106
|
+ printErrors(i);
|
|
107
|
+#endif
|
|
108
|
+ }
|
|
109
|
+
|
79
|
110
|
imageData = (uint8_t **)malloc(8 * sizeof(uint8_t *));
|
80
|
111
|
for (i = 0; i < 8; i++) {
|
81
|
112
|
imageData[i] = (uint8_t *)malloc(8 * sizeof(uint8_t));
|
|
@@ -132,14 +163,66 @@ int main(void) {
|
132
|
163
|
return 0;
|
133
|
164
|
}
|
134
|
165
|
|
|
166
|
+uint8_t selfTest(void) {
|
|
167
|
+ uint8_t result = NOERROR;
|
|
168
|
+
|
|
169
|
+ uint8_t *data = getAudioData();
|
|
170
|
+ if (data == NULL) {
|
|
171
|
+ result |= AUDIOERROR;
|
|
172
|
+ } else {
|
|
173
|
+ free(data);
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ data = memGetBytes(0, 1);
|
|
177
|
+ if (data == NULL) {
|
|
178
|
+ result |= MEMORYERROR;
|
|
179
|
+ } else {
|
|
180
|
+ free(data);
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ setGeneralPurposeByte(0, 0x42);
|
|
184
|
+ if (getGeneralPurposeByte(0) != 0x42) {
|
|
185
|
+ result |= MEMORYWRITEERROR;
|
|
186
|
+ }
|
|
187
|
+
|
|
188
|
+ return result;
|
|
189
|
+}
|
|
190
|
+
|
|
191
|
+#ifdef DEBUG
|
|
192
|
+void printErrors(uint8_t e) {
|
|
193
|
+ if (ISERROR(e, AUDIOERROR)) {
|
|
194
|
+ serialWriteString(" => No answer from Audio!\n");
|
|
195
|
+ }
|
|
196
|
+ if (ISERROR(e, MEMORYERROR)) {
|
|
197
|
+ serialWriteString(" => No answer from Memory!\n");
|
|
198
|
+ }
|
|
199
|
+ if (ISERROR(e, MEMORYWRITEERROR)) {
|
|
200
|
+ serialWriteString(" => Can't write to Memory!\n");
|
|
201
|
+ }
|
|
202
|
+}
|
|
203
|
+#endif
|
|
204
|
+
|
135
|
205
|
void serialHandler(char c) {
|
136
|
206
|
|
137
|
207
|
|
|
208
|
+#ifdef DEBUG
|
|
209
|
+ serialWrite(c);
|
|
210
|
+ serialWriteString(": ");
|
|
211
|
+#endif
|
|
212
|
+
|
138
|
213
|
switch(c) {
|
139
|
214
|
case OK:
|
140
|
215
|
serialWrite(OK);
|
141
|
216
|
break;
|
142
|
217
|
|
|
218
|
+ case 'h': case 'H':
|
|
219
|
+ serialWriteString("(d)elete, (g)et anims, (s)et anims, (v)ersion\n");
|
|
220
|
+#ifdef DEBUG
|
|
221
|
+ serialWriteString("(t)ime, (a)udio, (c)ount, (x)Custom count\n");
|
|
222
|
+ serialWriteString("(y)Set fixed animation count\n");
|
|
223
|
+#endif
|
|
224
|
+ break;
|
|
225
|
+
|
143
|
226
|
case 'd': case 'D':
|
144
|
227
|
clearMem();
|
145
|
228
|
serialWrite(OK);
|
|
@@ -157,6 +240,7 @@ void serialHandler(char c) {
|
157
|
240
|
serialWriteString(VERSION);
|
158
|
241
|
break;
|
159
|
242
|
|
|
243
|
+#ifdef DEBUG
|
160
|
244
|
case 't': case 'T':
|
161
|
245
|
serialWriteString("System Time: ");
|
162
|
246
|
serialWriteString(ltoa(getSystemTime(), buffer, 10));
|
|
@@ -190,42 +274,46 @@ void serialHandler(char c) {
|
190
|
274
|
|
191
|
275
|
case 'x': case 'X':
|
192
|
276
|
|
193
|
|
- serialWriteString("Send a byte...");
|
|
277
|
+ serialWriteString("Send a byte... ");
|
194
|
278
|
while (!serialHasChar());
|
195
|
|
- setAnimationCount(serialGet());
|
196
|
|
- serialWriteString(" Byte written!\n");
|
|
279
|
+ c = serialGet();
|
|
280
|
+ setAnimationCount(c);
|
|
281
|
+ serialWriteString(itoa(c, buffer, 10));
|
|
282
|
+ serialWriteString(" written!\n");
|
197
|
283
|
break;
|
198
|
284
|
|
199
|
|
- case '\n':
|
200
|
|
- serialWriteString(VERSION);
|
201
|
|
- serialWriteString("See xythobuz.org for more Infos!\n");
|
|
285
|
+ case 'y': case 'Y':
|
|
286
|
+ setAnimationCount(0x2201);
|
|
287
|
+ serialWriteString("Animation count now 8705!\n");
|
202
|
288
|
break;
|
|
289
|
+#endif
|
203
|
290
|
|
204
|
291
|
default:
|
205
|
292
|
serialWrite(ERROR);
|
206
|
293
|
break;
|
207
|
294
|
}
|
|
295
|
+
|
208
|
296
|
}
|
209
|
297
|
|
|
298
|
+#ifdef DEBUG
|
210
|
299
|
void sendAudioData(void) {
|
211
|
300
|
uint8_t i;
|
212
|
301
|
uint8_t *audioData = getAudioData();
|
213
|
302
|
if (audioData == NULL) {
|
214
|
303
|
serialWriteString("Could not access device!\n");
|
215
|
|
- return;
|
216
|
|
- }
|
217
|
|
-
|
218
|
|
- serialWriteString("Audio Data:\n");
|
219
|
|
- for (i = 0; i < 7; i++) {
|
220
|
|
- serialWrite(i + '0');
|
221
|
|
- serialWriteString(": ");
|
222
|
|
- itoa(audioData[i], buffer, 10);
|
223
|
|
- serialWriteString(buffer);
|
224
|
|
- serialWrite('\n');
|
|
304
|
+ } else {
|
|
305
|
+ serialWriteString("Audio Data:\n");
|
|
306
|
+ for (i = 0; i < 7; i++) {
|
|
307
|
+ serialWrite(i + '0');
|
|
308
|
+ serialWriteString(": ");
|
|
309
|
+ itoa(audioData[i], buffer, 10);
|
|
310
|
+ serialWriteString(buffer);
|
|
311
|
+ serialWrite('\n');
|
|
312
|
+ }
|
|
313
|
+ free(audioData);
|
225
|
314
|
}
|
226
|
|
-
|
227
|
|
- free(audioData);
|
228
|
315
|
}
|
|
316
|
+#endif
|
229
|
317
|
|
230
|
318
|
void recieveAnimations() {
|
231
|
319
|
uint8_t animCount, a, frameCount, f, i;
|