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();
138 #ifdef HAVE_LCD_BITMAP
142 viewportmanager_init();
144 /* All threads should be created and public queues registered by now */
145 usb_start_monitoring();
150 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
152 if(file_exists(filename
)) /* no complaint if it doesn't exist */
154 plugin_load((char*)filename
, NULL
); /* start if it does */
157 #endif /* #ifdef AUTOROCK */
162 static int init_dircache(bool preinit
)
171 if (!global_settings
.dircache
)
174 # ifdef HAVE_EEPROM_SETTINGS
175 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
178 result
= dircache_load();
182 firmware_settings
.disk_clean
= false;
183 if (global_status
.dircache_size
<= 0)
185 /* This will be in default language, settings are not
186 applied yet. Not really any easy way to fix that. */
187 splash(0, str(LANG_SCANNING_DISK
));
191 dircache_build(global_status
.dircache_size
);
200 if (!dircache_is_enabled()
201 && !dircache_is_initializing())
203 if (global_status
.dircache_size
<= 0)
205 splash(0, str(LANG_SCANNING_DISK
));
208 result
= dircache_build(global_status
.dircache_size
);
213 /* Initialization of dircache failed. Manual action is
214 * necessary to enable dircache again.
216 splashf(0, "Dircache failed, disabled. Result: %d", result
);
217 global_settings
.dircache
= false;
225 global_status
.dircache_size
= dircache_get_cache_size();
237 static void init_tagcache(void)
243 while (!tagcache_is_initialized())
245 #ifdef HAVE_LCD_CHARCELLS
248 int ret
= tagcache_get_commit_step();
252 #if CONFIG_CODEC == SWCODEC
253 /* hwcodec can't use voice here, as the database commit
254 * uses the audio buffer. */
255 static long talked_tick
= 0;
256 if(global_settings
.talk_menu
258 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
260 talked_tick
= current_tick
;
261 talk_id(LANG_TAGCACHE_INIT
, false);
262 talk_number(ret
, true);
263 talk_id(VOICE_OF
, true);
264 talk_number(tagcache_get_max_commit_step(), true);
267 #ifdef HAVE_LCD_BITMAP
270 splashf(0, "[%d/%d] %s", ret
, tagcache_get_max_commit_step(),
271 str(LANG_TAGCACHE_INIT
));
275 splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT
), ret
,
276 tagcache_get_max_commit_step());
279 lcd_double_height(false);
280 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
281 tagcache_get_max_commit_step());
301 static void init(void)
307 #ifdef HAVE_REMOTE_LCD
319 /* Must be done before any code uses the multi-screen API */
320 gui_syncstatusbar_init(&statusbars
);
323 settings_load(SETTINGS_ALL
);
326 settings_apply(true);
328 init_dircache(false);
337 #if CONFIG_CODEC != SWCODEC
338 mp3_init( global_settings
.volume
,
339 global_settings
.bass
,
340 global_settings
.treble
,
341 global_settings
.balance
,
342 global_settings
.loudness
,
344 global_settings
.channel_config
,
345 global_settings
.stereo_width
,
346 global_settings
.mdb_strength
,
347 global_settings
.mdb_harmonics
,
348 global_settings
.mdb_center
,
349 global_settings
.mdb_shape
,
350 global_settings
.mdb_enable
,
351 global_settings
.superbass
);
353 /* audio_init must to know the size of voice buffer so init voice first */
355 #endif /* CONFIG_CODEC != SWCODEC */
358 #if CONFIG_CODEC == SWCODEC
360 #endif /* CONFIG_CODEC == SWCODEC */
363 button_clear_queue(); /* Empty the keyboard buffer */
368 static void init(void)
371 bool mounted
= false;
372 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
373 /* if nobody initialized ATA before, I consider this a cold start */
374 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
380 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
381 set_cpu_frequency(CPUFREQ_NORMAL
);
383 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
401 #ifdef HAVE_REMOTE_LCD
421 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
427 #if CONFIG_USBOTG == USBOTG_ISP1362
429 #elif CONFIG_USBOTG == USBOTG_M5636
443 /* Must be done before any code uses the multi-screen API */
444 gui_syncstatusbar_init(&statusbars
);
446 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
447 /* charger_inserted() can't be used here because power_thread()
448 hasn't checked power_input_status() yet */
449 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
450 && !global_settings
.car_adapter_mode
451 #ifdef ATA_POWER_PLAYERSTYLE
452 && !ide_powered() /* relies on probing result from bootloader */
456 rc
= charging_screen(); /* display a "charging" screen */
457 if (rc
== 1) /* charger removed */
459 /* "On" pressed or USB connected: proceed */
460 show_logo(); /* again, to provide better visual feedback */
467 #ifdef HAVE_LCD_BITMAP
470 snprintf(str
, 31, "ATA error: %d", rc
);
472 lcd_puts(0, 3, "Press ON to debug");
474 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
477 panicf("ata: %d", rc
);
480 #ifdef HAVE_EEPROM_SETTINGS
481 eeprom_settings_init();
484 #ifndef HAVE_USBSTACK
485 usb_start_monitoring();
486 while (usb_detect() == USB_INSERTED
)
488 #ifdef HAVE_EEPROM_SETTINGS
489 firmware_settings
.disk_clean
= false;
491 /* enter USB mode early, before trying to mount */
492 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
493 #if (CONFIG_STORAGE & STORAGE_MMC)
494 if (!mmc_touched() ||
495 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
499 mounted
= true; /* mounting done @ end of USB mode */
501 #ifdef HAVE_USB_POWER
502 if (usb_powered()) /* avoid deadlock */
510 rc
= disk_mount_all();
514 lcd_puts(0, 0, "No partition");
515 lcd_puts(0, 1, "found.");
516 #ifdef HAVE_LCD_BITMAP
517 lcd_puts(0, 2, "Insert USB cable");
518 lcd_puts(0, 3, "and fix it.");
522 while(button_get(true) != SYS_USB_CONNECTED
) {};
528 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
529 (CONFIG_KEYPAD == IRIVER_H10_PAD)
530 #ifdef SETTINGS_RESET
531 /* Reset settings if holding the reset button. (Rec on Archos,
533 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
535 /* Reset settings if the hold button is turned on */
539 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
544 settings_load(SETTINGS_ALL
);
546 if (init_dircache(true) < 0)
549 remove(TAGCACHE_STATEFILE
);
554 settings_apply(true);
555 init_dircache(false);
560 #ifdef HAVE_EEPROM_SETTINGS
561 if (firmware_settings
.initialized
)
563 /* In case we crash. */
564 firmware_settings
.disk_clean
= false;
565 eeprom_settings_store();
572 #if CONFIG_CODEC == SWCODEC
574 #endif /* CONFIG_CODEC == SWCODEC */
576 #if CONFIG_CODEC != SWCODEC
577 /* No buffer allocation (see buffer.c) may take place after the call to
578 audio_init() since the mpeg thread takes the rest of the buffer space */
579 mp3_init( global_settings
.volume
,
580 global_settings
.bass
,
581 global_settings
.treble
,
582 global_settings
.balance
,
583 global_settings
.loudness
,
585 global_settings
.channel_config
,
586 global_settings
.stereo_width
,
587 global_settings
.mdb_strength
,
588 global_settings
.mdb_harmonics
,
589 global_settings
.mdb_center
,
590 global_settings
.mdb_shape
,
591 global_settings
.mdb_enable
,
592 global_settings
.superbass
);
594 /* audio_init must to know the size of voice buffer so init voice first */
596 #endif /* CONFIG_CODEC != SWCODEC */
600 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
604 /* runtime database has to be initialized after audio_init() */
608 car_adapter_mode_init();
610 #ifdef IPOD_ACCESSORY_PROTOCOL
611 iap_setup(global_settings
.serial_bitrate
);
613 #ifdef HAVE_ACCESSORY_SUPPLY
614 accessory_supply_set(global_settings
.accessory_supply
);
621 /* This is the entry point for the coprocessor
622 Anyone not running an upgraded bootloader will never reach this point,
623 so it should not be assumed that the coprocessor be usable even on
624 platforms which support it.
626 A kernel thread is initially setup on the coprocessor and immediately
627 destroyed for purposes of continuity. The cop sits idle until at least
628 one thread exists on it. */
630 /* 3G doesn't have Rolo or dual core support yet */
634 /* This should never be reached */
647 #if (CONFIG_LED == LED_REAL)
648 led(true); sleep(HZ
/10);
649 led(false); sleep(HZ
/10);