summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/drivers/button.c24
-rw-r--r--firmware/drivers/serial.c141
-rw-r--r--firmware/drivers/serial.h1
3 files changed, 99 insertions, 67 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index d6a2151dbd..9953f1aa22 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -28,6 +28,7 @@
28#include "kernel.h" 28#include "kernel.h"
29#include "backlight.h" 29#include "backlight.h"
30#include "adc.h" 30#include "adc.h"
31#include "serial.h"
31 32
32struct event_queue button_queue; 33struct event_queue button_queue;
33 34
@@ -52,18 +53,27 @@ static int button_read(void);
52 53
53static void button_tick(void) 54static void button_tick(void)
54{ 55{
55 static int tick=0; 56 static int tick = 0;
56 static int count=0; 57 static int count = 0;
57 static int lastbtn=0; 58 static int lastbtn = 0;
58 static int repeat_speed=REPEAT_INTERVAL_START; 59 static int repeat_speed = REPEAT_INTERVAL_START;
59 static bool repeat=false; 60 static bool repeat = false;
60 int diff; 61 int diff;
62 int btn;
61 63
64 /* Post events for the remote control */
65 btn = remote_control_rx();
66 if(btn)
67 {
68 queue_post(&button_queue, btn, NULL);
69 backlight_on();
70 }
71
62 /* only poll every X ticks */ 72 /* only poll every X ticks */
63 if ( ++tick >= POLL_FREQUENCY ) 73 if ( ++tick >= POLL_FREQUENCY )
64 { 74 {
65 bool post = false; 75 bool post = false;
66 int btn = button_read(); 76 btn = button_read();
67 77
68 /* Find out if a key has been released */ 78 /* Find out if a key has been released */
69 diff = btn ^ lastbtn; 79 diff = btn ^ lastbtn;
@@ -91,7 +101,7 @@ static void button_tick(void)
91 if (count == 0) { 101 if (count == 0) {
92 post = true; 102 post = true;
93 /* yes we have repeat */ 103 /* yes we have repeat */
94 repeat_speed--; 104 repeat_speed--;
95 if (repeat_speed < REPEAT_INTERVAL_FINISH) 105 if (repeat_speed < REPEAT_INTERVAL_FINISH)
96 repeat_speed = REPEAT_INTERVAL_FINISH; 106 repeat_speed = REPEAT_INTERVAL_FINISH;
97 count = repeat_speed; 107 count = repeat_speed;
diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c
index 91e2a6911f..982b99fc2c 100644
--- a/firmware/drivers/serial.c
+++ b/firmware/drivers/serial.c
@@ -43,84 +43,105 @@ static void screen_dump(void);
43 43
44void serial_setup (void) 44void serial_setup (void)
45{ 45{
46 char dummy;
47 dummy = SSR1;
48 SSR1 = 0;
49 SMR1 = 0x00; 46 SMR1 = 0x00;
50 SCR1 = 0; 47 SCR1 = 0;
51 BRR1 = (FREQ/(32*9600))-1; 48 BRR1 = (FREQ/(32*9600))-1;
49 SSR1 &= 0; /* The status bits must be read before they are cleared,
50 so we do an AND operation */
52 51
53 /* let the hardware settle */ 52 /* Let the hardware settle. The serial port needs to wait "at least
53 the interval required to transmit or receive one bit" before it
54 can be used. */
54 sleep(1); 55 sleep(1);
55 56
56 SCR1 = 0x50; 57 SCR1 = 0x10; /* Enable the receiver, no interrupt */
57
58 /* This enables the serial Rx interrupt*/
59 IPRE = (IPRE & 0x0FFF) | 0x8000; /* Set to medium priority */
60} 58}
61 59
62static void process_byte(int byte) 60/* This function returns the received remote control code only if it is
61 received without errors before or after the reception.
62 It therefore returns the received code on the second call after the
63 code has been received. */
64int remote_control_rx(void)
63{ 65{
64 int btn = 0; 66 static int last_valid_button = BUTTON_NONE;
67 static int last_was_error = false;
68 int btn;
69 int ret = BUTTON_NONE;
70
71 /* Errors? Just clear'em. The receiver stops if we don't */
72 if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) {
73 SSR1 &= ~(SCI_ORER | SCI_FER | SCI_PER);
74 last_valid_button = BUTTON_NONE;
75 last_was_error = true;
76 return BUTTON_NONE;
77 }
65 78
66 switch (byte) 79 if(SSR1 & SCI_RDRF) {
67 { 80 /* Read byte and clear the Rx Full bit */
68 case STOP: 81 btn = RDR1;
82 SSR1 &= ~SCI_RDRF;
83
84 if(last_was_error)
85 {
86 last_valid_button = BUTTON_NONE;
87 ret = BUTTON_NONE;
88 }
89 else
90 {
91 switch (btn)
92 {
93 case STOP:
69#ifdef HAVE_RECORDER_KEYPAD 94#ifdef HAVE_RECORDER_KEYPAD
70 btn = BUTTON_OFF; 95 last_valid_button = BUTTON_OFF;
71#else 96#else
72 btn = BUTTON_STOP; 97 last_valid_button = BUTTON_STOP;
73#endif 98#endif
74 break; 99 break;
75 100
76 case PLAY: 101 case PLAY:
77 btn = BUTTON_PLAY; 102 last_valid_button = BUTTON_PLAY;
78 break; 103 break;
79 104
80 case VOLUP: 105 case VOLUP:
81 btn = BUTTON_VOL_UP; 106 last_valid_button = BUTTON_VOL_UP;
82 break; 107 break;
83 108
84 case VOLDN: 109 case VOLDN:
85 btn = BUTTON_VOL_DOWN; 110 last_valid_button = BUTTON_VOL_DOWN;
86 break; 111 break;
87 112
88 case PREV: 113 case PREV:
89 btn = BUTTON_LEFT; 114 last_valid_button = BUTTON_LEFT;
90 break; 115 break;
91 116
92 case NEXT: 117 case NEXT:
93 btn = BUTTON_RIGHT; 118 last_valid_button = BUTTON_RIGHT;
94 break; 119 break;
95 120
96#ifdef SCREENDUMP 121#ifdef SCREENDUMP
97 case SCRDMP: 122 case SCRDMP:
98 screen_dump(); 123 screen_dump();
99 break; 124 break;
100#endif 125#endif
126 default:
127 last_valid_button = BUTTON_NONE;
128 break;
129 }
130 }
101 } 131 }
102 132 else
103 if ( btn ) { 133 {
104 queue_post(&button_queue, btn, NULL); 134 /* This means that a valid remote control character was received
105 backlight_on(); 135 the last time we were called, with no receiver errors either before
106 queue_post(&button_queue, btn | BUTTON_REL, NULL); 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;
107 } 140 }
108} 141
109 142 last_was_error = false;
110#pragma interrupt
111void REI1 (void)
112{
113 SSR1 = SSR1 & ~0x10; /* Clear FER */
114 SSR1 = SSR1 & ~0x40; /* Clear RDRF */
115}
116 143
117#pragma interrupt 144 return ret;
118void RXI1 (void)
119{
120 unsigned char serial_byte;
121 serial_byte = RDR1;
122 SSR1 = SSR1 & ~0x40; /* Clear RDRF */
123 process_byte(serial_byte);
124} 145}
125 146
126#ifdef SCREENDUMP 147#ifdef SCREENDUMP
diff --git a/firmware/drivers/serial.h b/firmware/drivers/serial.h
index d13b785b9d..f2e5a945dd 100644
--- a/firmware/drivers/serial.h
+++ b/firmware/drivers/serial.h
@@ -21,5 +21,6 @@
21#define __SERIAL_H__ 21#define __SERIAL_H__
22 22
23extern void serial_setup (void); 23extern void serial_setup (void);
24extern int remote_control_rx(void);
24 25
25#endif 26#endif