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
);
144 static int init_dircache(bool preinit
)
153 if (!global_settings
.dircache
)
156 # ifdef HAVE_EEPROM_SETTINGS
157 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
160 result
= dircache_load();
164 firmware_settings
.disk_clean
= false;
165 if (global_status
.dircache_size
<= 0)
167 /* This will be in default language, settings are not
168 applied yet. Not really any easy way to fix that. */
169 splash(0, str(LANG_SCANNING_DISK
));
173 dircache_build(global_status
.dircache_size
);
182 if (!dircache_is_enabled()
183 && !dircache_is_initializing())
185 if (global_status
.dircache_size
<= 0)
187 splash(0, str(LANG_SCANNING_DISK
));
190 result
= dircache_build(global_status
.dircache_size
);
195 /* Initialization of dircache failed. Manual action is
196 * necessary to enable dircache again.
198 splashf(0, "Dircache failed, disabled. Result: %d", result
);
199 global_settings
.dircache
= false;
208 global_status
.dircache_size
= dircache_get_cache_size();
220 static void init_tagcache(void)
226 while (!tagcache_is_initialized())
228 #ifdef HAVE_LCD_CHARCELLS
231 int ret
= tagcache_get_commit_step();
235 #if CONFIG_CODEC == SWCODEC
236 /* hwcodec can't use voice here, as the database commit
237 * uses the audio buffer. */
238 static long talked_tick
= 0;
239 if(global_settings
.talk_menu
241 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
243 talked_tick
= current_tick
;
244 talk_id(LANG_TAGCACHE_INIT
, false);
245 talk_number(ret
, true);
246 talk_id(VOICE_OF
, true);
247 talk_number(tagcache_get_max_commit_step(), true);
250 #ifdef HAVE_LCD_BITMAP
251 splashf(0, "%s [%d/%d]",
252 str(LANG_TAGCACHE_INIT
), ret
,
253 tagcache_get_max_commit_step());
255 lcd_double_height(false);
256 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
257 tagcache_get_max_commit_step());
277 static void init(void)
283 #ifdef HAVE_REMOTE_LCD
294 /* Must be done before any code uses the multi-screen APi */
295 gui_syncstatusbar_init(&statusbars
);
298 settings_load(SETTINGS_ALL
);
300 settings_apply(true);
302 init_dircache(false);
311 #if CONFIG_CODEC != SWCODEC
312 mp3_init( global_settings
.volume
,
313 global_settings
.bass
,
314 global_settings
.treble
,
315 global_settings
.balance
,
316 global_settings
.loudness
,
318 global_settings
.channel_config
,
319 global_settings
.stereo_width
,
320 global_settings
.mdb_strength
,
321 global_settings
.mdb_harmonics
,
322 global_settings
.mdb_center
,
323 global_settings
.mdb_shape
,
324 global_settings
.mdb_enable
,
325 global_settings
.superbass
);
327 /* audio_init must to know the size of voice buffer so init voice first */
329 #endif /* CONFIG_CODEC != SWCODEC */
335 button_clear_queue(); /* Empty the keyboard buffer */
340 static void init(void)
343 bool mounted
= false;
344 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
345 /* if nobody initialized ATA before, I consider this a cold start */
346 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
352 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
353 set_cpu_frequency(CPUFREQ_NORMAL
);
355 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
373 #ifdef HAVE_REMOTE_LCD
384 #if !defined(HAVE_FMADC) && !(CONFIG_STORAGE & STORAGE_MMC)
393 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
399 #if CONFIG_USBOTG == USBOTG_ISP1362
401 #elif CONFIG_USBOTG == USBOTG_M5636
415 /* Must be done before any code uses the multi-screen APi */
416 gui_syncstatusbar_init(&statusbars
);
418 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
419 if (coldstart
&& charger_inserted()
420 && !global_settings
.car_adapter_mode
421 #ifdef ATA_POWER_PLAYERSTYLE
422 && !ide_powered() /* relies on probing result from bootloader */
426 rc
= charging_screen(); /* display a "charging" screen */
427 if (rc
== 1) /* charger removed */
429 /* "On" pressed or USB connected: proceed */
430 show_logo(); /* again, to provide better visual feedback */
437 #ifdef HAVE_LCD_BITMAP
440 snprintf(str
, 31, "ATA error: %d", rc
);
442 lcd_puts(0, 3, "Press ON to debug");
444 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
447 panicf("ata: %d", rc
);
450 #ifdef HAVE_EEPROM_SETTINGS
451 eeprom_settings_init();
454 usb_start_monitoring();
455 #ifndef HAVE_USBSTACK
456 while (usb_detect() == USB_INSERTED
)
458 #ifdef HAVE_EEPROM_SETTINGS
459 firmware_settings
.disk_clean
= false;
461 /* enter USB mode early, before trying to mount */
462 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
463 #if (CONFIG_STORAGE & STORAGE_MMC)
464 if (!mmc_touched() ||
465 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
469 mounted
= true; /* mounting done @ end of USB mode */
471 #ifdef HAVE_USB_POWER
472 if (usb_powered()) /* avoid deadlock */
480 rc
= disk_mount_all();
484 lcd_puts(0, 0, "No partition");
485 lcd_puts(0, 1, "found.");
486 #ifdef HAVE_LCD_BITMAP
487 lcd_puts(0, 2, "Insert USB cable");
488 lcd_puts(0, 3, "and fix it.");
492 while(button_get(true) != SYS_USB_CONNECTED
) {};
498 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
499 (CONFIG_KEYPAD == IRIVER_H10_PAD)
500 #ifdef SETTINGS_RESET
501 /* Reset settings if holding the reset button. (Rec on Archos,
503 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
505 /* Reset settings if the hold button is turned on */
509 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
514 settings_load(SETTINGS_ALL
);
516 if (init_dircache(true) < 0)
519 remove(TAGCACHE_STATEFILE
);
524 settings_apply(true);
525 init_dircache(false);
530 #ifdef HAVE_EEPROM_SETTINGS
531 if (firmware_settings
.initialized
)
533 /* In case we crash. */
534 firmware_settings
.disk_clean
= false;
535 eeprom_settings_store();
545 #if CONFIG_CODEC != SWCODEC
546 /* No buffer allocation (see buffer.c) may take place after the call to
547 audio_init() since the mpeg thread takes the rest of the buffer space */
548 mp3_init( global_settings
.volume
,
549 global_settings
.bass
,
550 global_settings
.treble
,
551 global_settings
.balance
,
552 global_settings
.loudness
,
554 global_settings
.channel_config
,
555 global_settings
.stereo_width
,
556 global_settings
.mdb_strength
,
557 global_settings
.mdb_harmonics
,
558 global_settings
.mdb_center
,
559 global_settings
.mdb_shape
,
560 global_settings
.mdb_enable
,
561 global_settings
.superbass
);
563 /* audio_init must to know the size of voice buffer so init voice first */
565 #endif /* CONFIG_CODEC != SWCODEC */
569 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
573 /* runtime database has to be initialized after audio_init() */
578 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
580 if(file_exists(filename
)) /* no complaint if it doesn't exist */
582 plugin_load((char*)filename
, NULL
); /* start if it does */
585 #endif /* #ifdef AUTOROCK */
588 car_adapter_mode_init();
590 #ifdef IPOD_ACCESSORY_PROTOCOL
591 iap_setup(global_settings
.serial_bitrate
);
593 #ifdef HAVE_ACCESSORY_SUPPLY
594 accessory_supply_set(global_settings
.accessory_supply
);
601 /* This is the entry point for the coprocessor
602 Anyone not running an upgraded bootloader will never reach this point,
603 so it should not be assumed that the coprocessor be usable even on
604 platforms which support it.
606 A kernel thread is initially setup on the coprocessor and immediately
607 destroyed for purposes of continuity. The cop sits idle until at least
608 one thread exists on it. */
610 /* 3G doesn't have Rolo or dual core support yet */
614 /* This should never be reached */
627 #if (CONFIG_LED == LED_REAL)
628 led(true); sleep(HZ
/10);
629 led(false); sleep(HZ
/10);