diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-09-30 08:18:46 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-09-30 08:18:46 +0000 |
commit | a5e788fe8533f6172b3d6b52d2430fe163f7a6fd (patch) | |
tree | 3c02a246e903d743126658bfb94bbacbdeba8fc4 | |
parent | f548336e271f970d7ccd8a84e85ce8590ff7deab (diff) | |
download | rockbox-a5e788fe8533f6172b3d6b52d2430fe163f7a6fd.tar.gz rockbox-a5e788fe8533f6172b3d6b52d2430fe163f7a6fd.zip |
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
-rwxr-xr-x | bootloader/mrobe500.c | 9 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/button-mr500.c | 14 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/uart-mr500.c | 52 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/uart-target.h | 10 |
4 files changed, 66 insertions, 19 deletions
diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c index 86415cb560..ce1aa57224 100755 --- a/bootloader/mrobe500.c +++ b/bootloader/mrobe500.c | |||
@@ -58,7 +58,7 @@ void main(void) | |||
58 | adc_init(); | 58 | adc_init(); |
59 | button_init(); | 59 | button_init(); |
60 | backlight_init(); | 60 | backlight_init(); |
61 | uartSetup(); | 61 | uart_init(); |
62 | 62 | ||
63 | font_init(); | 63 | font_init(); |
64 | spi_init(); | 64 | spi_init(); |
@@ -104,6 +104,8 @@ void main(void) | |||
104 | while(true) | 104 | while(true) |
105 | { | 105 | { |
106 | button = button_read_device(); | 106 | button = button_read_device(); |
107 | if (button) | ||
108 | printf("btn: %x", button); | ||
107 | if (button == BUTTON_POWER) | 109 | if (button == BUTTON_POWER) |
108 | { | 110 | { |
109 | printf("reset"); | 111 | printf("reset"); |
@@ -121,6 +123,7 @@ void main(void) | |||
121 | // if ((IO_GIO_BITSET0&(1<<14) == 0) | 123 | // if ((IO_GIO_BITSET0&(1<<14) == 0) |
122 | { | 124 | { |
123 | short x,y,z1,z2, reg; | 125 | short x,y,z1,z2, reg; |
126 | extern int uart1count; | ||
124 | tsc2100_read_values(&x, &y, &z1, &z2); | 127 | tsc2100_read_values(&x, &y, &z1, &z2); |
125 | printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2); | 128 | printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2); |
126 | printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff); | 129 | printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff); |
@@ -128,8 +131,10 @@ void main(void) | |||
128 | printf("Address: 0x%08x Data: 0x%08x", address, *address); | 131 | printf("Address: 0x%08x Data: 0x%08x", address, *address); |
129 | printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1)); | 132 | printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1)); |
130 | printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2)); | 133 | printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2)); |
134 | printf("uart1count: %d", uart1count); | ||
135 | printf("%x %x", IO_UART1_RFCR & 0x3f, IO_UART1_DTRR & 0xff); | ||
131 | tsc2100_keyclick(); /* doesnt work :( */ | 136 | tsc2100_keyclick(); /* doesnt work :( */ |
132 | line -= 6; | 137 | line -= 8; |
133 | } | 138 | } |
134 | } | 139 | } |
135 | #endif | 140 | #endif |
diff --git a/firmware/target/arm/olympus/mrobe-500/button-mr500.c b/firmware/target/arm/olympus/mrobe-500/button-mr500.c index 7410875fd1..1d0d2714a8 100644 --- a/firmware/target/arm/olympus/mrobe-500/button-mr500.c +++ b/firmware/target/arm/olympus/mrobe-500/button-mr500.c | |||
@@ -37,7 +37,7 @@ | |||
37 | void button_init_device(void) | 37 | void button_init_device(void) |
38 | { | 38 | { |
39 | /* GIO is the power button, set as input */ | 39 | /* GIO is the power button, set as input */ |
40 | IO_GIO_DIR0|=0x01; | 40 | IO_GIO_DIR0 |= 0x01; |
41 | } | 41 | } |
42 | 42 | ||
43 | inline bool button_hold(void) | 43 | inline bool button_hold(void) |
@@ -48,20 +48,17 @@ inline bool button_hold(void) | |||
48 | int button_read_device(void) | 48 | int button_read_device(void) |
49 | { | 49 | { |
50 | char data[5], c; | 50 | char data[5], c; |
51 | int val; | ||
52 | int i = 0; | 51 | int i = 0; |
53 | int btn = BUTTON_NONE, timeout = BUTTON_TIMEOUT; | 52 | int btn = BUTTON_NONE; |
54 | 53 | ||
55 | if ((IO_GIO_BITSET0&0x01) == 0) | 54 | if ((IO_GIO_BITSET0&0x01) == 0) |
56 | btn |= BUTTON_POWER; | 55 | btn |= BUTTON_POWER; |
57 | 56 | ||
58 | uartHeartbeat(); | 57 | uart1_heartbeat(); |
59 | while (timeout > 0) | 58 | while (uartAvailable()) |
60 | { | 59 | { |
61 | val = uartPollch(BUTTON_TIMEOUT*100); | 60 | if (uart1_getch(&c)) |
62 | if (val > -1) | ||
63 | { | 61 | { |
64 | c = val&0xff; | ||
65 | if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2)) | 62 | if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2)) |
66 | { | 63 | { |
67 | data[i++] = c; | 64 | data[i++] = c; |
@@ -94,7 +91,6 @@ int button_read_device(void) | |||
94 | break; | 91 | break; |
95 | } | 92 | } |
96 | } | 93 | } |
97 | timeout--; | ||
98 | } | 94 | } |
99 | return btn; | 95 | return btn; |
100 | } | 96 | } |
diff --git a/firmware/target/arm/olympus/mrobe-500/uart-mr500.c b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c index 99cf0f2d36..66e59eaaac 100644 --- a/firmware/target/arm/olympus/mrobe-500/uart-mr500.c +++ b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c | |||
@@ -23,7 +23,10 @@ | |||
23 | 23 | ||
24 | /* UART 0/1 */ | 24 | /* UART 0/1 */ |
25 | 25 | ||
26 | #define CONFIG_UART_BRSR 87 | 26 | #define CONFIG_UART_BRSR 87 |
27 | #define MAX_UART_BUFFER 32 | ||
28 | static unsigned char uart1buffer[MAX_UART_BUFFER]; | ||
29 | int uart1read = 0, uart1write = 0, uart1count = 0; | ||
27 | 30 | ||
28 | void do_checksums(char *data, int len, char *xor, char *add) | 31 | void do_checksums(char *data, int len, char *xor, char *add) |
29 | { | 32 | { |
@@ -37,10 +40,24 @@ void do_checksums(char *data, int len, char *xor, char *add) | |||
37 | } | 40 | } |
38 | } | 41 | } |
39 | 42 | ||
40 | void uartSetup(void) { | 43 | void uart_init(void) |
44 | { | ||
41 | // 8-N-1 | 45 | // 8-N-1 |
42 | IO_UART1_MSR=0x8000; | 46 | IO_UART1_MSR=0x8000; |
43 | IO_UART1_BRSR=CONFIG_UART_BRSR; | 47 | IO_UART1_BRSR=CONFIG_UART_BRSR; |
48 | IO_UART1_RFCR = 0x8000; | ||
49 | /* gio 27 is input, uart1 rx | ||
50 | gio 28 is output, uart1 tx */ | ||
51 | IO_GIO_DIR1 |= (1<<11); /* gio 27 */ | ||
52 | IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */ | ||
53 | |||
54 | /* init the recieve buffer */ | ||
55 | uart1read = 0; | ||
56 | uart1write = 0; | ||
57 | uart1count = 0; | ||
58 | |||
59 | /* Enable the interrupt */ | ||
60 | IO_INTC_EINT0 |= (1<<IRQ_UART1); | ||
44 | } | 61 | } |
45 | 62 | ||
46 | void uartPutc(char ch) { | 63 | void uartPutc(char ch) { |
@@ -111,10 +128,10 @@ int uartPollch(unsigned int ticks) { | |||
111 | 128 | ||
112 | bool uartAvailable(void) | 129 | bool uartAvailable(void) |
113 | { | 130 | { |
114 | return (IO_UART1_RFCR & 0x3f)?true:false; | 131 | return uart1count > 0; |
115 | } | 132 | } |
116 | 133 | ||
117 | void uartHeartbeat(void) | 134 | void uart1_heartbeat(void) |
118 | { | 135 | { |
119 | char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; | 136 | char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; |
120 | uartPuts(data); | 137 | uartPuts(data); |
@@ -126,3 +143,30 @@ void uartSendData(char* data, int len) | |||
126 | for(i=0;i<len;i++) | 143 | for(i=0;i<len;i++) |
127 | uartPutc(data[i]); | 144 | uartPutc(data[i]); |
128 | } | 145 | } |
146 | |||
147 | bool uart1_getch(char *c) | ||
148 | { | ||
149 | if (uart1count > 0) | ||
150 | { | ||
151 | *c = uart1buffer[uart1read]; | ||
152 | uart1read = (uart1read+1) % MAX_UART_BUFFER; | ||
153 | uart1count--; | ||
154 | return true; | ||
155 | } | ||
156 | return false; | ||
157 | } | ||
158 | |||
159 | /* UART1 receive intterupt handler */ | ||
160 | void UART1(void) | ||
161 | { | ||
162 | if (IO_UART1_RFCR & 0x3f) | ||
163 | { | ||
164 | if (uart1count >= MAX_UART_BUFFER) | ||
165 | panicf("UART1 buffer overflow"); | ||
166 | uart1buffer[uart1write] = IO_UART1_DTRR & 0xff; | ||
167 | uart1write = (uart1write+1) % MAX_UART_BUFFER; | ||
168 | uart1count++; | ||
169 | } | ||
170 | |||
171 | IO_INTC_IRQ0 = (1<<IRQ_UART1); | ||
172 | } | ||
diff --git a/firmware/target/arm/olympus/mrobe-500/uart-target.h b/firmware/target/arm/olympus/mrobe-500/uart-target.h index b4e049f897..f077dc1025 100644 --- a/firmware/target/arm/olympus/mrobe-500/uart-target.h +++ b/firmware/target/arm/olympus/mrobe-500/uart-target.h | |||
@@ -20,12 +20,14 @@ | |||
20 | #ifndef UART_H | 20 | #ifndef UART_H |
21 | #define UART_H | 21 | #define UART_H |
22 | 22 | ||
23 | void uartPutc(char ch); | 23 | void uart_init(void); |
24 | void uartPutHex(unsigned int n); | 24 | bool uart1_getch(char *c); |
25 | void uartSetup(void); | 25 | void uart1_heartbeat(void); |
26 | |||
26 | void uartPuts(const char *str); | 27 | void uartPuts(const char *str); |
27 | void uartGets(char *str, unsigned int size); | 28 | void uartGets(char *str, unsigned int size); |
28 | int uartPollch(unsigned int ticks); | 29 | int uartPollch(unsigned int ticks); |
29 | void uartHeartbeat(void); | 30 | void uartPutc(char ch); |
31 | void uartPutHex(unsigned int n); | ||
30 | 32 | ||
31 | #endif | 33 | #endif |