Use the new progressbar value slot instead of wrapping around it.
[Rockbox.git] / bootloader / mrobe500.c
blob595839618862ce364b60dea347a20f4cb6a9ea2a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
10 * Copyright (C) 2007 by Karl Kurbjun
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "inttypes.h"
21 #include "string.h"
22 #include "cpu.h"
23 #include "system.h"
24 #include "lcd.h"
25 #include "kernel.h"
26 #include "thread.h"
27 #include "ata.h"
28 #include "fat.h"
29 #include "disk.h"
30 #include "font.h"
31 #include "adc.h"
32 #include "backlight.h"
33 #include "backlight-target.h"
34 #include "button.h"
35 #include "panic.h"
36 #include "power.h"
37 #include "file.h"
38 #include "common.h"
39 #include "rbunicode.h"
40 #include "usb.h"
41 #include "spi.h"
42 #include "uart-target.h"
43 #include "tsc2100.h"
44 #include "time.h"
45 #include "system-arm.h"
47 #define MRDEBUG
49 #if defined(MRDEBUG)
51 extern int line;
52 #if 0
53 struct touch_calibration_point tl, br;
55 void touchpad_get_one_point(struct touch_calibration_point *p)
57 int data = 0;
58 int start = current_tick;
59 while (TIME_AFTER(start+(HZ/3), current_tick))
61 if (button_read_device()&BUTTON_TOUCHPAD)
63 data = button_get_last_touch();
64 p->val_x = data>>16;
65 p->val_y = data&0xffff;
66 start = current_tick;
68 else if (data == 0)
69 start = current_tick;
73 #define MARGIN 25
74 #define LEN 7
75 void touchpad_calibrate_screen(void)
77 reset_screen();
78 printf("touch the center of the crosshairs to calibrate");
79 /* get the topleft value */
80 lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN);
81 lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN);
82 lcd_update();
83 tl.px_x = MARGIN; tl.px_y = MARGIN;
84 touchpad_get_one_point(&tl);
85 reset_screen();
86 printf("touch the center of the crosshairs to calibrate");
87 /* get the topright value */
88 lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN);
89 lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN);
90 lcd_update();
91 br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN;
92 touchpad_get_one_point(&br);
93 reset_screen();
94 line++;
95 printf("tl %d %d", tl.val_x, tl.val_y);
96 printf("br %d %d", br.val_x, br.val_y);
97 line++;
98 set_calibration_points(&tl, &br);
100 #endif
101 static uint8_t bl_command[] = {0xa4, 0x00, 0x00, 0xbb};
102 int brightness = 0;
104 void mrdebug(void)
106 int button=0;
107 #if 0
108 use_calibration(false);
109 touchpad_calibrate_screen();
110 use_calibration(true);
111 #endif
113 while(true)
115 #if 0
116 struct tm *t = get_time();
117 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);
118 printf("time: %d", mktime(t));
119 #endif
120 button = button_get(false);
121 if (button == BUTTON_POWER)
123 printf("reset");
124 IO_GIO_BITSET1|=1<<10;
126 if (button==BUTTON_RC_VOL_DOWN)
128 brightness = (brightness - 5) & 0x7f;
129 bl_command[2] = brightness;
130 spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
132 else if (button==BUTTON_RC_VOL_UP)
134 brightness = (brightness + 5) & 0x7f;
135 bl_command[2] = brightness;
136 spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
138 // {
139 // short x,y,z1,z2;
140 // tsc2100_read_values(&x, &y, &z1, &z2);
141 // printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
142 // printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
143 // // tsc2100_keyclick(); /* doesnt work :( */
144 // line -= 6;
145 // }
146 else if (button == BUTTON_RC_HEART)
148 printf("POINT");
149 touchpad_set_mode(TOUCHPAD_POINT);
151 else if (button == BUTTON_RC_MODE)
153 printf("BUTTON");
154 touchpad_set_mode(TOUCHPAD_BUTTON);
156 #if 1
157 else if (button&BUTTON_TOUCHPAD)
159 if (button&BUTTON_REL)
160 continue;
161 unsigned int data = button_get_data();
162 int x = (data&0xffff0000)>>16, y = data&0x0000ffff;
163 reset_screen();
164 line = 9;
165 printf("BB: %x %d %d", button, x,y);
166 lcd_hline(x-5, x+5, y);
167 lcd_vline(x, y-5, y+5);
168 lcd_update();
170 else if (button == BUTTON_RC_PLAY)
172 reset_screen();
175 else if (button)
177 // if (button&BUTTON_REL)
179 printf("%08x %s\n", button, (button&BUTTON_REL)?"yes":"no");
183 #endif
186 #endif
188 void main(void)
190 unsigned char* loadbuffer;
191 int buffer_size;
192 int rc;
193 int(*kernel_entry)(void);
195 power_init();
196 lcd_init();
197 system_init();
198 kernel_init();
200 enable_irq();
201 enable_fiq();
203 adc_init();
204 button_init();
205 backlight_init();
207 font_init();
209 lcd_setfont(FONT_SYSFIXED);
211 /* Show debug messages if button is pressed */
212 // if(button_read_device())
213 verbose = true;
215 printf("Rockbox boot loader");
216 printf("Version %s", APPSVERSION);
218 usb_init();
220 /* Enter USB mode without USB thread */
221 if(usb_detect())
223 const char msg[] = "Bootloader USB mode";
224 reset_screen();
225 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
226 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
227 lcd_update();
229 ide_power_enable(true);
230 ata_enable(false);
231 sleep(HZ/20);
232 usb_enable(true);
234 while (usb_detect())
236 ata_spin(); /* Prevent the drive from spinning down */
237 sleep(HZ);
240 usb_enable(false);
242 reset_screen();
243 lcd_update();
245 #if defined(MRDEBUG)
246 mrdebug();
247 #endif
248 printf("ATA");
249 rc = ata_init();
250 if(rc)
252 reset_screen();
253 error(EATA, rc);
256 printf("disk");
257 disk_init();
259 printf("mount");
260 rc = disk_mount_all();
261 if (rc<=0)
263 error(EDISK,rc);
266 printf("Loading firmware");
268 loadbuffer = (unsigned char*) 0x00900000;
269 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
271 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
272 if(rc < 0)
273 error(EBOOTFILE, rc);
275 if (rc == EOK)
277 kernel_entry = (void*) loadbuffer;
278 rc = kernel_entry();