Update Swedish translation.
[kugel-rb.git] / flash / bootbox / main.c
blob96020c3d00b81aa2c3d9add2e64bb68102278feb
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 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ****************************************************************************/
25 #include "config.h"
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include "cpu.h"
30 #include "system.h"
31 #include "lcd.h"
32 #include "kernel.h"
33 #include "thread.h"
34 #include "ata.h"
35 #include "disk.h"
36 #include "font.h"
37 #include "adc.h"
38 #include "button.h"
39 #include "panic.h"
40 #include "power.h"
41 #include "file.h"
42 #include "buffer.h"
43 #include "rolo.h"
44 #include "usb.h"
45 #include "powermgmt.h"
47 void usb_screen(void)
49 lcd_clear_display();
50 lcd_puts(0, 0, "USB mode");
51 lcd_update();
53 usb_acknowledge(SYS_USB_CONNECTED_ACK);
54 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
58 int show_logo(void)
60 lcd_clear_display();
61 lcd_puts(0, 0, "Rockbox");
62 lcd_puts(0, 1, "Rescue boot");
63 lcd_update();
65 return 0;
68 #if 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 / 1000, (battv % 1000) / 10, battery_level());
105 lcd_puts(0, 1, buf);
107 lcd_update();
109 button = button_get_w_tmo(HZ/2);
110 #ifdef BUTTON_ON
111 if (button == (BUTTON_ON | BUTTON_REL))
112 #else
113 if (button == (BUTTON_RIGHT | BUTTON_REL))
114 #endif
115 break; /* start */
116 else
118 if (usb_detect() == USB_INSERTED)
119 break;
120 else if (!charger_inserted())
121 power_off(); /* charger removed: power down */
123 } while (1);
125 #endif /* CONFIG_CHARGING */
127 /* prompt user to plug USB and fix a problem */
128 void prompt_usb(const char* msg1, const char* msg2)
130 int button;
131 lcd_clear_display();
132 lcd_puts(0, 0, msg1);
133 lcd_puts(0, 1, msg2);
134 #ifdef HAVE_LCD_BITMAP
135 lcd_puts(0, 2, "Insert USB cable");
136 lcd_puts(0, 3, "and fix it.");
137 #endif
138 lcd_update();
141 button = button_get(true);
142 if (button == SYS_POWEROFF)
144 power_off();
146 } while (button != SYS_USB_CONNECTED);
147 usb_screen();
148 system_reboot();
151 void main(void)
153 int rc;
155 power_init();
156 system_init();
157 kernel_init();
158 buffer_init();
159 lcd_init();
160 show_logo();
161 enable_irq();
162 adc_init();
163 usb_init();
164 button_init();
165 powermgmt_init();
167 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
168 if (charger_inserted()
169 #ifdef ATA_POWER_PLAYERSTYLE
170 && !ide_powered() /* relies on probing result from bootloader */
171 #endif
174 charging_screen(); /* display a "charging" screen */
175 show_logo(); /* again, to provide better visual feedback */
177 #endif
179 rc = ata_init();
180 if(rc)
182 #ifdef HAVE_LCD_BITMAP
183 char str[32];
184 lcd_clear_display();
185 snprintf(str, 31, "ATA error: %d", rc);
186 lcd_puts(0, 1, str);
187 lcd_update();
188 while(!(button_get(true) & BUTTON_REL));
189 #endif
190 panicf("ata: %d", rc);
193 //disk_init();
194 usb_start_monitoring();
195 while (usb_detect() == USB_INSERTED)
196 { /* enter USB mode early, before trying to mount */
197 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
199 usb_screen();
203 rc = disk_mount_all();
204 if (rc<=0)
206 prompt_usb("No partition", "found.");
209 { // rolo the firmware
210 static const char filename[] = "/" BOOTFILE;
211 rolo_load((char*)filename); /* won't return if started */
213 prompt_usb("No firmware", filename);
219 /* These functions are present in the firmware library, but we reimplement
220 them here because the originals do a lot more than we want */
222 void screen_dump(void)
226 int dbg_ports(void)
228 return 0;
231 void audio_stop(void)
235 int audio_status(void)
237 return 0;
240 void audio_stop_recording(void)
244 void mp3_shutdown(void)
248 void i2c_init(void)
252 void backlight_on(void)