aboutsummaryrefslogtreecommitdiff
path: root/src/inc/spi/dev/audio_vs1011.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/inc/spi/dev/audio_vs1011.c')
-rwxr-xr-xsrc/inc/spi/dev/audio_vs1011.c173
1 files changed, 173 insertions, 0 deletions
diff --git a/src/inc/spi/dev/audio_vs1011.c b/src/inc/spi/dev/audio_vs1011.c
new file mode 100755
index 0000000..ad44654
--- /dev/null
+++ b/src/inc/spi/dev/audio_vs1011.c
@@ -0,0 +1,173 @@
1#include "audio_vs1011.h"
2/// inline void audio_vs1011_setVolume(unsigned char left, unsigned char right)
3/// { audio_vs1011_cmd(SCI_VOL, left, right); }
4
5void audio_vs1011_init()
6{
7 // [initialize pins and ports]
8 DDRC |= ((1<<PC1) | (1<<PC2) | (1<<PC4)); // XCS/XDCS/RESET
9 DDRC &= ~(1<<PC3); // DREQ
10 //DDRA |= (1<<PA6); // activate O-Port A6 as [XCS]
11 //DDRC |= (1<<PC6); // activate O-Port C6 as [XDCS]
12 //DDRD |= (1<<PD6); // activate O-Port D6 as [RESET]
13 //DDRD &= ~(1<<PD5); // activate I-Port D5 as [DREQ]
14
15
16 // pins...
17 /// PORTA |= (1<<PA6);
18 /// PORTC |= (1<<PC6);
19 PORTC |= (1<<PC3); // enable pullup resistor for [DREQ]
20 audio_vs1011_exit_xcs(); // activate XCS: deactivate vs1011-cmd-line
21 audio_vs1011_exit_xdcs(); // activate XDCS: deactivate vs1011-data-line
22
23 // [reset vs1011]
24 // this ensures, that it finds XCS and XDCS in proper state (see below)
25 /// PORTD &= ~(1<<PD6); // <reset>
26 // Wait for at least 10 ms after startup (required!!)
27 // then make GPIO an output signal and set it to 1...
28 /// _delay_ms(20);
29 PORTC |= (1<<PC4); // </reset>
30 /// _delay_ms(20);
31
32 // wait until DREQ is set- so chip has rebooted from reset...
33 wait4dreq();
34
35 // [set vs1011 to 'new-mode']
36 // where xdcs is driven low, before you want to send mp3-data or test-bits
37 // where xcs is driven low to send SCI-commands.
38 // and both together may not been activated, why we started with resetting
39 // after having configured those output-ports.
40 audio_vs1011_cmd(SCI_MODE, (SM_SDINEW | SM_TESTS));
41
42 // [set clock-frequency...]
43 // formular:
44 // 32768{if clock doubler}
45 // + (F_CRYSTAL{crystals frequency in Hz} / 2000{const})
46 // = 0x9770 for a 12MHz-crystal (with clock-doubler), so send:
47 /// audio_vs1011_cmd(SCI_CLOCKF, 0x98, 0x00);
48 /// stdout_put_uint(uart_putc, ((F_CPU / 2000) | SC_CLK2X));
49 /// stdout_put_string(uart_putc, "\t< clock freq for vs1011\n");
50
51 audio_vs1011_cmd(SCI_CLOCKF, ((F_CPU / 2000) | SC_CLK2X));
52 audio_vs1011_cmd(SCI_AUDATA, 44100);
53
54 /*
55 spi_setspeed(SPICLK_FAST);
56 int q;
57 for(q=0; q<=30000; q++)
58 spi_putc(0x00);
59 spi_setspeed(SPICLK_DEFAULT);
60 // wait for at least 11000 clock cycles...
61 */
62
63 // wait until DREQ is set- so chip has rebooted from reset...
64 wait4dreq();
65
66
67 /// spi_putc(0xFF);
68
69 audio_vs1011_setVolume(1, 1); // left and right both to 100%=0xFF
70 /// _delay_ms(250);
71
72 /// stdout_put_string(uart_putc, "clock frequency set!\n");
73}
74
75
76void audio_vs1011_setVolume(const unsigned char left, const unsigned char right)
77{
78 //uint16_t volume = right + (256 * left);
79 /// stdout_put_uint(uart_putc, volume);
80 /// stdout_put_string(uart_putc, "\t< new volume for vs1011\n");
81 audio_vs1011_cmd(SCI_VOL, ((uint16_t) right) + ((uint16_t) left * 256));
82}
83
84void audio_vs1011_test_volume()
85{
86 audio_vs1011_setVolume(0, 0); // left and right to 0%=0x00 -> standby
87 _delay_ms(250);
88 audio_vs1011_setVolume(255, 255); // left and right both to 100%=0xFF
89 _delay_ms(250);
90}
91
92void audio_vs1011_test_sine()
93{
94 static const unsigned char sinetest[] = {0x53, 0xEF, 0x6E, 0x30, 0x0, 0x0, 0x0, 0x0};
95 static const unsigned char testexit[] = {'E', 'x', 'i', 't', 0x0, 0x0, 0x0, 0x0};
96
97 /// audio_vs1011_setVolume(255, 255); // left and right both to 100%=0xFF
98 /// stdout_put_string(uart_putc, "activating sine-test...\n");
99 audio_vs1011_dat(sinetest, sizeof(sinetest));
100 _delay_ms(250);
101
102 /// stdout_put_string(uart_putc, "deactivating sine-test...\n");
103 audio_vs1011_dat(testexit, sizeof(testexit));
104 _delay_ms(250);
105 /// audio_vs1011_setVolume(255, 255); // left and right both to 100%=0xFF
106}
107
108/*
109void audio_vs1011_test_eeprom()
110{
111 unsigned char block[512];
112 eeprom_read_block((void*) &block, (const void*) 0, 512);
113
114 int i,q;
115 for(i=0; i<512; i+=32)
116 {
117 audio_vs1011_enable();
118 loop_until_bit_is_set(PIND, PD5);
119 for(q=0; q<32; q++)
120 spi_putc(block[i+q]);
121 audio_vs1011_disable();
122 }
123 loop_until_bit_is_set(PIND, PD5);
124 _delay_ms(500);
125}
126*/
127
128void audio_vs1011_dat(const unsigned char* dat, const unsigned char size)
129{
130 audio_vs1011_enable();
131 unsigned char i;
132 for(i=0; i<size; i++)
133 spi_putc(dat[i]);
134 audio_vs1011_disable();
135}
136
137
138/*
139unsigned char audio_vs1011_stream(unsigned char (*readfn)())
140{
141 audio_vs1011_enable();
142 register unsigned char i;
143 for(i=0; i<32; i++)
144 spi_putc(readfn());
145 audio_vs1011_disable();
146 audio_vs1011_waitDREQ();
147 return 32;
148}*/
149
150
151
152
153void audio_vs1011_cmd(const unsigned char cmd, uint16_t dat)
154{
155 loop_until_bit_is_set(PIND, PD5);
156 /// audio_vs1011_enable();
157 //PORTA &= ~(1<<PA6); // <XCS>
158 audio_vs1011_init_xcs();
159 spi_putc(VS_WRITE);
160 spi_putc(cmd);
161 spi_putc((dat >> 8) & 0xFF);
162 spi_putc((dat >> 0) & 0xFF);
163 //PORTA |= (1<<PA6); // </XCS>
164 audio_vs1011_exit_xcs();
165 spi_putc(0);
166 spi_putc(0);
167 spi_putc(0);
168 spi_putc(0);
169 /// audio_vs1011_disable();
170 /// _delay_ms(1); // << wait to make sure vs1011 got the message
171 _delay_ms(5);
172 loop_until_bit_is_set(PIND, PD5); // << wait for DREQ to become ready again
173}
..