FS#10365 - Optional debug output for albumart.c
[kugel-rb.git] / bootloader / ondavx747.c
blob932710636f8c738bbd6824892858189a828207f4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Maurus Cuelenaere
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "jz4740.h"
24 #include "backlight.h"
25 #include "font.h"
26 #include "lcd.h"
27 #include "usb.h"
28 #include "system.h"
29 #include "button.h"
30 #include "common.h"
31 #include "storage.h"
32 #include "disk.h"
33 #include "string.h"
34 #include "adc.h"
36 static void show_splash(int timeout, const char *msg)
38 reset_screen();
39 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
40 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
41 lcd_update();
43 sleep(timeout);
46 static void usb_mode(void)
48 int button;
50 /* Init backlight */
51 backlight_init();
53 /* Init USB */
54 usb_init();
55 usb_start_monitoring();
57 /* Wait for threads to connect */
58 show_splash(HZ/2, "Waiting for USB");
60 while (1)
62 button = button_get_w_tmo(HZ/2);
64 if (button == SYS_USB_CONNECTED)
65 break; /* Hit */
68 if (button == SYS_USB_CONNECTED)
70 /* Got the message - wait for disconnect */
71 show_splash(0, "Bootloader USB mode");
73 usb_acknowledge(SYS_USB_CONNECTED_ACK);
75 while (1)
77 button = button_get(true);
78 if (button == SYS_USB_DISCONNECTED)
80 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
81 break;
86 reset_screen();
89 static void boot_of(void)
91 /* Init backlight */
92 backlight_init();
95 int main(void)
97 int rc;
98 #ifdef HAVE_TOUCHSCREEN
99 int dummy;
100 #endif
101 void (*kernel_entry)(void);
103 kernel_init();
104 lcd_init();
105 font_init();
106 lcd_setfont(FONT_SYSFIXED);
107 button_init();
108 adc_init();
109 storage_init();
111 reset_screen();
113 #ifdef HAVE_TOUCHSCREEN
114 rc = button_read_device(&dummy);
115 #else
116 rc = button_read_device();
117 #endif
119 if(rc & BUTTON_VOL_UP)
120 usb_mode();
121 else if(button_hold())
122 boot_of();
123 else if(rc)
124 verbose = true;
126 /* Only enable backlight when button is pressed */
127 if(verbose)
129 backlight_init();
130 printf(MODEL_NAME" Rockbox Bootloader");
131 printf("Version "APPSVERSION);
134 rc = storage_init();
135 if(rc)
136 error(EATA, rc);
138 rc = disk_mount_all();
139 if (rc <= 0)
140 error(EDISK,rc);
142 printf("Loading firmware");
143 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
144 if(rc < 0)
145 printf("Error: %s", strerror(rc));
147 if (rc == EOK)
149 printf("Starting Rockbox...");
150 adc_close(); /* Disable SADC */
151 disable_interrupt();
152 kernel_entry = (void*) CONFIG_SDRAM_START;
153 kernel_entry();
156 /* Halt */
157 while (1)
158 core_idle();
160 return 0;