1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr & Nick Robinson
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 #include "backlight.h"
30 #if CONFIG_CPU == IMX31L
31 #include "serial-imx31.h"
34 #if CONFIG_CPU == SH7034
36 /* FIX: this doesn't work on iRiver or iPod yet */
37 /* iFP7xx has no remote */
39 #if !defined(HAVE_FMADC) /* Recorder FM/V2 has no remote control pin */ \
40 && !defined(HAVE_MMC) /* MMC takes serial port 1, so don't mess with it */
42 /* Received byte identifiers */
50 void serial_setup (void)
52 /* Set PB10 function to serial Rx */
53 PBCR1
= (PBCR1
& 0xffcf) | 0x0020;
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 */
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
66 SCR1
= 0x10; /* Enable the receiver, no interrupt */
69 /* This function returns the received remote control code only if it is
70 received without errors before or after the reception.
71 It therefore returns the received code on the second call after the
72 code has been received. */
73 int remote_control_rx(void)
75 static int last_valid_button
= BUTTON_NONE
;
76 static int last_was_error
= false;
78 int ret
= BUTTON_NONE
;
80 /* Errors? Just clear'em. The receiver stops if we don't */
81 if(SSR1
& (SCI_ORER
| SCI_FER
| SCI_PER
)) {
82 and_b(~(SCI_ORER
| SCI_FER
| SCI_PER
), &SSR1
);
83 last_valid_button
= BUTTON_NONE
;
84 last_was_error
= true;
89 /* Read byte and clear the Rx Full bit */
91 and_b(~SCI_RDRF
, &SSR1
);
95 last_valid_button
= BUTTON_NONE
;
103 last_valid_button
= BUTTON_RC_STOP
;
107 last_valid_button
= BUTTON_RC_PLAY
;
111 last_valid_button
= BUTTON_RC_VOL_UP
;
115 last_valid_button
= BUTTON_RC_VOL_DOWN
;
119 last_valid_button
= BUTTON_RC_LEFT
;
123 last_valid_button
= BUTTON_RC_RIGHT
;
127 last_valid_button
= BUTTON_NONE
;
134 /* This means that a valid remote control character was received
135 the last time we were called, with no receiver errors either before
136 or after. Then we can assume that there really is a remote control
137 attached, and return the button code. */
138 ret
= last_valid_button
;
139 last_valid_button
= BUTTON_NONE
;
142 last_was_error
= false;
147 #endif /* !HAVE_FMADC && !HAVE_MMC */
148 #elif defined(CPU_COLDFIRE) && defined(HAVE_SERIAL)
150 void serial_tx(const unsigned char *buf
)
153 while(!(USR0
& 0x04))
160 void serial_setup (void)
162 UCR0
= 0x30; /* Reset transmitter */
163 UCSR0
= 0xdd; /* Timer mode */
165 UCR0
= 0x10; /* Reset pointer */
166 UMR0
= 0x13; /* No parity, 8 bits */
167 UMR0
= 0x07; /* 1 stop bit */
169 UCR0
= 0x04; /* Tx enable */
172 #elif (CONFIG_CPU == IMX31L)
174 void serial_setup(void)
176 #ifdef UART_INT /*enable UART Interrupts */
177 UCR1_1
|= (EUARTUCR1_TRDYEN
| EUARTUCR1_RRDYEN
| EUARTUCR1_TXMPTYEN
);
178 UCR4_1
|= (EUARTUCR4_TCEN
);
179 #else /*disable UART Interrupts*/
180 UCR1_1
&= ~(EUARTUCR1_TRDYEN
| EUARTUCR1_RRDYEN
| EUARTUCR1_TXMPTYEN
);
181 UCR4_1
&= ~(EUARTUCR4_TCEN
);
183 UCR1_1
|= EUARTUCR1_UARTEN
;
184 UCR2_1
|= (EUARTUCR2_TXEN
| EUARTUCR2_RXEN
| EUARTUCR2_IRTS
);
186 /* Tx,Rx Interrupt Trigger levels, Disable for now*/
187 /*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/
192 if((UTS1
& EUARTUTS_TXEMPTY
))
198 /*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY
199 keeps returning true*/
202 if(!(UTS1
& EUARTUTS_RXEMPTY
))
208 void tx_writec(char c
)
213 void dprintf(const char * str
, ... )
215 char dprintfbuff
[256];
222 vsnprintf(ptr
,sizeof(dprintfbuff
),str
,ap
);
228 void serial_tx(const unsigned char * buf
)
243 #else /* Other targets */
244 void serial_setup (void)