Procházet zdrojové kódy

Misc Firmware fixes.

Audio Firmware now with Watchdog. Removed unused code. Fixed compiler
warnings. Fixed cube coordinate system problems. Fixed audio display
rotation. Nicer Idle Display with SAP Logo. Increased Firmware Version
Number. Debug Build even more talky.
Thomas Buck před 12 roky
rodič
revize
91441ad45c

+ 1
- 20
AudioFirmware/eq.c Zobrazit soubor

@@ -46,25 +46,6 @@ void equalizerInit(void) {
46 46
 
47 47
 }
48 48
 
49
-void eqLed(uint8_t *d) {
50
-	uint8_t pins[7] = { PD2, PD3, PD4, PD5, PD6, PD7, PB0 };
51
-	uint8_t i;
52
-
53
-	for (i = 0; i < 7; i++) {
54
-		if (d[i] >= 127) {
55
-			if (i < 6)
56
-				PORTD |= (1 << pins[i]);
57
-			else
58
-				PORTB |= (1 << pins[i]);
59
-		} else {
60
-			if (i < 6)
61
-				PORTD &= ~(1 << pins[i]);
62
-			else
63
-				PORTB &= ~(1 << pins[i]);
64
-		}
65
-	}
66
-}
67
-
68 49
 uint8_t *equalizerGet(void) {
69 50
 	uint8_t *result = (uint8_t *)malloc(7); // Has to work... If not, were screwed anyway :)
70 51
 	uint8_t i, offset = getOffset();
@@ -78,7 +59,7 @@ uint8_t *equalizerGet(void) {
78 59
 		PORTC &= ~(1 << PC2);
79 60
 		adcStartConversion(0x00);
80 61
 		_delay_us(READDELAY); // Wait for result to appear
81
-		result[i] = offset + adcGetByte(); // This line hangs
62
+		result[i] = offset + adcGetByte();
82 63
 		_delay_us(STROBEDELAY);
83 64
 	}
84 65
 

+ 11
- 10
AudioFirmware/main.c Zobrazit soubor

@@ -24,6 +24,7 @@
24 24
 #include <stdint.h>
25 25
 #include <avr/io.h>
26 26
 #include <util/delay.h>
27
+#include <avr/wdt.h>
27 28
 
28 29
 #include "adc.h"
29 30
 #include "eq.h"
@@ -34,24 +35,20 @@
34 35
 #endif
35 36
 
36 37
 void blinkStatus(void) {
37
-	// uint8_t i, mem[7] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
38
-
39 38
 	PORTB |= (1 << PB2);
40 39
 	PORTB &= ~(1 << PB1);
41
-	// eqLed(mem);
42 40
 	_delay_ms(250);
43 41
 	PORTB &= ~(1 << PB2);
44 42
 	PORTB |= (1 << PB1);
45
-	// for (i = 0; i < 7; i++) {
46
-	// 	mem[i] = 0x00;
47
-	// }
48
-	// eqLed(mem);
49 43
 	_delay_ms(250);
50 44
 }
51 45
 
52 46
 int main(void) {
53 47
 	uint8_t *music;
54 48
 
49
+	MCUCSR = 0;
50
+	wdt_disable();
51
+
55 52
 	DDRB = 0x3F;
56 53
 	DDRC = 0x0C;
57 54
 	DDRD = 0xFF;
@@ -63,23 +60,27 @@ int main(void) {
63 60
 	blinkStatus();
64 61
 	blinkStatus();
65 62
 
63
+	wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
64
+
66 65
 	music = equalizerGet();
67 66
 	twiSetDataToSend(music);
68 67
 	free(music);
69 68
 
70 69
 	while (1) {
71
-		music = equalizerGet();
72 70
 		if (twiDataWasSent()) {
73 71
 			PORTB ^= (1 << PB2); // Toggle for every transaction
72
+			
73
+			music = equalizerGet();
74 74
 			twiSetDataToSend(music);
75
+			free(music);
75 76
 		}
76
-		// eqLed(music);
77
-		free(music);
78 77
 
79 78
 		// Heartbeat
80 79
 		PORTB ^= (1 << PB1);
81 80
 		_delay_ms(1); // Everything locks if this is removed :(
82 81
 		// still don't know why...
82
+
83
+		wdt_reset();
83 84
 	}
84 85
 
85 86
 	return 0;

+ 1
- 1
AudioFirmware/twislave.c Zobrazit soubor

@@ -82,7 +82,7 @@ void twiSetDataToSend(uint8_t *d) { // 7 bytes
82 82
 	}
83 83
 }
84 84
 
85
-uint8_t twiDataWasSent() {
85
+uint8_t twiDataWasSent(void) {
86 86
 	if (dataSent != 0) {
87 87
 		dataSent = 0;
88 88
 		return 1;

+ 1
- 1
CubeFirmware/cube.c Zobrazit soubor

@@ -85,7 +85,7 @@ void setImage(uint8_t *img) {
85 85
 		imgFlag = 0;
86 86
 		for (i = 0; i < 8; i++) {
87 87
 			for (j = 0; j < 8; j++) {
88
-				imgBuffer[i][j] = ~(img[j + (i * 8)]);
88
+				imgBuffer[j][i] = ~(img[j + (i * 8)]);
89 89
 			}
90 90
 		}
91 91
 	}

+ 63
- 32
CubeFirmware/main.c Zobrazit soubor

@@ -80,16 +80,37 @@ uint8_t lastButtonState = 0;
80 80
 uint8_t mcusr_mirror;
81 81
 char buffer[11];
82 82
 
83
-uint8_t defaultImage[64] = 	{	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
84
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
85
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
86
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
87
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
88
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
89
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
90
-								0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
91
-
92
-uint8_t DebugDone = 0; // Bit 0: 10s int. count, Bit 1: switch idle display
83
+uint8_t defaultImageA[64] = {	0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
84
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
85
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
86
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
87
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
88
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
89
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
90
+								0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff };
91
+
92
+uint8_t defaultImageB[64] = {	0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
93
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
94
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
95
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
96
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
97
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
98
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
99
+								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81 };
100
+
101
+uint8_t defaultImageC[64] = {	0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
102
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
103
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
104
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
105
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
106
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
107
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
108
+								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02 };
109
+
110
+#define IDLEANIMATIONCOUNT 3
111
+uint8_t *idleAnimation[IDLEANIMATIONCOUNT] = { defaultImageA, defaultImageB, defaultImageC };
112
+
113
+uint8_t DebugDone = 0; // Bit 0: 10s int. count, Bit 1: unused
93 114
 					   // Bit 2: state changed, disable idle
94 115
 
95 116
 int main(void) {
@@ -98,7 +119,10 @@ int main(void) {
98 119
 	uint8_t i, length = 0, lastMode;
99 120
 	uint16_t count;
100 121
 	uint64_t lastChecked;
122
+	uint8_t idleCounter = 0;
123
+#ifdef DEBUG
101 124
 	uint32_t temp;
125
+#endif
102 126
 
103 127
 	mcusr_mirror = MCUCSR;
104 128
 	MCUCSR = 0;
@@ -110,14 +134,15 @@ int main(void) {
110 134
 	initSystemTimer();
111 135
 	sei(); // Enable Interrupts
112 136
 
113
-	wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
137
+	// wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
138
+	wdt_enable(WDTO_1S); // Watchdog reset after 1 second
114 139
 
115 140
 	DDRA = 0xFF; // Latch Data Bus as Output
116 141
 	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
117 142
 	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
118 143
 	DDRB &= ~(1 << PB0); // Pushbutton as Input
119 144
 
120
-	setImage(defaultImage); // Display something
145
+	setImage(defaultImageA); // Display something
121 146
 
122 147
 #ifdef DEBUG
123 148
 	// Kill animation counter in debug mode
@@ -167,14 +192,14 @@ int main(void) {
167 192
 		if(lastMode) {
168 193
 			// Get Audio Data and visualize it
169 194
 			if (isFinished()) {
170
-				audioData = getAudioData();
195
+				audioData = getAudioData(); // Not malloc'ed => Don't free
171 196
 				if (audioData != NULL) {
172 197
 					imageData = (uint8_t *)malloc(64);
173 198
 					if (imageData == NULL) {
174 199
 #ifdef DEBUG
175 200
 						serialWriteString(getString(24));
176 201
 #endif
177
-						while(1);
202
+						while(1); // Ran out of heap => Watchdog Reset
178 203
 					}
179 204
 					visualizeAudioData(audioData, imageData);
180 205
 					setImage(imageData);
@@ -204,15 +229,14 @@ int main(void) {
204 229
 					free(imageData);
205 230
 				}
206 231
 			} else {
207
-				if (!(DebugDone & 4)) {
232
+				if (!(DebugDone & 4)) { // Idle animation allowed
208 233
 					if (isFinished() >= IDLELENGTH) {
209 234
 						// Should happen every half second
210
-						if (DebugDone & 2) {
211
-							fillBuffer(0);
212
-							DebugDone &= ~(2);
235
+						setImage(idleAnimation[idleCounter]);
236
+						if (idleCounter < (IDLEANIMATIONCOUNT - 1)) {
237
+							idleCounter++;
213 238
 						} else {
214
-							fillBuffer(0xFF);
215
-							DebugDone |= 2;
239
+							idleCounter = 0;
216 240
 						}
217 241
 					}
218 242
 				}
@@ -269,8 +293,8 @@ uint8_t selfTest(void) {
269 293
 		free(data);
270 294
 	}
271 295
 
272
-	setGeneralPurposeByte(0, 0x42);
273
-	if (getGeneralPurposeByte(0) != 0x42) {
296
+	setGeneralPurposeByte(0, 0x23);
297
+	if (getGeneralPurposeByte(0) != 0x23) {
274 298
 		result |= MEMORYWRITEERROR;
275 299
 	}
276 300
 
@@ -321,8 +345,8 @@ void randomAnimation(void) {
321 345
 void serialHandler(char c) {
322 346
 	// Used letters:
323 347
 	// a, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2
324
-	uint8_t i, y, z;
325 348
 #ifdef DEBUG
349
+	uint8_t i, y, z;
326 350
 	serialWrite(c);
327 351
 	serialWriteString(": ");
328 352
 #endif
@@ -371,6 +395,11 @@ void serialHandler(char c) {
371 395
 		break;
372 396
 
373 397
 #ifdef DEBUG
398
+	case 'm': case 'M':
399
+		lastButtonState = !lastButtonState;
400
+		serialWriteString(getString(40));
401
+		break;
402
+
374 403
 	case 'q': case 'Q':
375 404
 		shouldRestart = 1;
376 405
 		serialWriteString(getString(30));
@@ -434,15 +463,15 @@ void serialHandler(char c) {
434 463
 		DebugDone |= 4;
435 464
 		fillBuffer(0);
436 465
 		for (i = 0; i < 64; i++) {
437
-			defaultImage[i] = 0;
466
+			defaultImageA[i] = 0;
438 467
 		}
439 468
 		while(1) {
440 469
 			for (i = 0; i < 8; i++) {
441 470
 				for (y = 0; y < 8; y++) {
442
-					defaultImage[y + (i * 8)] = 0;
471
+					defaultImageA[y + (i * 8)] = 0;
443 472
 					for (z = 0; z < 8; z++) {
444
-						defaultImage[y + (i * 8)] |= (1 << z);
445
-						setImage(defaultImage);
473
+						defaultImageA[y + (i * 8)] |= (1 << z);
474
+						setImage(defaultImageA);
446 475
 						while (isFinished() == 0) {
447 476
 							if (serialHasChar()) {
448 477
 								goto killMeForIt; // Yes I know...
@@ -450,7 +479,7 @@ void serialHandler(char c) {
450 479
 							}
451 480
 						}
452 481
 					}
453
-					defaultImage[y + (i * 8)] = 0;
482
+					defaultImageA[y + (i * 8)] = 0;
454 483
 				}
455 484
 			}
456 485
 		}
@@ -669,9 +698,11 @@ uint8_t audioModeSelected(void) {
669 698
 		}
670 699
 
671 700
 #ifdef DEBUG
672
-		serialWriteString("New State (");
673
-		serialWriteString(itoa(lastButtonState, buffer, 10));
674
-		serialWriteString(")\n");
701
+		if (lastButtonState) {
702
+			serialWriteString(getString(38));
703
+		} else {
704
+			serialWriteString(getString(39));
705
+		}
675 706
 #endif
676 707
 
677 708
 	}
@@ -686,7 +717,7 @@ void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf) {
686 717
 }
687 718
 
688 719
 void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
689
-	buf[(8 * z) + y] |= (1 << x);
720
+	buf[(8 * z) + (7 - y)] |= (1 << x);
690 721
 }
691 722
 
692 723
 void visualizeAudioData(uint8_t *audioData, uint8_t *imageData) {

+ 9
- 5
CubeFirmware/strings.c Zobrazit soubor

@@ -25,9 +25,9 @@
25 25
 char buffer[60];
26 26
 
27 27
 #ifdef DEBUG
28
-char stringVersion[] PROGMEM = "v2 (Debug Build)\nNOT COMPATIBLE WITH CubeControl!\n"; // 0
28
+char stringVersion[] PROGMEM = "v2.3 Debug Build\nPROBABLY NOT COMPATIBLE WITH CubeControl Software!\n"; // 0
29 29
 #else
30
-char stringVersion[] PROGMEM = "v2 Release\n"; // 0
30
+char stringVersion[] PROGMEM = "v2.3 Release\n"; // 0
31 31
 #endif
32 32
 
33 33
 char stringInit[] PROGMEM = "\nInitialized: "; // 1
@@ -38,7 +38,7 @@ char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5
38 38
 char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
39 39
 char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
40 40
 char stringHelp3[] PROGMEM = "(y)Set fixed animation count\n"; // 8
41
-char stringHelp4[] PROGMEM = "S(e)lf Test\n"; // 9
41
+char stringHelp4[] PROGMEM = "S(e)lf Test, (m)ode\n"; // 9
42 42
 char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
43 43
 char stringHelp6[] PROGMEM = "(0): All LEDs Off\n"; // 11
44 44
 char stringHelp7[] PROGMEM = "(1): All LEDs On\n"; // 12
@@ -67,9 +67,12 @@ char stringExtern[] PROGMEM = "External Reset detected.\n"; // 34
67 67
 char stringJtag[] PROGMEM = "JTAG Reset detected.\n"; // 35
68 68
 char stringPowerOn[] PROGMEM = "Power-On Reset detected.\n"; // 36
69 69
 char stringMinute[] PROGMEM = "Yay! Another minute passed :)\n"; // 37
70
+char stringAudioMode[] PROGMEM = "Audio Mode!\n"; // 38
71
+char stringCubeMode[] PROGMEM = "Cube Mode!\n"; // 39
72
+char stringModeChange[] PROGMEM = "Cube mode changed!\n";
70 73
 
71 74
 // Last index + 1
72
-#define STRINGNUM 38
75
+#define STRINGNUM 41
73 76
 
74 77
 PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, stringInit,
75 78
 								stringAudioError, stringMemError, stringMemWriteError,
@@ -80,7 +83,8 @@ PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, str
80 83
 								stringSnakeControl, stringNoMoreHeap, stringKilledAnimation,
81 84
 								stringHelp9, stringInterrupts, stringFrames2, stringDeleted,
82 85
 								stringReset, stringWatchdog, stringBrownout, stringNothing,
83
-								stringExtern, stringJtag, stringPowerOn, stringMinute };
86
+								stringExtern, stringJtag, stringPowerOn, stringMinute, stringAudioMode,
87
+								stringCubeMode, stringModeChange };
84 88
 
85 89
 char stringNotFoundError[] PROGMEM = "String not found!\n";
86 90
 

Loading…
Zrušit
Uložit