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"
77 #ifdef IPOD_ACCESSORY_PROTOCOL
81 #if (CONFIG_CODEC == SWCODEC)
85 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
86 #include "pcm_record.h"
90 #define SETTINGS_RESET BUTTON_REC
91 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
92 #define SETTINGS_RESET BUTTON_A
98 #if (CONFIG_STORAGE & STORAGE_MMC)
102 #ifdef HAVE_REMOTE_LCD
103 #include "lcd-remote.h"
106 #if CONFIG_USBOTG == USBOTG_ISP1362
110 #if CONFIG_USBOTG == USBOTG_M5636
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 gui_syncstatusbar_init(&statusbars
);
140 viewportmanager_init();
142 /* All threads should be created and public queues registered by now */
143 usb_start_monitoring();
148 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
150 if(file_exists(filename
)) /* no complaint if it doesn't exist */
152 plugin_load((char*)filename
, NULL
); /* start if it does */
155 #endif /* #ifdef AUTOROCK */
160 static int init_dircache(bool preinit
)
169 if (!global_settings
.dircache
)
172 # ifdef HAVE_EEPROM_SETTINGS
173 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
176 result
= dircache_load();
180 firmware_settings
.disk_clean
= false;
181 if (global_status
.dircache_size
<= 0)
183 /* This will be in default language, settings are not
184 applied yet. Not really any easy way to fix that. */
185 splash(0, str(LANG_SCANNING_DISK
));
189 dircache_build(global_status
.dircache_size
);
198 if (!dircache_is_enabled()
199 && !dircache_is_initializing())
201 if (global_status
.dircache_size
<= 0)
203 splash(0, str(LANG_SCANNING_DISK
));
206 result
= dircache_build(global_status
.dircache_size
);
211 /* Initialization of dircache failed. Manual action is
212 * necessary to enable dircache again.
214 splashf(0, "Dircache failed, disabled. Result: %d", result
);
215 global_settings
.dircache
= false;
223 global_status
.dircache_size
= dircache_get_cache_size();
235 static void init_tagcache(void)
241 while (!tagcache_is_initialized())
243 #ifdef HAVE_LCD_CHARCELLS
246 int ret
= tagcache_get_commit_step();
250 #if CONFIG_CODEC == SWCODEC
251 /* hwcodec can't use voice here, as the database commit
252 * uses the audio buffer. */
253 static long talked_tick
= 0;
254 if(global_settings
.talk_menu
256 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
258 talked_tick
= current_tick
;
259 talk_id(LANG_TAGCACHE_INIT
, false);
260 talk_number(ret
, true);
261 talk_id(VOICE_OF
, true);
262 talk_number(tagcache_get_max_commit_step(), true);
265 #ifdef HAVE_LCD_BITMAP
266 splashf(0, "%s [%d/%d]",
267 str(LANG_TAGCACHE_INIT
), ret
,
268 tagcache_get_max_commit_step());
270 lcd_double_height(false);
271 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
272 tagcache_get_max_commit_step());
292 static void init(void)
298 #ifdef HAVE_REMOTE_LCD
312 settings_load(SETTINGS_ALL
);
314 settings_apply(true);
316 init_dircache(false);
325 #if CONFIG_CODEC != SWCODEC
326 mp3_init( global_settings
.volume
,
327 global_settings
.bass
,
328 global_settings
.treble
,
329 global_settings
.balance
,
330 global_settings
.loudness
,
332 global_settings
.channel_config
,
333 global_settings
.stereo_width
,
334 global_settings
.mdb_strength
,
335 global_settings
.mdb_harmonics
,
336 global_settings
.mdb_center
,
337 global_settings
.mdb_shape
,
338 global_settings
.mdb_enable
,
339 global_settings
.superbass
);
341 /* audio_init must to know the size of voice buffer so init voice first */
343 #endif /* CONFIG_CODEC != SWCODEC */
346 #if CONFIG_CODEC == SWCODEC
348 #endif /* CONFIG_CODEC == SWCODEC */
351 button_clear_queue(); /* Empty the keyboard buffer */
356 static void init(void)
359 bool mounted
= false;
360 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
361 /* if nobody initialized ATA before, I consider this a cold start */
362 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
368 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
369 set_cpu_frequency(CPUFREQ_NORMAL
);
371 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
389 #ifdef HAVE_REMOTE_LCD
409 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
415 #if CONFIG_USBOTG == USBOTG_ISP1362
417 #elif CONFIG_USBOTG == USBOTG_M5636
431 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
432 /* charger_inserted() can't be used here because power_thread()
433 hasn't checked power_input_status() yet */
434 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
435 && !global_settings
.car_adapter_mode
436 #ifdef ATA_POWER_PLAYERSTYLE
437 && !ide_powered() /* relies on probing result from bootloader */
441 rc
= charging_screen(); /* display a "charging" screen */
442 if (rc
== 1) /* charger removed */
444 /* "On" pressed or USB connected: proceed */
445 show_logo(); /* again, to provide better visual feedback */
452 #ifdef HAVE_LCD_BITMAP
455 snprintf(str
, 31, "ATA error: %d", rc
);
457 lcd_puts(0, 3, "Press ON to debug");
459 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
462 panicf("ata: %d", rc
);
465 #ifdef HAVE_EEPROM_SETTINGS
466 eeprom_settings_init();
469 #ifndef HAVE_USBSTACK
470 usb_start_monitoring();
471 while (usb_detect() == USB_INSERTED
)
473 #ifdef HAVE_EEPROM_SETTINGS
474 firmware_settings
.disk_clean
= false;
476 /* enter USB mode early, before trying to mount */
477 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
478 #if (CONFIG_STORAGE & STORAGE_MMC)
479 if (!mmc_touched() ||
480 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
484 mounted
= true; /* mounting done @ end of USB mode */
486 #ifdef HAVE_USB_POWER
487 if (usb_powered()) /* avoid deadlock */
495 rc
= disk_mount_all();
499 lcd_puts(0, 0, "No partition");
500 lcd_puts(0, 1, "found.");
501 #ifdef HAVE_LCD_BITMAP
502 lcd_puts(0, 2, "Insert USB cable");
503 lcd_puts(0, 3, "and fix it.");
507 while(button_get(true) != SYS_USB_CONNECTED
) {};
513 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
514 (CONFIG_KEYPAD == IRIVER_H10_PAD)
515 #ifdef SETTINGS_RESET
516 /* Reset settings if holding the reset button. (Rec on Archos,
518 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
520 /* Reset settings if the hold button is turned on */
524 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
529 settings_load(SETTINGS_ALL
);
531 if (init_dircache(true) < 0)
534 remove(TAGCACHE_STATEFILE
);
539 settings_apply(true);
540 init_dircache(false);
545 #ifdef HAVE_EEPROM_SETTINGS
546 if (firmware_settings
.initialized
)
548 /* In case we crash. */
549 firmware_settings
.disk_clean
= false;
550 eeprom_settings_store();
558 #if CONFIG_CODEC == SWCODEC
560 #endif /* CONFIG_CODEC == SWCODEC */
562 #if CONFIG_CODEC != SWCODEC
563 /* No buffer allocation (see buffer.c) may take place after the call to
564 audio_init() since the mpeg thread takes the rest of the buffer space */
565 mp3_init( global_settings
.volume
,
566 global_settings
.bass
,
567 global_settings
.treble
,
568 global_settings
.balance
,
569 global_settings
.loudness
,
571 global_settings
.channel_config
,
572 global_settings
.stereo_width
,
573 global_settings
.mdb_strength
,
574 global_settings
.mdb_harmonics
,
575 global_settings
.mdb_center
,
576 global_settings
.mdb_shape
,
577 global_settings
.mdb_enable
,
578 global_settings
.superbass
);
580 /* audio_init must to know the size of voice buffer so init voice first */
582 #endif /* CONFIG_CODEC != SWCODEC */
586 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
590 /* runtime database has to be initialized after audio_init() */
594 car_adapter_mode_init();
596 #ifdef IPOD_ACCESSORY_PROTOCOL
597 iap_setup(global_settings
.serial_bitrate
);
599 #ifdef HAVE_ACCESSORY_SUPPLY
600 accessory_supply_set(global_settings
.accessory_supply
);
607 /* This is the entry point for the coprocessor
608 Anyone not running an upgraded bootloader will never reach this point,
609 so it should not be assumed that the coprocessor be usable even on
610 platforms which support it.
612 A kernel thread is initially setup on the coprocessor and immediately
613 destroyed for purposes of continuity. The cop sits idle until at least
614 one thread exists on it. */
616 /* 3G doesn't have Rolo or dual core support yet */
620 /* This should never be reached */
633 #if (CONFIG_LED == LED_REAL)
634 led(true); sleep(HZ
/10);
635 led(false); sleep(HZ
/10);