diff options
author | Bertrik Sikken <bertrik@sikken.nl> | 2011-04-23 08:23:07 +0000 |
---|---|---|
committer | Bertrik Sikken <bertrik@sikken.nl> | 2011-04-23 08:23:07 +0000 |
commit | 55a7a31ce3a742feea2ff47f6ec35356ebb0ba06 (patch) | |
tree | 046dbe8a4bbc816be2cc7ad5f9653006eceb0ccf | |
parent | 0dfce1972b4ba781411b193b13d0c35c2b6769d7 (diff) | |
download | rockbox-55a7a31ce3a742feea2ff47f6ec35356ebb0ba06.tar.gz rockbox-55a7a31ce3a742feea2ff47f6ec35356ebb0ba06.zip |
Split off target-specific parts from firmware/drivers/serial.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29768 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/SOURCES | 4 | ||||
-rw-r--r-- | firmware/drivers/serial.c | 219 | ||||
-rw-r--r-- | firmware/target/arm/imx31/uart-imx31.c | 72 | ||||
-rw-r--r-- | firmware/target/coldfire/uart-coldfire.c | 60 | ||||
-rw-r--r-- | firmware/target/sh/archos/uart-archos.c | 167 |
5 files changed, 304 insertions, 218 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 21bb732798..bb33abcbc1 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -584,6 +584,7 @@ drivers/i2c.c | |||
584 | target/sh/archos/ata-archos.c | 584 | target/sh/archos/ata-archos.c |
585 | target/sh/archos/timer-archos.c | 585 | target/sh/archos/timer-archos.c |
586 | target/sh/archos/ata-as-archos.S | 586 | target/sh/archos/ata-as-archos.S |
587 | target/sh/archos/uart-archos.c | ||
587 | target/sh/archos/player/button-player.c | 588 | target/sh/archos/player/button-player.c |
588 | target/sh/archos/player/hwcompat-player.c | 589 | target/sh/archos/player/hwcompat-player.c |
589 | target/sh/archos/player/lcd-as-player.S | 590 | target/sh/archos/player/lcd-as-player.S |
@@ -601,6 +602,7 @@ target/sh/archos/audio-archos.c | |||
601 | target/sh/archos/ata-archos.c | 602 | target/sh/archos/ata-archos.c |
602 | target/sh/archos/timer-archos.c | 603 | target/sh/archos/timer-archos.c |
603 | target/sh/archos/ata-as-archos.S | 604 | target/sh/archos/ata-as-archos.S |
605 | target/sh/archos/uart-archos.c | ||
604 | target/sh/archos/lcd-archos-bitmap.c | 606 | target/sh/archos/lcd-archos-bitmap.c |
605 | target/sh/archos/lcd-as-archos-bitmap.S | 607 | target/sh/archos/lcd-as-archos-bitmap.S |
606 | target/sh/archos/recorder/button-recorder.c | 608 | target/sh/archos/recorder/button-recorder.c |
@@ -876,6 +878,7 @@ target/coldfire/iriver/udacodec-iriver.c | |||
876 | #ifndef SIMULATOR | 878 | #ifndef SIMULATOR |
877 | drivers/sw_i2c.c | 879 | drivers/sw_i2c.c |
878 | target/coldfire/ata-as-coldfire.S | 880 | target/coldfire/ata-as-coldfire.S |
881 | target/coldfire/uart-coldfire.c | ||
879 | target/coldfire/iriver/ata-iriver.c | 882 | target/coldfire/iriver/ata-iriver.c |
880 | target/coldfire/iriver/lcd-remote-iriver.c | 883 | target/coldfire/iriver/lcd-remote-iriver.c |
881 | target/coldfire/iriver/lcd-remote-as-iriver.S | 884 | target/coldfire/iriver/lcd-remote-as-iriver.S |
@@ -976,6 +979,7 @@ target/arm/imx31/mmu-imx31.c | |||
976 | target/arm/imx31/rolo_restart_firmware.S | 979 | target/arm/imx31/rolo_restart_firmware.S |
977 | target/arm/imx31/sdma-imx31.c | 980 | target/arm/imx31/sdma-imx31.c |
978 | target/arm/imx31/spi-imx31.c | 981 | target/arm/imx31/spi-imx31.c |
982 | target/arm/imx31/uart-imx31.c | ||
979 | target/arm/imx31/gigabeat-s/adc-gigabeat-s.c | 983 | target/arm/imx31/gigabeat-s/adc-gigabeat-s.c |
980 | target/arm/imx31/gigabeat-s/backlight-gigabeat-s.c | 984 | target/arm/imx31/gigabeat-s/backlight-gigabeat-s.c |
981 | target/arm/imx31/gigabeat-s/button-gigabeat-s.c | 985 | target/arm/imx31/gigabeat-s/button-gigabeat-s.c |
diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c index 26637f140c..fb8851daf2 100644 --- a/firmware/drivers/serial.c +++ b/firmware/drivers/serial.c | |||
@@ -30,223 +30,7 @@ | |||
30 | #include "serial.h" | 30 | #include "serial.h" |
31 | #include "iap.h" | 31 | #include "iap.h" |
32 | 32 | ||
33 | #if CONFIG_CPU == IMX31L | 33 | #if defined(IPOD_ACCESSORY_PROTOCOL) |
34 | #include "serial-imx31.h" | ||
35 | #endif | ||
36 | |||
37 | #if CONFIG_CPU == SH7034 | ||
38 | |||
39 | /* FIX: this doesn't work on iRiver or iPod yet */ | ||
40 | /* iFP7xx has no remote */ | ||
41 | |||
42 | /* Received byte identifiers */ | ||
43 | #define PLAY 0xC1 | ||
44 | #define STOP 0xC2 | ||
45 | #define PREV 0xC4 | ||
46 | #define NEXT 0xC8 | ||
47 | #define VOLUP 0xD0 | ||
48 | #define VOLDN 0xE0 | ||
49 | |||
50 | void serial_setup (void) | ||
51 | { | ||
52 | /* Set PB10 function to serial Rx */ | ||
53 | PBCR1 = (PBCR1 & 0xffcf) | 0x0020; | ||
54 | |||
55 | SMR1 = 0x00; | ||
56 | SCR1 = 0; | ||
57 | BRR1 = (FREQ/(32*9600))-1; | ||
58 | and_b(0, &SSR1); /* The status bits must be read before they are cleared, | ||
59 | so we do an AND operation */ | ||
60 | |||
61 | /* Let the hardware settle. The serial port needs to wait "at least | ||
62 | the interval required to transmit or receive one bit" before it | ||
63 | can be used. */ | ||
64 | sleep(1); | ||
65 | |||
66 | SCR1 = 0x10; /* Enable the receiver, no interrupt */ | ||
67 | } | ||
68 | |||
69 | int tx_rdy(void) | ||
70 | { | ||
71 | /* a dummy */ | ||
72 | return 1; | ||
73 | } | ||
74 | |||
75 | int rx_rdy(void) | ||
76 | { | ||
77 | if(SSR1 & SCI_RDRF) | ||
78 | return 1; | ||
79 | else | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | void tx_writec(unsigned char c) | ||
84 | { | ||
85 | /* a dummy */ | ||
86 | (void)c; | ||
87 | } | ||
88 | |||
89 | unsigned char rx_readc(void) | ||
90 | { | ||
91 | char tmp; | ||
92 | /* Read byte and clear the Rx Full bit */ | ||
93 | tmp = RDR1; | ||
94 | and_b(~SCI_RDRF, &SSR1); | ||
95 | return tmp; | ||
96 | } | ||
97 | |||
98 | |||
99 | /* This function returns the received remote control code only if it is | ||
100 | received without errors before or after the reception. | ||
101 | It therefore returns the received code on the second call after the | ||
102 | code has been received. */ | ||
103 | int remote_control_rx(void) | ||
104 | { | ||
105 | static int last_valid_button = BUTTON_NONE; | ||
106 | static int last_was_error = false; | ||
107 | int btn; | ||
108 | int ret = BUTTON_NONE; | ||
109 | |||
110 | /* Errors? Just clear'em. The receiver stops if we don't */ | ||
111 | if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) { | ||
112 | and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1); | ||
113 | last_valid_button = BUTTON_NONE; | ||
114 | last_was_error = true; | ||
115 | return BUTTON_NONE; | ||
116 | } | ||
117 | |||
118 | if(rx_rdy()) { | ||
119 | btn = rx_readc(); | ||
120 | |||
121 | if(last_was_error) | ||
122 | { | ||
123 | last_valid_button = BUTTON_NONE; | ||
124 | ret = BUTTON_NONE; | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | switch (btn) | ||
129 | { | ||
130 | case STOP: | ||
131 | last_valid_button = BUTTON_RC_STOP; | ||
132 | break; | ||
133 | |||
134 | case PLAY: | ||
135 | last_valid_button = BUTTON_RC_PLAY; | ||
136 | break; | ||
137 | |||
138 | case VOLUP: | ||
139 | last_valid_button = BUTTON_RC_VOL_UP; | ||
140 | break; | ||
141 | |||
142 | case VOLDN: | ||
143 | last_valid_button = BUTTON_RC_VOL_DOWN; | ||
144 | break; | ||
145 | |||
146 | case PREV: | ||
147 | last_valid_button = BUTTON_RC_LEFT; | ||
148 | break; | ||
149 | |||
150 | case NEXT: | ||
151 | last_valid_button = BUTTON_RC_RIGHT; | ||
152 | break; | ||
153 | |||
154 | default: | ||
155 | last_valid_button = BUTTON_NONE; | ||
156 | break; | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | /* This means that a valid remote control character was received | ||
163 | the last time we were called, with no receiver errors either before | ||
164 | or after. Then we can assume that there really is a remote control | ||
165 | attached, and return the button code. */ | ||
166 | ret = last_valid_button; | ||
167 | last_valid_button = BUTTON_NONE; | ||
168 | } | ||
169 | |||
170 | last_was_error = false; | ||
171 | |||
172 | return ret; | ||
173 | } | ||
174 | |||
175 | #elif defined(CPU_COLDFIRE) | ||
176 | |||
177 | void serial_setup (void) | ||
178 | { | ||
179 | UCR0 = 0x30; /* Reset transmitter */ | ||
180 | UCSR0 = 0xdd; /* Timer mode */ | ||
181 | |||
182 | UCR0 = 0x10; /* Reset pointer */ | ||
183 | UMR0 = 0x13; /* No parity, 8 bits */ | ||
184 | UMR0 = 0x07; /* 1 stop bit */ | ||
185 | |||
186 | UCR0 = 0x04; /* Tx enable */ | ||
187 | } | ||
188 | |||
189 | int tx_rdy(void) | ||
190 | { | ||
191 | if(USR0 & 0x04) | ||
192 | return 1; | ||
193 | else | ||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | int rx_rdy(void) | ||
198 | { | ||
199 | /* a dummy */ | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | void tx_writec(unsigned char c) | ||
204 | { | ||
205 | UTB0 = c; | ||
206 | } | ||
207 | |||
208 | #elif (CONFIG_CPU == IMX31L) | ||
209 | |||
210 | void serial_setup(void) | ||
211 | { | ||
212 | #ifdef UART_INT /*enable UART Interrupts */ | ||
213 | UCR1_1 |= (EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN); | ||
214 | UCR4_1 |= (EUARTUCR4_TCEN); | ||
215 | #else /*disable UART Interrupts*/ | ||
216 | UCR1_1 &= ~(EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN); | ||
217 | UCR4_1 &= ~(EUARTUCR4_TCEN); | ||
218 | #endif | ||
219 | UCR1_1 |= EUARTUCR1_UARTEN; | ||
220 | UCR2_1 |= (EUARTUCR2_TXEN | EUARTUCR2_RXEN | EUARTUCR2_IRTS); | ||
221 | |||
222 | /* Tx,Rx Interrupt Trigger levels, Disable for now*/ | ||
223 | /*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/ | ||
224 | } | ||
225 | |||
226 | int tx_rdy(void) | ||
227 | { | ||
228 | if((UTS1 & EUARTUTS_TXEMPTY)) | ||
229 | return 1; | ||
230 | else | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | /*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY | ||
235 | keeps returning true*/ | ||
236 | int rx_rdy(void) | ||
237 | { | ||
238 | if(!(UTS1 & EUARTUTS_RXEMPTY)) | ||
239 | return 1; | ||
240 | else | ||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | void tx_writec(unsigned char c) | ||
245 | { | ||
246 | UTXD1=(int) c; | ||
247 | } | ||
248 | |||
249 | #elif defined(IPOD_ACCESSORY_PROTOCOL) | ||
250 | static int autobaud = 0; | 34 | static int autobaud = 0; |
251 | void serial_setup (void) | 35 | void serial_setup (void) |
252 | { | 36 | { |
@@ -419,7 +203,6 @@ void SERIAL0(void) | |||
419 | newpkt = pkt; | 203 | newpkt = pkt; |
420 | } | 204 | } |
421 | } | 205 | } |
422 | |||
423 | #endif | 206 | #endif |
424 | 207 | ||
425 | void dprintf(const char * str, ... ) | 208 | void dprintf(const char * str, ... ) |
diff --git a/firmware/target/arm/imx31/uart-imx31.c b/firmware/target/arm/imx31/uart-imx31.c new file mode 100644 index 0000000000..c54ac0c0ce --- /dev/null +++ b/firmware/target/arm/imx31/uart-imx31.c | |||
@@ -0,0 +1,72 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr & Nick Robinson | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <stdarg.h> | ||
24 | |||
25 | #include "config.h" | ||
26 | #include "button.h" | ||
27 | #include "cpu.h" | ||
28 | #include "system.h" | ||
29 | #include "kernel.h" | ||
30 | #include "serial.h" | ||
31 | |||
32 | #include "serial-imx31.h" | ||
33 | |||
34 | void serial_setup(void) | ||
35 | { | ||
36 | #ifdef UART_INT /*enable UART Interrupts */ | ||
37 | UCR1_1 |= (EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN); | ||
38 | UCR4_1 |= (EUARTUCR4_TCEN); | ||
39 | #else /*disable UART Interrupts*/ | ||
40 | UCR1_1 &= ~(EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN); | ||
41 | UCR4_1 &= ~(EUARTUCR4_TCEN); | ||
42 | #endif | ||
43 | UCR1_1 |= EUARTUCR1_UARTEN; | ||
44 | UCR2_1 |= (EUARTUCR2_TXEN | EUARTUCR2_RXEN | EUARTUCR2_IRTS); | ||
45 | |||
46 | /* Tx,Rx Interrupt Trigger levels, Disable for now*/ | ||
47 | /*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/ | ||
48 | } | ||
49 | |||
50 | int tx_rdy(void) | ||
51 | { | ||
52 | if((UTS1 & EUARTUTS_TXEMPTY)) | ||
53 | return 1; | ||
54 | else | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | /*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY | ||
59 | keeps returning true*/ | ||
60 | int rx_rdy(void) | ||
61 | { | ||
62 | if(!(UTS1 & EUARTUTS_RXEMPTY)) | ||
63 | return 1; | ||
64 | else | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | void tx_writec(unsigned char c) | ||
69 | { | ||
70 | UTXD1=(int) c; | ||
71 | } | ||
72 | |||
diff --git a/firmware/target/coldfire/uart-coldfire.c b/firmware/target/coldfire/uart-coldfire.c new file mode 100644 index 0000000000..c5992a956c --- /dev/null +++ b/firmware/target/coldfire/uart-coldfire.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr & Nick Robinson | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <stdarg.h> | ||
24 | |||
25 | #include "config.h" | ||
26 | #include "cpu.h" | ||
27 | #include "system.h" | ||
28 | #include "serial.h" | ||
29 | |||
30 | void serial_setup (void) | ||
31 | { | ||
32 | UCR0 = 0x30; /* Reset transmitter */ | ||
33 | UCSR0 = 0xdd; /* Timer mode */ | ||
34 | |||
35 | UCR0 = 0x10; /* Reset pointer */ | ||
36 | UMR0 = 0x13; /* No parity, 8 bits */ | ||
37 | UMR0 = 0x07; /* 1 stop bit */ | ||
38 | |||
39 | UCR0 = 0x04; /* Tx enable */ | ||
40 | } | ||
41 | |||
42 | int tx_rdy(void) | ||
43 | { | ||
44 | if(USR0 & 0x04) | ||
45 | return 1; | ||
46 | else | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | int rx_rdy(void) | ||
51 | { | ||
52 | /* a dummy */ | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | void tx_writec(unsigned char c) | ||
57 | { | ||
58 | UTB0 = c; | ||
59 | } | ||
60 | |||
diff --git a/firmware/target/sh/archos/uart-archos.c b/firmware/target/sh/archos/uart-archos.c new file mode 100644 index 0000000000..14fea943b3 --- /dev/null +++ b/firmware/target/sh/archos/uart-archos.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr & Nick Robinson | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <stdarg.h> | ||
24 | |||
25 | #include "config.h" | ||
26 | #include "button.h" | ||
27 | #include "cpu.h" | ||
28 | #include "system.h" | ||
29 | #include "kernel.h" | ||
30 | #include "serial.h" | ||
31 | |||
32 | /* FIX: this doesn't work on iRiver or iPod yet */ | ||
33 | /* iFP7xx has no remote */ | ||
34 | |||
35 | /* Received byte identifiers */ | ||
36 | #define PLAY 0xC1 | ||
37 | #define STOP 0xC2 | ||
38 | #define PREV 0xC4 | ||
39 | #define NEXT 0xC8 | ||
40 | #define VOLUP 0xD0 | ||
41 | #define VOLDN 0xE0 | ||
42 | |||
43 | void serial_setup (void) | ||
44 | { | ||
45 | /* Set PB10 function to serial Rx */ | ||
46 | PBCR1 = (PBCR1 & 0xffcf) | 0x0020; | ||
47 | |||
48 | SMR1 = 0x00; | ||
49 | SCR1 = 0; | ||
50 | BRR1 = (FREQ/(32*9600))-1; | ||
51 | and_b(0, &SSR1); /* The status bits must be read before they are cleared, | ||
52 | so we do an AND operation */ | ||
53 | |||
54 | /* Let the hardware settle. The serial port needs to wait "at least | ||
55 | the interval required to transmit or receive one bit" before it | ||
56 | can be used. */ | ||
57 | sleep(1); | ||
58 | |||
59 | SCR1 = 0x10; /* Enable the receiver, no interrupt */ | ||
60 | } | ||
61 | |||
62 | int tx_rdy(void) | ||
63 | { | ||
64 | /* a dummy */ | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | int rx_rdy(void) | ||
69 | { | ||
70 | if(SSR1 & SCI_RDRF) | ||
71 | return 1; | ||
72 | else | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | void tx_writec(unsigned char c) | ||
77 | { | ||
78 | /* a dummy */ | ||
79 | (void)c; | ||
80 | } | ||
81 | |||
82 | unsigned char rx_readc(void) | ||
83 | { | ||
84 | char tmp; | ||
85 | /* Read byte and clear the Rx Full bit */ | ||
86 | tmp = RDR1; | ||
87 | and_b(~SCI_RDRF, &SSR1); | ||
88 | return tmp; | ||
89 | } | ||
90 | |||
91 | |||
92 | /* This function returns the received remote control code only if it is | ||
93 | received without errors before or after the reception. | ||
94 | It therefore returns the received code on the second call after the | ||
95 | code has been received. */ | ||
96 | int remote_control_rx(void) | ||
97 | { | ||
98 | static int last_valid_button = BUTTON_NONE; | ||
99 | static int last_was_error = false; | ||
100 | int btn; | ||
101 | int ret = BUTTON_NONE; | ||
102 | |||
103 | /* Errors? Just clear'em. The receiver stops if we don't */ | ||
104 | if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) { | ||
105 | and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1); | ||
106 | last_valid_button = BUTTON_NONE; | ||
107 | last_was_error = true; | ||
108 | return BUTTON_NONE; | ||
109 | } | ||
110 | |||
111 | if(rx_rdy()) { | ||
112 | btn = rx_readc(); | ||
113 | |||
114 | if(last_was_error) | ||
115 | { | ||
116 | last_valid_button = BUTTON_NONE; | ||
117 | ret = BUTTON_NONE; | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | switch (btn) | ||
122 | { | ||
123 | case STOP: | ||
124 | last_valid_button = BUTTON_RC_STOP; | ||
125 | break; | ||
126 | |||
127 | case PLAY: | ||
128 | last_valid_button = BUTTON_RC_PLAY; | ||
129 | break; | ||
130 | |||
131 | case VOLUP: | ||
132 | last_valid_button = BUTTON_RC_VOL_UP; | ||
133 | break; | ||
134 | |||
135 | case VOLDN: | ||
136 | last_valid_button = BUTTON_RC_VOL_DOWN; | ||
137 | break; | ||
138 | |||
139 | case PREV: | ||
140 | last_valid_button = BUTTON_RC_LEFT; | ||
141 | break; | ||
142 | |||
143 | case NEXT: | ||
144 | last_valid_button = BUTTON_RC_RIGHT; | ||
145 | break; | ||
146 | |||
147 | default: | ||
148 | last_valid_button = BUTTON_NONE; | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | /* This means that a valid remote control character was received | ||
156 | the last time we were called, with no receiver errors either before | ||
157 | or after. Then we can assume that there really is a remote control | ||
158 | attached, and return the button code. */ | ||
159 | ret = last_valid_button; | ||
160 | last_valid_button = BUTTON_NONE; | ||
161 | } | ||
162 | |||
163 | last_was_error = false; | ||
164 | |||
165 | return ret; | ||
166 | } | ||
167 | |||