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 "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 #ifdef HAVE_TOUCHSCREEN
139 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
141 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
142 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
143 viewportmanager_statusbar_changed
);
145 /* All threads should be created and public queues registered by now */
146 usb_start_monitoring();
151 static int init_dircache(bool preinit
)
160 if (!global_settings
.dircache
)
163 # ifdef HAVE_EEPROM_SETTINGS
164 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
167 result
= dircache_load();
171 firmware_settings
.disk_clean
= false;
172 if (global_status
.dircache_size
<= 0)
174 /* This will be in default language, settings are not
175 applied yet. Not really any easy way to fix that. */
176 splash(0, str(LANG_SCANNING_DISK
));
180 dircache_build(global_status
.dircache_size
);
189 if (!dircache_is_enabled()
190 && !dircache_is_initializing())
192 if (global_status
.dircache_size
<= 0)
194 splash(0, str(LANG_SCANNING_DISK
));
197 result
= dircache_build(global_status
.dircache_size
);
202 /* Initialization of dircache failed. Manual action is
203 * necessary to enable dircache again.
205 splashf(0, "Dircache failed, disabled. Result: %d", result
);
206 global_settings
.dircache
= false;
215 global_status
.dircache_size
= dircache_get_cache_size();
227 static void init_tagcache(void)
233 while (!tagcache_is_initialized())
235 #ifdef HAVE_LCD_CHARCELLS
238 int ret
= tagcache_get_commit_step();
242 #if CONFIG_CODEC == SWCODEC
243 /* hwcodec can't use voice here, as the database commit
244 * uses the audio buffer. */
245 static long talked_tick
= 0;
246 if(global_settings
.talk_menu
248 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
250 talked_tick
= current_tick
;
251 talk_id(LANG_TAGCACHE_INIT
, false);
252 talk_number(ret
, true);
253 talk_id(VOICE_OF
, true);
254 talk_number(tagcache_get_max_commit_step(), true);
257 #ifdef HAVE_LCD_BITMAP
258 splashf(0, "%s [%d/%d]",
259 str(LANG_TAGCACHE_INIT
), ret
,
260 tagcache_get_max_commit_step());
262 lcd_double_height(false);
263 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
264 tagcache_get_max_commit_step());
284 static void init(void)
290 #ifdef HAVE_REMOTE_LCD
301 /* Must be done before any code uses the multi-screen APi */
302 gui_syncstatusbar_init(&statusbars
);
305 settings_load(SETTINGS_ALL
);
307 settings_apply(true);
309 init_dircache(false);
318 #if CONFIG_CODEC != SWCODEC
319 mp3_init( global_settings
.volume
,
320 global_settings
.bass
,
321 global_settings
.treble
,
322 global_settings
.balance
,
323 global_settings
.loudness
,
325 global_settings
.channel_config
,
326 global_settings
.stereo_width
,
327 global_settings
.mdb_strength
,
328 global_settings
.mdb_harmonics
,
329 global_settings
.mdb_center
,
330 global_settings
.mdb_shape
,
331 global_settings
.mdb_enable
,
332 global_settings
.superbass
);
334 /* audio_init must to know the size of voice buffer so init voice first */
336 #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 if (coldstart
&& charger_inserted()
427 && !global_settings
.car_adapter_mode
428 #ifdef ATA_POWER_PLAYERSTYLE
429 && !ide_powered() /* relies on probing result from bootloader */
433 rc
= charging_screen(); /* display a "charging" screen */
434 if (rc
== 1) /* charger removed */
436 /* "On" pressed or USB connected: proceed */
437 show_logo(); /* again, to provide better visual feedback */
444 #ifdef HAVE_LCD_BITMAP
447 snprintf(str
, 31, "ATA error: %d", rc
);
449 lcd_puts(0, 3, "Press ON to debug");
451 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
454 panicf("ata: %d", rc
);
457 #ifdef HAVE_EEPROM_SETTINGS
458 eeprom_settings_init();
461 #ifndef HAVE_USBSTACK
462 usb_start_monitoring();
463 while (usb_detect() == USB_INSERTED
)
465 #ifdef HAVE_EEPROM_SETTINGS
466 firmware_settings
.disk_clean
= false;
468 /* enter USB mode early, before trying to mount */
469 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
470 #if (CONFIG_STORAGE & STORAGE_MMC)
471 if (!mmc_touched() ||
472 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
476 mounted
= true; /* mounting done @ end of USB mode */
478 #ifdef HAVE_USB_POWER
479 if (usb_powered()) /* avoid deadlock */
487 rc
= disk_mount_all();
491 lcd_puts(0, 0, "No partition");
492 lcd_puts(0, 1, "found.");
493 #ifdef HAVE_LCD_BITMAP
494 lcd_puts(0, 2, "Insert USB cable");
495 lcd_puts(0, 3, "and fix it.");
499 while(button_get(true) != SYS_USB_CONNECTED
) {};
505 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
506 (CONFIG_KEYPAD == IRIVER_H10_PAD)
507 #ifdef SETTINGS_RESET
508 /* Reset settings if holding the reset button. (Rec on Archos,
510 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
512 /* Reset settings if the hold button is turned on */
516 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
521 settings_load(SETTINGS_ALL
);
523 if (init_dircache(true) < 0)
526 remove(TAGCACHE_STATEFILE
);
531 settings_apply(true);
532 init_dircache(false);
537 #ifdef HAVE_EEPROM_SETTINGS
538 if (firmware_settings
.initialized
)
540 /* In case we crash. */
541 firmware_settings
.disk_clean
= false;
542 eeprom_settings_store();
552 #if CONFIG_CODEC != SWCODEC
553 /* No buffer allocation (see buffer.c) may take place after the call to
554 audio_init() since the mpeg thread takes the rest of the buffer space */
555 mp3_init( global_settings
.volume
,
556 global_settings
.bass
,
557 global_settings
.treble
,
558 global_settings
.balance
,
559 global_settings
.loudness
,
561 global_settings
.channel_config
,
562 global_settings
.stereo_width
,
563 global_settings
.mdb_strength
,
564 global_settings
.mdb_harmonics
,
565 global_settings
.mdb_center
,
566 global_settings
.mdb_shape
,
567 global_settings
.mdb_enable
,
568 global_settings
.superbass
);
570 /* audio_init must to know the size of voice buffer so init voice first */
572 #endif /* CONFIG_CODEC != SWCODEC */
576 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
580 /* runtime database has to be initialized after audio_init() */
585 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
587 if(file_exists(filename
)) /* no complaint if it doesn't exist */
589 plugin_load((char*)filename
, NULL
); /* start if it does */
592 #endif /* #ifdef AUTOROCK */
595 car_adapter_mode_init();
597 #ifdef IPOD_ACCESSORY_PROTOCOL
598 iap_setup(global_settings
.serial_bitrate
);
600 #ifdef HAVE_ACCESSORY_SUPPLY
601 accessory_supply_set(global_settings
.accessory_supply
);
608 /* This is the entry point for the coprocessor
609 Anyone not running an upgraded bootloader will never reach this point,
610 so it should not be assumed that the coprocessor be usable even on
611 platforms which support it.
613 A kernel thread is initially setup on the coprocessor and immediately
614 destroyed for purposes of continuity. The cop sits idle until at least
615 one thread exists on it. */
617 /* 3G doesn't have Rolo or dual core support yet */
621 /* This should never be reached */
634 #if (CONFIG_LED == LED_REAL)
635 led(true); sleep(HZ
/10);
636 led(false); sleep(HZ
/10);