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 #ifdef HAVE_TOUCHSCREEN
140 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
142 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
143 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
144 viewportmanager_statusbar_changed
);
146 /* All threads should be created and public queues registered by now */
147 usb_start_monitoring();
152 static int init_dircache(bool preinit
)
161 if (!global_settings
.dircache
)
164 # ifdef HAVE_EEPROM_SETTINGS
165 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
168 result
= dircache_load();
172 firmware_settings
.disk_clean
= false;
173 if (global_status
.dircache_size
<= 0)
175 /* This will be in default language, settings are not
176 applied yet. Not really any easy way to fix that. */
177 splash(0, str(LANG_SCANNING_DISK
));
181 dircache_build(global_status
.dircache_size
);
190 if (!dircache_is_enabled()
191 && !dircache_is_initializing())
193 if (global_status
.dircache_size
<= 0)
195 splash(0, str(LANG_SCANNING_DISK
));
198 result
= dircache_build(global_status
.dircache_size
);
203 /* Initialization of dircache failed. Manual action is
204 * necessary to enable dircache again.
206 splashf(0, "Dircache failed, disabled. Result: %d", result
);
207 global_settings
.dircache
= false;
216 global_status
.dircache_size
= dircache_get_cache_size();
228 static void init_tagcache(void)
234 while (!tagcache_is_initialized())
236 #ifdef HAVE_LCD_CHARCELLS
239 int ret
= tagcache_get_commit_step();
243 #if CONFIG_CODEC == SWCODEC
244 /* hwcodec can't use voice here, as the database commit
245 * uses the audio buffer. */
246 static long talked_tick
= 0;
247 if(global_settings
.talk_menu
249 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
251 talked_tick
= current_tick
;
252 talk_id(LANG_TAGCACHE_INIT
, false);
253 talk_number(ret
, true);
254 talk_id(VOICE_OF
, true);
255 talk_number(tagcache_get_max_commit_step(), true);
258 #ifdef HAVE_LCD_BITMAP
259 splashf(0, "%s [%d/%d]",
260 str(LANG_TAGCACHE_INIT
), ret
,
261 tagcache_get_max_commit_step());
263 lcd_double_height(false);
264 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
265 tagcache_get_max_commit_step());
285 static void init(void)
291 #ifdef HAVE_REMOTE_LCD
303 /* Must be done before any code uses the multi-screen APi */
304 gui_syncstatusbar_init(&statusbars
);
307 settings_load(SETTINGS_ALL
);
309 settings_apply(true);
311 init_dircache(false);
320 #if CONFIG_CODEC != SWCODEC
321 mp3_init( global_settings
.volume
,
322 global_settings
.bass
,
323 global_settings
.treble
,
324 global_settings
.balance
,
325 global_settings
.loudness
,
327 global_settings
.channel_config
,
328 global_settings
.stereo_width
,
329 global_settings
.mdb_strength
,
330 global_settings
.mdb_harmonics
,
331 global_settings
.mdb_center
,
332 global_settings
.mdb_shape
,
333 global_settings
.mdb_enable
,
334 global_settings
.superbass
);
336 /* audio_init must to know the size of voice buffer so init voice first */
338 #endif /* CONFIG_CODEC != SWCODEC */
344 button_clear_queue(); /* Empty the keyboard buffer */
349 static void init(void)
352 bool mounted
= false;
353 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
354 /* if nobody initialized ATA before, I consider this a cold start */
355 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
361 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
362 set_cpu_frequency(CPUFREQ_NORMAL
);
364 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
382 #ifdef HAVE_REMOTE_LCD
402 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
408 #if CONFIG_USBOTG == USBOTG_ISP1362
410 #elif CONFIG_USBOTG == USBOTG_M5636
424 /* Must be done before any code uses the multi-screen APi */
425 gui_syncstatusbar_init(&statusbars
);
427 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
428 if (coldstart
&& charger_inserted()
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();
554 #if CONFIG_CODEC != SWCODEC
555 /* No buffer allocation (see buffer.c) may take place after the call to
556 audio_init() since the mpeg thread takes the rest of the buffer space */
557 mp3_init( global_settings
.volume
,
558 global_settings
.bass
,
559 global_settings
.treble
,
560 global_settings
.balance
,
561 global_settings
.loudness
,
563 global_settings
.channel_config
,
564 global_settings
.stereo_width
,
565 global_settings
.mdb_strength
,
566 global_settings
.mdb_harmonics
,
567 global_settings
.mdb_center
,
568 global_settings
.mdb_shape
,
569 global_settings
.mdb_enable
,
570 global_settings
.superbass
);
572 /* audio_init must to know the size of voice buffer so init voice first */
574 #endif /* CONFIG_CODEC != SWCODEC */
578 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
582 /* runtime database has to be initialized after audio_init() */
587 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
589 if(file_exists(filename
)) /* no complaint if it doesn't exist */
591 plugin_load((char*)filename
, NULL
); /* start if it does */
594 #endif /* #ifdef AUTOROCK */
597 car_adapter_mode_init();
599 #ifdef IPOD_ACCESSORY_PROTOCOL
600 iap_setup(global_settings
.serial_bitrate
);
602 #ifdef HAVE_ACCESSORY_SUPPLY
603 accessory_supply_set(global_settings
.accessory_supply
);
610 /* This is the entry point for the coprocessor
611 Anyone not running an upgraded bootloader will never reach this point,
612 so it should not be assumed that the coprocessor be usable even on
613 platforms which support it.
615 A kernel thread is initially setup on the coprocessor and immediately
616 destroyed for purposes of continuity. The cop sits idle until at least
617 one thread exists on it. */
619 /* 3G doesn't have Rolo or dual core support yet */
623 /* This should never be reached */
636 #if (CONFIG_LED == LED_REAL)
637 led(true); sleep(HZ
/10);
638 led(false); sleep(HZ
/10);