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 #if (CONFIG_CODEC == SWCODEC)
79 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
80 #include "pcm_record.h"
84 #define SETTINGS_RESET BUTTON_REC
85 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
86 #define SETTINGS_RESET BUTTON_A
96 #ifdef HAVE_REMOTE_LCD
97 #include "lcd-remote.h"
100 #if CONFIG_USBOTG == USBOTG_ISP1362
104 #if CONFIG_USBOTG == USBOTG_M5636
108 #include "cuesheet.h"
111 #include "system-sdl.h"
114 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
116 const char appsversion
[]=APPSVERSION
;
118 static void init(void);
123 static void app_main(void)
130 screens
[i
].clear_display();
134 #ifdef HAVE_TOUCHSCREEN
135 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
140 static int init_dircache(bool preinit
)
149 if (!global_settings
.dircache
)
152 # ifdef HAVE_EEPROM_SETTINGS
153 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
156 result
= dircache_load();
160 firmware_settings
.disk_clean
= false;
161 if (global_status
.dircache_size
<= 0)
163 /* This will be in default language, settings are not
164 applied yet. Not really any easy way to fix that. */
165 splash(0, str(LANG_SCANNING_DISK
));
169 dircache_build(global_status
.dircache_size
);
178 if (!dircache_is_enabled()
179 && !dircache_is_initializing())
181 if (global_status
.dircache_size
<= 0)
183 splash(0, str(LANG_SCANNING_DISK
));
186 result
= dircache_build(global_status
.dircache_size
);
191 /* Initialization of dircache failed. Manual action is
192 * necessary to enable dircache again.
194 splashf(0, "Dircache failed, disabled. Result: %d", result
);
195 global_settings
.dircache
= false;
204 global_status
.dircache_size
= dircache_get_cache_size();
216 static void init_tagcache(void)
222 while (!tagcache_is_initialized())
224 #ifdef HAVE_LCD_CHARCELLS
227 int ret
= tagcache_get_commit_step();
231 #if CONFIG_CODEC == SWCODEC
232 /* hwcodec can't use voice here, as the database commit
233 * uses the audio buffer. */
234 static long talked_tick
= 0;
235 if(global_settings
.talk_menu
237 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
239 talked_tick
= current_tick
;
240 talk_id(LANG_TAGCACHE_INIT
, false);
241 talk_number(ret
, true);
242 talk_id(VOICE_OF
, true);
243 talk_number(tagcache_get_max_commit_step(), true);
246 #ifdef HAVE_LCD_BITMAP
247 splashf(0, "%s [%d/%d]",
248 str(LANG_TAGCACHE_INIT
), ret
,
249 tagcache_get_max_commit_step());
251 lcd_double_height(false);
252 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
253 tagcache_get_max_commit_step());
273 static void init(void)
279 #ifdef HAVE_REMOTE_LCD
290 /* Must be done before any code uses the multi-screen APi */
291 gui_syncstatusbar_init(&statusbars
);
294 settings_load(SETTINGS_ALL
);
296 settings_apply(true);
298 init_dircache(false);
307 #if CONFIG_CODEC != SWCODEC
308 mp3_init( global_settings
.volume
,
309 global_settings
.bass
,
310 global_settings
.treble
,
311 global_settings
.balance
,
312 global_settings
.loudness
,
314 global_settings
.channel_config
,
315 global_settings
.stereo_width
,
316 global_settings
.mdb_strength
,
317 global_settings
.mdb_harmonics
,
318 global_settings
.mdb_center
,
319 global_settings
.mdb_shape
,
320 global_settings
.mdb_enable
,
321 global_settings
.superbass
);
323 /* audio_init must to know the size of voice buffer so init voice first */
325 #endif /* CONFIG_CODEC != SWCODEC */
331 button_clear_queue(); /* Empty the keyboard buffer */
336 static void init(void)
339 bool mounted
= false;
340 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
341 /* if nobody initialized ATA before, I consider this a cold start */
342 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
348 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
349 set_cpu_frequency(CPUFREQ_NORMAL
);
351 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
369 #ifdef HAVE_REMOTE_LCD
380 #if !defined(HAVE_FMADC) && !defined(HAVE_MMC)
389 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
395 #if CONFIG_USBOTG == USBOTG_ISP1362
397 #elif CONFIG_USBOTG == USBOTG_M5636
411 /* Must be done before any code uses the multi-screen APi */
412 gui_syncstatusbar_init(&statusbars
);
414 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
415 if (coldstart
&& charger_inserted()
416 && !global_settings
.car_adapter_mode
417 #ifdef ATA_POWER_PLAYERSTYLE
418 && !ide_powered() /* relies on probing result from bootloader */
422 rc
= charging_screen(); /* display a "charging" screen */
423 if (rc
== 1) /* charger removed */
425 /* "On" pressed or USB connected: proceed */
426 show_logo(); /* again, to provide better visual feedback */
433 #ifdef HAVE_LCD_BITMAP
436 snprintf(str
, 31, "ATA error: %d", rc
);
438 lcd_puts(0, 3, "Press ON to debug");
440 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
443 panicf("ata: %d", rc
);
446 #ifdef HAVE_EEPROM_SETTINGS
447 eeprom_settings_init();
450 usb_start_monitoring();
451 #ifndef HAVE_USBSTACK
452 while (usb_detect() == USB_INSERTED
)
454 #ifdef HAVE_EEPROM_SETTINGS
455 firmware_settings
.disk_clean
= false;
457 /* enter USB mode early, before trying to mount */
458 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
460 if (!mmc_touched() ||
461 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
465 mounted
= true; /* mounting done @ end of USB mode */
467 #ifdef HAVE_USB_POWER
468 if (usb_powered()) /* avoid deadlock */
476 rc
= disk_mount_all();
480 lcd_puts(0, 0, "No partition");
481 lcd_puts(0, 1, "found.");
482 #ifdef HAVE_LCD_BITMAP
483 lcd_puts(0, 2, "Insert USB cable");
484 lcd_puts(0, 3, "and fix it.");
488 while(button_get(true) != SYS_USB_CONNECTED
) {};
494 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
495 (CONFIG_KEYPAD == IRIVER_H10_PAD)
496 #ifdef SETTINGS_RESET
497 /* Reset settings if holding the reset button. (Rec on Archos,
499 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
501 /* Reset settings if the hold button is turned on */
505 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
510 settings_load(SETTINGS_ALL
);
512 if (init_dircache(true) < 0)
515 remove(TAGCACHE_STATEFILE
);
520 settings_apply(true);
521 init_dircache(false);
526 #ifdef HAVE_EEPROM_SETTINGS
527 if (firmware_settings
.initialized
)
529 /* In case we crash. */
530 firmware_settings
.disk_clean
= false;
531 eeprom_settings_store();
541 #if CONFIG_CODEC != SWCODEC
542 /* No buffer allocation (see buffer.c) may take place after the call to
543 audio_init() since the mpeg thread takes the rest of the buffer space */
544 mp3_init( global_settings
.volume
,
545 global_settings
.bass
,
546 global_settings
.treble
,
547 global_settings
.balance
,
548 global_settings
.loudness
,
550 global_settings
.channel_config
,
551 global_settings
.stereo_width
,
552 global_settings
.mdb_strength
,
553 global_settings
.mdb_harmonics
,
554 global_settings
.mdb_center
,
555 global_settings
.mdb_shape
,
556 global_settings
.mdb_enable
,
557 global_settings
.superbass
);
559 /* audio_init must to know the size of voice buffer so init voice first */
561 #endif /* CONFIG_CODEC != SWCODEC */
565 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
569 /* runtime database has to be initialized after audio_init() */
574 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
576 if(file_exists(filename
)) /* no complaint if it doesn't exist */
578 plugin_load((char*)filename
, NULL
); /* start if it does */
581 #endif /* #ifdef AUTOROCK */
584 car_adapter_mode_init();
586 #ifdef HAVE_ACCESSORY_SUPPLY
587 accessory_supply_set(global_settings
.accessory_supply
);
594 /* This is the entry point for the coprocessor
595 Anyone not running an upgraded bootloader will never reach this point,
596 so it should not be assumed that the coprocessor be usable even on
597 platforms which support it.
599 A kernel thread is initially setup on the coprocessor and immediately
600 destroyed for purposes of continuity. The cop sits idle until at least
601 one thread exists on it. */
603 /* 3G doesn't have Rolo or dual core support yet */
607 /* This should never be reached */
620 #if (CONFIG_LED == LED_REAL)
621 led(true); sleep(HZ
/10);
622 led(false); sleep(HZ
/10);