Browse Source

Audio FW complete. New libs for Cube FW.

Thomas Buck 12 years ago
parent
commit
04c76e19ce

+ 3
- 7
AudioFirmware/eq.c View File

@@ -1,9 +1,5 @@
1 1
 /*
2
- * eq.h
3
-if (i < 6)
4
-				PORTD |= (1 << pins[i]);
5
-			else
6
-				PORTB |= (1 << pins[i]);
2
+ * eq.c
7 3
  *
8 4
  * Copyright 2011 Thomas Buck <xythobuz@me.com>
9 5
  * Copyright 2011 Max Nuding <max.nuding@gmail.com>
@@ -52,10 +48,10 @@ void equalizerInit(void) {
52 48
 
53 49
 void eqLed(uint8_t *d) {
54 50
 	uint8_t pins[7] = { PD2, PD3, PD4, PD5, PD6, PD7, PB0 };
55
-	uint8_t i, offset = getOffset();
51
+	uint8_t i;
56 52
 
57 53
 	for (i = 0; i < 7; i++) {
58
-		if ((d[i] + offset) >= 127) {
54
+		if (d[i] >= 127) {
59 55
 			if (i < 6)
60 56
 				PORTD |= (1 << pins[i]);
61 57
 			else

+ 9
- 1
AudioFirmware/main.c View File

@@ -63,14 +63,22 @@ int main(void) {
63 63
 	blinkStatus();
64 64
 	blinkStatus();
65 65
 
66
+	music = equalizerGet();
67
+	twiSetDataToSend(music);
68
+	free(music);
69
+
66 70
 	while (1) {
67 71
 		music = equalizerGet();
68
-
72
+		if (twiDataWasSent()) {
73
+			twiSetDataToSend(music);
74
+		}
75
+		eqLed(music);
69 76
 		free(music);
70 77
 
71 78
 		// Heartbeat
72 79
 		PORTB ^= (1 << PB1);
73 80
 		_delay_ms(1); // Everything locks if this is removed :(
81
+		// still don't know why...
74 82
 	}
75 83
 
76 84
 	return 0;

+ 1
- 0
AudioFirmware/makefile View File

@@ -391,6 +391,7 @@ clean: begin clean_list finished end
391 391
 clean_list :
392 392
 	@echo
393 393
 	@echo $(MSG_CLEANING)
394
+	$(REMOVE) $(TARGET).hex
394 395
 	$(REMOVE) $(TARGET).eep
395 396
 	$(REMOVE) $(TARGET).obj
396 397
 	$(REMOVE) $(TARGET).cof

+ 1
- 1
AudioFirmware/twislave.c View File

@@ -1,5 +1,5 @@
1 1
 /*
2
- * twislave.h
2
+ * twislave.c
3 3
  *
4 4
  * Copyright 2011 Thomas Buck <xythobuz@me.com>
5 5
  * Copyright 2011 Max Nuding <max.nuding@gmail.com>

+ 43
- 0
CubeFirmware/audio.c View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * audio.c
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
+#include <avr/io.h>
24
+#include <stdint.h>
25
+#include <stdlib.h>
26
+
27
+#include "twi.h"
28
+#include "audio.h"
29
+
30
+// free returned memory!
31
+uint8_t *getAudioData(void) {
32
+	// We read 7 bytes from our Audio µC
33
+	uint8_t i;
34
+	uint8_t *ret = (uint8_t *)malloc(7);
35
+
36
+	i2c_start(TWIADDRESSAUDIO | I2C_READ);
37
+	for (i = 0; i < 6; i++) {
38
+		ret[i] = i2c_readAck();
39
+	}
40
+	ret[6] = i2c_readNak();
41
+	i2c_stop();
42
+	return ret;
43
+}

+ 27
- 0
CubeFirmware/audio.h View File

@@ -0,0 +1,27 @@
1
+/*
2
+ * audio.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
+#define TWIADDRESSAUDIO 0x42
25
+
26
+// free returned memory!
27
+uint8_t *getAudioData(void);

+ 2
- 0
CubeFirmware/makefile View File

@@ -39,6 +39,8 @@ SRC = $(TARGET).c
39 39
 SRC += uart.c # Additional Source-File
40 40
 SRC += cube.c
41 41
 SRC += twi.c
42
+SRC += mem.c
43
+SRC += audio.c
42 44
 
43 45
 # List Assembler source files here.
44 46
 # Make them always end in a capital .S.  Files ending in a lowercase .s

+ 101
- 0
CubeFirmware/mem.c View File

@@ -0,0 +1,101 @@
1
+/*
2
+ * mem.c
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
+#include <avr/io.h>
24
+#include <stdlib.h>
25
+#include <stdint.h>
26
+#include "twi.h"
27
+#include "mem.h"
28
+
29
+// address is a number between (inclusive) zero and 131071
30
+uint8_t memGetByte(uint32_t address) {
31
+	uint8_t addA, addB, memAddress = MEMTWIADDRESS, ret;
32
+	if (address >= 65536) {
33
+		// Address needs more than 16 bits, we have to set the PAGE bit in i2c address
34
+		memAddress |= 2;
35
+	}
36
+	addA = memAddress & 0xFF00;
37
+	addB = memAddress & 0xFF;
38
+
39
+	i2c_start(memAddress | I2C_WRITE); // Send start, write address to read
40
+	i2c_write(addA);
41
+	i2c_write(addB); // Give address to memory
42
+	i2c_rep_start(memAddress | I2C_READ); // Start again, this time reading
43
+	ret = i2c_readNak(); // Read one byte from memory
44
+	i2c_stop();
45
+	return ret;
46
+}
47
+
48
+// Free returned memory!
49
+uint8_t *memGetBytes(uint32_t address, uint8_t length) {
50
+	// We could use the High-Speed Mode of the FM24V10 here, but we don't, right now...
51
+	uint8_t addA, addB, memAddress = MEMTWIADDRESS, i;
52
+	uint8_t *ret;
53
+	if (address >= 65536) {
54
+		// Address needs more than 16 bits, we have to set the PAGE bit in i2c address
55
+		memAddress |= 2;
56
+	}
57
+	addA = memAddress & 0xFF00;
58
+	addB = memAddress & 0xFF;
59
+	ret = (uint8_t *)malloc(length); // Allocate memory for values read
60
+
61
+	i2c_start(memAddress | I2C_WRITE);
62
+	i2c_write(addA);
63
+	i2c_write(addB);
64
+	i2c_rep_start(memAddress | I2C_READ);
65
+	for (i = 0; i < (length - 1); i++) {
66
+		ret[i] = i2c_readAck();
67
+	}
68
+	ret[length - 1] = i2c_readNak();
69
+	i2c_stop();
70
+	return ret;
71
+}
72
+
73
+void memWriteByte(uint32_t address, uint8_t data) {
74
+	uint8_t addA, addB, memAddress = MEMTWIADDRESS;
75
+	if (address >= 65536) {
76
+		// Address needs more than 16 bits, we have to set the PAGE bit in i2c address
77
+		memAddress |= 2;
78
+	}
79
+	addA = memAddress & 0xFF00;
80
+	addB = memAddress & 0xFF;
81
+	i2c_write(addA);
82
+	i2c_write(addB); // Give address to memory
83
+	i2c_write(data);
84
+	i2c_stop();
85
+}
86
+
87
+void memWriteBytes(uint32_t address, uint8_t *data, uint8_t length) {
88
+	uint8_t addA, addB, memAddress = MEMTWIADDRESS, i;
89
+	if (address >= 65536) {
90
+		// Address needs more than 16 bits, we have to set the PAGE bit in i2c address
91
+		memAddress |= 2;
92
+	}
93
+	addA = memAddress & 0xFF00;
94
+	addB = memAddress & 0xFF;
95
+	i2c_write(addA);
96
+	i2c_write(addB); // Give address to memory
97
+	for (i = 0; i < length; i++) {
98
+		i2c_write(data[i]);
99
+	}
100
+	i2c_stop();
101
+}

+ 34
- 0
CubeFirmware/mem.h View File

@@ -0,0 +1,34 @@
1
+/*
2
+ * mem.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
+#define MEMTWIADDRESS 0xA0
25
+
26
+// address is a number between (inclusive) zero and 131071
27
+uint8_t memGetByte(uint32_t address);
28
+
29
+// Free returned memory!
30
+uint8_t *memGetBytes(uint32_t address, uint8_t length);
31
+
32
+void memWriteByte(uint32_t address, uint8_t data);
33
+
34
+void memWriteBytes(uint32_t address, uint8_t *data, uint8_t length);

+ 0
- 73
CubeFirmware/twi.h View File

@@ -10,77 +10,6 @@
10 10
 * Usage:    see Doxygen manual
11 11
 **************************************************************************/
12 12
 
13
-#ifdef DOXYGEN
14
-/**
15
- @defgroup pfleury_ic2master I2C Master library
16
- @code #include <i2cmaster.h> @endcode
17
-  
18
- @brief I2C (TWI) Master Software Library
19
-
20
- Basic routines for communicating with I2C slave devices. This single master 
21
- implementation is limited to one bus master on the I2C bus. 
22
-
23
- This I2c library is implemented as a compact assembler software implementation of the I2C protocol 
24
- which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (twimaster.c).
25
- Since the API for these two implementations is exactly the same, an application can be linked either against the
26
- software I2C implementation or the hardware I2C implementation.
27
-
28
- Use 4.7k pull-up resistor on the SDA and SCL pin.
29
- 
30
- Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module 
31
- i2cmaster.S to your target when using the software I2C implementation ! 
32
- 
33
- Adjust the  CPU clock frequence F_CPU in twimaster.c or in the Makfile when using the TWI hardware implementaion.
34
-
35
- @note 
36
-    The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted 
37
-    to GNU assembler and AVR-GCC C call interface.
38
-    Replaced the incorrect quarter period delays found in AVR300 with 
39
-    half period delays. 
40
-    
41
- @author Peter Fleury pfleury@gmx.ch  http://jump.to/fleury
42
-
43
- @par API Usage Example
44
-  The following code shows typical usage of this library, see example test_i2cmaster.c
45
-
46
- @code
47
-
48
- #include <i2cmaster.h>
49
-
50
-
51
- #define Dev24C02  0xA2      // device address of EEPROM 24C02, see datasheet
52
-
53
- int main(void)
54
- {
55
-     unsigned char ret;
56
-
57
-     i2c_init();                             // initialize I2C library
58
-
59
-     // write 0x75 to EEPROM address 5 (Byte Write) 
60
-     i2c_start_wait(Dev24C02+I2C_WRITE);     // set device address and write mode
61
-     i2c_write(0x05);                        // write address = 5
62
-     i2c_write(0x75);                        // write value 0x75 to EEPROM
63
-     i2c_stop();                             // set stop conditon = release bus
64
-
65
-
66
-     // read previously written value back from EEPROM address 5 
67
-     i2c_start_wait(Dev24C02+I2C_WRITE);     // set device address and write mode
68
-
69
-     i2c_write(0x05);                        // write address = 5
70
-     i2c_rep_start(Dev24C02+I2C_READ);       // set device address and read mode
71
-
72
-     ret = i2c_readNak();                    // read one byte from EEPROM
73
-     i2c_stop();
74
-
75
-     for(;;);
76
- }
77
- @endcode
78
-
79
-*/
80
-#endif /* DOXYGEN */
81
-
82
-/**@{*/
83
-
84 13
 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
85 14
 #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
86 15
 #endif
@@ -173,6 +102,4 @@ extern unsigned char i2c_readNak(void);
173 102
 extern unsigned char i2c_read(unsigned char ack);
174 103
 #define i2c_read(ack)  (ack) ? i2c_readAck() : i2c_readNak(); 
175 104
 
176
-
177
-/**@}*/
178 105
 #endif

Loading…
Cancel
Save