Browse Source

Misc work.

Changed some more faulty transistors. cubeInit now displays short test
animation. Moved header files in own folder.
Thomas Buck 12 years ago
parent
commit
fe9794e99e

+ 29
- 0
CubeFirmware/cube.c View File

@@ -83,6 +83,7 @@ void setImage(uint8_t *img) {
83 83
 	ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
84 84
 		changedFlag = 1;
85 85
 		imgFlag = 0;
86
+		toggleFlag = 0;
86 87
 		for (i = 0; i < 8; i++) {
87 88
 			for (j = 0; j < 8; j++) {
88 89
 				imgBuffer[j][i] = ~(img[j + (i * 8)]);
@@ -96,6 +97,7 @@ void fillBuffer(uint8_t val) {
96 97
 	ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
97 98
 		changedFlag = 1;
98 99
 		imgFlag = 0;
100
+		toggleFlag = 0;
99 101
 		for (i = 0; i < 8; i++) {
100 102
 			for (j = 0; j < 8; j++) {
101 103
 				imgBuffer[i][j] = ~(val);
@@ -109,9 +111,36 @@ uint8_t isFinished(void) {
109 111
 }
110 112
 
111 113
 void initCube(void) {
114
+	uint8_t x, y;
115
+
112 116
 	TCCR1B |= (1 << CS10) | (1 << WGM12); // Prescaler: 1, CTC Mode
113 117
 	OCR1A = COUNT;
114 118
 	TIMSK = (1 << OCIE1A); // Enable Output Compare Interrupt
119
+
120
+	fillBuffer(0); // Clear memory
121
+	sei(); // Enable interrupts
122
+
123
+	// Show test animation
124
+	for (x = 0; x < 8; x++) {
125
+		for (y = 0; y < 8; y++) {
126
+			ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
127
+				imgBuffer[x][y] &= ~(0xFF); // Set a pixel
128
+				changedFlag = 1;
129
+				imgFlag = 0;
130
+				toggleFlag = COUNT2; // Ensure next interrupts starts displaying
131
+			}
132
+			while(imgFlag < 1); // Wait for frame to display
133
+			/* ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
134
+				imgBuffer[x][y] |= (0xFF); // Clear pixel
135
+			} */
136
+		}
137
+	}
138
+
139
+	cli(); // Disable interrupts
140
+
141
+	timesTriggered = 0;
142
+	imgFlag = 0;
143
+	toggleFlag = 0;
115 144
 }
116 145
 
117 146
 void close(void) {

CubeFirmware/audio.h → CubeFirmware/header/audio.h View File


CubeFirmware/cube.h → CubeFirmware/header/cube.h View File


CubeFirmware/mem.h → CubeFirmware/header/mem.h View File


CubeFirmware/memLayer.h → CubeFirmware/header/memLayer.h View File


CubeFirmware/serial.h → CubeFirmware/header/serial.h View File


CubeFirmware/strings.h → CubeFirmware/header/strings.h View File


CubeFirmware/time.h → CubeFirmware/header/time.h View File


CubeFirmware/twi.h → CubeFirmware/header/twi.h View File


+ 24
- 8
CubeFirmware/main.c View File

@@ -56,7 +56,7 @@
56 56
 #define ISERROR(x, e) ((x) & (e))
57 57
 
58 58
 // Length of an idle animation frame, 24 -> 1 second
59
-#define IDLELENGTH 24
59
+#define IDLELENGTH 48
60 60
 
61 61
 void serialHandler(char c);
62 62
 void sendAudioData(void);
@@ -107,6 +107,15 @@ uint8_t defaultImageC[64] = {	0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
107 107
 								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
108 108
 								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02 };
109 109
 
110
+uint8_t defaultImageCube[64] = {	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
111
+									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
112
+									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
113
+									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
114
+									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
115
+									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
116
+									0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
117
+									0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
118
+
110 119
 #define IDLEANIMATIONCOUNT 3
111 120
 uint8_t *idleAnimation[IDLEANIMATIONCOUNT] = { defaultImageA, defaultImageB, defaultImageC };
112 121
 
@@ -128,21 +137,23 @@ int main(void) {
128 137
 	MCUCSR = 0;
129 138
 	wdt_disable();
130 139
 
140
+	DDRA = 0xFF; // Latch Data Bus as Output
141
+	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
142
+	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
143
+	DDRB &= ~(1 << PB0); // Pushbutton as Input
144
+
131 145
 	initCube();
132 146
 	serialInit(25, 8, NONE, 1);
133 147
 	i2c_init();
134 148
 	initSystemTimer();
135 149
 	sei(); // Enable Interrupts
136 150
 
151
+#ifndef DEBUG
137 152
 	// wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
138 153
 	wdt_enable(WDTO_1S); // Watchdog reset after 1 second
154
+#endif
139 155
 
140
-	DDRA = 0xFF; // Latch Data Bus as Output
141
-	DDRD = 0xFC; DDRB = 24; // Mosfets as Output
142
-	DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
143
-	DDRB &= ~(1 << PB0); // Pushbutton as Input
144
-
145
-	setImage(defaultImageA); // Display something
156
+	setImage(defaultImageCube); // Display something
146 157
 
147 158
 #ifdef DEBUG
148 159
 	// Kill animation counter in debug mode
@@ -344,7 +355,7 @@ void randomAnimation(void) {
344 355
 
345 356
 void serialHandler(char c) {
346 357
 	// Used letters:
347
-	// a, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2
358
+	// a, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2, 3
348 359
 #ifdef DEBUG
349 360
 	uint8_t i, y, z;
350 361
 	serialWrite(c);
@@ -459,6 +470,11 @@ void serialHandler(char c) {
459 470
 		DebugDone |= 4;
460 471
 		break;
461 472
 
473
+	case '3':
474
+		setImage(defaultImageCube);
475
+		DebugDone |= 4;
476
+		break;
477
+
462 478
 	case '2':
463 479
 		DebugDone |= 4;
464 480
 		fillBuffer(0);

+ 1
- 1
CubeFirmware/makefile View File

@@ -69,7 +69,7 @@ OPT = s
69 69
 
70 70
 # List any extra directories to look for include files here.
71 71
 #     Each directory must be seperated by a space.
72
-EXTRAINCDIRS = 
72
+EXTRAINCDIRS = header
73 73
 
74 74
 
75 75
 # Compiler flag to set the C Standard level.

+ 3
- 3
CubeFirmware/strings.c View File

@@ -40,9 +40,9 @@ 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 41
 char stringHelp4[] PROGMEM = "S(e)lf Test, (m)ode\n"; // 9
42 42
 char stringHelp5[] PROGMEM = "Play S(n)ake\n"; // 10
43
-char stringHelp6[] PROGMEM = "(0): All LEDs Off\n"; // 11
44
-char stringHelp7[] PROGMEM = "(1): All LEDs On\n"; // 12
45
-char stringHelp8[] PROGMEM = "(2): Test Anim. 1\n"; // 13
43
+char stringHelp6[] PROGMEM = "All LEDs Off/On (0/1)\n"; // 11
44
+char stringHelp7[] PROGMEM = "(2): Test Anim. 1\n"; // 12
45
+char stringHelp8[] PROGMEM = "(3): All Surface LEDs on\n"; // 13
46 46
 char stringTime[] PROGMEM = "System Time: "; // 14
47 47
 char stringFrames[] PROGMEM = " Frames stored\n"; // 15
48 48
 char stringByte[] PROGMEM = "Send a byte... "; // 16

Loading…
Cancel
Save