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.c111
1 files changed, 79 insertions, 32 deletions
diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c
index ca69147cd3..ee83e2a474 100644
--- a/firmware/drivers/serial.c
+++ b/firmware/drivers/serial.c
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Alan Korr 10 * Copyright (C) 2002 by Alan Korr & Nick Robinson
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 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. 13 * See the file COPYING in the source tree root for full license agreement.
@@ -16,54 +16,101 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19#include <stdlib.h>
20#include "button.h"
21#include "config.h"
22#include "sh7034.h"
23#include "system.h"
24#include "kernel.h"
25#include "backlight.h"
26#include "adc.h"
27#include "lcd.h"
20#include "serial.h" 28#include "serial.h"
21 29
22static int serial_byte,serial_flag; 30/* Recieved byte identifiers */
31#define PLAY 0xC1
32#define STOP 0xC2
33#define PREV 0xC4
34#define NEXT 0xC8
35#define VOLUP 0xD0
36#define VOLDN 0xE0
23 37
24void serial_putc (char byte) 38void serial_setup (void)
25{ 39{
26 while (!(SSR1 & 0x80)); /* Wait for TDRE */ 40 char dummy;
27 TDR1 = byte; 41 int i;
28 SSR1 &= 0x80; /* Clear TDRE */ 42 int j;
29} 43 dummy = SSR1;
44 SSR1=0;
45 SMR1 = 0x00;
46 SCR1=0;
47 BRR1 = (FREQ/(32*9600))-1;
48
49 /* let the hardware settle */
50 for (i = 0; i < 1000; i++)
51 j++;
52
53 SCR1 = 0x50;
54
55 /* This enables the serial Rx interrupt*/
56 IPRE = (IPRE & 0x0FFF) | 0x8000; /* Set to medium priority */
30 57
31void serial_puts (char const *string)
32{
33 int byte;
34 while ((byte = *string++))
35 serial_putc (byte);
36} 58}
37 59
38int serial_getc( void ) 60static void process_byte(char byte)
39{ 61{
40 int byte; 62 int btn = 0;
41 while (!serial_flag); 63
42 byte = serial_byte; 64 switch (byte)
43 serial_flag = 0; 65 {
44 serial_putc (byte); 66 case STOP:
45 return byte; 67#ifdef HAVE_RECORDER_KEYPAD
46} 68 btn = BUTTON_OFF;
69#else
70 btn = BUTTON_STOP;
71#endif
72 break;
73
74 case PLAY:
75 btn = BUTTON_PLAY;
76 break;
77
78 case VOLUP:
79 btn = BUTTON_VOL_UP;
80 break;
81
82 case VOLDN:
83 btn = BUTTON_VOL_DOWN;
84 break;
85
86 case PREV:
87 btn = BUTTON_LEFT;
88 break;
89
90 case NEXT:
91 btn = BUTTON_RIGHT;
92 break;
93 }
47 94
48void serial_setup (int baudrate) 95 if ( btn ) {
49{ 96 queue_post(&button_queue, btn, NULL);
50 SCR1 = 0; 97 backlight_on();
51 SSR1 = 0; 98 queue_post(&button_queue, btn | BUTTON_REL, NULL);
52 SMR1 = 0; 99 }
53 BRR1 = (FREQ/(32*baudrate))-1;
54 SCR1 = 0x70;
55} 100}
56 101
57#pragma interrupt 102#pragma interrupt
58void REI1 (void) 103void REI1 (void)
59{ 104{
60 SSR1 &= 0x10; /* Clear FER */ 105 SSR1 = SSR1 & ~0x10; /* Clear FER */
106 SSR1 = SSR1 & ~0x40; /* Clear RDRF */
61} 107}
62 108
63#pragma interrupt 109#pragma interrupt
64void RXI1 (void) 110void RXI1 (void)
65{ 111{
112 char serial_byte;
66 serial_byte = RDR1; 113 serial_byte = RDR1;
67 serial_flag = 1; 114 SSR1 = SSR1 & ~0x40; /* Clear RDRF */
68 SSR1 &= 0x40; /* Clear RDRF */ 115 process_byte(serial_byte);
69} 116}