Some changes to the UART/button driver - reduce the number of interrupts - more work is needed
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15180 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a443614dd2
commit
fa1a38e7ce
3 changed files with 86 additions and 84 deletions
|
@ -43,7 +43,7 @@
|
|||
#include "tsc2100.h"
|
||||
#include "time.h"
|
||||
|
||||
//#define MRDEBUG
|
||||
#define MRDEBUG
|
||||
|
||||
#if defined(MRDEBUG)
|
||||
|
||||
|
@ -97,18 +97,22 @@ void touchpad_calibrate_screen(void)
|
|||
set_calibration_points(&tl, &br);
|
||||
}
|
||||
|
||||
void mrdebug()
|
||||
void mrdebug(void)
|
||||
{
|
||||
int button=0, *address=0x0;
|
||||
#if 0
|
||||
use_calibration(false);
|
||||
touchpad_calibrate_screen();
|
||||
use_calibration(true);
|
||||
#endif
|
||||
while(true)
|
||||
{
|
||||
#if 0
|
||||
struct tm *t = get_time();
|
||||
printf("%d:%d:%d %d %d %d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon, t->tm_year);
|
||||
printf("time: %d", mktime(t));
|
||||
button = button_read_device();
|
||||
#endif
|
||||
button = button_status();
|
||||
if (button == BUTTON_POWER)
|
||||
{
|
||||
printf("reset");
|
||||
|
@ -122,6 +126,19 @@ void mrdebug()
|
|||
address+=0x1000;
|
||||
else if (button==BUTTON_RC_REW)
|
||||
address-=0x1000;
|
||||
{
|
||||
short x,y,z1,z2;
|
||||
tsc2100_read_values(&x, &y, &z1, &z2);
|
||||
printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
|
||||
printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
|
||||
printf("current tick: %04x", current_tick);
|
||||
printf("Address: 0x%08x Data: 0x%08x", address, *address);
|
||||
printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
|
||||
printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
|
||||
// tsc2100_keyclick(); /* doesnt work :( */
|
||||
line -= 6;
|
||||
}
|
||||
#if 0
|
||||
if (button&BUTTON_TOUCHPAD)
|
||||
{
|
||||
unsigned int data = button_get_last_touch();
|
||||
|
@ -129,6 +146,7 @@ void mrdebug()
|
|||
line-=3;
|
||||
}
|
||||
else line -=2;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -69,6 +69,7 @@ static int touch_to_pixels(short val_x, short val_y)
|
|||
y = 0;
|
||||
return (x<<16)|y;
|
||||
}
|
||||
|
||||
void button_init_device(void)
|
||||
{
|
||||
last_touch = 0;
|
||||
|
@ -102,53 +103,56 @@ int button_get_last_touch(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void remote_heartbeat(void)
|
||||
{
|
||||
char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
|
||||
uart1_puts(data);
|
||||
}
|
||||
|
||||
int button_read_device(void)
|
||||
{
|
||||
char data[5], c;
|
||||
char c;
|
||||
int i = 0;
|
||||
int btn = BUTTON_NONE;
|
||||
|
||||
if (last_touch)
|
||||
btn |= BUTTON_TOUCHPAD;
|
||||
|
||||
|
||||
if ((IO_GIO_BITSET0&0x01) == 0)
|
||||
btn |= BUTTON_POWER;
|
||||
|
||||
uart1_heartbeat();
|
||||
while (uart1_available())
|
||||
|
||||
remote_heartbeat();
|
||||
while (uart1_getch(&c))
|
||||
{
|
||||
if (uart1_getch(&c))
|
||||
if (i==0 && (c == BUTTON_START_BYTE || c == BUTTON_START_BYTE2) )
|
||||
{
|
||||
if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2))
|
||||
i++;
|
||||
}
|
||||
else if (i)
|
||||
{
|
||||
i++;
|
||||
if(i==2)
|
||||
{
|
||||
data[i++] = c;
|
||||
}
|
||||
else if (c == BUTTON_START_BYTE ||
|
||||
c == BUTTON_START_BYTE2)
|
||||
{
|
||||
data[0] = c;
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if (i == 5)
|
||||
{
|
||||
if (data[1]& (1<<7))
|
||||
if (c& (1<<7))
|
||||
btn |= BUTTON_RC_HEART;
|
||||
if (data[1]& (1<<6))
|
||||
if (c& (1<<6))
|
||||
btn |= BUTTON_RC_MODE;
|
||||
if (data[1]& (1<<5))
|
||||
if (c& (1<<5))
|
||||
btn |= BUTTON_RC_VOL_DOWN;
|
||||
if (data[1]& (1<<4))
|
||||
if (c& (1<<4))
|
||||
btn |= BUTTON_RC_VOL_UP;
|
||||
if (data[1]& (1<<3))
|
||||
if (c& (1<<3))
|
||||
btn |= BUTTON_RC_REW;
|
||||
if (data[1]& (1<<2))
|
||||
if (c& (1<<2))
|
||||
btn |= BUTTON_RC_FF;
|
||||
if (data[1]& (1<<1))
|
||||
if (c& (1<<1))
|
||||
btn |= BUTTON_RC_DOWN;
|
||||
if (data[1]& (1<<0))
|
||||
if (c& (1<<0))
|
||||
btn |= BUTTON_RC_PLAY;
|
||||
break;
|
||||
}
|
||||
else if(i==5)
|
||||
{
|
||||
i=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
/*
|
||||
* (C) Copyright 2007 Catalin Patulea <cat@vv.carleton.ca>
|
||||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 2007 Catalin Patulea <cat@vv.carleton.ca>
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "cpu.h"
|
||||
#include "system.h"
|
||||
|
@ -24,8 +23,8 @@
|
|||
/* UART 0/1 */
|
||||
|
||||
#define CONFIG_UART_BRSR 87
|
||||
#define MAX_UART_BUFFER 32
|
||||
static unsigned char uart1buffer[MAX_UART_BUFFER];
|
||||
#define MAX_UART_BUFFER 31
|
||||
unsigned char uart1buffer[MAX_UART_BUFFER];
|
||||
int uart1read = 0, uart1write = 0, uart1count = 0;
|
||||
|
||||
/*
|
||||
|
@ -42,17 +41,17 @@ static void do_checksums(char *data, int len, char *xor, char *add)
|
|||
}
|
||||
*/
|
||||
|
||||
void uart_init(void)
|
||||
void uart_init(void)
|
||||
{
|
||||
// 8-N-1
|
||||
IO_UART1_MSR=0x8000;
|
||||
IO_UART1_BRSR=CONFIG_UART_BRSR;
|
||||
IO_UART1_RFCR = 0x8000;
|
||||
IO_UART1_RFCR = 0x8010; /* Trigger later */
|
||||
/* gio 27 is input, uart1 rx
|
||||
gio 28 is output, uart1 tx */
|
||||
IO_GIO_DIR1 |= (1<<11); /* gio 27 */
|
||||
IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */
|
||||
|
||||
|
||||
/* init the recieve buffer */
|
||||
uart1read = 0;
|
||||
uart1write = 0;
|
||||
|
@ -101,10 +100,7 @@ void uart1_gets(char *str, unsigned int size)
|
|||
|
||||
/* Read character */
|
||||
ch = (char)IO_UART1_DTRR;
|
||||
|
||||
/* Echo character back */
|
||||
IO_UART1_DTRR=ch;
|
||||
|
||||
|
||||
/* If CR, also echo LF, null-terminate, and return */
|
||||
if (ch == '\r') {
|
||||
IO_UART1_DTRR='\n';
|
||||
|
@ -122,33 +118,14 @@ void uart1_gets(char *str, unsigned int size)
|
|||
}
|
||||
}
|
||||
|
||||
int uart1_pollch(unsigned int ticks)
|
||||
{
|
||||
while (ticks--) {
|
||||
if (IO_UART1_RFCR & 0x3f) {
|
||||
return IO_UART1_DTRR & 0xff;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool uart1_available(void)
|
||||
{
|
||||
return uart1count > 0;
|
||||
}
|
||||
|
||||
void uart1_heartbeat(void)
|
||||
{
|
||||
char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
|
||||
uart1_puts(data);
|
||||
}
|
||||
|
||||
bool uart1_getch(char *c)
|
||||
{
|
||||
if (uart1count > 0)
|
||||
{
|
||||
*c = uart1buffer[uart1read];
|
||||
uart1read = (uart1read+1) % MAX_UART_BUFFER;
|
||||
if(uart1read>MAX_UART_BUFFER)
|
||||
uart1read=0;
|
||||
|
||||
*c = uart1buffer[uart1read++];
|
||||
uart1count--;
|
||||
return true;
|
||||
}
|
||||
|
@ -158,15 +135,18 @@ bool uart1_getch(char *c)
|
|||
/* UART1 receive intterupt handler */
|
||||
void UART1(void)
|
||||
{
|
||||
if (IO_UART1_RFCR & 0x3f)
|
||||
while (IO_UART1_RFCR & 0x3f)
|
||||
{
|
||||
/*
|
||||
if (uart1count >= MAX_UART_BUFFER)
|
||||
if (uart1count > MAX_UART_BUFFER)
|
||||
panicf("UART1 buffer overflow");
|
||||
*/
|
||||
uart1buffer[uart1write] = IO_UART1_DTRR & 0xff;
|
||||
uart1write = (uart1write+1) % MAX_UART_BUFFER;
|
||||
uart1count++;
|
||||
else
|
||||
{
|
||||
if(uart1write>MAX_UART_BUFFER)
|
||||
uart1write=0;
|
||||
|
||||
uart1buffer[uart1write++] = IO_UART1_DTRR & 0xff;
|
||||
uart1count++;
|
||||
}
|
||||
}
|
||||
|
||||
IO_INTC_IRQ0 = (1<<IRQ_UART1);
|
||||
|
|
Loading…
Reference in a new issue