1
0
Fork 0
forked from len0rd/rockbox

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:
Karl Kurbjun 2007-10-18 05:14:10 +00:00
parent a443614dd2
commit fa1a38e7ce
3 changed files with 86 additions and 84 deletions

View file

@ -43,7 +43,7 @@
#include "tsc2100.h" #include "tsc2100.h"
#include "time.h" #include "time.h"
//#define MRDEBUG #define MRDEBUG
#if defined(MRDEBUG) #if defined(MRDEBUG)
@ -97,18 +97,22 @@ void touchpad_calibrate_screen(void)
set_calibration_points(&tl, &br); set_calibration_points(&tl, &br);
} }
void mrdebug() void mrdebug(void)
{ {
int button=0, *address=0x0; int button=0, *address=0x0;
#if 0
use_calibration(false); use_calibration(false);
touchpad_calibrate_screen(); touchpad_calibrate_screen();
use_calibration(true); use_calibration(true);
#endif
while(true) while(true)
{ {
#if 0
struct tm *t = get_time(); 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("%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)); printf("time: %d", mktime(t));
button = button_read_device(); #endif
button = button_status();
if (button == BUTTON_POWER) if (button == BUTTON_POWER)
{ {
printf("reset"); printf("reset");
@ -122,6 +126,19 @@ void mrdebug()
address+=0x1000; address+=0x1000;
else if (button==BUTTON_RC_REW) else if (button==BUTTON_RC_REW)
address-=0x1000; 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) if (button&BUTTON_TOUCHPAD)
{ {
unsigned int data = button_get_last_touch(); unsigned int data = button_get_last_touch();
@ -129,6 +146,7 @@ void mrdebug()
line-=3; line-=3;
} }
else line -=2; else line -=2;
#endif
} }
} }
#endif #endif

View file

@ -69,6 +69,7 @@ static int touch_to_pixels(short val_x, short val_y)
y = 0; y = 0;
return (x<<16)|y; return (x<<16)|y;
} }
void button_init_device(void) void button_init_device(void)
{ {
last_touch = 0; last_touch = 0;
@ -102,53 +103,56 @@ int button_get_last_touch(void)
} }
#endif #endif
static void remote_heartbeat(void)
{
char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
uart1_puts(data);
}
int button_read_device(void) int button_read_device(void)
{ {
char data[5], c; char c;
int i = 0; int i = 0;
int btn = BUTTON_NONE; int btn = BUTTON_NONE;
if (last_touch) if (last_touch)
btn |= BUTTON_TOUCHPAD; btn |= BUTTON_TOUCHPAD;
if ((IO_GIO_BITSET0&0x01) == 0) if ((IO_GIO_BITSET0&0x01) == 0)
btn |= BUTTON_POWER; btn |= BUTTON_POWER;
uart1_heartbeat(); remote_heartbeat();
while (uart1_available()) 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; if (c& (1<<7))
}
else if (c == BUTTON_START_BYTE ||
c == BUTTON_START_BYTE2)
{
data[0] = c;
i = 1;
}
if (i == 5)
{
if (data[1]& (1<<7))
btn |= BUTTON_RC_HEART; btn |= BUTTON_RC_HEART;
if (data[1]& (1<<6)) if (c& (1<<6))
btn |= BUTTON_RC_MODE; btn |= BUTTON_RC_MODE;
if (data[1]& (1<<5)) if (c& (1<<5))
btn |= BUTTON_RC_VOL_DOWN; btn |= BUTTON_RC_VOL_DOWN;
if (data[1]& (1<<4)) if (c& (1<<4))
btn |= BUTTON_RC_VOL_UP; btn |= BUTTON_RC_VOL_UP;
if (data[1]& (1<<3)) if (c& (1<<3))
btn |= BUTTON_RC_REW; btn |= BUTTON_RC_REW;
if (data[1]& (1<<2)) if (c& (1<<2))
btn |= BUTTON_RC_FF; btn |= BUTTON_RC_FF;
if (data[1]& (1<<1)) if (c& (1<<1))
btn |= BUTTON_RC_DOWN; btn |= BUTTON_RC_DOWN;
if (data[1]& (1<<0)) if (c& (1<<0))
btn |= BUTTON_RC_PLAY; btn |= BUTTON_RC_PLAY;
break; }
else if(i==5)
{
i=0;
} }
} }
} }

View file

@ -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 * Copyright (C) 2007 Catalin Patulea <cat@vv.carleton.ca>
* 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.
* *
* This program is distributed in the hope that it will be useful, * All files in this archive are subject to the GNU General Public License.
* but WITHOUT ANY WARRANTY; without even the implied warranty of * See the file COPYING in the source tree root for full license agreement.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* along with this program; if not, write to the Free Software * KIND, either express or implied.
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* *
*/ ****************************************************************************/
#include "config.h" #include "config.h"
#include "cpu.h" #include "cpu.h"
#include "system.h" #include "system.h"
@ -24,8 +23,8 @@
/* UART 0/1 */ /* UART 0/1 */
#define CONFIG_UART_BRSR 87 #define CONFIG_UART_BRSR 87
#define MAX_UART_BUFFER 32 #define MAX_UART_BUFFER 31
static unsigned char uart1buffer[MAX_UART_BUFFER]; unsigned char uart1buffer[MAX_UART_BUFFER];
int uart1read = 0, uart1write = 0, uart1count = 0; 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 // 8-N-1
IO_UART1_MSR=0x8000; IO_UART1_MSR=0x8000;
IO_UART1_BRSR=CONFIG_UART_BRSR; IO_UART1_BRSR=CONFIG_UART_BRSR;
IO_UART1_RFCR = 0x8000; IO_UART1_RFCR = 0x8010; /* Trigger later */
/* gio 27 is input, uart1 rx /* gio 27 is input, uart1 rx
gio 28 is output, uart1 tx */ gio 28 is output, uart1 tx */
IO_GIO_DIR1 |= (1<<11); /* gio 27 */ IO_GIO_DIR1 |= (1<<11); /* gio 27 */
IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */ IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */
/* init the recieve buffer */ /* init the recieve buffer */
uart1read = 0; uart1read = 0;
uart1write = 0; uart1write = 0;
@ -101,10 +100,7 @@ void uart1_gets(char *str, unsigned int size)
/* Read character */ /* Read character */
ch = (char)IO_UART1_DTRR; ch = (char)IO_UART1_DTRR;
/* Echo character back */
IO_UART1_DTRR=ch;
/* If CR, also echo LF, null-terminate, and return */ /* If CR, also echo LF, null-terminate, and return */
if (ch == '\r') { if (ch == '\r') {
IO_UART1_DTRR='\n'; 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) bool uart1_getch(char *c)
{ {
if (uart1count > 0) if (uart1count > 0)
{ {
*c = uart1buffer[uart1read]; if(uart1read>MAX_UART_BUFFER)
uart1read = (uart1read+1) % MAX_UART_BUFFER; uart1read=0;
*c = uart1buffer[uart1read++];
uart1count--; uart1count--;
return true; return true;
} }
@ -158,15 +135,18 @@ bool uart1_getch(char *c)
/* UART1 receive intterupt handler */ /* UART1 receive intterupt handler */
void UART1(void) 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"); panicf("UART1 buffer overflow");
*/ else
uart1buffer[uart1write] = IO_UART1_DTRR & 0xff; {
uart1write = (uart1write+1) % MAX_UART_BUFFER; if(uart1write>MAX_UART_BUFFER)
uart1count++; uart1write=0;
uart1buffer[uart1write++] = IO_UART1_DTRR & 0xff;
uart1count++;
}
} }
IO_INTC_IRQ0 = (1<<IRQ_UART1); IO_INTC_IRQ0 = (1<<IRQ_UART1);