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, 4 insertions, 73 deletions
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c
index 575e61c2fa..6b3a68be6e 100644
--- a/bootloader/gigabeat.c
+++ b/bootloader/gigabeat.c
@@ -44,29 +44,11 @@
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"
48 47
49#include <stdarg.h> 48#include <stdarg.h>
50 49
51char version[] = APPSVERSION; 50char version[] = APPSVERSION;
52 51
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
70void main(void) 52void main(void)
71{ 53{
72 unsigned char* loadbuffer; 54 unsigned char* loadbuffer;
@@ -74,67 +56,14 @@ void main(void)
74 int rc; 56 int rc;
75 int(*kernel_entry)(void); 57 int(*kernel_entry)(void);
76 58
59 power_init();
77 system_init(); 60 system_init();
78 lcd_init(); 61 lcd_init();
79 backlight_init(); 62 backlight_init();
80 button_init();
81 font_init(); 63 font_init();
82 kernel_init(); /* Need the kernel to sleep */
83 adc_init();
84 64
85 lcd_setfont(FONT_SYSFIXED); 65 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 }
136 66
137 power_init();
138 usb_init(); 67 usb_init();
139 68
140 /* Enter USB mode without USB thread */ 69 /* Enter USB mode without USB thread */
@@ -159,7 +88,9 @@ void main(void)
159 lcd_update(); 88 lcd_update();
160 } 89 }
161 90
162 reset_screen(); 91 kernel_init();
92 adc_init();
93 button_init();
163 94
164 /* Show debug messages if button is pressed */ 95 /* Show debug messages if button is pressed */
165 if(button_read_device()) 96 if(button_read_device())