Preparing a Sansa C200 manual by adding the player's images
[kugel-rb.git] / firmware / drivers / serial.c
blob142f67e60991308ca145c32be9a54a7d3edf69de
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
19 #include <stdlib.h>
20 #include "button.h"
21 #include "config.h"
22 #include "cpu.h"
23 #include "system.h"
24 #include "kernel.h"
25 #include "backlight.h"
26 #include "adc.h"
27 #include "lcd.h"
28 #include "serial.h"
31 #if CONFIG_CPU == SH7034
33 /* FIX: this doesn't work on iRiver or iPod yet */
34 /* iFP7xx has no remote */
36 #if !defined(HAVE_FMADC) /* Recorder FM/V2 has no remote control pin */ \
37 && !defined(HAVE_MMC) /* MMC takes serial port 1, so don't mess with it */
39 /* Received byte identifiers */
40 #define PLAY 0xC1
41 #define STOP 0xC2
42 #define PREV 0xC4
43 #define NEXT 0xC8
44 #define VOLUP 0xD0
45 #define VOLDN 0xE0
47 void serial_setup (void)
49 /* Set PB10 function to serial Rx */
50 PBCR1 = (PBCR1 & 0xffcf) | 0x0020;
52 SMR1 = 0x00;
53 SCR1 = 0;
54 BRR1 = (FREQ/(32*9600))-1;
55 and_b(0, &SSR1); /* The status bits must be read before they are cleared,
56 so we do an AND operation */
58 /* Let the hardware settle. The serial port needs to wait "at least
59 the interval required to transmit or receive one bit" before it
60 can be used. */
61 sleep(1);
63 SCR1 = 0x10; /* Enable the receiver, no interrupt */
66 /* This function returns the received remote control code only if it is
67 received without errors before or after the reception.
68 It therefore returns the received code on the second call after the
69 code has been received. */
70 int remote_control_rx(void)
72 static int last_valid_button = BUTTON_NONE;
73 static int last_was_error = false;
74 int btn;
75 int ret = BUTTON_NONE;
77 /* Errors? Just clear'em. The receiver stops if we don't */
78 if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) {
79 and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1);
80 last_valid_button = BUTTON_NONE;
81 last_was_error = true;
82 return BUTTON_NONE;
85 if(SSR1 & SCI_RDRF) {
86 /* Read byte and clear the Rx Full bit */
87 btn = RDR1;
88 and_b(~SCI_RDRF, &SSR1);
90 if(last_was_error)
92 last_valid_button = BUTTON_NONE;
93 ret = BUTTON_NONE;
95 else
97 switch (btn)
99 case STOP:
100 last_valid_button = BUTTON_RC_STOP;
101 break;
103 case PLAY:
104 last_valid_button = BUTTON_RC_PLAY;
105 break;
107 case VOLUP:
108 last_valid_button = BUTTON_RC_VOL_UP;
109 break;
111 case VOLDN:
112 last_valid_button = BUTTON_RC_VOL_DOWN;
113 break;
115 case PREV:
116 last_valid_button = BUTTON_RC_LEFT;
117 break;
119 case NEXT:
120 last_valid_button = BUTTON_RC_RIGHT;
121 break;
123 default:
124 last_valid_button = BUTTON_NONE;
125 break;
129 else
131 /* This means that a valid remote control character was received
132 the last time we were called, with no receiver errors either before
133 or after. Then we can assume that there really is a remote control
134 attached, and return the button code. */
135 ret = last_valid_button;
136 last_valid_button = BUTTON_NONE;
139 last_was_error = false;
141 return ret;
144 #endif /* !HAVE_FMADC && !HAVE_MMC */
145 #elif defined(CPU_COLDFIRE) && defined(HAVE_SERIAL)
147 void serial_tx(const unsigned char *buf)
149 while(*buf) {
150 while(!(USR0 & 0x04))
153 UTB0 = *buf++;
157 void serial_setup (void)
159 UCR0 = 0x30; /* Reset transmitter */
160 UCSR0 = 0xdd; /* Timer mode */
162 UCR0 = 0x10; /* Reset pointer */
163 UMR0 = 0x13; /* No parity, 8 bits */
164 UMR0 = 0x07; /* 1 stop bit */
166 UCR0 = 0x04; /* Tx enable */
169 #else /* Other targets */
170 void serial_setup (void)
172 /* a dummy */
174 #endif