1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 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 ****************************************************************************/
31 #include "filetypes.h"
36 #include "powermgmt.h"
43 #include "mp3_playback.h"
46 #include "backlight.h"
48 #include "debug_menu.h"
70 #include "eeprom_settings.h"
71 #include "scrobbler.h"
74 #if (CONFIG_CODEC == SWCODEC)
80 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
81 #include "pcm_record.h"
85 #define SETTINGS_RESET BUTTON_REC
86 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
87 #define SETTINGS_RESET BUTTON_A
97 #ifdef HAVE_REMOTE_LCD
98 #include "lcd-remote.h"
101 #if CONFIG_USBOTG == USBOTG_ISP1362
105 #if CONFIG_USBOTG == USBOTG_M5636
109 #include "cuesheet.h"
112 #include "system-sdl.h"
115 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
117 const char appsversion
[]=APPSVERSION
;
119 static void init(void);
124 static void app_main(void)
131 screens
[i
].clear_display();
138 static int init_dircache(bool preinit
)
147 if (!global_settings
.dircache
)
150 # ifdef HAVE_EEPROM_SETTINGS
151 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
154 result
= dircache_load();
158 firmware_settings
.disk_clean
= false;
159 if (global_status
.dircache_size
<= 0)
161 /* This will be in default language, settings are not
162 applied yet. Not really any easy way to fix that. */
163 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
167 dircache_build(global_status
.dircache_size
);
176 if (!dircache_is_enabled()
177 && !dircache_is_initializing())
179 if (global_status
.dircache_size
<= 0)
181 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
184 result
= dircache_build(global_status
.dircache_size
);
189 /* Initialization of dircache failed. Manual action is
190 * necessary to enable dircache again.
192 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
193 global_settings
.dircache
= false;
202 global_status
.dircache_size
= dircache_get_cache_size();
214 static void init_tagcache(void)
220 while (!tagcache_is_initialized())
222 #ifdef HAVE_LCD_CHARCELLS
225 int ret
= tagcache_get_commit_step();
229 #if CONFIG_CODEC == SWCODEC
230 /* hwcodec can't use voice here, as the database commit
231 * uses the audio buffer. */
232 static long talked_tick
= 0;
233 if(global_settings
.talk_menu
235 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
237 talked_tick
= current_tick
;
238 talk_id(LANG_TAGCACHE_INIT
, false);
239 talk_number(ret
, true);
240 talk_id(VOICE_OF
, true);
241 talk_number(tagcache_get_max_commit_step(), true);
244 #ifdef HAVE_LCD_BITMAP
245 gui_syncsplash(0, "%s [%d/%d]",
246 str(LANG_TAGCACHE_INIT
), ret
,
247 tagcache_get_max_commit_step());
249 lcd_double_height(false);
250 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
251 tagcache_get_max_commit_step());
271 static void init(void)
277 #ifdef HAVE_REMOTE_LCD
288 /* Must be done before any code uses the multi-screen APi */
289 screen_access_init();
290 gui_syncstatusbar_init(&statusbars
);
293 settings_load(SETTINGS_ALL
);
295 settings_apply(true);
297 init_dircache(false);
306 #if CONFIG_CODEC != SWCODEC
307 mp3_init( global_settings
.volume
,
308 global_settings
.bass
,
309 global_settings
.treble
,
310 global_settings
.balance
,
311 global_settings
.loudness
,
313 global_settings
.channel_config
,
314 global_settings
.stereo_width
,
315 global_settings
.mdb_strength
,
316 global_settings
.mdb_harmonics
,
317 global_settings
.mdb_center
,
318 global_settings
.mdb_shape
,
319 global_settings
.mdb_enable
,
320 global_settings
.superbass
);
322 /* audio_init must to know the size of voice buffer so init voice first */
324 #endif /* CONFIG_CODEC != SWCODEC */
330 button_clear_queue(); /* Empty the keyboard buffer */
335 static void init(void)
338 bool mounted
= false;
339 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
340 /* if nobody initialized ATA before, I consider this a cold start */
341 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
347 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
348 set_cpu_frequency(CPUFREQ_NORMAL
);
350 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
365 set_fiq_status(FIQ_ENABLED
);
368 #ifdef HAVE_REMOTE_LCD
379 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
388 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
394 #if CONFIG_USBOTG == USBOTG_ISP1362
396 #elif CONFIG_USBOTG == USBOTG_M5636
410 /* Must be done before any code uses the multi-screen APi */
411 screen_access_init();
412 gui_syncstatusbar_init(&statusbars
);
414 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
415 if (coldstart
&& charger_inserted()
416 && !global_settings
.car_adapter_mode
417 #ifdef ATA_POWER_PLAYERSTYLE
418 && !ide_powered() /* relies on probing result from bootloader */
422 rc
= charging_screen(); /* display a "charging" screen */
423 if (rc
== 1) /* charger removed */
425 /* "On" pressed or USB connected: proceed */
426 show_logo(); /* again, to provide better visual feedback */
433 #ifdef HAVE_LCD_BITMAP
436 snprintf(str
, 31, "ATA error: %d", rc
);
438 lcd_puts(0, 3, "Press ON to debug");
440 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
443 panicf("ata: %d", rc
);
446 #ifdef HAVE_EEPROM_SETTINGS
447 eeprom_settings_init();
450 usb_start_monitoring();
451 #ifndef HAVE_USBSTACK
452 while (usb_detect() == USB_INSERTED
)
454 #ifdef HAVE_EEPROM_SETTINGS
455 firmware_settings
.disk_clean
= false;
457 /* enter USB mode early, before trying to mount */
458 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
460 if (!mmc_touched() ||
461 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
465 mounted
= true; /* mounting done @ end of USB mode */
467 #ifdef HAVE_USB_POWER
468 if (usb_powered()) /* avoid deadlock */
476 rc
= disk_mount_all();
480 lcd_puts(0, 0, "No partition");
481 lcd_puts(0, 1, "found.");
482 #ifdef HAVE_LCD_BITMAP
483 lcd_puts(0, 2, "Insert USB cable");
484 lcd_puts(0, 3, "and fix it.");
488 while(button_get(true) != SYS_USB_CONNECTED
) {};
494 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
495 (CONFIG_KEYPAD == IRIVER_H10_PAD)
496 #ifdef SETTINGS_RESET
497 /* Reset settings if holding the reset button. (Rec on Archos,
499 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
501 /* Reset settings if the hold button is turned on */
505 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
510 settings_load(SETTINGS_ALL
);
512 if (init_dircache(true) < 0)
515 remove(TAGCACHE_STATEFILE
);
520 settings_apply(true);
521 init_dircache(false);
526 #ifdef HAVE_EEPROM_SETTINGS
527 if (firmware_settings
.initialized
)
529 /* In case we crash. */
530 firmware_settings
.disk_clean
= false;
531 eeprom_settings_store();
541 #if CONFIG_CODEC != SWCODEC
542 /* No buffer allocation (see buffer.c) may take place after the call to
543 audio_init() since the mpeg thread takes the rest of the buffer space */
544 mp3_init( global_settings
.volume
,
545 global_settings
.bass
,
546 global_settings
.treble
,
547 global_settings
.balance
,
548 global_settings
.loudness
,
550 global_settings
.channel_config
,
551 global_settings
.stereo_width
,
552 global_settings
.mdb_strength
,
553 global_settings
.mdb_harmonics
,
554 global_settings
.mdb_center
,
555 global_settings
.mdb_shape
,
556 global_settings
.mdb_enable
,
557 global_settings
.superbass
);
559 /* audio_init must to know the size of voice buffer so init voice first */
561 #endif /* CONFIG_CODEC != SWCODEC */
565 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
569 /* runtime database has to be initialized after audio_init() */
575 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
577 fd
= open(filename
, O_RDONLY
);
578 if(fd
>= 0) /* no complaint if it doesn't exist */
581 plugin_load((char*)filename
, NULL
); /* start if it does */
584 #endif /* #ifdef AUTOROCK */
587 car_adapter_mode_init();
594 /* This is the entry point for the coprocessor
595 Anyone not running an upgraded bootloader will never reach this point,
596 so it should not be assumed that the coprocessor be usable even on
597 platforms which support it.
599 A kernel thread is initially setup on the coprocessor and immediately
600 destroyed for purposes of continuity. The cop sits idle until at least
601 one thread exists on it. */
603 /* 3G doesn't have Rolo or dual core support yet */
607 /* This should never be reached */
610 COP_CTL
= PROC_SLEEP
;
620 #if (CONFIG_LED == LED_REAL)
621 led(true); sleep(HZ
/10);
622 led(false); sleep(HZ
/10);