1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
35 #include "powermgmt.h"
42 #include "mp3_playback.h"
45 #include "backlight.h"
47 #include "debug_menu.h"
67 #if (CONFIG_CODEC == SWCODEC)
73 #if (defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)) && !defined(SIMULATOR)
74 #include "pcm_record.h"
75 #define SETTINGS_RESET BUTTON_REC
85 #ifdef HAVE_REMOTE_LCD
86 #include "lcd-remote.h"
89 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
91 const char appsversion
[]=APPSVERSION
;
102 void init_dircache(void)
109 if (global_settings
.dircache
)
111 /* Print "Scanning disk..." to the display. */
112 lcd_getstringsize("A", &font_w
, &font_h
);
113 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(str(LANG_DIRCACHE_BUILDING
))*font_w
)/2),
114 LCD_HEIGHT
-font_h
*3, str(LANG_DIRCACHE_BUILDING
));
117 result
= dircache_build(global_settings
.dircache_size
);
120 snprintf(buf
, sizeof(buf
),
121 "Failed! Result: %d",
123 lcd_getstringsize("A", &font_w
, &font_h
);
124 lcd_putsxy((LCD_WIDTH
/2) - ((strlen(buf
)*font_w
)/2),
125 LCD_HEIGHT
-font_h
*2, buf
);
129 /* Clean the text when we are done. */
130 lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
131 lcd_fillrect(0, LCD_HEIGHT
-font_h
*3, LCD_WIDTH
, font_h
);
132 lcd_set_drawmode(DRMODE_SOLID
);
138 # define init_dircache(...)
148 #ifdef HAVE_REMOTE_LCD
156 /* Must be done before any code uses the multi-screen APi */
157 screen_access_init();
158 gui_syncstatusbar_init(&statusbars
);
160 settings_calc_config_sector();
161 settings_load(SETTINGS_ALL
);
168 mp3_init( global_settings
.volume
,
169 global_settings
.bass
,
170 global_settings
.treble
,
171 global_settings
.balance
,
172 global_settings
.loudness
,
174 global_settings
.channel_config
,
175 global_settings
.stereo_width
,
176 global_settings
.mdb_strength
,
177 global_settings
.mdb_harmonics
,
178 global_settings
.mdb_center
,
179 global_settings
.mdb_shape
,
180 global_settings
.mdb_enable
,
181 global_settings
.superbass
);
182 #if CONFIG_CODEC == SWCODEC
186 button_clear_queue(); /* Empty the keyboard buffer */
187 #if CONFIG_CODEC == SWCODEC
197 bool mounted
= false;
198 #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
199 /* if nobody initialized ATA before, I consider this a cold start */
200 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
205 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
206 set_cpu_frequency(CPUFREQ_NORMAL
);
217 #ifdef HAVE_REMOTE_LCD
228 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
229 * (do debug builds on the Ondio make sense?) */
240 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
253 #if CONFIG_CODEC == SWCODEC
261 /* Must be done before any code uses the multi-screen APi */
262 screen_access_init();
263 gui_syncstatusbar_init(&statusbars
);
265 #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
266 if (coldstart
&& charger_inserted()
267 && !global_settings
.car_adapter_mode
268 #ifdef ATA_POWER_PLAYERSTYLE
269 && !ide_powered() /* relies on probing result from bootloader */
273 rc
= charging_screen(); /* display a "charging" screen */
274 if (rc
== 1) /* charger removed */
276 /* "On" pressed or USB connected: proceed */
277 show_logo(); /* again, to provide better visual feedback */
284 #ifdef HAVE_LCD_BITMAP
287 snprintf(str
, 31, "ATA error: %d", rc
);
289 lcd_puts(0, 3, "Press ON to debug");
291 while(!(button_get(true) & BUTTON_REL
));
294 panicf("ata: %d", rc
);
297 usb_start_monitoring();
299 { /* enter USB mode early, before trying to mount */
300 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
302 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
306 mounted
= true; /* mounting done @ end of USB mode */
308 #ifdef HAVE_USB_POWER
309 if (usb_powered()) /* avoid deadlock */
316 rc
= disk_mount_all();
320 lcd_puts(0, 0, "No partition");
321 lcd_puts(0, 1, "found.");
322 #ifdef HAVE_LCD_BITMAP
323 lcd_puts(0, 2, "Insert USB cable");
324 lcd_puts(0, 3, "and fix it.");
327 while(button_get(true) != SYS_USB_CONNECTED
) {};
333 settings_calc_config_sector();
335 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD)
336 #ifdef SETTINGS_RESET
337 /* Reset settings if holding the rec button. */
338 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
340 /* Reset settings if the hold button is turned on */
344 gui_syncsplash(HZ
*2, true, str(LANG_RESET_DONE_CLEAR
));
349 settings_load(SETTINGS_ALL
);
360 /* No buffer allocation (see buffer.c) may take place after the call to
361 audio_init() since the mpeg thread takes the rest of the buffer space */
362 mp3_init( global_settings
.volume
,
363 global_settings
.bass
,
364 global_settings
.treble
,
365 global_settings
.balance
,
366 global_settings
.loudness
,
368 global_settings
.channel_config
,
369 global_settings
.stereo_width
,
370 global_settings
.mdb_strength
,
371 global_settings
.mdb_harmonics
,
372 global_settings
.mdb_center
,
373 global_settings
.mdb_shape
,
374 global_settings
.mdb_enable
,
375 global_settings
.superbass
);
377 #if (defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)) && !defined(SIMULATOR)
381 /* runtime database has to be initialized after audio_init() */
388 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
390 fd
= open(filename
, O_RDONLY
);
391 if(fd
>= 0) /* no complaint if it doesn't exist */
394 plugin_load((char*)filename
, NULL
); /* start if it does */
397 #endif /* #ifdef AUTOROCK */
400 car_adapter_mode_init();
409 #if CONFIG_LED == LED_REAL
410 led(true); sleep(HZ
/10);
411 led(false); sleep(HZ
/10);