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 #include "statusbar-skinned.h"
78 #ifdef IPOD_ACCESSORY_PROTOCOL
82 #if (CONFIG_CODEC == SWCODEC)
86 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
87 #include "pcm_record.h"
91 #define SETTINGS_RESET BUTTON_REC
92 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
93 #define SETTINGS_RESET BUTTON_A
99 #if (CONFIG_STORAGE & STORAGE_MMC)
103 #ifdef HAVE_REMOTE_LCD
104 #include "lcd-remote.h"
107 #if CONFIG_USBOTG == USBOTG_ISP1362
111 #if CONFIG_USBOTG == USBOTG_M5636
116 #include "sim_tasks.h"
117 #include "system-sdl.h"
120 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
122 const char appsversion
[]=APPSVERSION
;
124 static void init(void);
129 static void app_main(void)
136 screens
[i
].clear_display();
139 #ifdef HAVE_LCD_BITMAP
143 viewportmanager_init();
145 /* All threads should be created and public queues registered by now */
146 usb_start_monitoring();
151 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
153 if(file_exists(filename
)) /* no complaint if it doesn't exist */
155 plugin_load((char*)filename
, NULL
); /* start if it does */
158 #endif /* #ifdef AUTOROCK */
163 static int init_dircache(bool preinit
)
172 if (!global_settings
.dircache
)
175 # ifdef HAVE_EEPROM_SETTINGS
176 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
179 result
= dircache_load();
183 firmware_settings
.disk_clean
= false;
184 if (global_status
.dircache_size
<= 0)
186 /* This will be in default language, settings are not
187 applied yet. Not really any easy way to fix that. */
188 splash(0, str(LANG_SCANNING_DISK
));
192 dircache_build(global_status
.dircache_size
);
201 if (!dircache_is_enabled()
202 && !dircache_is_initializing())
204 if (global_status
.dircache_size
<= 0)
206 splash(0, str(LANG_SCANNING_DISK
));
209 result
= dircache_build(global_status
.dircache_size
);
214 /* Initialization of dircache failed. Manual action is
215 * necessary to enable dircache again.
217 splashf(0, "Dircache failed, disabled. Result: %d", result
);
218 global_settings
.dircache
= false;
226 global_status
.dircache_size
= dircache_get_cache_size();
238 static void init_tagcache(void)
244 while (!tagcache_is_initialized())
246 int ret
= tagcache_get_commit_step();
250 #if CONFIG_CODEC == SWCODEC
251 /* hwcodec can't use voice here, as the database commit
252 * uses the audio buffer. */
253 static long talked_tick
= 0;
254 if(global_settings
.talk_menu
256 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
258 talked_tick
= current_tick
;
259 talk_id(LANG_TAGCACHE_INIT
, false);
260 talk_number(ret
, true);
261 talk_id(VOICE_OF
, true);
262 talk_number(tagcache_get_max_commit_step(), true);
265 #ifdef HAVE_LCD_BITMAP
268 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
269 str(LANG_TAGCACHE_INIT
));
273 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
274 tagcache_get_max_commit_step());
277 lcd_double_height(false);
278 lcd_putsf(0, 1, " DB [%d/%d]", ret
,
279 tagcache_get_max_commit_step());
298 static void init(void)
304 #ifdef HAVE_REMOTE_LCD
312 lang_init(core_language_builtin
, language_strings
,
313 LANG_LAST_INDEX_IN_ARRAY
);
317 /* Must be done before any code uses the multi-screen API */
318 gui_syncstatusbar_init(&statusbars
);
321 settings_load(SETTINGS_ALL
);
324 settings_apply(true);
326 init_dircache(false);
335 #if CONFIG_CODEC != SWCODEC
336 mp3_init( global_settings
.volume
,
337 global_settings
.bass
,
338 global_settings
.treble
,
339 global_settings
.balance
,
340 global_settings
.loudness
,
342 global_settings
.channel_config
,
343 global_settings
.stereo_width
,
344 global_settings
.mdb_strength
,
345 global_settings
.mdb_harmonics
,
346 global_settings
.mdb_center
,
347 global_settings
.mdb_shape
,
348 global_settings
.mdb_enable
,
349 global_settings
.superbass
);
351 /* audio_init must to know the size of voice buffer so init voice first */
353 #endif /* CONFIG_CODEC != SWCODEC */
356 #if CONFIG_CODEC == SWCODEC
358 #endif /* CONFIG_CODEC == SWCODEC */
361 button_clear_queue(); /* Empty the keyboard buffer */
366 static void init(void)
369 bool mounted
= false;
370 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
371 /* if nobody initialized ATA before, I consider this a cold start */
372 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
378 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
379 set_cpu_frequency(CPUFREQ_NORMAL
);
381 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
399 #ifdef HAVE_REMOTE_LCD
405 lang_init(core_language_builtin
, language_strings
,
406 LANG_LAST_INDEX_IN_ARRAY
);
420 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
426 #if CONFIG_USBOTG == USBOTG_ISP1362
428 #elif CONFIG_USBOTG == USBOTG_M5636
442 /* Must be done before any code uses the multi-screen API */
443 gui_syncstatusbar_init(&statusbars
);
445 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
446 /* charger_inserted() can't be used here because power_thread()
447 hasn't checked power_input_status() yet */
448 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
449 && !global_settings
.car_adapter_mode
450 #ifdef ATA_POWER_PLAYERSTYLE
451 && !ide_powered() /* relies on probing result from bootloader */
455 rc
= charging_screen(); /* display a "charging" screen */
456 if (rc
== 1) /* charger removed */
458 /* "On" pressed or USB connected: proceed */
459 show_logo(); /* again, to provide better visual feedback */
466 #ifdef HAVE_LCD_BITMAP
468 lcd_putsf(0, 1, "ATA error: %d", rc
);
469 lcd_puts(0, 3, "Press ON to debug");
471 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
474 panicf("ata: %d", rc
);
477 #ifdef HAVE_EEPROM_SETTINGS
478 eeprom_settings_init();
481 #ifndef HAVE_USBSTACK
482 usb_start_monitoring();
483 while (usb_detect() == USB_INSERTED
)
485 #ifdef HAVE_EEPROM_SETTINGS
486 firmware_settings
.disk_clean
= false;
488 /* enter USB mode early, before trying to mount */
489 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
490 #if (CONFIG_STORAGE & STORAGE_MMC)
491 if (!mmc_touched() ||
492 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
496 mounted
= true; /* mounting done @ end of USB mode */
498 #ifdef HAVE_USB_POWER
499 if (usb_powered()) /* avoid deadlock */
507 rc
= disk_mount_all();
511 lcd_puts(0, 0, "No partition");
512 lcd_puts(0, 1, "found.");
513 #ifdef HAVE_LCD_BITMAP
514 lcd_puts(0, 2, "Insert USB cable");
515 lcd_puts(0, 3, "and fix it.");
519 while(button_get(true) != SYS_USB_CONNECTED
) {};
525 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
526 (CONFIG_KEYPAD == IRIVER_H10_PAD)
527 #ifdef SETTINGS_RESET
528 /* Reset settings if holding the reset button. (Rec on Archos,
530 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
532 /* Reset settings if the hold button is turned on */
536 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
541 settings_load(SETTINGS_ALL
);
543 if (init_dircache(true) < 0)
546 remove(TAGCACHE_STATEFILE
);
552 settings_apply(true);
553 init_dircache(false);
558 #ifdef HAVE_EEPROM_SETTINGS
559 if (firmware_settings
.initialized
)
561 /* In case we crash. */
562 firmware_settings
.disk_clean
= false;
563 eeprom_settings_store();
570 #if CONFIG_CODEC == SWCODEC
572 #endif /* CONFIG_CODEC == SWCODEC */
574 #if CONFIG_CODEC != SWCODEC
575 /* No buffer allocation (see buffer.c) may take place after the call to
576 audio_init() since the mpeg thread takes the rest of the buffer space */
577 mp3_init( global_settings
.volume
,
578 global_settings
.bass
,
579 global_settings
.treble
,
580 global_settings
.balance
,
581 global_settings
.loudness
,
583 global_settings
.channel_config
,
584 global_settings
.stereo_width
,
585 global_settings
.mdb_strength
,
586 global_settings
.mdb_harmonics
,
587 global_settings
.mdb_center
,
588 global_settings
.mdb_shape
,
589 global_settings
.mdb_enable
,
590 global_settings
.superbass
);
592 /* audio_init must to know the size of voice buffer so init voice first */
594 #endif /* CONFIG_CODEC != SWCODEC */
598 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
602 /* runtime database has to be initialized after audio_init() */
606 car_adapter_mode_init();
608 #ifdef IPOD_ACCESSORY_PROTOCOL
609 iap_setup(global_settings
.serial_bitrate
);
611 #ifdef HAVE_ACCESSORY_SUPPLY
612 accessory_supply_set(global_settings
.accessory_supply
);
619 /* This is the entry point for the coprocessor
620 Anyone not running an upgraded bootloader will never reach this point,
621 so it should not be assumed that the coprocessor be usable even on
622 platforms which support it.
624 A kernel thread is initially setup on the coprocessor and immediately
625 destroyed for purposes of continuity. The cop sits idle until at least
626 one thread exists on it. */
628 /* 3G doesn't have Rolo or dual core support yet */
632 /* This should never be reached */
645 #if (CONFIG_LED == LED_REAL)
646 led(true); sleep(HZ
/10);
647 led(false); sleep(HZ
/10);