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 if (coldstart
&& charger_inserted()
426 && !global_settings
.car_adapter_mode
427 #ifdef ATA_POWER_PLAYERSTYLE
428 && !ide_powered() /* relies on probing result from bootloader */
432 rc
= charging_screen(); /* display a "charging" screen */
433 if (rc
== 1) /* charger removed */
435 /* "On" pressed or USB connected: proceed */
436 show_logo(); /* again, to provide better visual feedback */
443 #ifdef HAVE_LCD_BITMAP
446 snprintf(str
, 31, "ATA error: %d", rc
);
448 lcd_puts(0, 3, "Press ON to debug");
450 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
453 panicf("ata: %d", rc
);
456 #ifdef HAVE_EEPROM_SETTINGS
457 eeprom_settings_init();
460 #ifndef HAVE_USBSTACK
461 usb_start_monitoring();
462 while (usb_detect() == USB_INSERTED
)
464 #ifdef HAVE_EEPROM_SETTINGS
465 firmware_settings
.disk_clean
= false;
467 /* enter USB mode early, before trying to mount */
468 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
469 #if (CONFIG_STORAGE & STORAGE_MMC)
470 if (!mmc_touched() ||
471 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
475 mounted
= true; /* mounting done @ end of USB mode */
477 #ifdef HAVE_USB_POWER
478 if (usb_powered()) /* avoid deadlock */
486 rc
= disk_mount_all();
490 lcd_puts(0, 0, "No partition");
491 lcd_puts(0, 1, "found.");
492 #ifdef HAVE_LCD_BITMAP
493 lcd_puts(0, 2, "Insert USB cable");
494 lcd_puts(0, 3, "and fix it.");
498 while(button_get(true) != SYS_USB_CONNECTED
) {};
504 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
505 (CONFIG_KEYPAD == IRIVER_H10_PAD)
506 #ifdef SETTINGS_RESET
507 /* Reset settings if holding the reset button. (Rec on Archos,
509 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
511 /* Reset settings if the hold button is turned on */
515 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
520 settings_load(SETTINGS_ALL
);
522 if (init_dircache(true) < 0)
525 remove(TAGCACHE_STATEFILE
);
530 settings_apply(true);
531 init_dircache(false);
536 #ifdef HAVE_EEPROM_SETTINGS
537 if (firmware_settings
.initialized
)
539 /* In case we crash. */
540 firmware_settings
.disk_clean
= false;
541 eeprom_settings_store();
551 #if CONFIG_CODEC != SWCODEC
552 /* No buffer allocation (see buffer.c) may take place after the call to
553 audio_init() since the mpeg thread takes the rest of the buffer space */
554 mp3_init( global_settings
.volume
,
555 global_settings
.bass
,
556 global_settings
.treble
,
557 global_settings
.balance
,
558 global_settings
.loudness
,
560 global_settings
.channel_config
,
561 global_settings
.stereo_width
,
562 global_settings
.mdb_strength
,
563 global_settings
.mdb_harmonics
,
564 global_settings
.mdb_center
,
565 global_settings
.mdb_shape
,
566 global_settings
.mdb_enable
,
567 global_settings
.superbass
);
569 /* audio_init must to know the size of voice buffer so init voice first */
571 #endif /* CONFIG_CODEC != SWCODEC */
575 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
579 /* runtime database has to be initialized after audio_init() */
584 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
586 if(file_exists(filename
)) /* no complaint if it doesn't exist */
588 plugin_load((char*)filename
, NULL
); /* start if it does */
591 #endif /* #ifdef AUTOROCK */
594 car_adapter_mode_init();
596 #ifdef IPOD_ACCESSORY_PROTOCOL
597 iap_setup(global_settings
.serial_bitrate
);
599 #ifdef HAVE_ACCESSORY_SUPPLY
600 accessory_supply_set(global_settings
.accessory_supply
);
607 /* This is the entry point for the coprocessor
608 Anyone not running an upgraded bootloader will never reach this point,
609 so it should not be assumed that the coprocessor be usable even on
610 platforms which support it.
612 A kernel thread is initially setup on the coprocessor and immediately
613 destroyed for purposes of continuity. The cop sits idle until at least
614 one thread exists on it. */
616 /* 3G doesn't have Rolo or dual core support yet */
620 /* This should never be reached */
633 #if (CONFIG_LED == LED_REAL)
634 led(true); sleep(HZ
/10);
635 led(false); sleep(HZ
/10);