diff options
-rw-r--r--[-rwxr-xr-x] | bootloader/mrobe500.c | 564 |
1 files changed, 282 insertions, 282 deletions
diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c index c71d43d40e..8389d11b4b 100755..100644 --- a/bootloader/mrobe500.c +++ b/bootloader/mrobe500.c | |||
@@ -1,282 +1,282 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * __________ __ ___. | 2 | * __________ __ ___. |
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id: $ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2007 by Karl Kurbjun | 10 | * Copyright (C) 2007 by Karl Kurbjun |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU General Public License | 13 | * modify it under the terms of the GNU General Public License |
14 | * as published by the Free Software Foundation; either version 2 | 14 | * as published by the Free Software Foundation; either version 2 |
15 | * of the License, or (at your option) any later version. | 15 | * of the License, or (at your option) any later version. |
16 | * | 16 | * |
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "inttypes.h" | 22 | #include "inttypes.h" |
23 | #include "string.h" | 23 | #include "string.h" |
24 | #include "cpu.h" | 24 | #include "cpu.h" |
25 | #include "system.h" | 25 | #include "system.h" |
26 | #include "lcd.h" | 26 | #include "lcd.h" |
27 | #include "kernel.h" | 27 | #include "kernel.h" |
28 | #include "thread.h" | 28 | #include "thread.h" |
29 | #include "ata.h" | 29 | #include "ata.h" |
30 | #include "fat.h" | 30 | #include "fat.h" |
31 | #include "disk.h" | 31 | #include "disk.h" |
32 | #include "font.h" | 32 | #include "font.h" |
33 | #include "adc.h" | 33 | #include "adc.h" |
34 | #include "backlight.h" | 34 | #include "backlight.h" |
35 | #include "backlight-target.h" | 35 | #include "backlight-target.h" |
36 | #include "button.h" | 36 | #include "button.h" |
37 | #include "panic.h" | 37 | #include "panic.h" |
38 | #include "power.h" | 38 | #include "power.h" |
39 | #include "file.h" | 39 | #include "file.h" |
40 | #include "common.h" | 40 | #include "common.h" |
41 | #include "rbunicode.h" | 41 | #include "rbunicode.h" |
42 | #include "usb.h" | 42 | #include "usb.h" |
43 | #include "spi.h" | 43 | #include "spi.h" |
44 | #include "uart-target.h" | 44 | #include "uart-target.h" |
45 | #include "tsc2100.h" | 45 | #include "tsc2100.h" |
46 | #include "time.h" | 46 | #include "time.h" |
47 | #include "system-arm.h" | 47 | #include "system-arm.h" |
48 | 48 | ||
49 | #define MRDEBUG | 49 | #define MRDEBUG |
50 | 50 | ||
51 | #if defined(MRDEBUG) | 51 | #if defined(MRDEBUG) |
52 | 52 | ||
53 | extern int line; | 53 | extern int line; |
54 | #if 0 | 54 | #if 0 |
55 | struct touch_calibration_point tl, br; | 55 | struct touch_calibration_point tl, br; |
56 | 56 | ||
57 | void touchscreen_get_one_point(struct touch_calibration_point *p) | 57 | void touchscreen_get_one_point(struct touch_calibration_point *p) |
58 | { | 58 | { |
59 | int data = 0; | 59 | int data = 0; |
60 | int start = current_tick; | 60 | int start = current_tick; |
61 | while (TIME_AFTER(start+(HZ/3), current_tick)) | 61 | while (TIME_AFTER(start+(HZ/3), current_tick)) |
62 | { | 62 | { |
63 | if (button_read_device()&BUTTON_TOUCHSCREEN) | 63 | if (button_read_device()&BUTTON_TOUCHSCREEN) |
64 | { | 64 | { |
65 | data = button_get_last_touch(); | 65 | data = button_get_last_touch(); |
66 | p->val_x = data>>16; | 66 | p->val_x = data>>16; |
67 | p->val_y = data&0xffff; | 67 | p->val_y = data&0xffff; |
68 | start = current_tick; | 68 | start = current_tick; |
69 | } | 69 | } |
70 | else if (data == 0) | 70 | else if (data == 0) |
71 | start = current_tick; | 71 | start = current_tick; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | #define MARGIN 25 | 75 | #define MARGIN 25 |
76 | #define LEN 7 | 76 | #define LEN 7 |
77 | void touchscreen_calibrate_screen(void) | 77 | void touchscreen_calibrate_screen(void) |
78 | { | 78 | { |
79 | reset_screen(); | 79 | reset_screen(); |
80 | printf("touch the center of the crosshairs to calibrate"); | 80 | printf("touch the center of the crosshairs to calibrate"); |
81 | /* get the topleft value */ | 81 | /* get the topleft value */ |
82 | lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN); | 82 | lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN); |
83 | lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN); | 83 | lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN); |
84 | lcd_update(); | 84 | lcd_update(); |
85 | tl.px_x = MARGIN; tl.px_y = MARGIN; | 85 | tl.px_x = MARGIN; tl.px_y = MARGIN; |
86 | touchscreen_get_one_point(&tl); | 86 | touchscreen_get_one_point(&tl); |
87 | reset_screen(); | 87 | reset_screen(); |
88 | printf("touch the center of the crosshairs to calibrate"); | 88 | printf("touch the center of the crosshairs to calibrate"); |
89 | /* get the topright value */ | 89 | /* get the topright value */ |
90 | lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN); | 90 | lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN); |
91 | lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN); | 91 | lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN); |
92 | lcd_update(); | 92 | lcd_update(); |
93 | br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN; | 93 | br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN; |
94 | touchscreen_get_one_point(&br); | 94 | touchscreen_get_one_point(&br); |
95 | reset_screen(); | 95 | reset_screen(); |
96 | line++; | 96 | line++; |
97 | printf("tl %d %d", tl.val_x, tl.val_y); | 97 | printf("tl %d %d", tl.val_x, tl.val_y); |
98 | printf("br %d %d", br.val_x, br.val_y); | 98 | printf("br %d %d", br.val_x, br.val_y); |
99 | line++; | 99 | line++; |
100 | set_calibration_points(&tl, &br); | 100 | set_calibration_points(&tl, &br); |
101 | } | 101 | } |
102 | #endif | 102 | #endif |
103 | static uint8_t bl_command[] = {0xa4, 0x00, 0x00, 0xbb}; | 103 | static uint8_t bl_command[] = {0xa4, 0x00, 0x00, 0xbb}; |
104 | int brightness = 0; | 104 | int brightness = 0; |
105 | 105 | ||
106 | void mrdebug(void) | 106 | void mrdebug(void) |
107 | { | 107 | { |
108 | int button=0; | 108 | int button=0; |
109 | #if 0 | 109 | #if 0 |
110 | use_calibration(false); | 110 | use_calibration(false); |
111 | touchscreen_calibrate_screen(); | 111 | touchscreen_calibrate_screen(); |
112 | use_calibration(true); | 112 | use_calibration(true); |
113 | #endif | 113 | #endif |
114 | 114 | ||
115 | while(true) | 115 | while(true) |
116 | { | 116 | { |
117 | #if 0 | 117 | #if 0 |
118 | struct tm *t = get_time(); | 118 | struct tm *t = get_time(); |
119 | 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); | 119 | 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); |
120 | printf("time: %d", mktime(t)); | 120 | printf("time: %d", mktime(t)); |
121 | #endif | 121 | #endif |
122 | button = button_get(false); | 122 | button = button_get(false); |
123 | if (button == BUTTON_POWER) | 123 | if (button == BUTTON_POWER) |
124 | { | 124 | { |
125 | printf("reset"); | 125 | printf("reset"); |
126 | IO_GIO_BITSET1|=1<<10; | 126 | IO_GIO_BITSET1|=1<<10; |
127 | } | 127 | } |
128 | if (button==BUTTON_RC_VOL_DOWN) | 128 | if (button==BUTTON_RC_VOL_DOWN) |
129 | { | 129 | { |
130 | brightness = (brightness - 5) & 0x7f; | 130 | brightness = (brightness - 5) & 0x7f; |
131 | bl_command[2] = brightness; | 131 | bl_command[2] = brightness; |
132 | spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0); | 132 | spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0); |
133 | } | 133 | } |
134 | else if (button==BUTTON_RC_VOL_UP) | 134 | else if (button==BUTTON_RC_VOL_UP) |
135 | { | 135 | { |
136 | brightness = (brightness + 5) & 0x7f; | 136 | brightness = (brightness + 5) & 0x7f; |
137 | bl_command[2] = brightness; | 137 | bl_command[2] = brightness; |
138 | spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0); | 138 | spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0); |
139 | } | 139 | } |
140 | // { | 140 | // { |
141 | // short x,y,z1,z2; | 141 | // short x,y,z1,z2; |
142 | // tsc2100_read_values(&x, &y, &z1, &z2); | 142 | // tsc2100_read_values(&x, &y, &z1, &z2); |
143 | // printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2); | 143 | // printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2); |
144 | // printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff); | 144 | // printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff); |
145 | // // tsc2100_keyclick(); /* doesnt work :( */ | 145 | // // tsc2100_keyclick(); /* doesnt work :( */ |
146 | // line -= 6; | 146 | // line -= 6; |
147 | // } | 147 | // } |
148 | else if (button == BUTTON_RC_HEART) | 148 | else if (button == BUTTON_RC_HEART) |
149 | { | 149 | { |
150 | printf("POINT"); | 150 | printf("POINT"); |
151 | touchscreen_set_mode(TOUCHSCREEN_POINT); | 151 | touchscreen_set_mode(TOUCHSCREEN_POINT); |
152 | } | 152 | } |
153 | else if (button == BUTTON_RC_MODE) | 153 | else if (button == BUTTON_RC_MODE) |
154 | { | 154 | { |
155 | printf("BUTTON"); | 155 | printf("BUTTON"); |
156 | touchscreen_set_mode(TOUCHSCREEN_BUTTON); | 156 | touchscreen_set_mode(TOUCHSCREEN_BUTTON); |
157 | } | 157 | } |
158 | #if 1 | 158 | #if 1 |
159 | else if (button&BUTTON_TOUCHSCREEN) | 159 | else if (button&BUTTON_TOUCHSCREEN) |
160 | { | 160 | { |
161 | if (button&BUTTON_REL) | 161 | if (button&BUTTON_REL) |
162 | continue; | 162 | continue; |
163 | unsigned int data = button_get_data(); | 163 | unsigned int data = button_get_data(); |
164 | int x = (data&0xffff0000)>>16, y = data&0x0000ffff; | 164 | int x = (data&0xffff0000)>>16, y = data&0x0000ffff; |
165 | reset_screen(); | 165 | reset_screen(); |
166 | line = 9; | 166 | line = 9; |
167 | printf("BB: %x %d %d", button, x,y); | 167 | printf("BB: %x %d %d", button, x,y); |
168 | lcd_hline(x-5, x+5, y); | 168 | lcd_hline(x-5, x+5, y); |
169 | lcd_vline(x, y-5, y+5); | 169 | lcd_vline(x, y-5, y+5); |
170 | lcd_update(); | 170 | lcd_update(); |
171 | } | 171 | } |
172 | else if (button == BUTTON_RC_PLAY) | 172 | else if (button == BUTTON_RC_PLAY) |
173 | { | 173 | { |
174 | reset_screen(); | 174 | reset_screen(); |
175 | } | 175 | } |
176 | 176 | ||
177 | else if (button) | 177 | else if (button) |
178 | { | 178 | { |
179 | // if (button&BUTTON_REL) | 179 | // if (button&BUTTON_REL) |
180 | { | 180 | { |
181 | printf("%08x %s\n", button, (button&BUTTON_REL)?"yes":"no"); | 181 | printf("%08x %s\n", button, (button&BUTTON_REL)?"yes":"no"); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
185 | #endif | 185 | #endif |
186 | } | 186 | } |
187 | } | 187 | } |
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | void main(void) | 190 | void main(void) |
191 | { | 191 | { |
192 | unsigned char* loadbuffer; | 192 | unsigned char* loadbuffer; |
193 | int buffer_size; | 193 | int buffer_size; |
194 | int rc; | 194 | int rc; |
195 | int(*kernel_entry)(void); | 195 | int(*kernel_entry)(void); |
196 | 196 | ||
197 | power_init(); | 197 | power_init(); |
198 | lcd_init(); | 198 | lcd_init(); |
199 | system_init(); | 199 | system_init(); |
200 | kernel_init(); | 200 | kernel_init(); |
201 | 201 | ||
202 | enable_irq(); | 202 | enable_irq(); |
203 | enable_fiq(); | 203 | enable_fiq(); |
204 | 204 | ||
205 | adc_init(); | 205 | adc_init(); |
206 | button_init(); | 206 | button_init(); |
207 | backlight_init(); | 207 | backlight_init(); |
208 | 208 | ||
209 | font_init(); | 209 | font_init(); |
210 | 210 | ||
211 | lcd_setfont(FONT_SYSFIXED); | 211 | lcd_setfont(FONT_SYSFIXED); |
212 | 212 | ||
213 | /* Show debug messages if button is pressed */ | 213 | /* Show debug messages if button is pressed */ |
214 | // if(button_read_device()) | 214 | // if(button_read_device()) |
215 | verbose = true; | 215 | verbose = true; |
216 | 216 | ||
217 | printf("Rockbox boot loader"); | 217 | printf("Rockbox boot loader"); |
218 | printf("Version %s", APPSVERSION); | 218 | printf("Version %s", APPSVERSION); |
219 | 219 | ||
220 | usb_init(); | 220 | usb_init(); |
221 | 221 | ||
222 | /* Enter USB mode without USB thread */ | 222 | /* Enter USB mode without USB thread */ |
223 | if(usb_detect() == USB_INSERTED) | 223 | if(usb_detect() == USB_INSERTED) |
224 | { | 224 | { |
225 | const char msg[] = "Bootloader USB mode"; | 225 | const char msg[] = "Bootloader USB mode"; |
226 | reset_screen(); | 226 | reset_screen(); |
227 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, | 227 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, |
228 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); | 228 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); |
229 | lcd_update(); | 229 | lcd_update(); |
230 | 230 | ||
231 | ide_power_enable(true); | 231 | ide_power_enable(true); |
232 | ata_enable(false); | 232 | ata_enable(false); |
233 | sleep(HZ/20); | 233 | sleep(HZ/20); |
234 | usb_enable(true); | 234 | usb_enable(true); |
235 | 235 | ||
236 | while (usb_detect() == USB_INSERTED) | 236 | while (usb_detect() == USB_INSERTED) |
237 | { | 237 | { |
238 | ata_spin(); /* Prevent the drive from spinning down */ | 238 | ata_spin(); /* Prevent the drive from spinning down */ |
239 | sleep(HZ); | 239 | sleep(HZ); |
240 | } | 240 | } |
241 | 241 | ||
242 | usb_enable(false); | 242 | usb_enable(false); |
243 | 243 | ||
244 | reset_screen(); | 244 | reset_screen(); |
245 | lcd_update(); | 245 | lcd_update(); |
246 | } | 246 | } |
247 | #if defined(MRDEBUG) | 247 | #if defined(MRDEBUG) |
248 | mrdebug(); | 248 | mrdebug(); |
249 | #endif | 249 | #endif |
250 | printf("ATA"); | 250 | printf("ATA"); |
251 | rc = ata_init(); | 251 | rc = ata_init(); |
252 | if(rc) | 252 | if(rc) |
253 | { | 253 | { |
254 | reset_screen(); | 254 | reset_screen(); |
255 | error(EATA, rc); | 255 | error(EATA, rc); |
256 | } | 256 | } |
257 | 257 | ||
258 | printf("disk"); | 258 | printf("disk"); |
259 | disk_init(); | 259 | disk_init(); |
260 | 260 | ||
261 | printf("mount"); | 261 | printf("mount"); |
262 | rc = disk_mount_all(); | 262 | rc = disk_mount_all(); |
263 | if (rc<=0) | 263 | if (rc<=0) |
264 | { | 264 | { |
265 | error(EDISK,rc); | 265 | error(EDISK,rc); |
266 | } | 266 | } |
267 | 267 | ||
268 | printf("Loading firmware"); | 268 | printf("Loading firmware"); |
269 | 269 | ||
270 | loadbuffer = (unsigned char*) 0x00900000; | 270 | loadbuffer = (unsigned char*) 0x00900000; |
271 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; | 271 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; |
272 | 272 | ||
273 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); | 273 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
274 | if(rc < 0) | 274 | if(rc < 0) |
275 | error(EBOOTFILE, rc); | 275 | error(EBOOTFILE, rc); |
276 | 276 | ||
277 | if (rc == EOK) | 277 | if (rc == EOK) |
278 | { | 278 | { |
279 | kernel_entry = (void*) loadbuffer; | 279 | kernel_entry = (void*) loadbuffer; |
280 | rc = kernel_entry(); | 280 | rc = kernel_entry(); |
281 | } | 281 | } |
282 | } | 282 | } |