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 static void app_main(void)
137 screens
[i
].clear_display();
140 #ifdef HAVE_LCD_BITMAP
144 viewportmanager_init();
146 /* All threads should be created and public queues registered by now */
147 usb_start_monitoring();
152 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
154 if(file_exists(filename
)) /* no complaint if it doesn't exist */
156 plugin_load((char*)filename
, NULL
); /* start if it does */
159 #endif /* #ifdef AUTOROCK */
164 static int init_dircache(bool preinit
)
173 if (!global_settings
.dircache
)
176 # ifdef HAVE_EEPROM_SETTINGS
177 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
180 result
= dircache_load();
184 firmware_settings
.disk_clean
= false;
185 if (global_status
.dircache_size
<= 0)
187 /* This will be in default language, settings are not
188 applied yet. Not really any easy way to fix that. */
189 splash(0, str(LANG_SCANNING_DISK
));
193 dircache_build(global_status
.dircache_size
);
202 if (!dircache_is_enabled()
203 && !dircache_is_initializing())
205 if (global_status
.dircache_size
<= 0)
207 splash(0, str(LANG_SCANNING_DISK
));
210 result
= dircache_build(global_status
.dircache_size
);
215 /* Initialization of dircache failed. Manual action is
216 * necessary to enable dircache again.
218 splashf(0, "Dircache failed, disabled. Result: %d", result
);
219 global_settings
.dircache
= false;
227 global_status
.dircache_size
= dircache_get_cache_size();
239 static void init_tagcache(void)
245 while (!tagcache_is_initialized())
247 int ret
= tagcache_get_commit_step();
251 #if CONFIG_CODEC == SWCODEC
252 /* hwcodec can't use voice here, as the database commit
253 * uses the audio buffer. */
254 static long talked_tick
= 0;
255 if(global_settings
.talk_menu
257 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
259 talked_tick
= current_tick
;
260 talk_id(LANG_TAGCACHE_INIT
, false);
261 talk_number(ret
, true);
262 talk_id(VOICE_OF
, true);
263 talk_number(tagcache_get_max_commit_step(), true);
266 #ifdef HAVE_LCD_BITMAP
269 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
270 str(LANG_TAGCACHE_INIT
));
274 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
275 tagcache_get_max_commit_step());
278 lcd_double_height(false);
279 lcd_putsf(0, 1, " DB [%d/%d]", ret
,
280 tagcache_get_max_commit_step());
299 static void init(void)
305 #ifdef HAVE_REMOTE_LCD
313 lang_init(core_language_builtin
, language_strings
,
314 LANG_LAST_INDEX_IN_ARRAY
);
318 /* Must be done before any code uses the multi-screen API */
319 gui_syncstatusbar_init(&statusbars
);
322 settings_load(SETTINGS_ALL
);
325 settings_apply(true);
327 init_dircache(false);
336 #if CONFIG_CODEC != SWCODEC
337 mp3_init( global_settings
.volume
,
338 global_settings
.bass
,
339 global_settings
.treble
,
340 global_settings
.balance
,
341 global_settings
.loudness
,
343 global_settings
.channel_config
,
344 global_settings
.stereo_width
,
345 global_settings
.mdb_strength
,
346 global_settings
.mdb_harmonics
,
347 global_settings
.mdb_center
,
348 global_settings
.mdb_shape
,
349 global_settings
.mdb_enable
,
350 global_settings
.superbass
);
352 /* audio_init must to know the size of voice buffer so init voice first */
354 #endif /* CONFIG_CODEC != SWCODEC */
357 #if CONFIG_CODEC == SWCODEC
359 #endif /* CONFIG_CODEC == SWCODEC */
362 button_clear_queue(); /* Empty the keyboard buffer */
367 static void init(void)
370 bool mounted
= false;
371 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
372 /* if nobody initialized ATA before, I consider this a cold start */
373 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
379 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
380 set_cpu_frequency(CPUFREQ_NORMAL
);
382 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
400 #ifdef HAVE_REMOTE_LCD
406 lang_init(core_language_builtin
, language_strings
,
407 LANG_LAST_INDEX_IN_ARRAY
);
421 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
427 #if CONFIG_USBOTG == USBOTG_ISP1362
429 #elif CONFIG_USBOTG == USBOTG_M5636
443 /* Must be done before any code uses the multi-screen API */
444 gui_syncstatusbar_init(&statusbars
);
446 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
447 /* charger_inserted() can't be used here because power_thread()
448 hasn't checked power_input_status() yet */
449 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
450 && !global_settings
.car_adapter_mode
451 #ifdef ATA_POWER_PLAYERSTYLE
452 && !ide_powered() /* relies on probing result from bootloader */
456 rc
= charging_screen(); /* display a "charging" screen */
457 if (rc
== 1) /* charger removed */
459 /* "On" pressed or USB connected: proceed */
460 show_logo(); /* again, to provide better visual feedback */
467 #ifdef HAVE_LCD_BITMAP
469 lcd_putsf(0, 1, "ATA error: %d", rc
);
470 lcd_puts(0, 3, "Press ON to debug");
472 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
475 panicf("ata: %d", rc
);
478 #ifdef HAVE_EEPROM_SETTINGS
479 eeprom_settings_init();
482 #ifndef HAVE_USBSTACK
483 usb_start_monitoring();
484 while (usb_detect() == USB_INSERTED
)
486 #ifdef HAVE_EEPROM_SETTINGS
487 firmware_settings
.disk_clean
= false;
489 /* enter USB mode early, before trying to mount */
490 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
491 #if (CONFIG_STORAGE & STORAGE_MMC)
492 if (!mmc_touched() ||
493 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
496 gui_usb_screen_run();
497 mounted
= true; /* mounting done @ end of USB mode */
499 #ifdef HAVE_USB_POWER
500 if (usb_powered()) /* avoid deadlock */
508 rc
= disk_mount_all();
512 lcd_puts(0, 0, "No partition");
513 lcd_puts(0, 1, "found.");
514 #ifdef HAVE_LCD_BITMAP
515 lcd_puts(0, 2, "Insert USB cable");
516 lcd_puts(0, 3, "and fix it.");
520 while(button_get(true) != SYS_USB_CONNECTED
) {};
521 gui_usb_screen_run();
526 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
527 (CONFIG_KEYPAD == IRIVER_H10_PAD)
528 #ifdef SETTINGS_RESET
529 /* Reset settings if holding the reset button. (Rec on Archos,
531 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
533 /* Reset settings if the hold button is turned on */
537 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
542 settings_load(SETTINGS_ALL
);
544 if (init_dircache(true) < 0)
547 remove(TAGCACHE_STATEFILE
);
553 settings_apply(true);
554 init_dircache(false);
559 #ifdef HAVE_EEPROM_SETTINGS
560 if (firmware_settings
.initialized
)
562 /* In case we crash. */
563 firmware_settings
.disk_clean
= false;
564 eeprom_settings_store();
571 #if CONFIG_CODEC == SWCODEC
573 #endif /* CONFIG_CODEC == SWCODEC */
575 #if CONFIG_CODEC != SWCODEC
576 /* No buffer allocation (see buffer.c) may take place after the call to
577 audio_init() since the mpeg thread takes the rest of the buffer space */
578 mp3_init( global_settings
.volume
,
579 global_settings
.bass
,
580 global_settings
.treble
,
581 global_settings
.balance
,
582 global_settings
.loudness
,
584 global_settings
.channel_config
,
585 global_settings
.stereo_width
,
586 global_settings
.mdb_strength
,
587 global_settings
.mdb_harmonics
,
588 global_settings
.mdb_center
,
589 global_settings
.mdb_shape
,
590 global_settings
.mdb_enable
,
591 global_settings
.superbass
);
593 /* audio_init must to know the size of voice buffer so init voice first */
595 #endif /* CONFIG_CODEC != SWCODEC */
599 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
603 /* runtime database has to be initialized after audio_init() */
607 car_adapter_mode_init();
609 #ifdef IPOD_ACCESSORY_PROTOCOL
610 iap_setup(global_settings
.serial_bitrate
);
612 #ifdef HAVE_ACCESSORY_SUPPLY
613 accessory_supply_set(global_settings
.accessory_supply
);
620 /* This is the entry point for the coprocessor
621 Anyone not running an upgraded bootloader will never reach this point,
622 so it should not be assumed that the coprocessor be usable even on
623 platforms which support it.
625 A kernel thread is initially setup on the coprocessor and immediately
626 destroyed for purposes of continuity. The cop sits idle until at least
627 one thread exists on it. */
629 /* 3G doesn't have Rolo or dual core support yet */
633 /* This should never be reached */
646 #if (CONFIG_LED == LED_REAL)
647 led(true); sleep(HZ
/10);
648 led(false); sleep(HZ
/10);