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)
84 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
85 #include "pcm_record.h"
89 #define SETTINGS_RESET BUTTON_REC
90 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
91 #define SETTINGS_RESET BUTTON_A
97 #if (CONFIG_STORAGE & STORAGE_MMC)
101 #ifdef HAVE_REMOTE_LCD
102 #include "lcd-remote.h"
105 #if CONFIG_USBOTG == USBOTG_ISP1362
109 #if CONFIG_USBOTG == USBOTG_M5636
113 #include "cuesheet.h"
116 #include "sim_tasks.h"
117 #include "system-sdl.h"
120 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
122 const char appsversion
[]=APPSVERSION
;
124 static void init(void);
129 static void app_main(void)
136 screens
[i
].clear_display();
140 viewportmanager_set_statusbar(VP_SB_ALLSCREENS
);
141 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
142 viewportmanager_statusbar_changed
);
144 /* All threads should be created and public queues registered by now */
145 usb_start_monitoring();
150 static int init_dircache(bool preinit
)
159 if (!global_settings
.dircache
)
162 # ifdef HAVE_EEPROM_SETTINGS
163 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
166 result
= dircache_load();
170 firmware_settings
.disk_clean
= false;
171 if (global_status
.dircache_size
<= 0)
173 /* This will be in default language, settings are not
174 applied yet. Not really any easy way to fix that. */
175 splash(0, str(LANG_SCANNING_DISK
));
179 dircache_build(global_status
.dircache_size
);
188 if (!dircache_is_enabled()
189 && !dircache_is_initializing())
191 if (global_status
.dircache_size
<= 0)
193 splash(0, str(LANG_SCANNING_DISK
));
196 result
= dircache_build(global_status
.dircache_size
);
201 /* Initialization of dircache failed. Manual action is
202 * necessary to enable dircache again.
204 splashf(0, "Dircache failed, disabled. Result: %d", result
);
205 global_settings
.dircache
= false;
214 global_status
.dircache_size
= dircache_get_cache_size();
226 static void init_tagcache(void)
232 while (!tagcache_is_initialized())
234 #ifdef HAVE_LCD_CHARCELLS
237 int ret
= tagcache_get_commit_step();
241 #if CONFIG_CODEC == SWCODEC
242 /* hwcodec can't use voice here, as the database commit
243 * uses the audio buffer. */
244 static long talked_tick
= 0;
245 if(global_settings
.talk_menu
247 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
249 talked_tick
= current_tick
;
250 talk_id(LANG_TAGCACHE_INIT
, false);
251 talk_number(ret
, true);
252 talk_id(VOICE_OF
, true);
253 talk_number(tagcache_get_max_commit_step(), true);
256 #ifdef HAVE_LCD_BITMAP
257 splashf(0, "%s [%d/%d]",
258 str(LANG_TAGCACHE_INIT
), ret
,
259 tagcache_get_max_commit_step());
261 lcd_double_height(false);
262 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
263 tagcache_get_max_commit_step());
283 static void init(void)
289 #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 */
340 #if CONFIG_CODEC == SWCODEC
342 #endif /* CONFIG_CODEC == SWCODEC */
345 button_clear_queue(); /* Empty the keyboard buffer */
350 static void init(void)
353 bool mounted
= false;
354 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
355 /* if nobody initialized ATA before, I consider this a cold start */
356 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
362 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
363 set_cpu_frequency(CPUFREQ_NORMAL
);
365 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
383 #ifdef HAVE_REMOTE_LCD
403 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
409 #if CONFIG_USBOTG == USBOTG_ISP1362
411 #elif CONFIG_USBOTG == USBOTG_M5636
425 /* Must be done before any code uses the multi-screen APi */
426 gui_syncstatusbar_init(&statusbars
);
428 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
429 /* charger_inserted() can't be used here because power_thread()
430 hasn't checked power_input_status() yet */
431 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
432 && !global_settings
.car_adapter_mode
433 #ifdef ATA_POWER_PLAYERSTYLE
434 && !ide_powered() /* relies on probing result from bootloader */
438 rc
= charging_screen(); /* display a "charging" screen */
439 if (rc
== 1) /* charger removed */
441 /* "On" pressed or USB connected: proceed */
442 show_logo(); /* again, to provide better visual feedback */
449 #ifdef HAVE_LCD_BITMAP
452 snprintf(str
, 31, "ATA error: %d", rc
);
454 lcd_puts(0, 3, "Press ON to debug");
456 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
459 panicf("ata: %d", rc
);
462 #ifdef HAVE_EEPROM_SETTINGS
463 eeprom_settings_init();
466 #ifndef HAVE_USBSTACK
467 usb_start_monitoring();
468 while (usb_detect() == USB_INSERTED
)
470 #ifdef HAVE_EEPROM_SETTINGS
471 firmware_settings
.disk_clean
= false;
473 /* enter USB mode early, before trying to mount */
474 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
475 #if (CONFIG_STORAGE & STORAGE_MMC)
476 if (!mmc_touched() ||
477 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
481 mounted
= true; /* mounting done @ end of USB mode */
483 #ifdef HAVE_USB_POWER
484 if (usb_powered()) /* avoid deadlock */
492 rc
= disk_mount_all();
496 lcd_puts(0, 0, "No partition");
497 lcd_puts(0, 1, "found.");
498 #ifdef HAVE_LCD_BITMAP
499 lcd_puts(0, 2, "Insert USB cable");
500 lcd_puts(0, 3, "and fix it.");
504 while(button_get(true) != SYS_USB_CONNECTED
) {};
510 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
511 (CONFIG_KEYPAD == IRIVER_H10_PAD)
512 #ifdef SETTINGS_RESET
513 /* Reset settings if holding the reset button. (Rec on Archos,
515 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
517 /* Reset settings if the hold button is turned on */
521 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
526 settings_load(SETTINGS_ALL
);
528 if (init_dircache(true) < 0)
531 remove(TAGCACHE_STATEFILE
);
536 settings_apply(true);
537 init_dircache(false);
542 #ifdef HAVE_EEPROM_SETTINGS
543 if (firmware_settings
.initialized
)
545 /* In case we crash. */
546 firmware_settings
.disk_clean
= false;
547 eeprom_settings_store();
556 #if CONFIG_CODEC == SWCODEC
558 #endif /* CONFIG_CODEC == SWCODEC */
560 #if CONFIG_CODEC != SWCODEC
561 /* No buffer allocation (see buffer.c) may take place after the call to
562 audio_init() since the mpeg thread takes the rest of the buffer space */
563 mp3_init( global_settings
.volume
,
564 global_settings
.bass
,
565 global_settings
.treble
,
566 global_settings
.balance
,
567 global_settings
.loudness
,
569 global_settings
.channel_config
,
570 global_settings
.stereo_width
,
571 global_settings
.mdb_strength
,
572 global_settings
.mdb_harmonics
,
573 global_settings
.mdb_center
,
574 global_settings
.mdb_shape
,
575 global_settings
.mdb_enable
,
576 global_settings
.superbass
);
578 /* audio_init must to know the size of voice buffer so init voice first */
580 #endif /* CONFIG_CODEC != SWCODEC */
584 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
588 /* runtime database has to be initialized after audio_init() */
593 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
595 if(file_exists(filename
)) /* no complaint if it doesn't exist */
597 plugin_load((char*)filename
, NULL
); /* start if it does */
600 #endif /* #ifdef AUTOROCK */
603 car_adapter_mode_init();
605 #ifdef IPOD_ACCESSORY_PROTOCOL
606 iap_setup(global_settings
.serial_bitrate
);
608 #ifdef HAVE_ACCESSORY_SUPPLY
609 accessory_supply_set(global_settings
.accessory_supply
);
616 /* This is the entry point for the coprocessor
617 Anyone not running an upgraded bootloader will never reach this point,
618 so it should not be assumed that the coprocessor be usable even on
619 platforms which support it.
621 A kernel thread is initially setup on the coprocessor and immediately
622 destroyed for purposes of continuity. The cop sits idle until at least
623 one thread exists on it. */
625 /* 3G doesn't have Rolo or dual core support yet */
629 /* This should never be reached */
642 #if (CONFIG_LED == LED_REAL)
643 led(true); sleep(HZ
/10);
644 led(false); sleep(HZ
/10);