diff options
Diffstat (limited to 'bootloader')
-rw-r--r-- | bootloader/gigabeat.c | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c index 6b3a68be6e..11ab93a5e2 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 | ||
50 | char version[] = APPSVERSION; | 51 | char version[] = APPSVERSION; |
51 | 52 | ||
53 | void 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 | |||
52 | void main(void) | 70 | void main(void) |
53 | { | 71 | { |
54 | unsigned char* loadbuffer; | 72 | unsigned char* loadbuffer; |
@@ -56,14 +74,72 @@ 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 | /* These checks should only run if the bootloader is flashed */ | ||
88 | if(GSTATUS3&0x02) | ||
89 | { | ||
90 | GSTATUS3&=0xFFFFFFFD; | ||
91 | if(!(GPGDAT&BUTTON_POWER) && charger_inserted()) | ||
92 | { | ||
93 | while(!(GPGDAT&BUTTON_POWER) && charger_inserted()) | ||
94 | { | ||
95 | char msg[20]; | ||
96 | if(charging_state()) | ||
97 | { | ||
98 | snprintf(msg,sizeof(msg),"Charging"); | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | snprintf(msg,sizeof(msg),"Charge Complete"); | ||
103 | } | ||
104 | reset_screen(); | ||
105 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, | ||
106 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); | ||
107 | lcd_update(); | ||
108 | |||
109 | #if defined(HAVE_RTC_ALARM) | ||
110 | /* Check if the alarm went off while charging */ | ||
111 | if(rtc_check_alarm_flag()) | ||
112 | { | ||
113 | GSTATUS3=1; /* Normally this is set in crt0.s */ | ||
114 | break; | ||
115 | } | ||
116 | #endif | ||
117 | } | ||
118 | if(!(GPGDAT&BUTTON_POWER) | ||
119 | #if defined(HAVE_RTC_ALARM) | ||
120 | && !GSTATUS3 | ||
121 | #endif | ||
122 | ) | ||
123 | { | ||
124 | shutdown(); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | if(button_hold()) | ||
129 | { | ||
130 | const char msg[] = "HOLD is enabled"; | ||
131 | reset_screen(); | ||
132 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, | ||
133 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); | ||
134 | lcd_update(); | ||
135 | |||
136 | sleep(2*HZ); | ||
137 | |||
138 | shutdown(); | ||
139 | } | ||
140 | } | ||
66 | 141 | ||
142 | power_init(); | ||
67 | usb_init(); | 143 | usb_init(); |
68 | 144 | ||
69 | /* Enter USB mode without USB thread */ | 145 | /* Enter USB mode without USB thread */ |
@@ -88,9 +164,7 @@ void main(void) | |||
88 | lcd_update(); | 164 | lcd_update(); |
89 | } | 165 | } |
90 | 166 | ||
91 | kernel_init(); | 167 | reset_screen(); |
92 | adc_init(); | ||
93 | button_init(); | ||
94 | 168 | ||
95 | /* Show debug messages if button is pressed */ | 169 | /* Show debug messages if button is pressed */ |
96 | if(button_read_device()) | 170 | if(button_read_device()) |