1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
33 #include "filetypes.h"
38 #include "powermgmt.h"
45 #include "mp3_playback.h"
48 #include "backlight.h"
50 #include "debug_menu.h"
72 #include "eeprom_settings.h"
73 #include "scrobbler.h"
76 #if (CONFIG_CODEC == SWCODEC)
79 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
80 #include "pcm_record.h"
84 #define SETTINGS_RESET BUTTON_REC
85 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
86 #define SETTINGS_RESET BUTTON_A
96 #ifdef HAVE_REMOTE_LCD
97 #include "lcd-remote.h"
100 #if CONFIG_USBOTG == USBOTG_ISP1362
104 #if CONFIG_USBOTG == USBOTG_M5636
108 #include "cuesheet.h"
111 #include "system-sdl.h"
114 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
116 const char appsversion
[]=APPSVERSION
;
118 static void init(void);
123 static void app_main(void)
130 screens
[i
].clear_display();
135 touchpad_set_mode(TOUCHPAD_BUTTON
);
140 static int init_dircache(bool preinit
)
149 if (!global_settings
.dircache
)
152 # ifdef HAVE_EEPROM_SETTINGS
153 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
156 result
= dircache_load();
160 firmware_settings
.disk_clean
= false;
161 if (global_status
.dircache_size
<= 0)
163 /* This will be in default language, settings are not
164 applied yet. Not really any easy way to fix that. */
165 splash(0, str(LANG_SCANNING_DISK
));
169 dircache_build(global_status
.dircache_size
);
178 if (!dircache_is_enabled()
179 && !dircache_is_initializing())
181 if (global_status
.dircache_size
<= 0)
183 splash(0, str(LANG_SCANNING_DISK
));
186 result
= dircache_build(global_status
.dircache_size
);
191 /* Initialization of dircache failed. Manual action is
192 * necessary to enable dircache again.
194 splashf(0, "Dircache failed, disabled. Result: %d", result
);
195 global_settings
.dircache
= false;
204 global_status
.dircache_size
= dircache_get_cache_size();
216 static void init_tagcache(void)
222 while (!tagcache_is_initialized())
224 #ifdef HAVE_LCD_CHARCELLS
227 int ret
= tagcache_get_commit_step();
231 #if CONFIG_CODEC == SWCODEC
232 /* hwcodec can't use voice here, as the database commit
233 * uses the audio buffer. */
234 static long talked_tick
= 0;
235 if(global_settings
.talk_menu
237 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
239 talked_tick
= current_tick
;
240 talk_id(LANG_TAGCACHE_INIT
, false);
241 talk_number(ret
, true);
242 talk_id(VOICE_OF
, true);
243 talk_number(tagcache_get_max_commit_step(), true);
246 #ifdef HAVE_LCD_BITMAP
247 splashf(0, "%s [%d/%d]",
248 str(LANG_TAGCACHE_INIT
), ret
,
249 tagcache_get_max_commit_step());
251 lcd_double_height(false);
252 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
253 tagcache_get_max_commit_step());
273 static void init(void)
279 #ifdef HAVE_REMOTE_LCD
290 /* Must be done before any code uses the multi-screen APi */
291 screen_access_init();
292 gui_syncstatusbar_init(&statusbars
);
295 settings_load(SETTINGS_ALL
);
297 settings_apply(true);
299 init_dircache(false);
308 #if CONFIG_CODEC != SWCODEC
309 mp3_init( global_settings
.volume
,
310 global_settings
.bass
,
311 global_settings
.treble
,
312 global_settings
.balance
,
313 global_settings
.loudness
,
315 global_settings
.channel_config
,
316 global_settings
.stereo_width
,
317 global_settings
.mdb_strength
,
318 global_settings
.mdb_harmonics
,
319 global_settings
.mdb_center
,
320 global_settings
.mdb_shape
,
321 global_settings
.mdb_enable
,
322 global_settings
.superbass
);
324 /* audio_init must to know the size of voice buffer so init voice first */
326 #endif /* CONFIG_CODEC != SWCODEC */
332 button_clear_queue(); /* Empty the keyboard buffer */
337 static void init(void)
340 bool mounted
= false;
341 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
342 /* if nobody initialized ATA before, I consider this a cold start */
343 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
349 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
350 set_cpu_frequency(CPUFREQ_NORMAL
);
352 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
370 #ifdef HAVE_REMOTE_LCD
381 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
390 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
396 #if CONFIG_USBOTG == USBOTG_ISP1362
398 #elif CONFIG_USBOTG == USBOTG_M5636
412 /* Must be done before any code uses the multi-screen APi */
413 screen_access_init();
414 gui_syncstatusbar_init(&statusbars
);
416 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
417 if (coldstart
&& charger_inserted()
418 && !global_settings
.car_adapter_mode
419 #ifdef ATA_POWER_PLAYERSTYLE
420 && !ide_powered() /* relies on probing result from bootloader */
424 rc
= charging_screen(); /* display a "charging" screen */
425 if (rc
== 1) /* charger removed */
427 /* "On" pressed or USB connected: proceed */
428 show_logo(); /* again, to provide better visual feedback */
435 #ifdef HAVE_LCD_BITMAP
438 snprintf(str
, 31, "ATA error: %d", rc
);
440 lcd_puts(0, 3, "Press ON to debug");
442 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
445 panicf("ata: %d", rc
);
448 #ifdef HAVE_EEPROM_SETTINGS
449 eeprom_settings_init();
452 usb_start_monitoring();
453 #ifndef HAVE_USBSTACK
454 while (usb_detect() == USB_INSERTED
)
456 #ifdef HAVE_EEPROM_SETTINGS
457 firmware_settings
.disk_clean
= false;
459 /* enter USB mode early, before trying to mount */
460 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
462 if (!mmc_touched() ||
463 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
467 mounted
= true; /* mounting done @ end of USB mode */
469 #ifdef HAVE_USB_POWER
470 if (usb_powered()) /* avoid deadlock */
478 rc
= disk_mount_all();
482 lcd_puts(0, 0, "No partition");
483 lcd_puts(0, 1, "found.");
484 #ifdef HAVE_LCD_BITMAP
485 lcd_puts(0, 2, "Insert USB cable");
486 lcd_puts(0, 3, "and fix it.");
490 while(button_get(true) != SYS_USB_CONNECTED
) {};
496 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
497 (CONFIG_KEYPAD == IRIVER_H10_PAD)
498 #ifdef SETTINGS_RESET
499 /* Reset settings if holding the reset button. (Rec on Archos,
501 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
503 /* Reset settings if the hold button is turned on */
507 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
512 settings_load(SETTINGS_ALL
);
514 if (init_dircache(true) < 0)
517 remove(TAGCACHE_STATEFILE
);
522 settings_apply(true);
523 init_dircache(false);
528 #ifdef HAVE_EEPROM_SETTINGS
529 if (firmware_settings
.initialized
)
531 /* In case we crash. */
532 firmware_settings
.disk_clean
= false;
533 eeprom_settings_store();
543 #if CONFIG_CODEC != SWCODEC
544 /* No buffer allocation (see buffer.c) may take place after the call to
545 audio_init() since the mpeg thread takes the rest of the buffer space */
546 mp3_init( global_settings
.volume
,
547 global_settings
.bass
,
548 global_settings
.treble
,
549 global_settings
.balance
,
550 global_settings
.loudness
,
552 global_settings
.channel_config
,
553 global_settings
.stereo_width
,
554 global_settings
.mdb_strength
,
555 global_settings
.mdb_harmonics
,
556 global_settings
.mdb_center
,
557 global_settings
.mdb_shape
,
558 global_settings
.mdb_enable
,
559 global_settings
.superbass
);
561 /* audio_init must to know the size of voice buffer so init voice first */
563 #endif /* CONFIG_CODEC != SWCODEC */
567 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
571 /* runtime database has to be initialized after audio_init() */
576 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
578 if(file_exists(filename
)) /* no complaint if it doesn't exist */
580 plugin_load((char*)filename
, NULL
); /* start if it does */
583 #endif /* #ifdef AUTOROCK */
586 car_adapter_mode_init();
588 #ifdef HAVE_ACCESSORY_SUPPLY
589 accessory_supply_set(global_settings
.accessory_supply
);
596 /* This is the entry point for the coprocessor
597 Anyone not running an upgraded bootloader will never reach this point,
598 so it should not be assumed that the coprocessor be usable even on
599 platforms which support it.
601 A kernel thread is initially setup on the coprocessor and immediately
602 destroyed for purposes of continuity. The cop sits idle until at least
603 one thread exists on it. */
605 /* 3G doesn't have Rolo or dual core support yet */
609 /* This should never be reached */
622 #if (CONFIG_LED == LED_REAL)
623 led(true); sleep(HZ
/10);
624 led(false); sleep(HZ
/10);