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();
136 touchpad_set_mode(TOUCHPAD_BUTTON
);
141 static int init_dircache(bool preinit
)
150 if (!global_settings
.dircache
)
153 # ifdef HAVE_EEPROM_SETTINGS
154 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
157 result
= dircache_load();
161 firmware_settings
.disk_clean
= false;
162 if (global_status
.dircache_size
<= 0)
164 /* This will be in default language, settings are not
165 applied yet. Not really any easy way to fix that. */
166 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
170 dircache_build(global_status
.dircache_size
);
179 if (!dircache_is_enabled()
180 && !dircache_is_initializing())
182 if (global_status
.dircache_size
<= 0)
184 gui_syncsplash(0, str(LANG_SCANNING_DISK
));
187 result
= dircache_build(global_status
.dircache_size
);
192 /* Initialization of dircache failed. Manual action is
193 * necessary to enable dircache again.
195 gui_syncsplash(0, "Dircache failed, disabled. Result: %d", result
);
196 global_settings
.dircache
= false;
205 global_status
.dircache_size
= dircache_get_cache_size();
217 static void init_tagcache(void)
223 while (!tagcache_is_initialized())
225 #ifdef HAVE_LCD_CHARCELLS
228 int ret
= tagcache_get_commit_step();
232 #if CONFIG_CODEC == SWCODEC
233 /* hwcodec can't use voice here, as the database commit
234 * uses the audio buffer. */
235 static long talked_tick
= 0;
236 if(global_settings
.talk_menu
238 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
240 talked_tick
= current_tick
;
241 talk_id(LANG_TAGCACHE_INIT
, false);
242 talk_number(ret
, true);
243 talk_id(VOICE_OF
, true);
244 talk_number(tagcache_get_max_commit_step(), true);
247 #ifdef HAVE_LCD_BITMAP
248 gui_syncsplash(0, "%s [%d/%d]",
249 str(LANG_TAGCACHE_INIT
), ret
,
250 tagcache_get_max_commit_step());
252 lcd_double_height(false);
253 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
254 tagcache_get_max_commit_step());
274 static void init(void)
280 #ifdef HAVE_REMOTE_LCD
291 /* Must be done before any code uses the multi-screen APi */
292 screen_access_init();
293 gui_syncstatusbar_init(&statusbars
);
296 settings_load(SETTINGS_ALL
);
298 settings_apply(true);
300 init_dircache(false);
309 #if CONFIG_CODEC != SWCODEC
310 mp3_init( global_settings
.volume
,
311 global_settings
.bass
,
312 global_settings
.treble
,
313 global_settings
.balance
,
314 global_settings
.loudness
,
316 global_settings
.channel_config
,
317 global_settings
.stereo_width
,
318 global_settings
.mdb_strength
,
319 global_settings
.mdb_harmonics
,
320 global_settings
.mdb_center
,
321 global_settings
.mdb_shape
,
322 global_settings
.mdb_enable
,
323 global_settings
.superbass
);
325 /* audio_init must to know the size of voice buffer so init voice first */
327 #endif /* CONFIG_CODEC != SWCODEC */
333 button_clear_queue(); /* Empty the keyboard buffer */
338 static void init(void)
341 bool mounted
= false;
342 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
343 /* if nobody initialized ATA before, I consider this a cold start */
344 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
350 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
351 set_cpu_frequency(CPUFREQ_NORMAL
);
353 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
371 #ifdef HAVE_REMOTE_LCD
382 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
391 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
397 #if CONFIG_USBOTG == USBOTG_ISP1362
399 #elif CONFIG_USBOTG == USBOTG_M5636
413 /* Must be done before any code uses the multi-screen APi */
414 screen_access_init();
415 gui_syncstatusbar_init(&statusbars
);
417 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
418 if (coldstart
&& charger_inserted()
419 && !global_settings
.car_adapter_mode
420 #ifdef ATA_POWER_PLAYERSTYLE
421 && !ide_powered() /* relies on probing result from bootloader */
425 rc
= charging_screen(); /* display a "charging" screen */
426 if (rc
== 1) /* charger removed */
428 /* "On" pressed or USB connected: proceed */
429 show_logo(); /* again, to provide better visual feedback */
436 #ifdef HAVE_LCD_BITMAP
439 snprintf(str
, 31, "ATA error: %d", rc
);
441 lcd_puts(0, 3, "Press ON to debug");
443 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
446 panicf("ata: %d", rc
);
449 #ifdef HAVE_EEPROM_SETTINGS
450 eeprom_settings_init();
453 usb_start_monitoring();
454 #ifndef HAVE_USBSTACK
455 while (usb_detect() == USB_INSERTED
)
457 #ifdef HAVE_EEPROM_SETTINGS
458 firmware_settings
.disk_clean
= false;
460 /* enter USB mode early, before trying to mount */
461 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
463 if (!mmc_touched() ||
464 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
468 mounted
= true; /* mounting done @ end of USB mode */
470 #ifdef HAVE_USB_POWER
471 if (usb_powered()) /* avoid deadlock */
479 rc
= disk_mount_all();
483 lcd_puts(0, 0, "No partition");
484 lcd_puts(0, 1, "found.");
485 #ifdef HAVE_LCD_BITMAP
486 lcd_puts(0, 2, "Insert USB cable");
487 lcd_puts(0, 3, "and fix it.");
491 while(button_get(true) != SYS_USB_CONNECTED
) {};
497 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
498 (CONFIG_KEYPAD == IRIVER_H10_PAD)
499 #ifdef SETTINGS_RESET
500 /* Reset settings if holding the reset button. (Rec on Archos,
502 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
504 /* Reset settings if the hold button is turned on */
508 gui_syncsplash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
513 settings_load(SETTINGS_ALL
);
515 if (init_dircache(true) < 0)
518 remove(TAGCACHE_STATEFILE
);
523 settings_apply(true);
524 init_dircache(false);
529 #ifdef HAVE_EEPROM_SETTINGS
530 if (firmware_settings
.initialized
)
532 /* In case we crash. */
533 firmware_settings
.disk_clean
= false;
534 eeprom_settings_store();
544 #if CONFIG_CODEC != SWCODEC
545 /* No buffer allocation (see buffer.c) may take place after the call to
546 audio_init() since the mpeg thread takes the rest of the buffer space */
547 mp3_init( global_settings
.volume
,
548 global_settings
.bass
,
549 global_settings
.treble
,
550 global_settings
.balance
,
551 global_settings
.loudness
,
553 global_settings
.channel_config
,
554 global_settings
.stereo_width
,
555 global_settings
.mdb_strength
,
556 global_settings
.mdb_harmonics
,
557 global_settings
.mdb_center
,
558 global_settings
.mdb_shape
,
559 global_settings
.mdb_enable
,
560 global_settings
.superbass
);
562 /* audio_init must to know the size of voice buffer so init voice first */
564 #endif /* CONFIG_CODEC != SWCODEC */
568 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
572 /* runtime database has to be initialized after audio_init() */
578 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
580 fd
= open(filename
, O_RDONLY
);
581 if(fd
>= 0) /* no complaint if it doesn't exist */
584 plugin_load((char*)filename
, NULL
); /* start if it does */
587 #endif /* #ifdef AUTOROCK */
590 car_adapter_mode_init();
597 /* This is the entry point for the coprocessor
598 Anyone not running an upgraded bootloader will never reach this point,
599 so it should not be assumed that the coprocessor be usable even on
600 platforms which support it.
602 A kernel thread is initially setup on the coprocessor and immediately
603 destroyed for purposes of continuity. The cop sits idle until at least
604 one thread exists on it. */
606 /* 3G doesn't have Rolo or dual core support yet */
610 /* This should never be reached */
613 COP_CTL
= PROC_SLEEP
;
623 #if (CONFIG_LED == LED_REAL)
624 led(true); sleep(HZ
/10);
625 led(false); sleep(HZ
/10);