Thomas Buck 13 anni fa
parent
commit
9d43274163
5 ha cambiato i file con 132 aggiunte e 41 eliminazioni
  1. 13
    4
      AudioFirmware/eq.c
  2. 1
    0
      AudioFirmware/eq.h
  3. 7
    37
      AudioFirmware/main.c
  4. 86
    0
      AudioFirmware/main.hex
  5. 25
    0
      AudioFirmware/twislave.h

+ 13
- 4
AudioFirmware/eq.c Vedi File

@@ -1,5 +1,9 @@
1 1
 /*
2 2
  * eq.h
3
+if (i < 6)
4
+				PORTD |= (1 << pins[i]);
5
+			else
6
+				PORTB |= (1 << pins[i]);
3 7
  *
4 8
  * Copyright 2011 Thomas Buck <xythobuz@me.com>
5 9
  * Copyright 2011 Max Nuding <max.nuding@gmail.com>
@@ -48,10 +52,10 @@ void equalizerInit(void) {
48 52
 
49 53
 void eqLed(uint8_t *d) {
50 54
 	uint8_t pins[7] = { PD2, PD3, PD4, PD5, PD6, PD7, PB0 };
51
-	uint8_t i;
55
+	uint8_t i, offset = getOffset();
52 56
 
53 57
 	for (i = 0; i < 7; i++) {
54
-		if (d[i] >= 127) {
58
+		if ((d[i] + offset) >= 127) {
55 59
 			if (i < 6)
56 60
 				PORTD |= (1 << pins[i]);
57 61
 			else
@@ -67,7 +71,7 @@ void eqLed(uint8_t *d) {
67 71
 
68 72
 uint8_t *equalizerGet(void) {
69 73
 	uint8_t *result = (uint8_t *)malloc(7); // Has to work... If not, were screwed anyway :)
70
-	uint8_t i;
74
+	uint8_t i, offset = getOffset();
71 75
 
72 76
 	PORTC &= ~(1 << PC3); // Disable reset
73 77
 	_delay_us(RESETSTROBEDELAY); // Wait trs
@@ -78,10 +82,15 @@ uint8_t *equalizerGet(void) {
78 82
 		PORTC &= ~(1 << PC2);
79 83
 		adcStartConversion(0x00);
80 84
 		_delay_us(READDELAY); // Wait for result to appear
81
-		result[i] = adcGetByte(); // This line hangs
85
+		result[i] = offset + adcGetByte(); // This line hangs
82 86
 		_delay_us(STROBEDELAY);
83 87
 	}
84 88
 
85 89
 	eqLed(result);
86 90
 	return result;
87 91
 }
92
+
93
+uint8_t getOffset(void) {
94
+	adcStartConversion(0x01);
95
+	return (adcGetByte() / 2);
96
+}

+ 1
- 0
AudioFirmware/eq.h Vedi File

@@ -28,3 +28,4 @@ void equalizerInit(void);
28 28
 uint8_t *equalizerGet(void);
29 29
 
30 30
 void eqLed(uint8_t *d);
31
+uint8_t getOffset(void);

+ 7
- 37
AudioFirmware/main.c Vedi File

@@ -48,39 +48,9 @@ void blinkStatus(void) {
48 48
 	_delay_ms(250);
49 49
 }
50 50
 
51
-void showMusicOnLED(void) {
51
+int main(void) {
52 52
 	uint8_t *music;
53
-	uint8_t i, val;
54
-
55
-	music = equalizerGet();
56
-	val = 0;
57
-	for (i = 0; i < 7; i++) {
58
-		val += music[i];
59
-	}
60
-	val /= 7;
61
-
62
-	free(music);
63
-
64
-	if (val >= 20) {
65
-		PORTB |= (1 << PB2);
66
-	} else {
67
-		PORTB &= ~(1 << PB2);
68
-	}
69
-}
70 53
 
71
-void showPotOnLED(void) {
72
-	uint8_t val = 0;
73
-	adcStartConversion(0x01); // 0x0E -> 1,3 V Ref.
74
-	val = adcGetByte();
75
-
76
-	if (val >= 127) {
77
-		PORTB |= (1 << PB1);
78
-	} else {
79
-		PORTB &= ~(1 << PB1);
80
-	}
81
-}
82
-
83
-int main(void) {
84 54
 	DDRB = 0x3F;
85 55
 	DDRC = 0x0C;
86 56
 	DDRD = 0xFF;
@@ -91,14 +61,14 @@ int main(void) {
91 61
 	blinkStatus();
92 62
 	blinkStatus();
93 63
 
94
-	// Blink led :)
95
-	while (1) {		
96
-		//showPotOnLED();
97
-		showMusicOnLED();
98
-		
64
+	while (1) {
65
+		music = equalizerGet();
66
+
67
+		free(music);
68
+
99 69
 		// Heartbeat
100 70
 		PORTB ^= (1 << PB1);
101
-		_delay_ms(1);
71
+		_delay_ms(1); // Everything locks if this is removed :(
102 72
 	}
103 73
 
104 74
 	return 0;

+ 86
- 0
AudioFirmware/main.hex Vedi File

@@ -0,0 +1,86 @@
1
+:1000000012C02CC02BC02AC029C028C027C026C0BF
2
+:1000100025C024C023C022C021C020C01FC01EC0D4
3
+:100020001DC01CC01BC011241FBECFE5D4E0DEBF25
4
+:10003000CDBF10E0A0E6B0E0E8E2F5E002C0059038
5
+:100040000D92A437B107D9F710E0A4E7B0E001C0E2
6
+:100050001D92A837B107E1F764D064C2D1CF81E027
7
+:1000600078D09CD08F3710F0C19A0895C198089528
8
+:100070001F9313D1AC0110E020E030E0FA01E20F51
9
+:10008000F31F8081180F2F5F3F4F27303105B1F7E5
10
+:10009000CA01F0D11C3810F0C29A01C0C2981F9159
11
+:1000A0000895DF93CF93CDB7DEB727970FB6F894B7
12
+:1000B000DEBF0FBECDBFDE011196E0E6F0E087E0C7
13
+:1000C00001900D928150E1F7C29AC198CE0101963C
14
+:1000D00078D084EC99E020E931E0F9013197F1F72B
15
+:1000E0000197D9F7C298C19AFE013196CE010896C0
16
+:1000F0001192E817F907E1F7CE01019662D084EC7E
17
+:1001000099E020E931E0F9013197F1F70197D9F74A
18
+:1001100027960FB6F894DEBF0FBECDBFCF91DF910B
19
+:1001200008951F93CF93DF938FE387BB8CE084BB4D
20
+:100130008FEF81BB26D038D0B4DFB3DF12E0C0EA46
21
+:10014000DFE096DF88B3812788BBCE010197F1F706
22
+:10015000F8CF97B1907F97B997B18F70892B87B9F6
23
+:10016000369A089586B18295869586958370809596
24
+:10017000817008953699FECF369824B135B1C90102
25
+:10018000089584B38C7F84BB17B83E9A86B185608E
26
+:1001900086B9379A80E0DDDFEDDF0895EBDF9695D5
27
+:1001A000879596958795089584B38C6084BBAB9AA8
28
+:1001B00085E08A95F1F7089581E0CBDFEFDF869542
29
+:1001C0000895DF92EF92FF920F931F93DF93CF93E7
30
+:1001D000CDB7DEB727970FB6F894DEBF0FBECDBF01
31
+:1001E0007C01DE011196E7E6F0E087E001900D92D8
32
+:1001F0008150E1F7E1DF21E030E00F8002C0220F03
33
+:10020000331F0A94E2F7322FD22ED094DE011196DA
34
+:1002100040E050E0682F70E001E010E0F701E40FEB
35
+:10022000F51F8081FB01E80FF11DEF37F10584F028
36
+:10023000463059F022B3C8010C9002C0880F991FB4
37
+:100240000A94E2F7282B22BB14C088B3832B10C07A
38
+:10025000463061F022B3C8010C9002C0880F991F8C
39
+:100260000A94E2F78095822382BB03C088B38D2174
40
+:1002700088BB4F5F5F4F11964730510579F627963F
41
+:100280000FB6F894DEBF0FBECDBFCF91DF911F91A7
42
+:100290000F91FF90EF90DF900895BF92CF92DF9281
43
+:1002A000EF92FF920F931F93CF93DF9387E090E03D
44
+:1002B00034D0F92E182FE82E7FDFC82EAB9880E2BD
45
+:1002C00091E00197F1F7812F9F2DEC0190E6D92E57
46
+:1002D00080ECB82E8E01095F1F4FAA9A8D2D8A954A
47
+:1002E000F1F7AA9880E035DF8B2D8A95F1F756DF7C
48
+:1002F0008C0D89938D2D8A95F1F7C017D10769F779
49
+:10030000C7015FDFC701DF91CF911F910F91FF9070
50
+:10031000EF90DF90CF90BF900895CF93DF93BC0113
51
+:100320008230910510F462E070E0A0917600B09107
52
+:100330007700ED01E0E0F0E040E050E021C088818E
53
+:1003400099818617970769F48A819B81309719F004
54
+:100350009383828304C09093770080937600FE019C
55
+:1003600034C06817790738F44115510519F084171E
56
+:10037000950708F4AC01FE018A819B819C01E9018B
57
+:100380002097E9F641155105A9F1CA01861B970B83
58
+:10039000049708F4BA01E0E0F0E02AC08D919C9146
59
+:1003A000119784179507F9F46417750781F412966D
60
+:1003B0008D919C911397309719F09383828304C099
61
+:1003C0009093770080937600FD0132964FC0CA016A
62
+:1003D000861B970BFD01E80FF91F6193719302973C
63
+:1003E0008D939C9343C0FD01828193819C01D9012F
64
+:1003F0001097A1F68091740090917500892B41F4BB
65
+:1004000080917000909171009093750080937400BA
66
+:1004100040917200509173004115510541F44DB760
67
+:100420005EB780916E0090916F00481B590B209130
68
+:1004300074003091750024173507B0F4CA01821B8F
69
+:10044000930B8617970780F0AB014E5F5F4F8417C1
70
+:10045000950750F0420F531F50937500409374005E
71
+:10046000F9016193719302C0E0E0F0E0CF01DF9108
72
+:10047000CF910895CF93DF93009709F450C0EC011A
73
+:1004800022971B821A82A0917600B0917700109774
74
+:1004900009F140E050E0AC17BD0708F1BB83AA8327
75
+:1004A000FE0121913191E20FF31FAE17BF0779F4DE
76
+:1004B0008D919C911197280F391F2E5F3F4F3983E3
77
+:1004C000288312968D919C9113979B838A83411563
78
+:1004D000510571F4D0937700C093760020C0129636
79
+:1004E0008D919C911397AD01009711F0DC01D3CF52
80
+:1004F000FA01D383C28321913191E20FF31FCE170A
81
+:10050000DF0769F488819981280F391F2E5F3F4FDB
82
+:10051000FA01318320838A819B8193838283DF91D7
83
+:08052000CF910895F894FFCF7C
84
+:10052800FFFFFFFFFFFFFF0203040506070020008F
85
+:040538007800000047
86
+:00000001FF

+ 25
- 0
AudioFirmware/twislave.h Vedi File

@@ -0,0 +1,25 @@
1
+/*
2
+ * twislave.h
3
+ *
4
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
+ *
8
+ * This file is part of LED-Cube.
9
+ *
10
+ * LED-Cube is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * LED-Cube is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
+ */
23
+
24
+void twiInit(uint8_t adress);
25
+void twiSetDataToSend(uint8_t *data);

Loading…
Annulla
Salva