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 int init_dircache(bool preinit
)
157 if (!global_settings
.dircache
)
160 # ifdef HAVE_EEPROM_SETTINGS
161 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
164 result
= dircache_load();
168 firmware_settings
.disk_clean
= false;
169 if (global_status
.dircache_size
<= 0)
171 /* This will be in default language, settings are not
172 applied yet. Not really any easy way to fix that. */
173 splash(0, str(LANG_SCANNING_DISK
));
177 dircache_build(global_status
.dircache_size
);
186 if (!dircache_is_enabled()
187 && !dircache_is_initializing())
189 if (global_status
.dircache_size
<= 0)
191 splash(0, str(LANG_SCANNING_DISK
));
194 result
= dircache_build(global_status
.dircache_size
);
199 /* Initialization of dircache failed. Manual action is
200 * necessary to enable dircache again.
202 splashf(0, "Dircache failed, disabled. Result: %d", result
);
203 global_settings
.dircache
= false;
212 global_status
.dircache_size
= dircache_get_cache_size();
224 static void init_tagcache(void)
230 while (!tagcache_is_initialized())
232 #ifdef HAVE_LCD_CHARCELLS
235 int ret
= tagcache_get_commit_step();
239 #if CONFIG_CODEC == SWCODEC
240 /* hwcodec can't use voice here, as the database commit
241 * uses the audio buffer. */
242 static long talked_tick
= 0;
243 if(global_settings
.talk_menu
245 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
247 talked_tick
= current_tick
;
248 talk_id(LANG_TAGCACHE_INIT
, false);
249 talk_number(ret
, true);
250 talk_id(VOICE_OF
, true);
251 talk_number(tagcache_get_max_commit_step(), true);
254 #ifdef HAVE_LCD_BITMAP
255 splashf(0, "%s [%d/%d]",
256 str(LANG_TAGCACHE_INIT
), ret
,
257 tagcache_get_max_commit_step());
259 lcd_double_height(false);
260 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
261 tagcache_get_max_commit_step());
281 static void init(void)
287 #ifdef HAVE_REMOTE_LCD
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 */
335 #if CONFIG_CODEC == SWCODEC
337 #endif /* CONFIG_CODEC == SWCODEC */
340 button_clear_queue(); /* Empty the keyboard buffer */
345 static void init(void)
348 bool mounted
= false;
349 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
350 /* if nobody initialized ATA before, I consider this a cold start */
351 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
357 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
358 set_cpu_frequency(CPUFREQ_NORMAL
);
360 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
378 #ifdef HAVE_REMOTE_LCD
398 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
404 #if CONFIG_USBOTG == USBOTG_ISP1362
406 #elif CONFIG_USBOTG == USBOTG_M5636
420 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
421 /* charger_inserted() can't be used here because power_thread()
422 hasn't checked power_input_status() yet */
423 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
424 && !global_settings
.car_adapter_mode
425 #ifdef ATA_POWER_PLAYERSTYLE
426 && !ide_powered() /* relies on probing result from bootloader */
430 rc
= charging_screen(); /* display a "charging" screen */
431 if (rc
== 1) /* charger removed */
433 /* "On" pressed or USB connected: proceed */
434 show_logo(); /* again, to provide better visual feedback */
441 #ifdef HAVE_LCD_BITMAP
444 snprintf(str
, 31, "ATA error: %d", rc
);
446 lcd_puts(0, 3, "Press ON to debug");
448 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
451 panicf("ata: %d", rc
);
454 #ifdef HAVE_EEPROM_SETTINGS
455 eeprom_settings_init();
458 #ifndef HAVE_USBSTACK
459 usb_start_monitoring();
460 while (usb_detect() == USB_INSERTED
)
462 #ifdef HAVE_EEPROM_SETTINGS
463 firmware_settings
.disk_clean
= false;
465 /* enter USB mode early, before trying to mount */
466 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
467 #if (CONFIG_STORAGE & STORAGE_MMC)
468 if (!mmc_touched() ||
469 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
473 mounted
= true; /* mounting done @ end of USB mode */
475 #ifdef HAVE_USB_POWER
476 if (usb_powered()) /* avoid deadlock */
484 rc
= disk_mount_all();
488 lcd_puts(0, 0, "No partition");
489 lcd_puts(0, 1, "found.");
490 #ifdef HAVE_LCD_BITMAP
491 lcd_puts(0, 2, "Insert USB cable");
492 lcd_puts(0, 3, "and fix it.");
496 while(button_get(true) != SYS_USB_CONNECTED
) {};
502 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
503 (CONFIG_KEYPAD == IRIVER_H10_PAD)
504 #ifdef SETTINGS_RESET
505 /* Reset settings if holding the reset button. (Rec on Archos,
507 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
509 /* Reset settings if the hold button is turned on */
513 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
518 settings_load(SETTINGS_ALL
);
520 if (init_dircache(true) < 0)
523 remove(TAGCACHE_STATEFILE
);
528 settings_apply(true);
529 init_dircache(false);
534 #ifdef HAVE_EEPROM_SETTINGS
535 if (firmware_settings
.initialized
)
537 /* In case we crash. */
538 firmware_settings
.disk_clean
= false;
539 eeprom_settings_store();
547 #if CONFIG_CODEC == SWCODEC
549 #endif /* CONFIG_CODEC == SWCODEC */
551 #if CONFIG_CODEC != SWCODEC
552 /* No buffer allocation (see buffer.c) may take place after the call to
553 audio_init() since the mpeg thread takes the rest of the buffer space */
554 mp3_init( global_settings
.volume
,
555 global_settings
.bass
,
556 global_settings
.treble
,
557 global_settings
.balance
,
558 global_settings
.loudness
,
560 global_settings
.channel_config
,
561 global_settings
.stereo_width
,
562 global_settings
.mdb_strength
,
563 global_settings
.mdb_harmonics
,
564 global_settings
.mdb_center
,
565 global_settings
.mdb_shape
,
566 global_settings
.mdb_enable
,
567 global_settings
.superbass
);
569 /* audio_init must to know the size of voice buffer so init voice first */
571 #endif /* CONFIG_CODEC != SWCODEC */
575 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
579 /* runtime database has to be initialized after audio_init() */
584 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
586 if(file_exists(filename
)) /* no complaint if it doesn't exist */
588 plugin_load((char*)filename
, NULL
); /* start if it does */
591 #endif /* #ifdef AUTOROCK */
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);