summaryrefslogtreecommitdiff
path: root/bootloader/gigabeat.c
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/gigabeat.c')
-rw-r--r--bootloader/gigabeat.c77
1 files changed, 73 insertions, 4 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c
index 6b3a68be6e..575e61c2fa 100644
--- a/bootloader/gigabeat.c
+++ b/bootloader/gigabeat.c
@@ -44,11 +44,29 @@
44#include "rbunicode.h" 44#include "rbunicode.h"
45#include "usb.h" 45#include "usb.h"
46#include "mmu-arm.h" 46#include "mmu-arm.h"
47#include "rtc.h"
47 48
48#include <stdarg.h> 49#include <stdarg.h>
49 50
50char version[] = APPSVERSION; 51char version[] = APPSVERSION;
51 52
53void shutdown(void)
54{
55 /* We need to gracefully spin down the disk to prevent clicks. */
56 if (ide_powered())
57 {
58 /* Make sure ATA has been initialized. */
59 ata_init();
60
61 /* And put the disk into sleep immediately. */
62 ata_sleepnow();
63 }
64
65 _backlight_off();
66
67 power_off();
68}
69
52void main(void) 70void main(void)
53{ 71{
54 unsigned char* loadbuffer; 72 unsigned char* loadbuffer;
@@ -56,14 +74,67 @@ void main(void)
56 int rc; 74 int rc;
57 int(*kernel_entry)(void); 75 int(*kernel_entry)(void);
58 76
59 power_init();
60 system_init(); 77 system_init();
61 lcd_init(); 78 lcd_init();
62 backlight_init(); 79 backlight_init();
80 button_init();
63 font_init(); 81 font_init();
82 kernel_init(); /* Need the kernel to sleep */
83 adc_init();
64 84
65 lcd_setfont(FONT_SYSFIXED); 85 lcd_setfont(FONT_SYSFIXED);
86
87 if(!(GPGDAT&BUTTON_POWER) && charger_inserted())
88 {
89 while(!(GPGDAT&BUTTON_POWER) && charger_inserted())
90 {
91 char msg[20];
92 if(charging_state())
93 {
94 snprintf(msg,sizeof(msg),"Charging");
95 }
96 else
97 {
98 snprintf(msg,sizeof(msg),"Charge Complete");
99 }
100 reset_screen();
101 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
102 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
103 lcd_update();
104
105#if defined(HAVE_RTC_ALARM)
106 /* Check if the alarm went off while charging */
107 if(rtc_check_alarm_flag())
108 {
109 GSTATUS4=1; /* Normally this is set in crt0.s */
110 break;
111 }
112#endif
113 }
114 if(!(GPGDAT&BUTTON_POWER)
115#if defined(HAVE_RTC_ALARM)
116 && !GSTATUS4
117#endif
118 )
119 {
120 shutdown();
121 }
122 }
123
124 if(button_hold())
125 {
126 const char msg[] = "HOLD is enabled";
127 reset_screen();
128 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
129 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
130 lcd_update();
131
132 sleep(2*HZ);
133
134 shutdown();
135 }
66 136
137 power_init();
67 usb_init(); 138 usb_init();
68 139
69 /* Enter USB mode without USB thread */ 140 /* Enter USB mode without USB thread */
@@ -88,9 +159,7 @@ void main(void)
88 lcd_update(); 159 lcd_update();
89 } 160 }
90 161
91 kernel_init(); 162 reset_screen();
92 adc_init();
93 button_init();
94 163
95 /* Show debug messages if button is pressed */ 164 /* Show debug messages if button is pressed */
96 if(button_read_device()) 165 if(button_read_device())