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)
84 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
85 #include "pcm_record.h"
89 #define SETTINGS_RESET BUTTON_REC
90 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
91 #define SETTINGS_RESET BUTTON_A
97 #if (CONFIG_STORAGE & STORAGE_MMC)
101 #ifdef HAVE_REMOTE_LCD
102 #include "lcd-remote.h"
105 #if CONFIG_USBOTG == USBOTG_ISP1362
109 #if CONFIG_USBOTG == USBOTG_M5636
114 #include "sim_tasks.h"
115 #include "system-sdl.h"
118 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
120 const char appsversion
[]=APPSVERSION
;
122 static void init(void);
127 static void app_main(void)
134 screens
[i
].clear_display();
138 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
139 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
140 viewportmanager_statusbar_changed
);
142 /* All threads should be created and public queues registered by now */
143 usb_start_monitoring();
148 static int init_dircache(bool preinit
)
157 if (!global_settings
.dircache
)
160 # ifdef HAVE_EEPROM_SETTINGS
161 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
164 result
= dircache_load();
168 firmware_settings
.disk_clean
= false;
169 if (global_status
.dircache_size
<= 0)
171 /* This will be in default language, settings are not
172 applied yet. Not really any easy way to fix that. */
173 splash(0, str(LANG_SCANNING_DISK
));
177 dircache_build(global_status
.dircache_size
);
186 if (!dircache_is_enabled()
187 && !dircache_is_initializing())
189 if (global_status
.dircache_size
<= 0)
191 splash(0, str(LANG_SCANNING_DISK
));
194 result
= dircache_build(global_status
.dircache_size
);
199 /* Initialization of dircache failed. Manual action is
200 * necessary to enable dircache again.
202 splashf(0, "Dircache failed, disabled. Result: %d", result
);
203 global_settings
.dircache
= false;
212 global_status
.dircache_size
= dircache_get_cache_size();
224 static void init_tagcache(void)
230 while (!tagcache_is_initialized())
232 #ifdef HAVE_LCD_CHARCELLS
235 int ret
= tagcache_get_commit_step();
239 #if CONFIG_CODEC == SWCODEC
240 /* hwcodec can't use voice here, as the database commit
241 * uses the audio buffer. */
242 static long talked_tick
= 0;
243 if(global_settings
.talk_menu
245 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
247 talked_tick
= current_tick
;
248 talk_id(LANG_TAGCACHE_INIT
, false);
249 talk_number(ret
, true);
250 talk_id(VOICE_OF
, true);
251 talk_number(tagcache_get_max_commit_step(), true);
254 #ifdef HAVE_LCD_BITMAP
255 splashf(0, "%s [%d/%d]",
256 str(LANG_TAGCACHE_INIT
), ret
,
257 tagcache_get_max_commit_step());
259 lcd_double_height(false);
260 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
261 tagcache_get_max_commit_step());
281 static void init(void)
287 #ifdef HAVE_REMOTE_LCD
299 /* Must be done before any code uses the multi-screen APi */
300 gui_syncstatusbar_init(&statusbars
);
303 settings_load(SETTINGS_ALL
);
305 settings_apply(true);
307 init_dircache(false);
316 #if CONFIG_CODEC != SWCODEC
317 mp3_init( global_settings
.volume
,
318 global_settings
.bass
,
319 global_settings
.treble
,
320 global_settings
.balance
,
321 global_settings
.loudness
,
323 global_settings
.channel_config
,
324 global_settings
.stereo_width
,
325 global_settings
.mdb_strength
,
326 global_settings
.mdb_harmonics
,
327 global_settings
.mdb_center
,
328 global_settings
.mdb_shape
,
329 global_settings
.mdb_enable
,
330 global_settings
.superbass
);
332 /* audio_init must to know the size of voice buffer so init voice first */
334 #endif /* CONFIG_CODEC != SWCODEC */
337 #if CONFIG_CODEC == SWCODEC
339 #endif /* CONFIG_CODEC == SWCODEC */
342 button_clear_queue(); /* Empty the keyboard buffer */
347 static void init(void)
350 bool mounted
= false;
351 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
352 /* if nobody initialized ATA before, I consider this a cold start */
353 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
359 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
360 set_cpu_frequency(CPUFREQ_NORMAL
);
362 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
380 #ifdef HAVE_REMOTE_LCD
400 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
406 #if CONFIG_USBOTG == USBOTG_ISP1362
408 #elif CONFIG_USBOTG == USBOTG_M5636
422 /* Must be done before any code uses the multi-screen APi */
423 gui_syncstatusbar_init(&statusbars
);
425 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
426 /* charger_inserted() can't be used here because power_thread()
427 hasn't checked power_input_status() yet */
428 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
429 && !global_settings
.car_adapter_mode
430 #ifdef ATA_POWER_PLAYERSTYLE
431 && !ide_powered() /* relies on probing result from bootloader */
435 rc
= charging_screen(); /* display a "charging" screen */
436 if (rc
== 1) /* charger removed */
438 /* "On" pressed or USB connected: proceed */
439 show_logo(); /* again, to provide better visual feedback */
446 #ifdef HAVE_LCD_BITMAP
449 snprintf(str
, 31, "ATA error: %d", rc
);
451 lcd_puts(0, 3, "Press ON to debug");
453 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
456 panicf("ata: %d", rc
);
459 #ifdef HAVE_EEPROM_SETTINGS
460 eeprom_settings_init();
463 #ifndef HAVE_USBSTACK
464 usb_start_monitoring();
465 while (usb_detect() == USB_INSERTED
)
467 #ifdef HAVE_EEPROM_SETTINGS
468 firmware_settings
.disk_clean
= false;
470 /* enter USB mode early, before trying to mount */
471 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
472 #if (CONFIG_STORAGE & STORAGE_MMC)
473 if (!mmc_touched() ||
474 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
478 mounted
= true; /* mounting done @ end of USB mode */
480 #ifdef HAVE_USB_POWER
481 if (usb_powered()) /* avoid deadlock */
489 rc
= disk_mount_all();
493 lcd_puts(0, 0, "No partition");
494 lcd_puts(0, 1, "found.");
495 #ifdef HAVE_LCD_BITMAP
496 lcd_puts(0, 2, "Insert USB cable");
497 lcd_puts(0, 3, "and fix it.");
501 while(button_get(true) != SYS_USB_CONNECTED
) {};
507 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
508 (CONFIG_KEYPAD == IRIVER_H10_PAD)
509 #ifdef SETTINGS_RESET
510 /* Reset settings if holding the reset button. (Rec on Archos,
512 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
514 /* Reset settings if the hold button is turned on */
518 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
523 settings_load(SETTINGS_ALL
);
525 if (init_dircache(true) < 0)
528 remove(TAGCACHE_STATEFILE
);
533 settings_apply(true);
534 init_dircache(false);
539 #ifdef HAVE_EEPROM_SETTINGS
540 if (firmware_settings
.initialized
)
542 /* In case we crash. */
543 firmware_settings
.disk_clean
= false;
544 eeprom_settings_store();
552 #if CONFIG_CODEC == SWCODEC
554 #endif /* CONFIG_CODEC == SWCODEC */
556 #if CONFIG_CODEC != SWCODEC
557 /* No buffer allocation (see buffer.c) may take place after the call to
558 audio_init() since the mpeg thread takes the rest of the buffer space */
559 mp3_init( global_settings
.volume
,
560 global_settings
.bass
,
561 global_settings
.treble
,
562 global_settings
.balance
,
563 global_settings
.loudness
,
565 global_settings
.channel_config
,
566 global_settings
.stereo_width
,
567 global_settings
.mdb_strength
,
568 global_settings
.mdb_harmonics
,
569 global_settings
.mdb_center
,
570 global_settings
.mdb_shape
,
571 global_settings
.mdb_enable
,
572 global_settings
.superbass
);
574 /* audio_init must to know the size of voice buffer so init voice first */
576 #endif /* CONFIG_CODEC != SWCODEC */
580 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
584 /* runtime database has to be initialized after audio_init() */
589 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
591 if(file_exists(filename
)) /* no complaint if it doesn't exist */
593 plugin_load((char*)filename
, NULL
); /* start if it does */
596 #endif /* #ifdef AUTOROCK */
599 car_adapter_mode_init();
601 #ifdef IPOD_ACCESSORY_PROTOCOL
602 iap_setup(global_settings
.serial_bitrate
);
604 #ifdef HAVE_ACCESSORY_SUPPLY
605 accessory_supply_set(global_settings
.accessory_supply
);
612 /* This is the entry point for the coprocessor
613 Anyone not running an upgraded bootloader will never reach this point,
614 so it should not be assumed that the coprocessor be usable even on
615 platforms which support it.
617 A kernel thread is initially setup on the coprocessor and immediately
618 destroyed for purposes of continuity. The cop sits idle until at least
619 one thread exists on it. */
621 /* 3G doesn't have Rolo or dual core support yet */
625 /* This should never be reached */
638 #if (CONFIG_LED == LED_REAL)
639 led(true); sleep(HZ
/10);
640 led(false); sleep(HZ
/10);