Browse Source

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 12 years ago
parent
commit
91441ad45c
6 changed files with 86 additions and 69 deletions
  1. 1
    20
      AudioFirmware/eq.c
  2. 11
    10
      AudioFirmware/main.c
  3. 1
    1
      AudioFirmware/twislave.c
  4. 1
    1
      CubeFirmware/cube.c
  5. 63
    32
      CubeFirmware/main.c
  6. 9
    5
      CubeFirmware/strings.c

+ 1
- 20
AudioFirmware/eq.c View File

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
 uint8_t *equalizerGet(void) {
49
 uint8_t *equalizerGet(void) {
69
 	uint8_t *result = (uint8_t *)malloc(7); // Has to work... If not, were screwed anyway :)
50
 	uint8_t *result = (uint8_t *)malloc(7); // Has to work... If not, were screwed anyway :)
70
 	uint8_t i, offset = getOffset();
51
 	uint8_t i, offset = getOffset();
78
 		PORTC &= ~(1 << PC2);
59
 		PORTC &= ~(1 << PC2);
79
 		adcStartConversion(0x00);
60
 		adcStartConversion(0x00);
80
 		_delay_us(READDELAY); // Wait for result to appear
61
 		_delay_us(READDELAY); // Wait for result to appear
81
-		result[i] = offset + adcGetByte(); // This line hangs
62
+		result[i] = offset + adcGetByte();
82
 		_delay_us(STROBEDELAY);
63
 		_delay_us(STROBEDELAY);
83
 	}
64
 	}
84
 
65
 

+ 11
- 10
AudioFirmware/main.c View File

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

+ 1
- 1
AudioFirmware/twislave.c View File

82
 	}
82
 	}
83
 }
83
 }
84
 
84
 
85
-uint8_t twiDataWasSent() {
85
+uint8_t twiDataWasSent(void) {
86
 	if (dataSent != 0) {
86
 	if (dataSent != 0) {
87
 		dataSent = 0;
87
 		dataSent = 0;
88
 		return 1;
88
 		return 1;

+ 1
- 1
CubeFirmware/cube.c View File

85
 		imgFlag = 0;
85
 		imgFlag = 0;
86
 		for (i = 0; i < 8; i++) {
86
 		for (i = 0; i < 8; i++) {
87
 			for (j = 0; j < 8; j++) {
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 View File

80
 uint8_t mcusr_mirror;
80
 uint8_t mcusr_mirror;
81
 char buffer[11];
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
 					   // Bit 2: state changed, disable idle
114
 					   // Bit 2: state changed, disable idle
94
 
115
 
95
 int main(void) {
116
 int main(void) {
98
 	uint8_t i, length = 0, lastMode;
119
 	uint8_t i, length = 0, lastMode;
99
 	uint16_t count;
120
 	uint16_t count;
100
 	uint64_t lastChecked;
121
 	uint64_t lastChecked;
122
+	uint8_t idleCounter = 0;
123
+#ifdef DEBUG
101
 	uint32_t temp;
124
 	uint32_t temp;
125
+#endif
102
 
126
 
103
 	mcusr_mirror = MCUCSR;
127
 	mcusr_mirror = MCUCSR;
104
 	MCUCSR = 0;
128
 	MCUCSR = 0;
110
 	initSystemTimer();
134
 	initSystemTimer();
111
 	sei(); // Enable Interrupts
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
 	DDRA = 0xFF; // Latch Data Bus as Output
140
 	DDRA = 0xFF; // Latch Data Bus as Output
116
 	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
141
 	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
117
 	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
142
 	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
118
 	DDRB &= ~(1 << PB0); // Pushbutton as Input
143
 	DDRB &= ~(1 << PB0); // Pushbutton as Input
119
 
144
 
120
-	setImage(defaultImage); // Display something
145
+	setImage(defaultImageA); // Display something
121
 
146
 
122
 #ifdef DEBUG
147
 #ifdef DEBUG
123
 	// Kill animation counter in debug mode
148
 	// Kill animation counter in debug mode
167
 		if(lastMode) {
192
 		if(lastMode) {
168
 			// Get Audio Data and visualize it
193
 			// Get Audio Data and visualize it
169
 			if (isFinished()) {
194
 			if (isFinished()) {
170
-				audioData = getAudioData();
195
+				audioData = getAudioData(); // Not malloc'ed => Don't free
171
 				if (audioData != NULL) {
196
 				if (audioData != NULL) {
172
 					imageData = (uint8_t *)malloc(64);
197
 					imageData = (uint8_t *)malloc(64);
173
 					if (imageData == NULL) {
198
 					if (imageData == NULL) {
174
 #ifdef DEBUG
199
 #ifdef DEBUG
175
 						serialWriteString(getString(24));
200
 						serialWriteString(getString(24));
176
 #endif
201
 #endif
177
-						while(1);
202
+						while(1); // Ran out of heap => Watchdog Reset
178
 					}
203
 					}
179
 					visualizeAudioData(audioData, imageData);
204
 					visualizeAudioData(audioData, imageData);
180
 					setImage(imageData);
205
 					setImage(imageData);
204
 					free(imageData);
229
 					free(imageData);
205
 				}
230
 				}
206
 			} else {
231
 			} else {
207
-				if (!(DebugDone & 4)) {
232
+				if (!(DebugDone & 4)) { // Idle animation allowed
208
 					if (isFinished() >= IDLELENGTH) {
233
 					if (isFinished() >= IDLELENGTH) {
209
 						// Should happen every half second
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
 						} else {
238
 						} else {
214
-							fillBuffer(0xFF);
215
-							DebugDone |= 2;
239
+							idleCounter = 0;
216
 						}
240
 						}
217
 					}
241
 					}
218
 				}
242
 				}
269
 		free(data);
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
 		result |= MEMORYWRITEERROR;
298
 		result |= MEMORYWRITEERROR;
275
 	}
299
 	}
276
 
300
 
321
 void serialHandler(char c) {
345
 void serialHandler(char c) {
322
 	// Used letters:
346
 	// Used letters:
323
 	// a, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2
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
 #ifdef DEBUG
348
 #ifdef DEBUG
349
+	uint8_t i, y, z;
326
 	serialWrite(c);
350
 	serialWrite(c);
327
 	serialWriteString(": ");
351
 	serialWriteString(": ");
328
 #endif
352
 #endif
371
 		break;
395
 		break;
372
 
396
 
373
 #ifdef DEBUG
397
 #ifdef DEBUG
398
+	case 'm': case 'M':
399
+		lastButtonState = !lastButtonState;
400
+		serialWriteString(getString(40));
401
+		break;
402
+
374
 	case 'q': case 'Q':
403
 	case 'q': case 'Q':
375
 		shouldRestart = 1;
404
 		shouldRestart = 1;
376
 		serialWriteString(getString(30));
405
 		serialWriteString(getString(30));
434
 		DebugDone |= 4;
463
 		DebugDone |= 4;
435
 		fillBuffer(0);
464
 		fillBuffer(0);
436
 		for (i = 0; i < 64; i++) {
465
 		for (i = 0; i < 64; i++) {
437
-			defaultImage[i] = 0;
466
+			defaultImageA[i] = 0;
438
 		}
467
 		}
439
 		while(1) {
468
 		while(1) {
440
 			for (i = 0; i < 8; i++) {
469
 			for (i = 0; i < 8; i++) {
441
 				for (y = 0; y < 8; y++) {
470
 				for (y = 0; y < 8; y++) {
442
-					defaultImage[y + (i * 8)] = 0;
471
+					defaultImageA[y + (i * 8)] = 0;
443
 					for (z = 0; z < 8; z++) {
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
 						while (isFinished() == 0) {
475
 						while (isFinished() == 0) {
447
 							if (serialHasChar()) {
476
 							if (serialHasChar()) {
448
 								goto killMeForIt; // Yes I know...
477
 								goto killMeForIt; // Yes I know...
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
 		}
698
 		}
670
 
699
 
671
 #ifdef DEBUG
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
 #endif
706
 #endif
676
 
707
 
677
 	}
708
 	}
686
 }
717
 }
687
 
718
 
688
 void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
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
 void visualizeAudioData(uint8_t *audioData, uint8_t *imageData) {
723
 void visualizeAudioData(uint8_t *audioData, uint8_t *imageData) {

+ 9
- 5
CubeFirmware/strings.c View File

25
 char buffer[60];
25
 char buffer[60];
26
 
26
 
27
 #ifdef DEBUG
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
 #else
29
 #else
30
-char stringVersion[] PROGMEM = "v2 Release\n"; // 0
30
+char stringVersion[] PROGMEM = "v2.3 Release\n"; // 0
31
 #endif
31
 #endif
32
 
32
 
33
 char stringInit[] PROGMEM = "\nInitialized: "; // 1
33
 char stringInit[] PROGMEM = "\nInitialized: "; // 1
38
 char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
38
 char stringHelp1[] PROGMEM = "(d)elete, (g)et anims, (s)et anims, (v)ersion\n"; // 6
39
 char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
39
 char stringHelp2[] PROGMEM = "(t)ime, (a)udio, (c)ount, (x)Custom count\n"; // 7
40
 char stringHelp3[] PROGMEM = "(y)Set fixed animation count\n"; // 8
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
 char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
42
 char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
43
 char stringHelp6[] PROGMEM = "(0): All LEDs Off\n"; // 11
43
 char stringHelp6[] PROGMEM = "(0): All LEDs Off\n"; // 11
44
 char stringHelp7[] PROGMEM = "(1): All LEDs On\n"; // 12
44
 char stringHelp7[] PROGMEM = "(1): All LEDs On\n"; // 12
67
 char stringJtag[] PROGMEM = "JTAG Reset detected.\n"; // 35
67
 char stringJtag[] PROGMEM = "JTAG Reset detected.\n"; // 35
68
 char stringPowerOn[] PROGMEM = "Power-On Reset detected.\n"; // 36
68
 char stringPowerOn[] PROGMEM = "Power-On Reset detected.\n"; // 36
69
 char stringMinute[] PROGMEM = "Yay! Another minute passed :)\n"; // 37
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
 // Last index + 1
74
 // Last index + 1
72
-#define STRINGNUM 38
75
+#define STRINGNUM 41
73
 
76
 
74
 PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, stringInit,
77
 PGM_P stringTable[STRINGNUM] PROGMEM = { stringVersion, stringSelfTestError, stringInit,
75
 								stringAudioError, stringMemError, stringMemWriteError,
78
 								stringAudioError, stringMemError, stringMemWriteError,
80
 								stringSnakeControl, stringNoMoreHeap, stringKilledAnimation,
83
 								stringSnakeControl, stringNoMoreHeap, stringKilledAnimation,
81
 								stringHelp9, stringInterrupts, stringFrames2, stringDeleted,
84
 								stringHelp9, stringInterrupts, stringFrames2, stringDeleted,
82
 								stringReset, stringWatchdog, stringBrownout, stringNothing,
85
 								stringReset, stringWatchdog, stringBrownout, stringNothing,
83
-								stringExtern, stringJtag, stringPowerOn, stringMinute };
86
+								stringExtern, stringJtag, stringPowerOn, stringMinute, stringAudioMode,
87
+								stringCubeMode, stringModeChange };
84
 
88
 
85
 char stringNotFoundError[] PROGMEM = "String not found!\n";
89
 char stringNotFoundError[] PROGMEM = "String not found!\n";
86
 
90
 

Loading…
Cancel
Save