Unify semitone and cent macros and make the formula a bit more obvious
[kugel-rb/myfork.git] / bootloader / ondavx747.c
blob6a04c1ba8532f7a0fe1b308732ecea1616075925
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 "backlight-target.h"
26 #include "font.h"
27 #include "lcd.h"
28 #include "usb.h"
29 #include "system.h"
30 #include "button.h"
31 #include "common.h"
32 #include "storage.h"
33 #include "disk.h"
34 #include "string.h"
35 #include "adc.h"
37 static void show_splash(int timeout, const char *msg)
39 reset_screen();
40 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
41 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
42 lcd_update();
44 sleep(timeout);
47 static void usb_mode(void)
49 int button;
51 /* Init USB */
52 usb_init();
53 usb_start_monitoring();
55 /* Wait for threads to connect */
56 show_splash(HZ/2, "Waiting for USB");
58 while (1)
60 button = button_get_w_tmo(HZ/2);
62 if (button == SYS_USB_CONNECTED)
63 break; /* Hit */
66 if (button == SYS_USB_CONNECTED)
68 /* Got the message - wait for disconnect */
69 show_splash(0, "Bootloader USB mode");
71 usb_acknowledge(SYS_USB_CONNECTED_ACK);
73 while (1)
75 button = button_get(true);
76 if (button == SYS_USB_DISCONNECTED)
78 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
79 break;
84 reset_screen();
87 static void boot_of(void)
89 /* Do nothing atm */
92 int main(void)
94 int rc;
95 #ifdef HAVE_TOUCHSCREEN
96 int dummy;
97 #endif
98 void (*kernel_entry)(void);
100 kernel_init();
101 lcd_init();
102 font_init();
103 lcd_setfont(FONT_SYSFIXED);
104 button_init();
105 adc_init();
106 backlight_init();
108 reset_screen();
109 printf(MODEL_NAME" Rockbox Bootloader");
110 printf("Version "APPSVERSION);
112 rc = storage_init();
113 if(rc)
114 error(EATA, rc);
116 #ifdef HAVE_TOUCHSCREEN
117 rc = button_read_device(&dummy);
118 #else
119 rc = button_read_device();
120 #endif
122 if(rc & BUTTON_VOL_UP)
123 usb_mode();
124 else if(button_hold())
125 boot_of();
127 rc = disk_mount_all();
128 if (rc <= 0)
129 error(EDISK,rc);
131 printf("Loading firmware");
132 rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000);
133 if(rc < 0)
134 printf("Error: %s", strerror(rc));
136 if (rc == EOK)
138 printf("Starting Rockbox...");
139 adc_close(); /* Disable SADC */
140 _backlight_off(); /* Force backlight off to prevent LCD 'flicker' */
142 disable_interrupt();
143 kernel_entry = (void*) CONFIG_SDRAM_START;
144 kernel_entry();
147 /* Halt */
148 while (1)
149 core_idle();
151 return 0;