2002-03-28 15:09:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2002-08-12 12:44:18 +00:00
|
|
|
* Copyright (C) 2002 by Alan Korr & Nick Robinson
|
2002-03-28 15:09:10 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-03-28 15:09:10 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-08-12 12:44:18 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "button.h"
|
|
|
|
#include "config.h"
|
2005-02-02 21:47:43 +00:00
|
|
|
#include "cpu.h"
|
2002-08-12 12:44:18 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "lcd.h"
|
2002-04-21 21:50:00 +00:00
|
|
|
#include "serial.h"
|
2002-03-28 15:09:10 +00:00
|
|
|
|
2007-09-22 02:17:08 +00:00
|
|
|
#if CONFIG_CPU == IMX31L
|
|
|
|
#include "serial-imx31.h"
|
|
|
|
#endif
|
2006-02-05 17:16:34 +00:00
|
|
|
|
2006-08-12 08:01:54 +00:00
|
|
|
#if CONFIG_CPU == SH7034
|
2006-02-05 17:16:34 +00:00
|
|
|
|
2006-11-10 20:26:01 +00:00
|
|
|
/* FIX: this doesn't work on iRiver or iPod yet */
|
2006-01-12 00:35:50 +00:00
|
|
|
/* iFP7xx has no remote */
|
2005-02-04 15:07:50 +00:00
|
|
|
|
2006-11-27 02:16:32 +00:00
|
|
|
#if !defined(HAVE_FMADC) /* Recorder FM/V2 has no remote control pin */ \
|
|
|
|
&& !defined(HAVE_MMC) /* MMC takes serial port 1, so don't mess with it */
|
2004-09-20 22:15:35 +00:00
|
|
|
|
2002-09-04 12:34:13 +00:00
|
|
|
/* Received byte identifiers */
|
2002-08-12 12:44:18 +00:00
|
|
|
#define PLAY 0xC1
|
|
|
|
#define STOP 0xC2
|
|
|
|
#define PREV 0xC4
|
|
|
|
#define NEXT 0xC8
|
|
|
|
#define VOLUP 0xD0
|
|
|
|
#define VOLDN 0xE0
|
2002-03-28 15:09:10 +00:00
|
|
|
|
2002-08-12 12:44:18 +00:00
|
|
|
void serial_setup (void)
|
2003-07-11 07:30:59 +00:00
|
|
|
{
|
|
|
|
/* Set PB10 function to serial Rx */
|
|
|
|
PBCR1 = (PBCR1 & 0xffcf) | 0x0020;
|
|
|
|
|
2002-08-12 12:44:18 +00:00
|
|
|
SMR1 = 0x00;
|
2002-08-13 20:58:03 +00:00
|
|
|
SCR1 = 0;
|
2002-08-12 12:44:18 +00:00
|
|
|
BRR1 = (FREQ/(32*9600))-1;
|
2006-11-27 02:16:32 +00:00
|
|
|
and_b(0, &SSR1); /* The status bits must be read before they are cleared,
|
|
|
|
so we do an AND operation */
|
2002-08-13 20:58:03 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
/* 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. */
|
2002-08-13 20:58:03 +00:00
|
|
|
sleep(1);
|
2002-08-12 12:44:18 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
SCR1 = 0x10; /* Enable the receiver, no interrupt */
|
2002-04-20 13:25:58 +00:00
|
|
|
}
|
2002-03-28 15:09:10 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
/* 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)
|
2002-04-20 13:25:58 +00:00
|
|
|
{
|
2002-09-30 08:55:22 +00:00
|
|
|
static int last_valid_button = BUTTON_NONE;
|
|
|
|
static int last_was_error = false;
|
|
|
|
int btn;
|
|
|
|
int ret = BUTTON_NONE;
|
|
|
|
|
|
|
|
/* Errors? Just clear'em. The receiver stops if we don't */
|
|
|
|
if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) {
|
2006-11-27 02:16:32 +00:00
|
|
|
and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1);
|
2002-09-30 08:55:22 +00:00
|
|
|
last_valid_button = BUTTON_NONE;
|
|
|
|
last_was_error = true;
|
|
|
|
return BUTTON_NONE;
|
|
|
|
}
|
2002-08-12 12:44:18 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
if(SSR1 & SCI_RDRF) {
|
|
|
|
/* Read byte and clear the Rx Full bit */
|
|
|
|
btn = RDR1;
|
2006-11-27 02:16:32 +00:00
|
|
|
and_b(~SCI_RDRF, &SSR1);
|
2002-09-30 08:55:22 +00:00
|
|
|
|
|
|
|
if(last_was_error)
|
|
|
|
{
|
|
|
|
last_valid_button = BUTTON_NONE;
|
|
|
|
ret = BUTTON_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (btn)
|
|
|
|
{
|
|
|
|
case STOP:
|
2003-04-23 09:21:37 +00:00
|
|
|
last_valid_button = BUTTON_RC_STOP;
|
2002-09-30 08:55:22 +00:00
|
|
|
break;
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
case PLAY:
|
2003-04-23 09:21:37 +00:00
|
|
|
last_valid_button = BUTTON_RC_PLAY;
|
2002-09-30 08:55:22 +00:00
|
|
|
break;
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
case VOLUP:
|
2003-04-23 09:21:37 +00:00
|
|
|
last_valid_button = BUTTON_RC_VOL_UP;
|
2002-09-30 08:55:22 +00:00
|
|
|
break;
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
case VOLDN:
|
2003-04-23 09:21:37 +00:00
|
|
|
last_valid_button = BUTTON_RC_VOL_DOWN;
|
2002-09-30 08:55:22 +00:00
|
|
|
break;
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
case PREV:
|
2003-04-23 09:21:37 +00:00
|
|
|
last_valid_button = BUTTON_RC_LEFT;
|
2002-09-30 08:55:22 +00:00
|
|
|
break;
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
case NEXT:
|
2003-04-23 09:21:37 +00:00
|
|
|
last_valid_button = BUTTON_RC_RIGHT;
|
2002-09-30 08:55:22 +00:00
|
|
|
break;
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
default:
|
|
|
|
last_valid_button = BUTTON_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-08-12 12:44:18 +00:00
|
|
|
}
|
2002-09-30 08:55:22 +00:00
|
|
|
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;
|
2002-08-12 12:44:18 +00:00
|
|
|
}
|
2002-09-30 08:55:22 +00:00
|
|
|
|
|
|
|
last_was_error = false;
|
2002-03-28 15:09:10 +00:00
|
|
|
|
2002-09-30 08:55:22 +00:00
|
|
|
return ret;
|
2002-04-20 13:25:58 +00:00
|
|
|
}
|
2004-09-20 22:15:35 +00:00
|
|
|
|
2006-11-27 02:16:32 +00:00
|
|
|
#endif /* !HAVE_FMADC && !HAVE_MMC */
|
2006-10-12 20:22:16 +00:00
|
|
|
#elif defined(CPU_COLDFIRE) && defined(HAVE_SERIAL)
|
|
|
|
|
|
|
|
void serial_tx(const unsigned char *buf)
|
|
|
|
{
|
|
|
|
while(*buf) {
|
|
|
|
while(!(USR0 & 0x04))
|
|
|
|
{
|
|
|
|
};
|
|
|
|
UTB0 = *buf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial_setup (void)
|
|
|
|
{
|
|
|
|
UCR0 = 0x30; /* Reset transmitter */
|
|
|
|
UCSR0 = 0xdd; /* Timer mode */
|
|
|
|
|
|
|
|
UCR0 = 0x10; /* Reset pointer */
|
|
|
|
UMR0 = 0x13; /* No parity, 8 bits */
|
|
|
|
UMR0 = 0x07; /* 1 stop bit */
|
|
|
|
|
|
|
|
UCR0 = 0x04; /* Tx enable */
|
|
|
|
}
|
|
|
|
|
2007-09-22 02:17:08 +00:00
|
|
|
#elif (CONFIG_CPU == IMX31L)
|
|
|
|
|
|
|
|
void serial_setup(void)
|
|
|
|
{
|
|
|
|
#ifdef UART_INT /*enable UART Interrupts */
|
2008-02-19 14:30:29 +00:00
|
|
|
UCR1_1 |= (EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN);
|
2008-02-19 14:15:59 +00:00
|
|
|
UCR4_1 |= (EUARTUCR4_TCEN);
|
2007-09-22 02:17:08 +00:00
|
|
|
#else /*disable UART Interrupts*/
|
2008-02-19 14:15:59 +00:00
|
|
|
UCR1_1 &= ~(EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN);
|
|
|
|
UCR4_1 &= ~(EUARTUCR4_TCEN);
|
2007-09-22 02:17:08 +00:00
|
|
|
#endif
|
2008-02-19 14:15:59 +00:00
|
|
|
UCR1_1 |= EUARTUCR1_UARTEN;
|
|
|
|
UCR2_1 |= (EUARTUCR2_TXEN | EUARTUCR2_RXEN | EUARTUCR2_IRTS);
|
2007-09-22 02:17:08 +00:00
|
|
|
|
|
|
|
/* Tx,Rx Interrupt Trigger levels, Disable for now*/
|
|
|
|
/*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/
|
|
|
|
}
|
|
|
|
|
2008-02-19 14:15:59 +00:00
|
|
|
int tx_rdy(void)
|
2007-09-22 02:17:08 +00:00
|
|
|
{
|
2008-02-19 14:15:59 +00:00
|
|
|
if((UTS1 & EUARTUTS_TXEMPTY))
|
2007-09-22 02:17:08 +00:00
|
|
|
return 1;
|
2008-02-19 14:15:59 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2007-09-22 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY
|
|
|
|
keeps returning true*/
|
2008-02-19 14:15:59 +00:00
|
|
|
int rx_rdy(void)
|
2007-09-22 02:17:08 +00:00
|
|
|
{
|
2008-02-19 14:15:59 +00:00
|
|
|
if(!(UTS1 & EUARTUTS_RXEMPTY))
|
2007-09-22 02:17:08 +00:00
|
|
|
return 1;
|
2008-02-19 14:15:59 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2007-09-22 02:17:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-19 14:15:59 +00:00
|
|
|
void tx_writec(char c)
|
2007-09-22 02:17:08 +00:00
|
|
|
{
|
|
|
|
UTXD1=(int) c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dprintf(const char * str, ... )
|
|
|
|
{
|
|
|
|
char dprintfbuff[256];
|
|
|
|
unsigned char * ptr;
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, str);
|
|
|
|
|
|
|
|
ptr = dprintfbuff;
|
|
|
|
vsnprintf(ptr,sizeof(dprintfbuff),str,ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
serial_tx(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial_tx(const unsigned char * buf)
|
|
|
|
{
|
|
|
|
/*Tx*/
|
|
|
|
for(;;) {
|
2008-02-19 14:15:59 +00:00
|
|
|
if(tx_rdy()) {
|
2007-09-22 02:17:08 +00:00
|
|
|
if(*buf == '\0')
|
|
|
|
return;
|
|
|
|
if(*buf == '\n')
|
2008-02-19 14:15:59 +00:00
|
|
|
tx_writec('\r');
|
|
|
|
tx_writec(*buf);
|
2007-09-22 02:17:08 +00:00
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-12 20:22:16 +00:00
|
|
|
#else /* Other targets */
|
2005-02-02 21:47:43 +00:00
|
|
|
void serial_setup (void)
|
|
|
|
{
|
|
|
|
/* a dummy */
|
|
|
|
}
|
2006-11-10 20:26:01 +00:00
|
|
|
#endif
|