2010-04-26 21:40:16 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-10-22 12:28:43 +00:00
|
|
|
* $Id$
|
2010-04-26 21:40:16 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Marcin Bukat
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "inttypes.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "storage.h"
|
|
|
|
#include "usb.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "backlight-target.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "powermgmt.h"
|
|
|
|
#include "file.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
2010-05-27 09:41:46 +00:00
|
|
|
#include "version.h"
|
2010-04-26 21:40:16 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
/* Maximum allowed firmware image size. 10MB is more than enough */
|
|
|
|
#define MAX_LOADSIZE (10*1024*1024)
|
|
|
|
|
|
|
|
#define DRAM_START 0x31000000
|
|
|
|
|
|
|
|
#define BOOTMENU_TIMEOUT (10*HZ)
|
|
|
|
#define BOOTMENU_OPTIONS 3
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
#define EVENT_NONE 0x00
|
|
|
|
#define EVENT_ON 0x01
|
|
|
|
#define EVENT_AC 0x02
|
|
|
|
#define EVENT_USB 0x04
|
2010-12-06 10:24:29 +00:00
|
|
|
#define EVENT_RTC 0x08
|
2010-05-04 11:16:17 +00:00
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
/* From common.c */
|
|
|
|
extern int line;
|
|
|
|
static const char *bootmenu_options[] = {
|
|
|
|
"Boot rockbox",
|
|
|
|
"Boot MPIO firmware",
|
|
|
|
"Shutdown"
|
|
|
|
};
|
|
|
|
|
|
|
|
enum option_t {
|
|
|
|
rockbox,
|
|
|
|
mpio_firmware,
|
|
|
|
shutdown
|
|
|
|
};
|
|
|
|
|
|
|
|
int usb_screen(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
/* return true if charger is present */
|
2010-05-04 11:16:17 +00:00
|
|
|
static inline bool _charger_inserted(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
return (GPIO1_READ & (1<<14)) ? false : true;
|
|
|
|
}
|
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
/* returns true if end of charge condition is reached */
|
2010-05-04 11:16:17 +00:00
|
|
|
static inline bool _battery_full(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
return (GPIO_READ & (1<<30)) ? true : false;
|
|
|
|
}
|
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
#ifdef MPIO_HD300
|
|
|
|
/* returns true if startup is due to RTC alarm */
|
|
|
|
static inline bool _rtc_alarm(void)
|
|
|
|
{
|
|
|
|
if ( (GPIO1_READ & (1<<4)) && (GPIO1_READ & (1<<5)) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
/* Reset the cookie for the crt0 crash check */
|
2010-05-04 11:16:17 +00:00
|
|
|
static inline void __reset_cookie(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
asm(" move.l #0,%d0");
|
|
|
|
asm(" move.l %d0,0x10017ffc");
|
|
|
|
}
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
static void start_rockbox(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
adc_close();
|
|
|
|
asm(" move.w #0x2700,%sr");
|
|
|
|
__reset_cookie();
|
|
|
|
asm(" move.l %0,%%d0" :: "i"(DRAM_START));
|
|
|
|
asm(" movec.l %d0,%vbr");
|
|
|
|
asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START));
|
|
|
|
asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4)));
|
|
|
|
asm(" jmp (%a0)");
|
|
|
|
}
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
static void start_mpio_firmware(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
asm(" move.w #0x2700,%sr");
|
|
|
|
__reset_cookie();
|
|
|
|
asm(" movec.l %d0,%vbr");
|
|
|
|
asm(" move.l 0,%sp");
|
|
|
|
asm(" jmp 8");
|
|
|
|
}
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
static void __shutdown(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
2010-07-09 09:12:51 +00:00
|
|
|
if (_charger_inserted())
|
|
|
|
/* if AC power do nothing */
|
|
|
|
return;
|
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
/* We need to gracefully spin down the disk to prevent clicks. */
|
|
|
|
if (ide_powered())
|
|
|
|
{
|
|
|
|
/* Make sure ATA has been initialized. */
|
|
|
|
storage_init();
|
|
|
|
|
|
|
|
/* And put the disk into sleep immediately. */
|
|
|
|
storage_sleepnow();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Backlight OFF */
|
|
|
|
_backlight_off();
|
|
|
|
__reset_cookie();
|
|
|
|
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print the battery voltage (and a warning message). */
|
2010-05-04 11:16:17 +00:00
|
|
|
static void check_battery(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int battery_voltage, batt_int, batt_frac;
|
|
|
|
|
2012-01-03 23:44:38 +00:00
|
|
|
battery_voltage = _battery_voltage();
|
2010-04-26 21:40:16 +00:00
|
|
|
batt_int = battery_voltage / 1000;
|
|
|
|
batt_frac = (battery_voltage % 1000) / 10;
|
|
|
|
|
|
|
|
printf("Battery: %d.%02dV", batt_int, batt_frac);
|
|
|
|
|
|
|
|
if (battery_voltage <= 3500)
|
|
|
|
{
|
|
|
|
printf("WARNING! BATTERY LOW!!");
|
|
|
|
sleep(HZ*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
static void lcd_putstring_centered(const char *string)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
int w,h;
|
|
|
|
font_getstringsize(string, &w, &h, FONT_SYSFIXED);
|
|
|
|
lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, string);
|
|
|
|
}
|
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
/* This function initializes ATA driver, mounts partitions,
|
|
|
|
* loads rockbox image from disk to ram and finally
|
|
|
|
* jumps to entry point in ram
|
|
|
|
*/
|
2010-05-04 11:16:17 +00:00
|
|
|
static void rb_boot(void)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
|
|
|
int rc;
|
2010-05-04 11:16:17 +00:00
|
|
|
|
2010-07-06 17:30:10 +00:00
|
|
|
/* boost to speedup rb image loading */
|
|
|
|
cpu_boost(true);
|
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
reset_screen();
|
2010-11-28 23:10:09 +00:00
|
|
|
printf("Rockbox boot loader");
|
|
|
|
printf("Version " RBVERSION);
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
rc = storage_init();
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
printf("ATA error: %d", rc);
|
|
|
|
sleep(HZ*5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
disk_init();
|
|
|
|
|
|
|
|
rc = disk_mount_all();
|
|
|
|
if (rc<=0)
|
|
|
|
{
|
|
|
|
printf("No partition found");
|
|
|
|
sleep(HZ*5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Loading firmware");
|
|
|
|
|
|
|
|
rc = load_firmware((unsigned char *)DRAM_START,
|
|
|
|
BOOTFILE, MAX_LOADSIZE);
|
|
|
|
|
|
|
|
if (rc < EOK)
|
|
|
|
{
|
|
|
|
printf("Error!");
|
|
|
|
printf("Can't load " BOOTFILE ": ");
|
|
|
|
printf("Result: %s", strerror(rc));
|
|
|
|
sleep(HZ*5);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-06 17:30:10 +00:00
|
|
|
cpu_boost(false);
|
2010-05-04 11:16:17 +00:00
|
|
|
start_rockbox();
|
|
|
|
}
|
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
/* This function prints small bootmenu where
|
|
|
|
* you can choose to boot OF, rockbox or just shutdown
|
|
|
|
*/
|
2010-05-04 11:16:17 +00:00
|
|
|
static void bootmenu(void)
|
|
|
|
{
|
2010-04-26 21:40:16 +00:00
|
|
|
enum option_t i;
|
|
|
|
enum option_t option = rockbox;
|
|
|
|
int button;
|
|
|
|
const char select[] = "->";
|
|
|
|
long start_tick = current_tick;
|
|
|
|
|
|
|
|
/* backbone of menu */
|
|
|
|
/* run the loader */
|
|
|
|
printf("Rockbox boot loader");
|
2010-05-27 09:41:46 +00:00
|
|
|
printf("Ver: " RBVERSION);
|
2010-04-26 21:40:16 +00:00
|
|
|
|
|
|
|
check_battery();
|
|
|
|
|
|
|
|
printf("");
|
|
|
|
printf("=========================");
|
|
|
|
|
|
|
|
line += BOOTMENU_OPTIONS+2; /* skip lines */
|
|
|
|
|
|
|
|
printf("=========================");
|
|
|
|
printf("");
|
2010-11-02 10:51:04 +00:00
|
|
|
printf(" [FF] [REW] to move ");
|
2010-04-26 21:40:16 +00:00
|
|
|
printf(" [PLAY] to confirm ");
|
|
|
|
|
|
|
|
/* content of menu and keys handling */
|
|
|
|
while (TIME_BEFORE(current_tick,start_tick + BOOTMENU_TIMEOUT))
|
|
|
|
{
|
|
|
|
/* Draw the menu. */
|
|
|
|
line = 6; /* move below header */
|
|
|
|
|
|
|
|
for (i=0;i<BOOTMENU_OPTIONS;i++)
|
|
|
|
{
|
|
|
|
if (i != option)
|
|
|
|
printf(" %s",bootmenu_options[i]);
|
|
|
|
else
|
|
|
|
printf("%s %s",select,bootmenu_options[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
line = 15;
|
|
|
|
|
|
|
|
printf("Time left: %ds",(BOOTMENU_TIMEOUT -
|
|
|
|
(current_tick - start_tick))/HZ);
|
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
|
2010-07-09 09:12:51 +00:00
|
|
|
button = BUTTON_NONE;
|
2010-04-26 21:40:16 +00:00
|
|
|
button = button_get_w_tmo(HZ);
|
|
|
|
|
|
|
|
switch (button)
|
|
|
|
{
|
2010-11-02 10:51:04 +00:00
|
|
|
case BUTTON_REW:
|
2010-11-26 23:28:08 +00:00
|
|
|
#ifdef MPIO_HD200
|
2010-11-02 10:51:04 +00:00
|
|
|
case BUTTON_RC_REW:
|
2010-11-26 23:28:08 +00:00
|
|
|
#endif
|
2010-04-26 21:40:16 +00:00
|
|
|
if (option > rockbox)
|
|
|
|
option--;
|
|
|
|
else
|
|
|
|
option = shutdown;
|
|
|
|
break;
|
|
|
|
|
2010-11-02 10:51:04 +00:00
|
|
|
case BUTTON_FF:
|
2010-11-26 23:28:08 +00:00
|
|
|
#ifdef MPIO_HD200
|
2010-11-02 10:51:04 +00:00
|
|
|
case BUTTON_RC_FF:
|
2010-11-26 23:28:08 +00:00
|
|
|
#endif
|
2010-04-26 21:40:16 +00:00
|
|
|
if (option < shutdown)
|
|
|
|
option++;
|
|
|
|
else
|
|
|
|
option = rockbox;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_PLAY:
|
2010-11-26 23:28:08 +00:00
|
|
|
#ifdef MPIO_HD200
|
2010-07-06 17:30:10 +00:00
|
|
|
case BUTTON_RC_PLAY:
|
2010-04-26 21:40:16 +00:00
|
|
|
case (BUTTON_PLAY|BUTTON_REC):
|
2010-11-26 23:28:08 +00:00
|
|
|
#endif
|
2010-04-26 21:40:16 +00:00
|
|
|
reset_screen();
|
|
|
|
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case rockbox:
|
2010-05-04 11:16:17 +00:00
|
|
|
rb_boot();
|
2010-04-26 21:40:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case mpio_firmware:
|
|
|
|
start_mpio_firmware();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-12-06 10:24:29 +00:00
|
|
|
__shutdown();
|
2010-04-26 21:40:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* timeout */
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
/* messages */
|
|
|
|
const char usb_connect_msg[] = "Bootloader USB mode";
|
|
|
|
const char charging_msg[] = "Charging...";
|
|
|
|
const char complete_msg[] = "Charging complete";
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
/* helper variable for messages */
|
2010-04-26 21:40:16 +00:00
|
|
|
bool blink_toggle = false;
|
|
|
|
|
|
|
|
int button;
|
2011-01-03 13:11:48 +00:00
|
|
|
|
|
|
|
/* hold status variables
|
|
|
|
* this two must have different
|
|
|
|
* values in the begining
|
|
|
|
*/
|
|
|
|
bool hold = false;
|
|
|
|
bool last_hold = true;
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
unsigned int event = EVENT_NONE;
|
|
|
|
unsigned int last_event = EVENT_NONE;
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-07-06 17:30:10 +00:00
|
|
|
/* this is default mode after power_init() */
|
|
|
|
bool high_current_charging = true;
|
|
|
|
|
2010-10-22 12:11:58 +00:00
|
|
|
/* setup GPIOs related to power functions */
|
2010-04-26 21:40:16 +00:00
|
|
|
power_init();
|
|
|
|
|
|
|
|
system_init();
|
|
|
|
kernel_init();
|
|
|
|
|
2010-10-22 12:11:58 +00:00
|
|
|
/* run at 45MHz */
|
2010-04-26 21:40:16 +00:00
|
|
|
set_cpu_frequency(CPUFREQ_NORMAL);
|
|
|
|
|
2010-10-22 12:11:58 +00:00
|
|
|
/* IRQs are needed by button driver */
|
2010-04-26 21:40:16 +00:00
|
|
|
enable_irq();
|
2010-10-22 12:11:58 +00:00
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
lcd_init();
|
|
|
|
|
2011-01-03 13:11:48 +00:00
|
|
|
/* setup font system */
|
2010-04-26 21:40:16 +00:00
|
|
|
font_init();
|
|
|
|
lcd_setfont(FONT_SYSFIXED);
|
2010-10-22 12:11:58 +00:00
|
|
|
|
2011-01-03 13:11:48 +00:00
|
|
|
/* buttons reading init */
|
2010-04-26 21:40:16 +00:00
|
|
|
adc_init();
|
|
|
|
button_init();
|
2010-05-04 11:16:17 +00:00
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
usb_init();
|
2010-05-04 11:16:17 +00:00
|
|
|
cpu_idle_mode(true);
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2011-01-03 13:11:48 +00:00
|
|
|
/* lowlevel init only */
|
|
|
|
_backlight_init();
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
/* Handle wakeup event. Possibilities are:
|
2010-12-06 10:24:29 +00:00
|
|
|
* RTC alarm (HD300)
|
|
|
|
* ON button (PLAY or RC_PLAY on HD200)
|
2010-05-04 11:16:17 +00:00
|
|
|
* USB insert
|
|
|
|
* AC charger plug
|
|
|
|
*/
|
|
|
|
while(1)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
2011-01-03 13:11:48 +00:00
|
|
|
/* check hold status */
|
|
|
|
hold = button_hold();
|
|
|
|
|
|
|
|
/* backlight handling
|
|
|
|
* change only on hold toggle */
|
|
|
|
if ( hold != last_hold )
|
|
|
|
{
|
|
|
|
if ( hold )
|
|
|
|
_backlight_hw_off();
|
|
|
|
else
|
|
|
|
_backlight_hw_on();
|
|
|
|
|
|
|
|
last_hold = hold;
|
|
|
|
}
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
/* read buttons */
|
|
|
|
event = EVENT_NONE;
|
|
|
|
button = button_get_w_tmo(HZ);
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-11-26 23:28:08 +00:00
|
|
|
if ( (button & BUTTON_PLAY)
|
|
|
|
#ifdef MPIO_HD200
|
|
|
|
|| (button & BUTTON_RC_PLAY)
|
|
|
|
#endif
|
|
|
|
)
|
2010-05-04 11:16:17 +00:00
|
|
|
event |= EVENT_ON;
|
|
|
|
|
|
|
|
if ( usb_detect() == USB_INSERTED )
|
|
|
|
event |= EVENT_USB;
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
if ( _charger_inserted() )
|
|
|
|
event |= EVENT_AC;
|
2010-12-06 10:24:29 +00:00
|
|
|
#ifdef MPIO_HD300
|
|
|
|
if ( _rtc_alarm() )
|
|
|
|
event |= EVENT_RTC;
|
|
|
|
#endif
|
2011-01-03 13:11:48 +00:00
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
reset_screen();
|
|
|
|
switch (event)
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
2010-12-06 10:24:29 +00:00
|
|
|
#ifdef MPIO_HD300
|
|
|
|
case EVENT_RTC:
|
|
|
|
case (EVENT_RTC | EVENT_ON):
|
|
|
|
/* start regardles of buttons state */
|
|
|
|
rb_boot();
|
|
|
|
break;
|
|
|
|
#endif
|
2010-05-04 11:16:17 +00:00
|
|
|
case EVENT_ON:
|
|
|
|
case (EVENT_ON | EVENT_AC):
|
|
|
|
/* hold is handled in button driver */
|
2010-12-06 10:24:29 +00:00
|
|
|
cpu_idle_mode(false);
|
|
|
|
ide_power_enable(true);
|
2010-05-04 11:16:17 +00:00
|
|
|
|
2010-12-06 10:24:29 +00:00
|
|
|
if (button & BUTTON_REC)
|
|
|
|
bootmenu();
|
|
|
|
else
|
|
|
|
rb_boot();
|
2010-04-26 21:40:16 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
case EVENT_AC:
|
2010-07-09 09:12:51 +00:00
|
|
|
/* AC plug in */
|
2010-05-04 11:16:17 +00:00
|
|
|
if (!(last_event & EVENT_AC))
|
2010-06-14 10:42:45 +00:00
|
|
|
{
|
2010-07-06 17:30:10 +00:00
|
|
|
/* reset charging circuit */
|
2010-06-14 10:42:45 +00:00
|
|
|
and_l(~(1<<23), &GPIO_ENABLE);
|
|
|
|
}
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
/* USB unplug */
|
|
|
|
if (last_event & EVENT_USB)
|
2010-06-14 10:42:45 +00:00
|
|
|
{
|
2010-05-04 11:16:17 +00:00
|
|
|
usb_enable(false);
|
2010-07-09 09:12:51 +00:00
|
|
|
sleep(HZ);
|
2010-06-14 10:42:45 +00:00
|
|
|
ide_power_enable(false);
|
2010-07-09 09:12:51 +00:00
|
|
|
sleep(HZ);
|
2010-06-14 10:42:45 +00:00
|
|
|
}
|
2010-05-04 11:16:17 +00:00
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
if(!_battery_full())
|
|
|
|
{
|
2010-05-04 11:16:17 +00:00
|
|
|
if (blink_toggle)
|
|
|
|
lcd_putstring_centered(charging_msg);
|
|
|
|
|
2010-04-26 21:40:16 +00:00
|
|
|
blink_toggle = !blink_toggle;
|
|
|
|
}
|
2010-07-06 17:30:10 +00:00
|
|
|
else /* end of charge condition */
|
2010-04-26 21:40:16 +00:00
|
|
|
{
|
2010-07-06 17:30:10 +00:00
|
|
|
/* put LTC1733 into shutdown mode */
|
|
|
|
or_l((1<<23), &GPIO_ENABLE);
|
|
|
|
|
|
|
|
if (high_current_charging)
|
|
|
|
{
|
|
|
|
/* switch to low current mode */
|
|
|
|
and_l(~(1<<15), &GPIO_OUT);
|
|
|
|
|
|
|
|
/* reset charging circuit */
|
|
|
|
and_l(~(1<<23), &GPIO_ENABLE);
|
|
|
|
|
|
|
|
high_current_charging = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcd_putstring_centered(complete_msg);
|
|
|
|
}
|
2010-04-26 21:40:16 +00:00
|
|
|
}
|
|
|
|
check_battery();
|
|
|
|
break;
|
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
case EVENT_USB:
|
|
|
|
case (EVENT_USB | EVENT_AC):
|
2010-07-09 09:12:51 +00:00
|
|
|
/* AC plug in while in USB mode */
|
2010-05-04 11:16:17 +00:00
|
|
|
if (!(last_event & EVENT_AC))
|
2010-06-14 10:42:45 +00:00
|
|
|
{
|
2010-07-06 17:30:10 +00:00
|
|
|
/* reset charger circuit */
|
2010-06-14 10:42:45 +00:00
|
|
|
and_l(~(1<<23), &GPIO_ENABLE);
|
|
|
|
}
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-07-09 09:12:51 +00:00
|
|
|
/* USB plug in */
|
2010-05-04 11:16:17 +00:00
|
|
|
if (!(last_event & EVENT_USB))
|
|
|
|
{
|
|
|
|
/* init USB */
|
|
|
|
ide_power_enable(true);
|
|
|
|
sleep(HZ/20);
|
2010-12-09 11:31:08 +00:00
|
|
|
ata_enable(false);
|
2010-05-04 11:16:17 +00:00
|
|
|
usb_enable(true);
|
|
|
|
}
|
2010-07-09 09:12:51 +00:00
|
|
|
|
|
|
|
/* display blinking USB indicator */
|
2010-05-04 11:16:17 +00:00
|
|
|
line = 0;
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
if (blink_toggle)
|
|
|
|
lcd_putstring_centered(usb_connect_msg);
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
check_battery();
|
|
|
|
blink_toggle = !blink_toggle;
|
|
|
|
storage_spin();
|
|
|
|
break;
|
2010-04-26 21:40:16 +00:00
|
|
|
|
2010-05-04 11:16:17 +00:00
|
|
|
default:
|
2010-07-09 09:12:51 +00:00
|
|
|
/* USB unplug */
|
2010-07-06 17:30:10 +00:00
|
|
|
if (last_event & EVENT_USB)
|
|
|
|
{
|
2010-07-09 09:12:51 +00:00
|
|
|
/* disable USB */
|
2010-07-06 17:30:10 +00:00
|
|
|
usb_enable(false);
|
2010-12-09 11:31:08 +00:00
|
|
|
ata_enable(true);
|
2010-07-09 09:12:51 +00:00
|
|
|
sleep(HZ);
|
2010-07-06 17:30:10 +00:00
|
|
|
ide_power_enable(false);
|
2010-07-09 09:12:51 +00:00
|
|
|
sleep(HZ);
|
2010-07-06 17:30:10 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:12:51 +00:00
|
|
|
/* spurious wakeup ?*/
|
2010-05-04 11:16:17 +00:00
|
|
|
__shutdown();
|
|
|
|
break;
|
2010-04-26 21:40:16 +00:00
|
|
|
}
|
|
|
|
lcd_update();
|
2010-05-04 11:16:17 +00:00
|
|
|
last_event = event;
|
2010-04-26 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These functions are present in the firmware library, but we reimplement
|
|
|
|
them here because the originals do a lot more than we want */
|
|
|
|
void screen_dump(void)
|
|
|
|
{
|
|
|
|
}
|