aboutsummaryrefslogtreecommitdiff
path: root/src/inc/spi/dev
diff options
context:
space:
mode:
authorMax Christian Pohle2015-07-27 15:12:22 +0200
committerMax Christian Pohle2015-07-27 15:12:22 +0200
commit2df2697107d7873232c31a25a6947711b0903edb (patch)
treeff7247e9e970c69f3d3385950b19db9997a511b8 /src/inc/spi/dev
downloadalarmclock-2df2697107d7873232c31a25a6947711b0903edb.tar.bz2
alarmclock-2df2697107d7873232c31a25a6947711b0903edb.zip
latest running version from march 2011, not having been in repo before,
dcf77 working, mp3 playback and two display types are supported
Diffstat (limited to 'src/inc/spi/dev')
-rwxr-xr-xsrc/inc/spi/dev/audio_vs1011.c173
-rwxr-xr-xsrc/inc/spi/dev/audio_vs1011.h91
-rwxr-xr-xsrc/inc/spi/dev/display_dogm.c39
-rwxr-xr-xsrc/inc/spi/dev/display_dogm.h31
m---------src/inc/spi/dev/petit0
5 files changed, 334 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}
diff --git a/src/inc/spi/dev/audio_vs1011.h b/src/inc/spi/dev/audio_vs1011.h
new file mode 100755
index 0000000..ec97550
--- /dev/null
+++ b/src/inc/spi/dev/audio_vs1011.h
@@ -0,0 +1,91 @@
1#ifndef AUDIO_VS1011_H
2#define AUDIO_VS1011_H
3
4 #include <avr/io.h>
5 #include <util/delay.h>
6 #include <inttypes.h>
7 #include <avr/eeprom.h>
8
9 #include "../spi.h"
10 /// #include "../../uart/uart.h"
11 /// #include "../../stdout.h"
12
13
14 #define audio_vs1011_enable() PORTC &= ~(1<<PC6); // <XDCS>
15 #define audio_vs1011_disable() PORTC |= (1<<PC6); // </XDCS>
16 #define audio_vs1011_isDREQ() (PIND & (1<<PD5))
17 #define audio_vs1011_waitDREQ(); loop_until_bit_is_set(PIND, PD5);
18
19
20 // [OPERATIONS]
21 #define VS_WRITE 0x2
22 #define VS_READ 0x3
23
24
25 // [SCI REGISTERS] - page 29
26 #define SCI_MODE 0x0 // Mode control
27 #define SCI_STATUS 0x1 // Status of VS1011e
28 #define SCI_BASS 0x2 // Built-in bass/treble enhancer
29 #define SCI_CLOCKF 0x3 // Clock freq + multiplier
30 #define SCI_DECODE_TIME 0x4 // Decode time in seconds
31 #define SCI_AUDATA 0x5 // Misc. audio data
32 #define SCI_WRAM 0x6 // RAM write/read
33 #define SCI_WRAMADDR 0x7 // Base address for RAM write/read
34 #define SCI_HDAT0 0x8 // Stream header data 0
35 #define SCI_HDAT1 0x9 // Stream header data 1
36 #define SCI_AIADDR 0xA // Start address of application
37 #define SCI_VOL 0xB // Volume control
38 #define SCI_AICTRL0 0xC // Application control register 0
39 #define SCI_AICTRL1 0xD // Application control register 1
40 #define SCI_AICTRL2 0xE // Application control register 2
41 #define SCI_AICTRL3 0xF // Application control register 3
42
43 // [VALUES::SCI_MODE]
44 #define SM_DIFF 0x1 // Differential
45 #define SM_LAYER12 0x2 // Allow MPEG layers I & II
46 #define SM_RESET 0x4 // Soft reset
47 #define SM_OUTOFWAV 0x8 // Jump out of WAV decoding
48 #define SM_SETTOZERO1 0x10 // set to zero
49 #define SM_TESTS 0x20 // Allow SDI tests
50 #define SM_STREAM 0x40 // Stream mode
51 #define SM_SETTOZERO2 0x80 // set to zero
52
53 #define SM_DACT 0x100 // DCLK active edge
54 #define SM_SDIORD 0x200 // SDI bit order
55 #define SM_SDISHARE 0x400 // Share SPI chip select
56 #define SM_SDINEW 0x800 // VS1002 native SPI modes
57 #define SM_SETTOZERO3 0x1000 // set to zero
58
59 // [VALUES::SCI_CLOCKF]
60 #define SC_CLK2X 0x8000 // clock doubler
61
62 #define audio_vs1011_init_xcs() PORTC &= ~(1<<PC1) // <XCS>
63 #define audio_vs1011_exit_xcs() PORTC |= (1<<PC1); // </XCS>
64
65 #define audio_vs1011_init_xdcs() PORTC &= ~(1<<PC2) // <XCS>
66 #define audio_vs1011_exit_xdcs() PORTC |= (1<<PC2); // </XCS>
67
68 #define wait4dreq() loop_until_bit_is_set(PINC, PC3); // <DREQ></DREQ>
69
70
71 /// void audio_vs1011_cmd(const unsigned char sci_cmd, const unsigned char hdata,
72 /// const unsigned char ldata);
73 void audio_vs1011_init();
74 void audio_vs1011_cmd(const unsigned char cmd, uint16_t dat);
75 void audio_vs1011_setVolume(const unsigned char left, const unsigned char right);
76
77 //void audio_vs1011_dat(const unsigned char dat[32]);
78 void audio_vs1011_dat(const unsigned char* dat, const unsigned char size);
79 /// unsigned char audio_vs1011_stream(unsigned char (*readfn)());
80 void audio_vs1011_test_sine();
81 void audio_vs1011_test_volume();
82 /// void audio_vs1011_test_eeprom();
83 /// void audio_vs1011_enable();
84 /// void audio_vs1011_disable();
85 /// char audio_vs1011_isDREQ();
86
87
88 /// void audio_vs1011_test_softreset();
89
90
91#endif
diff --git a/src/inc/spi/dev/display_dogm.c b/src/inc/spi/dev/display_dogm.c
new file mode 100755
index 0000000..a655769
--- /dev/null
+++ b/src/inc/spi/dev/display_dogm.c
@@ -0,0 +1,39 @@
1#include "display_dogm.h"
2
3void display_dogm_init()
4{
5 //DDRA |= (1<<PA7); // activate portA for display
6 //DDRC |= (1<<PC7); // activate portC for display
7 DDRD |= (1<<PD7) | (1<<PD6);
8 PORTD |= (1<<PD7) | (1<<PD6);
9
10 // Wait time >40mS after VDD stable
11 _delay_ms(50); // 10ms for safty
12
13 display_dogm_exec(CMD_FUNCTION_SET);
14 display_dogm_exec(CMD_FUNCTION_SET);
15 display_dogm_exec(CMD_CONTRAST_SET);
16 display_dogm_exec(CMD_POWER_CONTROL);
17 display_dogm_exec(CMD_FOLLOWER_CONTROL);
18 display_dogm_exec(CMD_DISPLAY_ONOFF);
19 display_dogm_exec(CMD_ENTRY_MODE_SET);
20 display_dogm_exec(CMD_DISPLAY_CLEAR);
21}
22
23void display_dogm_putc(char c)
24{
25 PORTD &= ~(1<<PD7); // chip select: activate display
26 PORTD |= (1<<PD6); // L=Commandmode, H=Datamode
27 spi_putc(c);
28 _delay_us(40); // try and error value (you get chinese chars? increase!)
29 PORTD |= (1<<PD7); // chip select: deactivate display
30}
31
32void display_dogm_exec(char c)
33{
34 PORTD &= ~(1<<PD7); // chip select: activate display
35 PORTD &= ~(1<<PD6); // L=Commandmode, H=Datamode
36 spi_putc(c);
37 _delay_ms(4); // time the longest command takes on display
38 PORTD |= (1<<PD7); // chip select: deactivate display
39}
diff --git a/src/inc/spi/dev/display_dogm.h b/src/inc/spi/dev/display_dogm.h
new file mode 100755
index 0000000..d9cf560
--- /dev/null
+++ b/src/inc/spi/dev/display_dogm.h
@@ -0,0 +1,31 @@
1#ifndef DISPLAY_DOGM_H
2#define DISPLAY_DOGM_H
3
4 #include <avr/io.h>
5 #include <util/delay.h>
6 #include "../spi.h"
7
8 #define CONTAST 3
9
10 #define CMD_FUNCTION_SET 32 + 16 + 8 + 0 + 1
11 #define CMD_POWER_CONTROL 64 + 0 + 16 + 0 + 4 + CONTAST
12 #define CMD_FOLLOWER_CONTROL 0x6E
13
14 #define CMD_ENTRY_MODE_SET 4 + 2 + 0
15 #define CMD_DISPLAY_HOME 0 + 2 + 0
16 #define CMD_DISPLAY_CLEAR 0 + 0 + 1
17
18 #define CMD_CONTRAST_SET 0x7F
19 #define CMD_FUNCTION_SET2 0x38
20 #define CMD_DISPLAY_ONOFF 0x0C
21 #define CMD_DISPLAY_POS 0x80
22
23 //#define display_dogm_enable() PORTD &= ~(1<<PD7); PORTD |= (1<<PD6); // <XDCS>
24 //#define display_dogm_disable() PORTD |= (1<<PD7); PORTD &= ~(1<<PD6); // </XDCS>
25
26
27 void display_dogm_init();
28 void display_dogm_putc(char);
29 void display_dogm_exec(char);
30
31#endif
diff --git a/src/inc/spi/dev/petit b/src/inc/spi/dev/petit
new file mode 160000
Subproject b1109539d5d34b62849d67a65ce244fcb1d0f5e
..