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"
60 #include "usb_screen.h"
73 #include "eeprom_settings.h"
74 #include "scrobbler.h"
77 #include "statusbar-skinned.h"
79 #ifdef IPOD_ACCESSORY_PROTOCOL
83 #if (CONFIG_CODEC == SWCODEC)
87 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
88 #include "pcm_record.h"
92 #define SETTINGS_RESET BUTTON_REC
93 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
94 #define SETTINGS_RESET BUTTON_A
100 #if (CONFIG_STORAGE & STORAGE_MMC)
104 #ifdef HAVE_REMOTE_LCD
105 #include "lcd-remote.h"
108 #if CONFIG_USBOTG == USBOTG_ISP1362
112 #if CONFIG_USBOTG == USBOTG_M5636
117 #include "sim_tasks.h"
118 #include "system-sdl.h"
121 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
123 const char appsversion
[]=APPSVERSION
;
125 static void init(void);
130 /* main(), and various functions called by main() and init() may be
131 * be INIT_ATTR. These functions must not be called after the final call
132 * to root_menu() at the end of main()
133 * see definition of INIT_ATTR in config.h */
134 int main(void) INIT_ATTR
__attribute__((noreturn
));
142 screens
[i
].clear_display();
145 #ifdef HAVE_LCD_BITMAP
149 /* Keep the order of this 3
150 * Must be done before any code uses the multi-screen API */
152 /* All threads should be created and public queues registered by now */
153 usb_start_monitoring();
158 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
160 if(file_exists(filename
)) /* no complaint if it doesn't exist */
162 plugin_load((char*)filename
, NULL
); /* start if it does */
165 #endif /* #ifdef AUTOROCK */
167 global_status
.last_volume_change
= 0;
168 /* no calls INIT_ATTR functions after this point anymore!
169 * see definition of INIT_ATTR in config.h */
173 static int init_dircache(bool preinit
) INIT_ATTR
;
174 static int init_dircache(bool preinit
)
183 if (!global_settings
.dircache
)
186 # ifdef HAVE_EEPROM_SETTINGS
187 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
190 result
= dircache_load();
194 firmware_settings
.disk_clean
= false;
195 if (global_status
.dircache_size
<= 0)
197 /* This will be in default language, settings are not
198 applied yet. Not really any easy way to fix that. */
199 splash(0, str(LANG_SCANNING_DISK
));
203 dircache_build(global_status
.dircache_size
);
212 if (!dircache_is_enabled()
213 && !dircache_is_initializing())
215 if (global_status
.dircache_size
<= 0)
217 splash(0, str(LANG_SCANNING_DISK
));
220 result
= dircache_build(global_status
.dircache_size
);
225 /* Initialization of dircache failed. Manual action is
226 * necessary to enable dircache again.
228 splashf(0, "Dircache failed, disabled. Result: %d", result
);
229 global_settings
.dircache
= false;
237 global_status
.dircache_size
= dircache_get_cache_size();
249 static void init_tagcache(void) INIT_ATTR
;
250 static void init_tagcache(void)
253 #if CONFIG_CODEC == SWCODEC
254 long talked_tick
= 0;
258 while (!tagcache_is_initialized())
260 int ret
= tagcache_get_commit_step();
264 #if CONFIG_CODEC == SWCODEC
265 /* hwcodec can't use voice here, as the database commit
266 * uses the audio buffer. */
267 if(global_settings
.talk_menu
269 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
271 talked_tick
= current_tick
;
272 talk_id(LANG_TAGCACHE_INIT
, false);
273 talk_number(ret
, true);
274 talk_id(VOICE_OF
, true);
275 talk_number(tagcache_get_max_commit_step(), true);
278 #ifdef HAVE_LCD_BITMAP
281 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
282 str(LANG_TAGCACHE_INIT
));
286 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
287 tagcache_get_max_commit_step());
290 lcd_double_height(false);
291 lcd_putsf(0, 1, " DB [%d/%d]", ret
,
292 tagcache_get_max_commit_step());
311 static void init(void)
317 #ifdef HAVE_REMOTE_LCD
325 lang_init(core_language_builtin
, language_strings
,
326 LANG_LAST_INDEX_IN_ARRAY
);
330 /* Keep the order of this 3 (viewportmanager handles statusbars)
331 * Must be done before any code uses the multi-screen API */
332 gui_syncstatusbar_init(&statusbars
);
335 viewportmanager_init();
339 settings_load(SETTINGS_ALL
);
340 settings_apply(true);
342 init_dircache(false);
351 #if CONFIG_CODEC != SWCODEC
352 mp3_init( global_settings
.volume
,
353 global_settings
.bass
,
354 global_settings
.treble
,
355 global_settings
.balance
,
356 global_settings
.loudness
,
358 global_settings
.channel_config
,
359 global_settings
.stereo_width
,
360 global_settings
.mdb_strength
,
361 global_settings
.mdb_harmonics
,
362 global_settings
.mdb_center
,
363 global_settings
.mdb_shape
,
364 global_settings
.mdb_enable
,
365 global_settings
.superbass
);
367 /* audio_init must to know the size of voice buffer so init voice first */
369 #endif /* CONFIG_CODEC != SWCODEC */
372 #if CONFIG_CODEC == SWCODEC
374 #endif /* CONFIG_CODEC == SWCODEC */
377 button_clear_queue(); /* Empty the keyboard buffer */
379 settings_apply_skins();
384 static void init(void) INIT_ATTR
;
385 static void init(void)
388 bool mounted
= false;
389 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
390 /* if nobody initialized ATA before, I consider this a cold start */
391 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
397 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
398 set_cpu_frequency(CPUFREQ_NORMAL
);
400 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
418 #ifdef HAVE_REMOTE_LCD
424 lang_init(core_language_builtin
, language_strings
,
425 LANG_LAST_INDEX_IN_ARRAY
);
439 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
445 #if CONFIG_USBOTG == USBOTG_ISP1362
447 #elif CONFIG_USBOTG == USBOTG_M5636
461 /* Keep the order of this 3 (viewportmanager handles statusbars)
462 * Must be done before any code uses the multi-screen API */
463 gui_syncstatusbar_init(&statusbars
);
466 viewportmanager_init();
468 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
469 /* charger_inserted() can't be used here because power_thread()
470 hasn't checked power_input_status() yet */
471 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
472 && !global_settings
.car_adapter_mode
473 #ifdef ATA_POWER_PLAYERSTYLE
474 && !ide_powered() /* relies on probing result from bootloader */
478 rc
= charging_screen(); /* display a "charging" screen */
479 if (rc
== 1) /* charger removed */
481 /* "On" pressed or USB connected: proceed */
482 show_logo(); /* again, to provide better visual feedback */
489 #ifdef HAVE_LCD_BITMAP
491 lcd_putsf(0, 1, "ATA error: %d", rc
);
492 lcd_puts(0, 3, "Press ON to debug");
494 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
497 panicf("ata: %d", rc
);
500 #ifdef HAVE_EEPROM_SETTINGS
501 eeprom_settings_init();
504 #ifndef HAVE_USBSTACK
505 usb_start_monitoring();
506 while (usb_detect() == USB_INSERTED
)
508 #ifdef HAVE_EEPROM_SETTINGS
509 firmware_settings
.disk_clean
= false;
511 /* enter USB mode early, before trying to mount */
512 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
513 #if (CONFIG_STORAGE & STORAGE_MMC)
514 if (!mmc_touched() ||
515 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
518 gui_usb_screen_run();
519 mounted
= true; /* mounting done @ end of USB mode */
521 #ifdef HAVE_USB_POWER
522 if (usb_powered()) /* avoid deadlock */
530 rc
= disk_mount_all();
534 lcd_puts(0, 0, "No partition");
535 lcd_puts(0, 1, "found.");
536 #ifdef HAVE_LCD_BITMAP
537 lcd_puts(0, 2, "Insert USB cable");
538 lcd_puts(0, 3, "and fix it.");
542 while(button_get(true) != SYS_USB_CONNECTED
) {};
543 gui_usb_screen_run();
548 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
549 (CONFIG_KEYPAD == IRIVER_H10_PAD)
550 #ifdef SETTINGS_RESET
551 /* Reset settings if holding the reset button. (Rec on Archos,
553 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
555 /* Reset settings if the hold button is turned on */
559 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
564 settings_load(SETTINGS_ALL
);
566 if (init_dircache(true) < 0)
569 remove(TAGCACHE_STATEFILE
);
573 settings_apply(true);
574 init_dircache(false);
579 #ifdef HAVE_EEPROM_SETTINGS
580 if (firmware_settings
.initialized
)
582 /* In case we crash. */
583 firmware_settings
.disk_clean
= false;
584 eeprom_settings_store();
591 #if CONFIG_CODEC == SWCODEC
593 #endif /* CONFIG_CODEC == SWCODEC */
595 #if CONFIG_CODEC != SWCODEC
596 /* No buffer allocation (see buffer.c) may take place after the call to
597 audio_init() since the mpeg thread takes the rest of the buffer space */
598 mp3_init( global_settings
.volume
,
599 global_settings
.bass
,
600 global_settings
.treble
,
601 global_settings
.balance
,
602 global_settings
.loudness
,
604 global_settings
.channel_config
,
605 global_settings
.stereo_width
,
606 global_settings
.mdb_strength
,
607 global_settings
.mdb_harmonics
,
608 global_settings
.mdb_center
,
609 global_settings
.mdb_shape
,
610 global_settings
.mdb_enable
,
611 global_settings
.superbass
);
613 /* audio_init must to know the size of voice buffer so init voice first */
615 #endif /* CONFIG_CODEC != SWCODEC */
619 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
623 /* runtime database has to be initialized after audio_init() */
627 car_adapter_mode_init();
629 #ifdef IPOD_ACCESSORY_PROTOCOL
630 iap_setup(global_settings
.serial_bitrate
);
632 #ifdef HAVE_ACCESSORY_SUPPLY
633 accessory_supply_set(global_settings
.accessory_supply
);
635 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
636 check_bootfile(false); /* remember write time and filesize */
638 settings_apply_skins();
644 /* This is the entry point for the coprocessor
645 Anyone not running an upgraded bootloader will never reach this point,
646 so it should not be assumed that the coprocessor be usable even on
647 platforms which support it.
649 A kernel thread is initially setup on the coprocessor and immediately
650 destroyed for purposes of continuity. The cop sits idle until at least
651 one thread exists on it. */
653 /* 3G doesn't have Rolo or dual core support yet */
657 /* This should never be reached */