summaryrefslogtreecommitdiff
path: root/firmware/drivers/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/serial.c')
-rw-r--r--firmware/drivers/serial.c219
1 files changed, 1 insertions, 218 deletions
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
50void 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
69int tx_rdy(void)
70{
71 /* a dummy */
72 return 1;
73}
74
75int rx_rdy(void)
76{
77 if(SSR1 & SCI_RDRF)
78 return 1;
79 else
80 return 0;
81}
82
83void tx_writec(unsigned char c)
84{
85 /* a dummy */
86 (void)c;
87}
88
89unsigned 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. */
103int 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
177void 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
189int tx_rdy(void)
190{
191 if(USR0 & 0x04)
192 return 1;
193 else
194 return 0;
195}
196
197int rx_rdy(void)
198{
199 /* a dummy */
200 return 0;
201}
202
203void tx_writec(unsigned char c)
204{
205 UTB0 = c;
206}
207
208#elif (CONFIG_CPU == IMX31L)
209
210void 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
226int 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*/
236int rx_rdy(void)
237{
238 if(!(UTS1 & EUARTUTS_RXEMPTY))
239 return 1;
240 else
241 return 0;
242}
243
244void tx_writec(unsigned char c)
245{
246 UTXD1=(int) c;
247}
248
249#elif defined(IPOD_ACCESSORY_PROTOCOL)
250static int autobaud = 0; 34static int autobaud = 0;
251void serial_setup (void) 35void 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
425void dprintf(const char * str, ... ) 208void dprintf(const char * str, ... )