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 int main(void) __attribute__((noreturn
));
138 screens
[i
].clear_display();
141 #ifdef HAVE_LCD_BITMAP
145 /* Keep the order of this 3
146 * Must be done before any code uses the multi-screen API */
148 /* All threads should be created and public queues registered by now */
149 usb_start_monitoring();
154 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
156 if(file_exists(filename
)) /* no complaint if it doesn't exist */
158 plugin_load((char*)filename
, NULL
); /* start if it does */
161 #endif /* #ifdef AUTOROCK */
163 global_status
.last_volume_change
= 0;
167 static int init_dircache(bool preinit
)
176 if (!global_settings
.dircache
)
179 # ifdef HAVE_EEPROM_SETTINGS
180 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
183 result
= dircache_load();
187 firmware_settings
.disk_clean
= false;
188 if (global_status
.dircache_size
<= 0)
190 /* This will be in default language, settings are not
191 applied yet. Not really any easy way to fix that. */
192 splash(0, str(LANG_SCANNING_DISK
));
196 dircache_build(global_status
.dircache_size
);
205 if (!dircache_is_enabled()
206 && !dircache_is_initializing())
208 if (global_status
.dircache_size
<= 0)
210 splash(0, str(LANG_SCANNING_DISK
));
213 result
= dircache_build(global_status
.dircache_size
);
218 /* Initialization of dircache failed. Manual action is
219 * necessary to enable dircache again.
221 splashf(0, "Dircache failed, disabled. Result: %d", result
);
222 global_settings
.dircache
= false;
230 global_status
.dircache_size
= dircache_get_cache_size();
242 static void init_tagcache(void)
245 #if CONFIG_CODEC == SWCODEC
246 long talked_tick
= 0;
250 while (!tagcache_is_initialized())
252 int ret
= tagcache_get_commit_step();
256 #if CONFIG_CODEC == SWCODEC
257 /* hwcodec can't use voice here, as the database commit
258 * uses the audio buffer. */
259 if(global_settings
.talk_menu
261 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
263 talked_tick
= current_tick
;
264 talk_id(LANG_TAGCACHE_INIT
, false);
265 talk_number(ret
, true);
266 talk_id(VOICE_OF
, true);
267 talk_number(tagcache_get_max_commit_step(), true);
270 #ifdef HAVE_LCD_BITMAP
273 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
274 str(LANG_TAGCACHE_INIT
));
278 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
279 tagcache_get_max_commit_step());
282 lcd_double_height(false);
283 lcd_putsf(0, 1, " DB [%d/%d]", ret
,
284 tagcache_get_max_commit_step());
303 static void init(void)
309 #ifdef HAVE_REMOTE_LCD
317 lang_init(core_language_builtin
, language_strings
,
318 LANG_LAST_INDEX_IN_ARRAY
);
322 /* Keep the order of this 3 (viewportmanager handles statusbars)
323 * Must be done before any code uses the multi-screen API */
324 gui_syncstatusbar_init(&statusbars
);
326 viewportmanager_init();
331 settings_load(SETTINGS_ALL
);
332 settings_apply(false);
334 init_dircache(false);
343 #if CONFIG_CODEC != SWCODEC
344 mp3_init( global_settings
.volume
,
345 global_settings
.bass
,
346 global_settings
.treble
,
347 global_settings
.balance
,
348 global_settings
.loudness
,
350 global_settings
.channel_config
,
351 global_settings
.stereo_width
,
352 global_settings
.mdb_strength
,
353 global_settings
.mdb_harmonics
,
354 global_settings
.mdb_center
,
355 global_settings
.mdb_shape
,
356 global_settings
.mdb_enable
,
357 global_settings
.superbass
);
359 /* audio_init must to know the size of voice buffer so init voice first */
361 #endif /* CONFIG_CODEC != SWCODEC */
364 #if CONFIG_CODEC == SWCODEC
366 #endif /* CONFIG_CODEC == SWCODEC */
369 button_clear_queue(); /* Empty the keyboard buffer */
371 settings_apply(true);
376 static void init(void)
379 bool mounted
= false;
380 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
381 /* if nobody initialized ATA before, I consider this a cold start */
382 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
388 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
389 set_cpu_frequency(CPUFREQ_NORMAL
);
391 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
409 #ifdef HAVE_REMOTE_LCD
415 lang_init(core_language_builtin
, language_strings
,
416 LANG_LAST_INDEX_IN_ARRAY
);
430 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
436 #if CONFIG_USBOTG == USBOTG_ISP1362
438 #elif CONFIG_USBOTG == USBOTG_M5636
452 /* Keep the order of this 3 (viewportmanager handles statusbars)
453 * Must be done before any code uses the multi-screen API */
454 gui_syncstatusbar_init(&statusbars
);
456 viewportmanager_init();
460 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
461 /* charger_inserted() can't be used here because power_thread()
462 hasn't checked power_input_status() yet */
463 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
464 && !global_settings
.car_adapter_mode
465 #ifdef ATA_POWER_PLAYERSTYLE
466 && !ide_powered() /* relies on probing result from bootloader */
470 rc
= charging_screen(); /* display a "charging" screen */
471 if (rc
== 1) /* charger removed */
473 /* "On" pressed or USB connected: proceed */
474 show_logo(); /* again, to provide better visual feedback */
481 #ifdef HAVE_LCD_BITMAP
483 lcd_putsf(0, 1, "ATA error: %d", rc
);
484 lcd_puts(0, 3, "Press ON to debug");
486 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
489 panicf("ata: %d", rc
);
492 #ifdef HAVE_EEPROM_SETTINGS
493 eeprom_settings_init();
496 #ifndef HAVE_USBSTACK
497 usb_start_monitoring();
498 while (usb_detect() == USB_INSERTED
)
500 #ifdef HAVE_EEPROM_SETTINGS
501 firmware_settings
.disk_clean
= false;
503 /* enter USB mode early, before trying to mount */
504 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
505 #if (CONFIG_STORAGE & STORAGE_MMC)
506 if (!mmc_touched() ||
507 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
510 gui_usb_screen_run();
511 mounted
= true; /* mounting done @ end of USB mode */
513 #ifdef HAVE_USB_POWER
514 if (usb_powered()) /* avoid deadlock */
522 rc
= disk_mount_all();
526 lcd_puts(0, 0, "No partition");
527 lcd_puts(0, 1, "found.");
528 #ifdef HAVE_LCD_BITMAP
529 lcd_puts(0, 2, "Insert USB cable");
530 lcd_puts(0, 3, "and fix it.");
534 while(button_get(true) != SYS_USB_CONNECTED
) {};
535 gui_usb_screen_run();
540 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
541 (CONFIG_KEYPAD == IRIVER_H10_PAD)
542 #ifdef SETTINGS_RESET
543 /* Reset settings if holding the reset button. (Rec on Archos,
545 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
547 /* Reset settings if the hold button is turned on */
551 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
556 settings_load(SETTINGS_ALL
);
558 if (init_dircache(true) < 0)
561 remove(TAGCACHE_STATEFILE
);
565 settings_apply(false);
566 init_dircache(false);
571 #ifdef HAVE_EEPROM_SETTINGS
572 if (firmware_settings
.initialized
)
574 /* In case we crash. */
575 firmware_settings
.disk_clean
= false;
576 eeprom_settings_store();
583 #if CONFIG_CODEC == SWCODEC
585 #endif /* CONFIG_CODEC == SWCODEC */
587 #if CONFIG_CODEC != SWCODEC
588 /* No buffer allocation (see buffer.c) may take place after the call to
589 audio_init() since the mpeg thread takes the rest of the buffer space */
590 mp3_init( global_settings
.volume
,
591 global_settings
.bass
,
592 global_settings
.treble
,
593 global_settings
.balance
,
594 global_settings
.loudness
,
596 global_settings
.channel_config
,
597 global_settings
.stereo_width
,
598 global_settings
.mdb_strength
,
599 global_settings
.mdb_harmonics
,
600 global_settings
.mdb_center
,
601 global_settings
.mdb_shape
,
602 global_settings
.mdb_enable
,
603 global_settings
.superbass
);
605 /* audio_init must to know the size of voice buffer so init voice first */
607 #endif /* CONFIG_CODEC != SWCODEC */
611 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
615 /* runtime database has to be initialized after audio_init() */
619 car_adapter_mode_init();
621 #ifdef IPOD_ACCESSORY_PROTOCOL
622 iap_setup(global_settings
.serial_bitrate
);
624 #ifdef HAVE_ACCESSORY_SUPPLY
625 accessory_supply_set(global_settings
.accessory_supply
);
627 #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN
628 check_bootfile(false); /* remember write time and filesize */
631 settings_apply(true);
637 /* This is the entry point for the coprocessor
638 Anyone not running an upgraded bootloader will never reach this point,
639 so it should not be assumed that the coprocessor be usable even on
640 platforms which support it.
642 A kernel thread is initially setup on the coprocessor and immediately
643 destroyed for purposes of continuity. The cop sits idle until at least
644 one thread exists on it. */
646 /* 3G doesn't have Rolo or dual core support yet */
650 /* This should never be reached */