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"
72 #include "eeprom_settings.h"
73 #include "scrobbler.h"
76 #ifdef IPOD_ACCESSORY_PROTOCOL
80 #if (CONFIG_CODEC == SWCODEC)
83 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
84 #include "pcm_record.h"
88 #define SETTINGS_RESET BUTTON_REC
89 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
90 #define SETTINGS_RESET BUTTON_A
96 #if (CONFIG_STORAGE & STORAGE_MMC)
100 #ifdef HAVE_REMOTE_LCD
101 #include "lcd-remote.h"
104 #if CONFIG_USBOTG == USBOTG_ISP1362
108 #if CONFIG_USBOTG == USBOTG_M5636
112 #include "cuesheet.h"
115 #include "sim_tasks.h"
116 #include "system-sdl.h"
119 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
121 const char appsversion
[]=APPSVERSION
;
123 static void init(void);
128 static void app_main(void)
135 screens
[i
].clear_display();
139 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
140 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
141 viewportmanager_statusbar_changed
);
143 /* All threads should be created and public queues registered by now */
144 usb_start_monitoring();
149 static int init_dircache(bool preinit
)
158 if (!global_settings
.dircache
)
161 # ifdef HAVE_EEPROM_SETTINGS
162 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
165 result
= dircache_load();
169 firmware_settings
.disk_clean
= false;
170 if (global_status
.dircache_size
<= 0)
172 /* This will be in default language, settings are not
173 applied yet. Not really any easy way to fix that. */
174 splash(0, str(LANG_SCANNING_DISK
));
178 dircache_build(global_status
.dircache_size
);
187 if (!dircache_is_enabled()
188 && !dircache_is_initializing())
190 if (global_status
.dircache_size
<= 0)
192 splash(0, str(LANG_SCANNING_DISK
));
195 result
= dircache_build(global_status
.dircache_size
);
200 /* Initialization of dircache failed. Manual action is
201 * necessary to enable dircache again.
203 splashf(0, "Dircache failed, disabled. Result: %d", result
);
204 global_settings
.dircache
= false;
213 global_status
.dircache_size
= dircache_get_cache_size();
225 static void init_tagcache(void)
231 while (!tagcache_is_initialized())
233 #ifdef HAVE_LCD_CHARCELLS
236 int ret
= tagcache_get_commit_step();
240 #if CONFIG_CODEC == SWCODEC
241 /* hwcodec can't use voice here, as the database commit
242 * uses the audio buffer. */
243 static long talked_tick
= 0;
244 if(global_settings
.talk_menu
246 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
248 talked_tick
= current_tick
;
249 talk_id(LANG_TAGCACHE_INIT
, false);
250 talk_number(ret
, true);
251 talk_id(VOICE_OF
, true);
252 talk_number(tagcache_get_max_commit_step(), true);
255 #ifdef HAVE_LCD_BITMAP
256 splashf(0, "%s [%d/%d]",
257 str(LANG_TAGCACHE_INIT
), ret
,
258 tagcache_get_max_commit_step());
260 lcd_double_height(false);
261 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
262 tagcache_get_max_commit_step());
282 static void init(void)
288 #ifdef HAVE_REMOTE_LCD
300 /* Must be done before any code uses the multi-screen APi */
301 gui_syncstatusbar_init(&statusbars
);
304 settings_load(SETTINGS_ALL
);
306 settings_apply(true);
308 init_dircache(false);
317 #if CONFIG_CODEC != SWCODEC
318 mp3_init( global_settings
.volume
,
319 global_settings
.bass
,
320 global_settings
.treble
,
321 global_settings
.balance
,
322 global_settings
.loudness
,
324 global_settings
.channel_config
,
325 global_settings
.stereo_width
,
326 global_settings
.mdb_strength
,
327 global_settings
.mdb_harmonics
,
328 global_settings
.mdb_center
,
329 global_settings
.mdb_shape
,
330 global_settings
.mdb_enable
,
331 global_settings
.superbass
);
333 /* audio_init must to know the size of voice buffer so init voice first */
335 #endif /* CONFIG_CODEC != SWCODEC */
341 button_clear_queue(); /* Empty the keyboard buffer */
346 static void init(void)
349 bool mounted
= false;
350 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
351 /* if nobody initialized ATA before, I consider this a cold start */
352 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
358 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
359 set_cpu_frequency(CPUFREQ_NORMAL
);
361 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
379 #ifdef HAVE_REMOTE_LCD
399 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
405 #if CONFIG_USBOTG == USBOTG_ISP1362
407 #elif CONFIG_USBOTG == USBOTG_M5636
421 /* Must be done before any code uses the multi-screen APi */
422 gui_syncstatusbar_init(&statusbars
);
424 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
425 /* charger_inserted() can't be used here because power_thread()
426 hasn't checked power_input_status() yet */
427 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
428 && !global_settings
.car_adapter_mode
429 #ifdef ATA_POWER_PLAYERSTYLE
430 && !ide_powered() /* relies on probing result from bootloader */
434 rc
= charging_screen(); /* display a "charging" screen */
435 if (rc
== 1) /* charger removed */
437 /* "On" pressed or USB connected: proceed */
438 show_logo(); /* again, to provide better visual feedback */
445 #ifdef HAVE_LCD_BITMAP
448 snprintf(str
, 31, "ATA error: %d", rc
);
450 lcd_puts(0, 3, "Press ON to debug");
452 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
455 panicf("ata: %d", rc
);
458 #ifdef HAVE_EEPROM_SETTINGS
459 eeprom_settings_init();
462 #ifndef HAVE_USBSTACK
463 usb_start_monitoring();
464 while (usb_detect() == USB_INSERTED
)
466 #ifdef HAVE_EEPROM_SETTINGS
467 firmware_settings
.disk_clean
= false;
469 /* enter USB mode early, before trying to mount */
470 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
471 #if (CONFIG_STORAGE & STORAGE_MMC)
472 if (!mmc_touched() ||
473 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
477 mounted
= true; /* mounting done @ end of USB mode */
479 #ifdef HAVE_USB_POWER
480 if (usb_powered()) /* avoid deadlock */
488 rc
= disk_mount_all();
492 lcd_puts(0, 0, "No partition");
493 lcd_puts(0, 1, "found.");
494 #ifdef HAVE_LCD_BITMAP
495 lcd_puts(0, 2, "Insert USB cable");
496 lcd_puts(0, 3, "and fix it.");
500 while(button_get(true) != SYS_USB_CONNECTED
) {};
506 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
507 (CONFIG_KEYPAD == IRIVER_H10_PAD)
508 #ifdef SETTINGS_RESET
509 /* Reset settings if holding the reset button. (Rec on Archos,
511 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
513 /* Reset settings if the hold button is turned on */
517 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
522 settings_load(SETTINGS_ALL
);
524 if (init_dircache(true) < 0)
527 remove(TAGCACHE_STATEFILE
);
532 settings_apply(true);
533 init_dircache(false);
538 #ifdef HAVE_EEPROM_SETTINGS
539 if (firmware_settings
.initialized
)
541 /* In case we crash. */
542 firmware_settings
.disk_clean
= false;
543 eeprom_settings_store();
553 #if CONFIG_CODEC != SWCODEC
554 /* No buffer allocation (see buffer.c) may take place after the call to
555 audio_init() since the mpeg thread takes the rest of the buffer space */
556 mp3_init( global_settings
.volume
,
557 global_settings
.bass
,
558 global_settings
.treble
,
559 global_settings
.balance
,
560 global_settings
.loudness
,
562 global_settings
.channel_config
,
563 global_settings
.stereo_width
,
564 global_settings
.mdb_strength
,
565 global_settings
.mdb_harmonics
,
566 global_settings
.mdb_center
,
567 global_settings
.mdb_shape
,
568 global_settings
.mdb_enable
,
569 global_settings
.superbass
);
571 /* audio_init must to know the size of voice buffer so init voice first */
573 #endif /* CONFIG_CODEC != SWCODEC */
577 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
581 /* runtime database has to be initialized after audio_init() */
586 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
588 if(file_exists(filename
)) /* no complaint if it doesn't exist */
590 plugin_load((char*)filename
, NULL
); /* start if it does */
593 #endif /* #ifdef AUTOROCK */
596 car_adapter_mode_init();
598 #ifdef IPOD_ACCESSORY_PROTOCOL
599 iap_setup(global_settings
.serial_bitrate
);
601 #ifdef HAVE_ACCESSORY_SUPPLY
602 accessory_supply_set(global_settings
.accessory_supply
);
609 /* This is the entry point for the coprocessor
610 Anyone not running an upgraded bootloader will never reach this point,
611 so it should not be assumed that the coprocessor be usable even on
612 platforms which support it.
614 A kernel thread is initially setup on the coprocessor and immediately
615 destroyed for purposes of continuity. The cop sits idle until at least
616 one thread exists on it. */
618 /* 3G doesn't have Rolo or dual core support yet */
622 /* This should never be reached */
635 #if (CONFIG_LED == LED_REAL)
636 led(true); sleep(HZ
/10);
637 led(false); sleep(HZ
/10);