Fix remote screen check in graphic equalizer, so that it can be used on logf-enabled...
[Rockbox.git] / flash / bootbox / main.c
blobaf822b4a6448e30a3ada9bfec46902cbae4274e2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon
12 * This is "Bootbox", a minimalistic loader, rescue firmware for just
13 * booting into a full features one. Aside from that it does charging
14 * and USB mode, to enable copying the desired firmware.
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "config.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include "cpu.h"
28 #include "system.h"
29 #include "lcd.h"
30 #include "kernel.h"
31 #include "thread.h"
32 #include "ata.h"
33 #include "disk.h"
34 #include "font.h"
35 #include "adc.h"
36 #include "button.h"
37 #include "panic.h"
38 #include "power.h"
39 #include "file.h"
40 #include "buffer.h"
41 #include "rolo.h"
42 #include "usb.h"
43 #include "powermgmt.h"
45 void usb_screen(void)
47 lcd_clear_display();
48 lcd_puts(0, 0, "USB mode");
49 #ifdef HAVE_LCD_BITMAP
50 lcd_update();
51 #endif
52 usb_acknowledge(SYS_USB_CONNECTED_ACK);
53 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
57 int show_logo(void)
59 lcd_clear_display();
60 lcd_puts(0, 0, "Rockbox");
61 lcd_puts(0, 1, "Rescue boot");
62 #ifdef HAVE_LCD_BITMAP
63 lcd_update();
64 #endif
65 return 0;
68 #ifdef CONFIG_CHARGING
70 bool backlight_get_on_when_charging(void)
72 return false;
75 void charging_screen(void)
77 unsigned int button;
78 const char* msg;
80 ide_power_enable(false); /* power down the disk, else would be spinning */
82 lcd_clear_display();
86 #if CONFIG_CHARGING == CHARGING_CONTROL
87 if (charge_state == CHARGING)
88 msg = "charging";
89 else if (charge_state == TOPOFF)
90 msg = "topoff charge";
91 else if (charge_state == TRICKLE)
92 msg = "trickle charge";
93 else
94 msg = "not charging";
96 #else
97 msg = "charging";
98 #endif
99 lcd_puts(0, 0, msg);
101 char buf[32];
102 int battv = battery_voltage();
103 snprintf(buf, sizeof(buf), "%d.%02dV %d%%",
104 battv / 100, battv % 100, battery_level());
105 lcd_puts(0, 1, buf);
108 #ifdef HAVE_LCD_BITMAP
109 lcd_update();
110 #endif
112 button = button_get_w_tmo(HZ/2);
113 #ifdef BUTTON_ON
114 if (button == (BUTTON_ON | BUTTON_REL))
115 #else
116 if (button == (BUTTON_RIGHT | BUTTON_REL))
117 #endif
118 break; /* start */
119 else
121 if (usb_detect())
122 break;
123 else if (!charger_inserted())
124 power_off(); /* charger removed: power down */
126 } while (1);
128 #endif /* CONFIG_CHARGING */
130 /* prompt user to plug USB and fix a problem */
131 void prompt_usb(const char* msg1, const char* msg2)
133 int button;
134 lcd_clear_display();
135 lcd_puts(0, 0, msg1);
136 lcd_puts(0, 1, msg2);
137 #ifdef HAVE_LCD_BITMAP
138 lcd_puts(0, 2, "Insert USB cable");
139 lcd_puts(0, 3, "and fix it.");
140 lcd_update();
141 #endif
144 button = button_get(true);
145 if (button == SYS_POWEROFF)
147 power_off();
149 } while (button != SYS_USB_CONNECTED);
150 usb_screen();
151 system_reboot();
154 void main(void)
156 int rc;
158 power_init();
159 system_init();
160 kernel_init();
161 buffer_init();
162 lcd_init();
163 show_logo();
164 set_irq_level(0);
165 adc_init();
166 usb_init();
167 button_init();
168 powermgmt_init();
170 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
171 if (charger_inserted()
172 #ifdef ATA_POWER_PLAYERSTYLE
173 && !ide_powered() /* relies on probing result from bootloader */
174 #endif
177 charging_screen(); /* display a "charging" screen */
178 show_logo(); /* again, to provide better visual feedback */
180 #endif
182 rc = ata_init();
183 if(rc)
185 #ifdef HAVE_LCD_BITMAP
186 char str[32];
187 lcd_clear_display();
188 snprintf(str, 31, "ATA error: %d", rc);
189 lcd_puts(0, 1, str);
190 lcd_update();
191 while(!(button_get(true) & BUTTON_REL));
192 #endif
193 panicf("ata: %d", rc);
196 //disk_init();
197 usb_start_monitoring();
198 while (usb_detect())
199 { /* enter USB mode early, before trying to mount */
200 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
202 usb_screen();
206 rc = disk_mount_all();
207 if (rc<=0)
209 prompt_usb("No partition", "found.");
212 { // rolo the firmware
213 static const char filename[] = "/" BOOTFILE;
214 rolo_load((char*)filename); /* won't return if started */
216 prompt_usb("No firmware", filename);
222 /* These functions are present in the firmware library, but we reimplement
223 them here because the originals do a lot more than we want */
225 void screen_dump(void)
229 int dbg_ports(void)
231 return 0;
234 void audio_stop(void)
238 int audio_status(void)
240 return 0;
243 void mp3_shutdown(void)
247 void i2c_init(void)
251 void backlight_on(void)