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 viewportmanager_init();
147 /* All threads should be created and public queues registered by now */
148 usb_start_monitoring();
153 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
155 if(file_exists(filename
)) /* no complaint if it doesn't exist */
157 plugin_load((char*)filename
, NULL
); /* start if it does */
160 #endif /* #ifdef AUTOROCK */
162 global_status
.last_volume_change
= 0;
166 static int init_dircache(bool preinit
)
175 if (!global_settings
.dircache
)
178 # ifdef HAVE_EEPROM_SETTINGS
179 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
182 result
= dircache_load();
186 firmware_settings
.disk_clean
= false;
187 if (global_status
.dircache_size
<= 0)
189 /* This will be in default language, settings are not
190 applied yet. Not really any easy way to fix that. */
191 splash(0, str(LANG_SCANNING_DISK
));
195 dircache_build(global_status
.dircache_size
);
204 if (!dircache_is_enabled()
205 && !dircache_is_initializing())
207 if (global_status
.dircache_size
<= 0)
209 splash(0, str(LANG_SCANNING_DISK
));
212 result
= dircache_build(global_status
.dircache_size
);
217 /* Initialization of dircache failed. Manual action is
218 * necessary to enable dircache again.
220 splashf(0, "Dircache failed, disabled. Result: %d", result
);
221 global_settings
.dircache
= false;
229 global_status
.dircache_size
= dircache_get_cache_size();
241 static void init_tagcache(void)
244 #if CONFIG_CODEC == SWCODEC
245 long talked_tick
= 0;
249 while (!tagcache_is_initialized())
251 int ret
= tagcache_get_commit_step();
255 #if CONFIG_CODEC == SWCODEC
256 /* hwcodec can't use voice here, as the database commit
257 * uses the audio buffer. */
258 if(global_settings
.talk_menu
260 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
262 talked_tick
= current_tick
;
263 talk_id(LANG_TAGCACHE_INIT
, false);
264 talk_number(ret
, true);
265 talk_id(VOICE_OF
, true);
266 talk_number(tagcache_get_max_commit_step(), true);
269 #ifdef HAVE_LCD_BITMAP
272 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
273 str(LANG_TAGCACHE_INIT
));
277 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
278 tagcache_get_max_commit_step());
281 lcd_double_height(false);
282 lcd_putsf(0, 1, " DB [%d/%d]", ret
,
283 tagcache_get_max_commit_step());
302 static void init(void)
308 #ifdef HAVE_REMOTE_LCD
316 lang_init(core_language_builtin
, language_strings
,
317 LANG_LAST_INDEX_IN_ARRAY
);
321 /* Must be done before any code uses the multi-screen API */
322 gui_syncstatusbar_init(&statusbars
);
325 settings_load(SETTINGS_ALL
);
328 settings_apply(true);
330 init_dircache(false);
339 #if CONFIG_CODEC != SWCODEC
340 mp3_init( global_settings
.volume
,
341 global_settings
.bass
,
342 global_settings
.treble
,
343 global_settings
.balance
,
344 global_settings
.loudness
,
346 global_settings
.channel_config
,
347 global_settings
.stereo_width
,
348 global_settings
.mdb_strength
,
349 global_settings
.mdb_harmonics
,
350 global_settings
.mdb_center
,
351 global_settings
.mdb_shape
,
352 global_settings
.mdb_enable
,
353 global_settings
.superbass
);
355 /* audio_init must to know the size of voice buffer so init voice first */
357 #endif /* CONFIG_CODEC != SWCODEC */
360 #if CONFIG_CODEC == SWCODEC
362 #endif /* CONFIG_CODEC == SWCODEC */
365 button_clear_queue(); /* Empty the keyboard buffer */
370 static void init(void)
373 bool mounted
= false;
374 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
375 /* if nobody initialized ATA before, I consider this a cold start */
376 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
382 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
383 set_cpu_frequency(CPUFREQ_NORMAL
);
385 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
403 #ifdef HAVE_REMOTE_LCD
409 lang_init(core_language_builtin
, language_strings
,
410 LANG_LAST_INDEX_IN_ARRAY
);
424 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
430 #if CONFIG_USBOTG == USBOTG_ISP1362
432 #elif CONFIG_USBOTG == USBOTG_M5636
446 /* Must be done before any code uses the multi-screen API */
447 gui_syncstatusbar_init(&statusbars
);
449 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
450 /* charger_inserted() can't be used here because power_thread()
451 hasn't checked power_input_status() yet */
452 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
453 && !global_settings
.car_adapter_mode
454 #ifdef ATA_POWER_PLAYERSTYLE
455 && !ide_powered() /* relies on probing result from bootloader */
459 rc
= charging_screen(); /* display a "charging" screen */
460 if (rc
== 1) /* charger removed */
462 /* "On" pressed or USB connected: proceed */
463 show_logo(); /* again, to provide better visual feedback */
470 #ifdef HAVE_LCD_BITMAP
472 lcd_putsf(0, 1, "ATA error: %d", rc
);
473 lcd_puts(0, 3, "Press ON to debug");
475 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
478 panicf("ata: %d", rc
);
481 #ifdef HAVE_EEPROM_SETTINGS
482 eeprom_settings_init();
485 #ifndef HAVE_USBSTACK
486 usb_start_monitoring();
487 while (usb_detect() == USB_INSERTED
)
489 #ifdef HAVE_EEPROM_SETTINGS
490 firmware_settings
.disk_clean
= false;
492 /* enter USB mode early, before trying to mount */
493 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
494 #if (CONFIG_STORAGE & STORAGE_MMC)
495 if (!mmc_touched() ||
496 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
499 gui_usb_screen_run();
500 mounted
= true; /* mounting done @ end of USB mode */
502 #ifdef HAVE_USB_POWER
503 if (usb_powered()) /* avoid deadlock */
511 rc
= disk_mount_all();
515 lcd_puts(0, 0, "No partition");
516 lcd_puts(0, 1, "found.");
517 #ifdef HAVE_LCD_BITMAP
518 lcd_puts(0, 2, "Insert USB cable");
519 lcd_puts(0, 3, "and fix it.");
523 while(button_get(true) != SYS_USB_CONNECTED
) {};
524 gui_usb_screen_run();
529 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
530 (CONFIG_KEYPAD == IRIVER_H10_PAD)
531 #ifdef SETTINGS_RESET
532 /* Reset settings if holding the reset button. (Rec on Archos,
534 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
536 /* Reset settings if the hold button is turned on */
540 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
545 settings_load(SETTINGS_ALL
);
547 if (init_dircache(true) < 0)
550 remove(TAGCACHE_STATEFILE
);
556 settings_apply(true);
557 init_dircache(false);
562 #ifdef HAVE_EEPROM_SETTINGS
563 if (firmware_settings
.initialized
)
565 /* In case we crash. */
566 firmware_settings
.disk_clean
= false;
567 eeprom_settings_store();
574 #if CONFIG_CODEC == SWCODEC
576 #endif /* CONFIG_CODEC == SWCODEC */
578 #if CONFIG_CODEC != SWCODEC
579 /* No buffer allocation (see buffer.c) may take place after the call to
580 audio_init() since the mpeg thread takes the rest of the buffer space */
581 mp3_init( global_settings
.volume
,
582 global_settings
.bass
,
583 global_settings
.treble
,
584 global_settings
.balance
,
585 global_settings
.loudness
,
587 global_settings
.channel_config
,
588 global_settings
.stereo_width
,
589 global_settings
.mdb_strength
,
590 global_settings
.mdb_harmonics
,
591 global_settings
.mdb_center
,
592 global_settings
.mdb_shape
,
593 global_settings
.mdb_enable
,
594 global_settings
.superbass
);
596 /* audio_init must to know the size of voice buffer so init voice first */
598 #endif /* CONFIG_CODEC != SWCODEC */
602 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
606 /* runtime database has to be initialized after audio_init() */
610 car_adapter_mode_init();
612 #ifdef IPOD_ACCESSORY_PROTOCOL
613 iap_setup(global_settings
.serial_bitrate
);
615 #ifdef HAVE_ACCESSORY_SUPPLY
616 accessory_supply_set(global_settings
.accessory_supply
);
623 /* This is the entry point for the coprocessor
624 Anyone not running an upgraded bootloader will never reach this point,
625 so it should not be assumed that the coprocessor be usable even on
626 platforms which support it.
628 A kernel thread is initially setup on the coprocessor and immediately
629 destroyed for purposes of continuity. The cop sits idle until at least
630 one thread exists on it. */
632 /* 3G doesn't have Rolo or dual core support yet */
636 /* This should never be reached */