slow - but working - IRQ based uart/button driver.
change some of the uart function names from CamelCase git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14908 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f548336e27
commit
a5e788fe85
4 changed files with 66 additions and 19 deletions
|
@ -58,7 +58,7 @@ void main(void)
|
|||
adc_init();
|
||||
button_init();
|
||||
backlight_init();
|
||||
uartSetup();
|
||||
uart_init();
|
||||
|
||||
font_init();
|
||||
spi_init();
|
||||
|
@ -104,6 +104,8 @@ void main(void)
|
|||
while(true)
|
||||
{
|
||||
button = button_read_device();
|
||||
if (button)
|
||||
printf("btn: %x", button);
|
||||
if (button == BUTTON_POWER)
|
||||
{
|
||||
printf("reset");
|
||||
|
@ -121,6 +123,7 @@ void main(void)
|
|||
// if ((IO_GIO_BITSET0&(1<<14) == 0)
|
||||
{
|
||||
short x,y,z1,z2, reg;
|
||||
extern int uart1count;
|
||||
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);
|
||||
|
@ -128,8 +131,10 @@ void main(void)
|
|||
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));
|
||||
printf("uart1count: %d", uart1count);
|
||||
printf("%x %x", IO_UART1_RFCR & 0x3f, IO_UART1_DTRR & 0xff);
|
||||
tsc2100_keyclick(); /* doesnt work :( */
|
||||
line -= 6;
|
||||
line -= 8;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
void button_init_device(void)
|
||||
{
|
||||
/* GIO is the power button, set as input */
|
||||
IO_GIO_DIR0|=0x01;
|
||||
IO_GIO_DIR0 |= 0x01;
|
||||
}
|
||||
|
||||
inline bool button_hold(void)
|
||||
|
@ -48,20 +48,17 @@ inline bool button_hold(void)
|
|||
int button_read_device(void)
|
||||
{
|
||||
char data[5], c;
|
||||
int val;
|
||||
int i = 0;
|
||||
int btn = BUTTON_NONE, timeout = BUTTON_TIMEOUT;
|
||||
int btn = BUTTON_NONE;
|
||||
|
||||
if ((IO_GIO_BITSET0&0x01) == 0)
|
||||
btn |= BUTTON_POWER;
|
||||
|
||||
uartHeartbeat();
|
||||
while (timeout > 0)
|
||||
uart1_heartbeat();
|
||||
while (uartAvailable())
|
||||
{
|
||||
val = uartPollch(BUTTON_TIMEOUT*100);
|
||||
if (val > -1)
|
||||
if (uart1_getch(&c))
|
||||
{
|
||||
c = val&0xff;
|
||||
if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2))
|
||||
{
|
||||
data[i++] = c;
|
||||
|
@ -94,7 +91,6 @@ int button_read_device(void)
|
|||
break;
|
||||
}
|
||||
}
|
||||
timeout--;
|
||||
}
|
||||
return btn;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
|
||||
/* UART 0/1 */
|
||||
|
||||
#define CONFIG_UART_BRSR 87
|
||||
#define CONFIG_UART_BRSR 87
|
||||
#define MAX_UART_BUFFER 32
|
||||
static unsigned char uart1buffer[MAX_UART_BUFFER];
|
||||
int uart1read = 0, uart1write = 0, uart1count = 0;
|
||||
|
||||
void do_checksums(char *data, int len, char *xor, char *add)
|
||||
{
|
||||
|
@ -37,10 +40,24 @@ void do_checksums(char *data, int len, char *xor, char *add)
|
|||
}
|
||||
}
|
||||
|
||||
void uartSetup(void) {
|
||||
void uart_init(void)
|
||||
{
|
||||
// 8-N-1
|
||||
IO_UART1_MSR=0x8000;
|
||||
IO_UART1_BRSR=CONFIG_UART_BRSR;
|
||||
IO_UART1_RFCR = 0x8000;
|
||||
/* 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;
|
||||
uart1count = 0;
|
||||
|
||||
/* Enable the interrupt */
|
||||
IO_INTC_EINT0 |= (1<<IRQ_UART1);
|
||||
}
|
||||
|
||||
void uartPutc(char ch) {
|
||||
|
@ -111,10 +128,10 @@ int uartPollch(unsigned int ticks) {
|
|||
|
||||
bool uartAvailable(void)
|
||||
{
|
||||
return (IO_UART1_RFCR & 0x3f)?true:false;
|
||||
return uart1count > 0;
|
||||
}
|
||||
|
||||
void uartHeartbeat(void)
|
||||
void uart1_heartbeat(void)
|
||||
{
|
||||
char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
|
||||
uartPuts(data);
|
||||
|
@ -126,3 +143,30 @@ void uartSendData(char* data, int len)
|
|||
for(i=0;i<len;i++)
|
||||
uartPutc(data[i]);
|
||||
}
|
||||
|
||||
bool uart1_getch(char *c)
|
||||
{
|
||||
if (uart1count > 0)
|
||||
{
|
||||
*c = uart1buffer[uart1read];
|
||||
uart1read = (uart1read+1) % MAX_UART_BUFFER;
|
||||
uart1count--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* UART1 receive intterupt handler */
|
||||
void UART1(void)
|
||||
{
|
||||
if (IO_UART1_RFCR & 0x3f)
|
||||
{
|
||||
if (uart1count >= MAX_UART_BUFFER)
|
||||
panicf("UART1 buffer overflow");
|
||||
uart1buffer[uart1write] = IO_UART1_DTRR & 0xff;
|
||||
uart1write = (uart1write+1) % MAX_UART_BUFFER;
|
||||
uart1count++;
|
||||
}
|
||||
|
||||
IO_INTC_IRQ0 = (1<<IRQ_UART1);
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@
|
|||
#ifndef UART_H
|
||||
#define UART_H
|
||||
|
||||
void uartPutc(char ch);
|
||||
void uartPutHex(unsigned int n);
|
||||
void uartSetup(void);
|
||||
void uart_init(void);
|
||||
bool uart1_getch(char *c);
|
||||
void uart1_heartbeat(void);
|
||||
|
||||
void uartPuts(const char *str);
|
||||
void uartGets(char *str, unsigned int size);
|
||||
int uartPollch(unsigned int ticks);
|
||||
void uartHeartbeat(void);
|
||||
void uartPutc(char ch);
|
||||
void uartPutHex(unsigned int n);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue