From 300f64c99a28bf76dfc23b8730f4ef2749a61140 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 20 Sep 2007 09:08:40 +0000 Subject: [PATCH] uart driver (which the buttons need) and button test code in the bootloader git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14768 a1c6a512-1295-4272-9138-f99709370657 --- bootloader/mrobe500.c | 14 +- firmware/SOURCES | 1 + .../arm/olympus/mrobe-500/button-mr500.c | 1 + .../target/arm/olympus/mrobe-500/uart-mr500.c | 142 ++++++++++++++++++ .../arm/olympus/mrobe-500/uart-target.h | 30 ++++ 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 firmware/target/arm/olympus/mrobe-500/uart-mr500.c create mode 100644 firmware/target/arm/olympus/mrobe-500/uart-target.h diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c index 02726dde5a..fd2587eda2 100755 --- a/bootloader/mrobe500.c +++ b/bootloader/mrobe500.c @@ -52,7 +52,7 @@ void main(void) adc_init(); button_init(); backlight_init(); - + uartSetup(); lcd_init(); font_init(); @@ -96,8 +96,20 @@ void main(void) #endif printf("ATA"); + int count = 0, i = 0, c = 0; + char data[64]; while(true) { + i = button_read_device(); + c++; + if (i) + { + c = 0; + __backlight_on(); + printf("button: %x", i); + } + else if (c>50) + __backlight_off(); } #if 0 rc = ata_init(); diff --git a/firmware/SOURCES b/firmware/SOURCES index 0f5da2fe6c..e62d9331a5 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -600,6 +600,7 @@ target/arm/olympus/mrobe-500/power-mr500.c target/arm/olympus/mrobe-500/system-mr500.c target/arm/olympus/mrobe-500/timer-mr500.c target/arm/olympus/mrobe-500/usb-mr500.c +target/arm/olympus/mrobe-500/uart-mr500.c #ifndef BOOTLOADER #endif diff --git a/firmware/target/arm/olympus/mrobe-500/button-mr500.c b/firmware/target/arm/olympus/mrobe-500/button-mr500.c index 388dbf0689..f85eeca912 100644 --- a/firmware/target/arm/olympus/mrobe-500/button-mr500.c +++ b/firmware/target/arm/olympus/mrobe-500/button-mr500.c @@ -26,6 +26,7 @@ #include "adc.h" #include "system.h" #include "backlight-target.h" +#include "uart-target.h" #define BUTTON_TIMEOUT 50 void button_init_device(void) diff --git a/firmware/target/arm/olympus/mrobe-500/uart-mr500.c b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c new file mode 100644 index 0000000000..f8208f8717 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c @@ -0,0 +1,142 @@ +/* + * (C) Copyright 2007 Catalin Patulea + * + * 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. + * + * 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. + * + * 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 + * + */ +#include "config.h" +#include "cpu.h" +#include "system.h" + +/* UART 0/1 */ +#define IO_UART0_DTRR 0x0300 +#define IO_UART0_BRSR 0x0302 +#define IO_UART0_MSR 0x0304 +#define IO_UART0_RFCR 0x0306 +#define IO_UART0_TFCR 0x0308 +#define IO_UART0_LCR 0x030A +#define IO_UART0_SR 0x030C + +#define IO_UART1_DTRR 0x0380 +#define IO_UART1_BRSR 0x0382 +#define IO_UART1_MSR 0x0384 +#define IO_UART1_RFCR 0x0386 +#define IO_UART1_TFCR 0x0388 +#define IO_UART1_LCR 0x038A +#define IO_UART1_SR 0x038C +#define CONFIG_UART_BRSR 87 + +void do_checksums(char *data, int len, char *xor, char *add) +{ + int i; + *xor = data[0]; + *add = data[0]; + for(i=1;i= 0x20); + + // Write character + outw(ch, IO_UART1_DTRR); +} + +// Unsigned integer to ASCII hexadecimal conversion +void uartPutHex(unsigned int n) { + unsigned int i; + + for (i = 8; i != 0; i--) { + unsigned int digit = n >> 28; + uartPutc(digit >= 10 ? digit - 10 + 'A' : digit + '0'); + n <<= 4; + } +} + +void uartPuts(const char *str) { + char ch; + while ((ch = *str++) != '\0') { + uartPutc(ch); + } +} + +void uartGets(char *str, unsigned int size) { + for (;;) { + char ch; + + // Wait for FIFO to contain something + while ((inw(IO_UART1_RFCR) & 0x3f) == 0); + + // Read character + ch = (char)inw(IO_UART1_DTRR); + + // Echo character back + outw(ch, IO_UART1_DTRR); + + // If CR, also echo LF, null-terminate, and return + if (ch == '\r') { + outw('\n', IO_UART1_DTRR); + if (size) { + *str++ = '\0'; + } + return; + } + + // Append to buffer + if (size) { + *str++ = ch; + --size; + } + } +} + +int uartPollch(unsigned int ticks) { + while (ticks--) { + if (inw(IO_UART1_RFCR) & 0x3f) { + return inw(IO_UART1_DTRR) & 0xff; + } + } + + return -1; +} + +bool uartAvailable(void) +{ + return (inw(IO_UART1_RFCR) & 0x3f)?true:false; +} + +void uartHeartbeat(void) +{ + char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; + uartPuts(data); +} + +void uartSendData(char* data, int len) +{ + int i; + for(i=0;i + * + * 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. + * + * 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. + * + * 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 + * + */ +#ifndef UART_H +#define UART_H + +void uartPutc(char ch); +void uartPutHex(unsigned int n); +void uartSetup(void); +void uartPuts(const char *str); +void uartGets(char *str, unsigned int size); +int uartPollch(unsigned int ticks); + +#endif