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(true);
142 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
143 viewportmanager_statusbar_changed
);
147 static int init_dircache(bool preinit
)
156 if (!global_settings
.dircache
)
159 # ifdef HAVE_EEPROM_SETTINGS
160 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
163 result
= dircache_load();
167 firmware_settings
.disk_clean
= false;
168 if (global_status
.dircache_size
<= 0)
170 /* This will be in default language, settings are not
171 applied yet. Not really any easy way to fix that. */
172 splash(0, str(LANG_SCANNING_DISK
));
176 dircache_build(global_status
.dircache_size
);
185 if (!dircache_is_enabled()
186 && !dircache_is_initializing())
188 if (global_status
.dircache_size
<= 0)
190 splash(0, str(LANG_SCANNING_DISK
));
193 result
= dircache_build(global_status
.dircache_size
);
198 /* Initialization of dircache failed. Manual action is
199 * necessary to enable dircache again.
201 splashf(0, "Dircache failed, disabled. Result: %d", result
);
202 global_settings
.dircache
= false;
211 global_status
.dircache_size
= dircache_get_cache_size();
223 static void init_tagcache(void)
229 while (!tagcache_is_initialized())
231 #ifdef HAVE_LCD_CHARCELLS
234 int ret
= tagcache_get_commit_step();
238 #if CONFIG_CODEC == SWCODEC
239 /* hwcodec can't use voice here, as the database commit
240 * uses the audio buffer. */
241 static long talked_tick
= 0;
242 if(global_settings
.talk_menu
244 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
246 talked_tick
= current_tick
;
247 talk_id(LANG_TAGCACHE_INIT
, false);
248 talk_number(ret
, true);
249 talk_id(VOICE_OF
, true);
250 talk_number(tagcache_get_max_commit_step(), true);
253 #ifdef HAVE_LCD_BITMAP
254 splashf(0, "%s [%d/%d]",
255 str(LANG_TAGCACHE_INIT
), ret
,
256 tagcache_get_max_commit_step());
258 lcd_double_height(false);
259 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
260 tagcache_get_max_commit_step());
280 static void init(void)
286 #ifdef HAVE_REMOTE_LCD
297 /* Must be done before any code uses the multi-screen APi */
298 gui_syncstatusbar_init(&statusbars
);
301 settings_load(SETTINGS_ALL
);
303 settings_apply(true);
305 init_dircache(false);
314 #if CONFIG_CODEC != SWCODEC
315 mp3_init( global_settings
.volume
,
316 global_settings
.bass
,
317 global_settings
.treble
,
318 global_settings
.balance
,
319 global_settings
.loudness
,
321 global_settings
.channel_config
,
322 global_settings
.stereo_width
,
323 global_settings
.mdb_strength
,
324 global_settings
.mdb_harmonics
,
325 global_settings
.mdb_center
,
326 global_settings
.mdb_shape
,
327 global_settings
.mdb_enable
,
328 global_settings
.superbass
);
330 /* audio_init must to know the size of voice buffer so init voice first */
332 #endif /* CONFIG_CODEC != SWCODEC */
338 button_clear_queue(); /* Empty the keyboard buffer */
343 static void init(void)
346 bool mounted
= false;
347 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
348 /* if nobody initialized ATA before, I consider this a cold start */
349 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
355 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
356 set_cpu_frequency(CPUFREQ_NORMAL
);
358 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
376 #ifdef HAVE_REMOTE_LCD
387 #if !defined(HAVE_FMADC) && !(CONFIG_STORAGE & STORAGE_MMC)
396 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
402 #if CONFIG_USBOTG == USBOTG_ISP1362
404 #elif CONFIG_USBOTG == USBOTG_M5636
418 /* Must be done before any code uses the multi-screen APi */
419 gui_syncstatusbar_init(&statusbars
);
421 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
422 if (coldstart
&& charger_inserted()
423 && !global_settings
.car_adapter_mode
424 #ifdef ATA_POWER_PLAYERSTYLE
425 && !ide_powered() /* relies on probing result from bootloader */
429 rc
= charging_screen(); /* display a "charging" screen */
430 if (rc
== 1) /* charger removed */
432 /* "On" pressed or USB connected: proceed */
433 show_logo(); /* again, to provide better visual feedback */
440 #ifdef HAVE_LCD_BITMAP
443 snprintf(str
, 31, "ATA error: %d", rc
);
445 lcd_puts(0, 3, "Press ON to debug");
447 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
450 panicf("ata: %d", rc
);
453 #ifdef HAVE_EEPROM_SETTINGS
454 eeprom_settings_init();
457 usb_start_monitoring();
458 #ifndef HAVE_USBSTACK
459 while (usb_detect() == USB_INSERTED
)
461 #ifdef HAVE_EEPROM_SETTINGS
462 firmware_settings
.disk_clean
= false;
464 /* enter USB mode early, before trying to mount */
465 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
466 #if (CONFIG_STORAGE & STORAGE_MMC)
467 if (!mmc_touched() ||
468 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
472 mounted
= true; /* mounting done @ end of USB mode */
474 #ifdef HAVE_USB_POWER
475 if (usb_powered()) /* avoid deadlock */
483 rc
= disk_mount_all();
487 lcd_puts(0, 0, "No partition");
488 lcd_puts(0, 1, "found.");
489 #ifdef HAVE_LCD_BITMAP
490 lcd_puts(0, 2, "Insert USB cable");
491 lcd_puts(0, 3, "and fix it.");
495 while(button_get(true) != SYS_USB_CONNECTED
) {};
501 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
502 (CONFIG_KEYPAD == IRIVER_H10_PAD)
503 #ifdef SETTINGS_RESET
504 /* Reset settings if holding the reset button. (Rec on Archos,
506 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
508 /* Reset settings if the hold button is turned on */
512 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
517 settings_load(SETTINGS_ALL
);
519 if (init_dircache(true) < 0)
522 remove(TAGCACHE_STATEFILE
);
527 settings_apply(true);
528 init_dircache(false);
533 #ifdef HAVE_EEPROM_SETTINGS
534 if (firmware_settings
.initialized
)
536 /* In case we crash. */
537 firmware_settings
.disk_clean
= false;
538 eeprom_settings_store();
548 #if CONFIG_CODEC != SWCODEC
549 /* No buffer allocation (see buffer.c) may take place after the call to
550 audio_init() since the mpeg thread takes the rest of the buffer space */
551 mp3_init( global_settings
.volume
,
552 global_settings
.bass
,
553 global_settings
.treble
,
554 global_settings
.balance
,
555 global_settings
.loudness
,
557 global_settings
.channel_config
,
558 global_settings
.stereo_width
,
559 global_settings
.mdb_strength
,
560 global_settings
.mdb_harmonics
,
561 global_settings
.mdb_center
,
562 global_settings
.mdb_shape
,
563 global_settings
.mdb_enable
,
564 global_settings
.superbass
);
566 /* audio_init must to know the size of voice buffer so init voice first */
568 #endif /* CONFIG_CODEC != SWCODEC */
572 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
576 /* runtime database has to be initialized after audio_init() */
581 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
583 if(file_exists(filename
)) /* no complaint if it doesn't exist */
585 plugin_load((char*)filename
, NULL
); /* start if it does */
588 #endif /* #ifdef AUTOROCK */
591 car_adapter_mode_init();
593 #ifdef IPOD_ACCESSORY_PROTOCOL
594 iap_setup(global_settings
.serial_bitrate
);
596 #ifdef HAVE_ACCESSORY_SUPPLY
597 accessory_supply_set(global_settings
.accessory_supply
);
604 /* This is the entry point for the coprocessor
605 Anyone not running an upgraded bootloader will never reach this point,
606 so it should not be assumed that the coprocessor be usable even on
607 platforms which support it.
609 A kernel thread is initially setup on the coprocessor and immediately
610 destroyed for purposes of continuity. The cop sits idle until at least
611 one thread exists on it. */
613 /* 3G doesn't have Rolo or dual core support yet */
617 /* This should never be reached */
630 #if (CONFIG_LED == LED_REAL)
631 led(true); sleep(HZ
/10);
632 led(false); sleep(HZ
/10);