forked from len0rd/rockbox
A lot more stable remote control handling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2447 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
07557e5612
commit
cfec25bb9e
3 changed files with 99 additions and 67 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "backlight.h"
|
#include "backlight.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
struct event_queue button_queue;
|
struct event_queue button_queue;
|
||||||
|
|
||||||
|
@ -52,18 +53,27 @@ static int button_read(void);
|
||||||
|
|
||||||
static void button_tick(void)
|
static void button_tick(void)
|
||||||
{
|
{
|
||||||
static int tick=0;
|
static int tick = 0;
|
||||||
static int count=0;
|
static int count = 0;
|
||||||
static int lastbtn=0;
|
static int lastbtn = 0;
|
||||||
static int repeat_speed=REPEAT_INTERVAL_START;
|
static int repeat_speed = REPEAT_INTERVAL_START;
|
||||||
static bool repeat=false;
|
static bool repeat = false;
|
||||||
int diff;
|
int diff;
|
||||||
|
int btn;
|
||||||
|
|
||||||
|
/* Post events for the remote control */
|
||||||
|
btn = remote_control_rx();
|
||||||
|
if(btn)
|
||||||
|
{
|
||||||
|
queue_post(&button_queue, btn, NULL);
|
||||||
|
backlight_on();
|
||||||
|
}
|
||||||
|
|
||||||
/* only poll every X ticks */
|
/* only poll every X ticks */
|
||||||
if ( ++tick >= POLL_FREQUENCY )
|
if ( ++tick >= POLL_FREQUENCY )
|
||||||
{
|
{
|
||||||
bool post = false;
|
bool post = false;
|
||||||
int btn = button_read();
|
btn = button_read();
|
||||||
|
|
||||||
/* Find out if a key has been released */
|
/* Find out if a key has been released */
|
||||||
diff = btn ^ lastbtn;
|
diff = btn ^ lastbtn;
|
||||||
|
@ -91,7 +101,7 @@ static void button_tick(void)
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
post = true;
|
post = true;
|
||||||
/* yes we have repeat */
|
/* yes we have repeat */
|
||||||
repeat_speed--;
|
repeat_speed--;
|
||||||
if (repeat_speed < REPEAT_INTERVAL_FINISH)
|
if (repeat_speed < REPEAT_INTERVAL_FINISH)
|
||||||
repeat_speed = REPEAT_INTERVAL_FINISH;
|
repeat_speed = REPEAT_INTERVAL_FINISH;
|
||||||
count = repeat_speed;
|
count = repeat_speed;
|
||||||
|
|
|
@ -43,84 +43,105 @@ static void screen_dump(void);
|
||||||
|
|
||||||
void serial_setup (void)
|
void serial_setup (void)
|
||||||
{
|
{
|
||||||
char dummy;
|
|
||||||
dummy = SSR1;
|
|
||||||
SSR1 = 0;
|
|
||||||
SMR1 = 0x00;
|
SMR1 = 0x00;
|
||||||
SCR1 = 0;
|
SCR1 = 0;
|
||||||
BRR1 = (FREQ/(32*9600))-1;
|
BRR1 = (FREQ/(32*9600))-1;
|
||||||
|
SSR1 &= 0; /* The status bits must be read before they are cleared,
|
||||||
|
so we do an AND operation */
|
||||||
|
|
||||||
/* let the hardware settle */
|
/* Let the hardware settle. The serial port needs to wait "at least
|
||||||
|
the interval required to transmit or receive one bit" before it
|
||||||
|
can be used. */
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
SCR1 = 0x50;
|
SCR1 = 0x10; /* Enable the receiver, no interrupt */
|
||||||
|
|
||||||
/* This enables the serial Rx interrupt*/
|
|
||||||
IPRE = (IPRE & 0x0FFF) | 0x8000; /* Set to medium priority */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_byte(int byte)
|
/* This function returns the received remote control code only if it is
|
||||||
|
received without errors before or after the reception.
|
||||||
|
It therefore returns the received code on the second call after the
|
||||||
|
code has been received. */
|
||||||
|
int remote_control_rx(void)
|
||||||
{
|
{
|
||||||
int btn = 0;
|
static int last_valid_button = BUTTON_NONE;
|
||||||
|
static int last_was_error = false;
|
||||||
|
int btn;
|
||||||
|
int ret = BUTTON_NONE;
|
||||||
|
|
||||||
switch (byte)
|
/* Errors? Just clear'em. The receiver stops if we don't */
|
||||||
{
|
if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) {
|
||||||
case STOP:
|
SSR1 &= ~(SCI_ORER | SCI_FER | SCI_PER);
|
||||||
|
last_valid_button = BUTTON_NONE;
|
||||||
|
last_was_error = true;
|
||||||
|
return BUTTON_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SSR1 & SCI_RDRF) {
|
||||||
|
/* Read byte and clear the Rx Full bit */
|
||||||
|
btn = RDR1;
|
||||||
|
SSR1 &= ~SCI_RDRF;
|
||||||
|
|
||||||
|
if(last_was_error)
|
||||||
|
{
|
||||||
|
last_valid_button = BUTTON_NONE;
|
||||||
|
ret = BUTTON_NONE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (btn)
|
||||||
|
{
|
||||||
|
case STOP:
|
||||||
#ifdef HAVE_RECORDER_KEYPAD
|
#ifdef HAVE_RECORDER_KEYPAD
|
||||||
btn = BUTTON_OFF;
|
last_valid_button = BUTTON_OFF;
|
||||||
#else
|
#else
|
||||||
btn = BUTTON_STOP;
|
last_valid_button = BUTTON_STOP;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAY:
|
case PLAY:
|
||||||
btn = BUTTON_PLAY;
|
last_valid_button = BUTTON_PLAY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VOLUP:
|
case VOLUP:
|
||||||
btn = BUTTON_VOL_UP;
|
last_valid_button = BUTTON_VOL_UP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VOLDN:
|
case VOLDN:
|
||||||
btn = BUTTON_VOL_DOWN;
|
last_valid_button = BUTTON_VOL_DOWN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PREV:
|
case PREV:
|
||||||
btn = BUTTON_LEFT;
|
last_valid_button = BUTTON_LEFT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NEXT:
|
case NEXT:
|
||||||
btn = BUTTON_RIGHT;
|
last_valid_button = BUTTON_RIGHT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef SCREENDUMP
|
#ifdef SCREENDUMP
|
||||||
case SCRDMP:
|
case SCRDMP:
|
||||||
screen_dump();
|
screen_dump();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
default:
|
||||||
|
last_valid_button = BUTTON_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This means that a valid remote control character was received
|
||||||
|
the last time we were called, with no receiver errors either before
|
||||||
|
or after. Then we can assume that there really is a remote control
|
||||||
|
attached, and return the button code. */
|
||||||
|
ret = last_valid_button;
|
||||||
|
last_valid_button = BUTTON_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( btn ) {
|
last_was_error = false;
|
||||||
queue_post(&button_queue, btn, NULL);
|
|
||||||
backlight_on();
|
|
||||||
queue_post(&button_queue, btn | BUTTON_REL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma interrupt
|
return ret;
|
||||||
void REI1 (void)
|
|
||||||
{
|
|
||||||
SSR1 = SSR1 & ~0x10; /* Clear FER */
|
|
||||||
SSR1 = SSR1 & ~0x40; /* Clear RDRF */
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma interrupt
|
|
||||||
void RXI1 (void)
|
|
||||||
{
|
|
||||||
unsigned char serial_byte;
|
|
||||||
serial_byte = RDR1;
|
|
||||||
SSR1 = SSR1 & ~0x40; /* Clear RDRF */
|
|
||||||
process_byte(serial_byte);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SCREENDUMP
|
#ifdef SCREENDUMP
|
||||||
|
|
|
@ -21,5 +21,6 @@
|
||||||
#define __SERIAL_H__
|
#define __SERIAL_H__
|
||||||
|
|
||||||
extern void serial_setup (void);
|
extern void serial_setup (void);
|
||||||
|
extern int remote_control_rx(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue