diff -ub -r rockbox-cvs/bootloader/main.c rockbox-jsl/bootloader/main.c --- rockbox-cvs/bootloader/main.c Thu Feb 16 16:30:48 2006 +++ rockbox-jsl/bootloader/main.c Thu Feb 16 07:38:29 2006 @@ -72,10 +72,10 @@ unsigned char *buf = (unsigned char *)DRAM_START; char str[80]; - fd = open("/.rockbox/" BOOTFILE, O_RDONLY); + fd = open("/" BOOTFILE, O_RDONLY); if(fd < 0) { - fd = open("/" BOOTFILE, O_RDONLY); + fd = open("/.rockbox/" BOOTFILE, O_RDONLY); if(fd < 0) return -1; } @@ -144,15 +144,34 @@ asm(" jmp (%a0)"); } +void boot_poweroff(void) +{ + lcd_update(); + sleep(HZ*2); + + /* Backlight OFF */ +#ifdef HAVE_REMOTE_LCD +#ifdef IRIVER_H300_SERIES + or_l(0x00000002, &GPIO1_OUT); +#else + or_l(0x00000800, &GPIO_OUT); +#endif +#endif + /* Reset the cookie for the crt0 crash check */ + asm(" move.l #0,%d0"); + asm(" move.l %d0,0x10017ffc"); + power_off(); +} + void main(void) { int i; int rc; - char buf[256]; + char buf[64]; bool rc_on_button = false; bool on_button = false; int data; - int adc_battery, battery_voltage, batt_int, batt_frac; + int battery_cV; /* We want to read the buttons as early as possible, before the user releases the ON button */ @@ -245,49 +264,34 @@ if(!usb_detect() && ((on_button && button_hold()) || (rc_on_button && remote_button_hold()))) { lcd_puts(0, 8, "HOLD switch on, power off..."); - lcd_update(); - sleep(HZ*2); - - /* Backlight OFF */ -#ifdef HAVE_REMOTE_LCD -#ifdef IRIVER_H300_SERIES - or_l(0x00000002, &GPIO1_OUT); -#else - or_l(0x00000800, &GPIO_OUT); -#endif -#endif - /* Reset the cookie for the crt0 crash check */ - asm(" move.l #0,%d0"); - asm(" move.l %d0,0x10017ffc"); - power_off(); + boot_poweroff(); } usb_init(); - adc_battery = adc_read(ADC_BATTERY); + battery_cV = adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR / 10000; - battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; - batt_int = battery_voltage / 100; - batt_frac = battery_voltage % 100; - - snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac); + snprintf(buf, 32, "Batt: %d.%02dV", battery_cV / 100, battery_cV % 100); lcd_puts(0, line++, buf); lcd_update(); - if(battery_voltage <= 300) { + if(battery_cV < 305) { + lcd_puts(0, 8, "BATTERY EMPTY! Power off..."); + boot_poweroff(); + } + else if(battery_cV < 350) { line++; lcd_puts(0, line++, "WARNING! BATTERY LOW!!"); lcd_update(); - sleep(HZ*2); + sleep(HZ); } rc = ata_init(); if(rc) { - char str[32]; lcd_clear_display(); - snprintf(str, 31, "ATA error: %d", rc); - lcd_puts(0, line++, str); + snprintf(buf, 31, "ATA error: %d", rc); + lcd_puts(0, line++, buf); lcd_puts(0, line++, "Insert USB cable and press"); lcd_puts(0, line++, "a button"); lcd_update(); @@ -298,7 +302,7 @@ if(usb_detect()) { const char msg[] = "Bootloader USB mode"; - int w, h; + int w, h, batt; font_getstringsize(msg, &w, &h, FONT_SYSFIXED); lcd_clear_display(); lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg); @@ -317,6 +321,14 @@ ata_spin(); /* Prevent the drive from spinning down */ sleep(HZ); + /* Show battery voltage and simple batt percent approximation */ + batt = MIN(MAX(100 * (battery_cV - 358) / 53, 0), 100); + snprintf(buf, 32, "Batt: %d.%02dV %d%%", + batt, battery_cV / 100, battery_cV % 100); + lcd_puts(0, 0, buf); + lcd_update(); + battery_cV = adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR / 10000; + /* Backlight OFF */ or_l(0x00020000, &GPIO1_OUT); } @@ -343,7 +355,7 @@ lcd_puts(0, line++, "Loading firmware"); lcd_update(); i = load_firmware(); - snprintf(buf, 256, "Result: %d", i); + snprintf(buf, 32, "Result: %d", i); lcd_puts(0, line++, buf); lcd_update();