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(false);
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(true);
380 settings_apply_skins();
385 static void init(void) INIT_ATTR
;
386 static void init(void)
389 bool mounted
= false;
390 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
391 /* if nobody initialized ATA before, I consider this a cold start */
392 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
398 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
399 set_cpu_frequency(CPUFREQ_NORMAL
);
401 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
419 #ifdef HAVE_REMOTE_LCD
425 lang_init(core_language_builtin
, language_strings
,
426 LANG_LAST_INDEX_IN_ARRAY
);
440 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
446 #if CONFIG_USBOTG == USBOTG_ISP1362
448 #elif CONFIG_USBOTG == USBOTG_M5636
462 /* Keep the order of this 3 (viewportmanager handles statusbars)
463 * Must be done before any code uses the multi-screen API */
464 gui_syncstatusbar_init(&statusbars
);
467 viewportmanager_init();
469 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
470 /* charger_inserted() can't be used here because power_thread()
471 hasn't checked power_input_status() yet */
472 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
473 && !global_settings
.car_adapter_mode
474 #ifdef ATA_POWER_PLAYERSTYLE
475 && !ide_powered() /* relies on probing result from bootloader */
479 rc
= charging_screen(); /* display a "charging" screen */
480 if (rc
== 1) /* charger removed */
482 /* "On" pressed or USB connected: proceed */
483 show_logo(); /* again, to provide better visual feedback */
490 #ifdef HAVE_LCD_BITMAP
492 lcd_putsf(0, 1, "ATA error: %d", rc
);
493 lcd_puts(0, 3, "Press ON to debug");
495 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
498 panicf("ata: %d", rc
);
501 #ifdef HAVE_EEPROM_SETTINGS
502 eeprom_settings_init();
505 #ifndef HAVE_USBSTACK
506 usb_start_monitoring();
507 while (usb_detect() == USB_INSERTED
)
509 #ifdef HAVE_EEPROM_SETTINGS
510 firmware_settings
.disk_clean
= false;
512 /* enter USB mode early, before trying to mount */
513 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
514 #if (CONFIG_STORAGE & STORAGE_MMC)
515 if (!mmc_touched() ||
516 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
519 gui_usb_screen_run();
520 mounted
= true; /* mounting done @ end of USB mode */
522 #ifdef HAVE_USB_POWER
523 if (usb_powered()) /* avoid deadlock */
531 rc
= disk_mount_all();
535 lcd_puts(0, 0, "No partition");
536 lcd_puts(0, 1, "found.");
537 #ifdef HAVE_LCD_BITMAP
538 lcd_puts(0, 2, "Insert USB cable");
539 lcd_puts(0, 3, "and fix it.");
543 while(button_get(true) != SYS_USB_CONNECTED
) {};
544 gui_usb_screen_run();
549 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
550 (CONFIG_KEYPAD == IRIVER_H10_PAD)
551 #ifdef SETTINGS_RESET
552 /* Reset settings if holding the reset button. (Rec on Archos,
554 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
556 /* Reset settings if the hold button is turned on */
560 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
565 settings_load(SETTINGS_ALL
);
567 if (init_dircache(true) < 0)
570 remove(TAGCACHE_STATEFILE
);
574 settings_apply(false);
575 init_dircache(false);
580 #ifdef HAVE_EEPROM_SETTINGS
581 if (firmware_settings
.initialized
)
583 /* In case we crash. */
584 firmware_settings
.disk_clean
= false;
585 eeprom_settings_store();
592 #if CONFIG_CODEC == SWCODEC
594 #endif /* CONFIG_CODEC == SWCODEC */
596 #if CONFIG_CODEC != SWCODEC
597 /* No buffer allocation (see buffer.c) may take place after the call to
598 audio_init() since the mpeg thread takes the rest of the buffer space */
599 mp3_init( global_settings
.volume
,
600 global_settings
.bass
,
601 global_settings
.treble
,
602 global_settings
.balance
,
603 global_settings
.loudness
,
605 global_settings
.channel_config
,
606 global_settings
.stereo_width
,
607 global_settings
.mdb_strength
,
608 global_settings
.mdb_harmonics
,
609 global_settings
.mdb_center
,
610 global_settings
.mdb_shape
,
611 global_settings
.mdb_enable
,
612 global_settings
.superbass
);
614 /* audio_init must to know the size of voice buffer so init voice first */
616 #endif /* CONFIG_CODEC != SWCODEC */
620 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
624 /* runtime database has to be initialized after audio_init() */
628 car_adapter_mode_init();
630 #ifdef IPOD_ACCESSORY_PROTOCOL
631 iap_setup(global_settings
.serial_bitrate
);
633 #ifdef HAVE_ACCESSORY_SUPPLY
634 accessory_supply_set(global_settings
.accessory_supply
);
636 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
637 check_bootfile(false); /* remember write time and filesize */
639 settings_apply(true);
640 settings_apply_skins();
646 /* This is the entry point for the coprocessor
647 Anyone not running an upgraded bootloader will never reach this point,
648 so it should not be assumed that the coprocessor be usable even on
649 platforms which support it.
651 A kernel thread is initially setup on the coprocessor and immediately
652 destroyed for purposes of continuity. The cop sits idle until at least
653 one thread exists on it. */
655 /* 3G doesn't have Rolo or dual core support yet */
659 /* This should never be reached */