diff options
Diffstat (limited to 'firmware/target/sh/archos')
-rw-r--r-- | firmware/target/sh/archos/uart-archos.c | 167 |
1 files changed, 167 insertions, 0 deletions
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 | |||