HD200 - add support for remote in bootloader

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27316 a1c6a512-1295-4272-9138-f99709370657
diff --git a/bootloader/mpio_hd200.c b/bootloader/mpio_hd200.c
index 5b72dd3..0eec84d 100644
--- a/bootloader/mpio_hd200.c
+++ b/bootloader/mpio_hd200.c
@@ -186,6 +186,9 @@
 {
     int rc;
 
+    /* boost to speedup rb image loading */
+    cpu_boost(true);
+
     rc = storage_init();
     if(rc)
     {
@@ -218,6 +221,7 @@
         return;
     }
 
+    cpu_boost(false);
     start_rockbox();
 }
 
@@ -272,6 +276,7 @@
         switch (button)
         {
             case BUTTON_PREV:
+            case BUTTON_RC_PREV:
                 if (option > rockbox)
                     option--;
                 else
@@ -279,6 +284,7 @@
                 break;
 
             case BUTTON_NEXT:
+            case BUTTON_RC_NEXT:
                 if (option < shutdown)
                     option++;
                 else
@@ -286,6 +292,7 @@
                 break;
 
             case BUTTON_PLAY:
+            case BUTTON_RC_PLAY:
             case (BUTTON_PLAY|BUTTON_REC):
                 reset_screen();
 
@@ -322,6 +329,9 @@
     unsigned int event = EVENT_NONE;
     unsigned int last_event = EVENT_NONE;
 
+    /* this is default mode after power_init() */
+    bool high_current_charging = true;
+
     power_init();
 
     system_init();
@@ -360,7 +370,7 @@
         event = EVENT_NONE;
         button = button_get_w_tmo(HZ);
 
-        if ( button & BUTTON_PLAY )
+        if ( (button & BUTTON_PLAY) || (button & BUTTON_RC_PLAY) )
             event |= EVENT_ON;
  
         if ( usb_detect() == USB_INSERTED )
@@ -388,8 +398,7 @@
             case EVENT_AC:
                 if (!(last_event & EVENT_AC))
                 {
-                    /* high current charge */
-                    or_l((1<<15),&GPIO_OUT);
+                    /* reset charging circuit */
                     and_l(~(1<<23), &GPIO_ENABLE);
                 }
 
@@ -407,9 +416,25 @@
 
                     blink_toggle = !blink_toggle;
                 }
-                else
+                else /* end of charge condition */
                 {
-                    lcd_putstring_centered(complete_msg);
+                    /* 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);
+                    }
                 }
                 check_battery();
                 break;
@@ -418,8 +443,7 @@
             case (EVENT_USB | EVENT_AC):
                 if (!(last_event & EVENT_AC))
                 {
-                    /* high current charge */
-                    or_l((1<<15),&GPIO_OUT);
+                    /* reset charger circuit */
                     and_l(~(1<<23), &GPIO_ENABLE);
                 }
 
@@ -442,6 +466,13 @@
                 break;
 
             default:
+                if (last_event & EVENT_USB)
+                {
+                    /* USB unplug */
+                    usb_enable(false);
+                    ide_power_enable(false);
+                }
+
                 /* spurious wakeup */
                 __shutdown();
                 break;