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 gui_syncstatusbar_init(&statusbars
);
143 viewportmanager_init();
145 /* All threads should be created and public queues registered by now */
146 usb_start_monitoring();
151 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
153 if(file_exists(filename
)) /* no complaint if it doesn't exist */
155 plugin_load((char*)filename
, NULL
); /* start if it does */
158 #endif /* #ifdef AUTOROCK */
163 static int init_dircache(bool preinit
)
172 if (!global_settings
.dircache
)
175 # ifdef HAVE_EEPROM_SETTINGS
176 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
179 result
= dircache_load();
183 firmware_settings
.disk_clean
= false;
184 if (global_status
.dircache_size
<= 0)
186 /* This will be in default language, settings are not
187 applied yet. Not really any easy way to fix that. */
188 splash(0, str(LANG_SCANNING_DISK
));
192 dircache_build(global_status
.dircache_size
);
201 if (!dircache_is_enabled()
202 && !dircache_is_initializing())
204 if (global_status
.dircache_size
<= 0)
206 splash(0, str(LANG_SCANNING_DISK
));
209 result
= dircache_build(global_status
.dircache_size
);
214 /* Initialization of dircache failed. Manual action is
215 * necessary to enable dircache again.
217 splashf(0, "Dircache failed, disabled. Result: %d", result
);
218 global_settings
.dircache
= false;
226 global_status
.dircache_size
= dircache_get_cache_size();
238 static void init_tagcache(void)
244 while (!tagcache_is_initialized())
246 #ifdef HAVE_LCD_CHARCELLS
249 int ret
= tagcache_get_commit_step();
253 #if CONFIG_CODEC == SWCODEC
254 /* hwcodec can't use voice here, as the database commit
255 * uses the audio buffer. */
256 static long talked_tick
= 0;
257 if(global_settings
.talk_menu
259 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
261 talked_tick
= current_tick
;
262 talk_id(LANG_TAGCACHE_INIT
, false);
263 talk_number(ret
, true);
264 talk_id(VOICE_OF
, true);
265 talk_number(tagcache_get_max_commit_step(), true);
268 #ifdef HAVE_LCD_BITMAP
269 splashf(0, "%s [%d/%d]",
270 str(LANG_TAGCACHE_INIT
), ret
,
271 tagcache_get_max_commit_step());
273 lcd_double_height(false);
274 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
275 tagcache_get_max_commit_step());
295 static void init(void)
301 #ifdef HAVE_REMOTE_LCD
315 settings_load(SETTINGS_ALL
);
317 settings_apply(true);
319 init_dircache(false);
328 #if CONFIG_CODEC != SWCODEC
329 mp3_init( global_settings
.volume
,
330 global_settings
.bass
,
331 global_settings
.treble
,
332 global_settings
.balance
,
333 global_settings
.loudness
,
335 global_settings
.channel_config
,
336 global_settings
.stereo_width
,
337 global_settings
.mdb_strength
,
338 global_settings
.mdb_harmonics
,
339 global_settings
.mdb_center
,
340 global_settings
.mdb_shape
,
341 global_settings
.mdb_enable
,
342 global_settings
.superbass
);
344 /* audio_init must to know the size of voice buffer so init voice first */
346 #endif /* CONFIG_CODEC != SWCODEC */
349 #if CONFIG_CODEC == SWCODEC
351 #endif /* CONFIG_CODEC == SWCODEC */
354 button_clear_queue(); /* Empty the keyboard buffer */
359 static void init(void)
362 bool mounted
= false;
363 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
364 /* if nobody initialized ATA before, I consider this a cold start */
365 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
371 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
372 set_cpu_frequency(CPUFREQ_NORMAL
);
374 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
392 #ifdef HAVE_REMOTE_LCD
412 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
418 #if CONFIG_USBOTG == USBOTG_ISP1362
420 #elif CONFIG_USBOTG == USBOTG_M5636
434 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
435 /* charger_inserted() can't be used here because power_thread()
436 hasn't checked power_input_status() yet */
437 if (coldstart
&& (power_input_status() & POWER_INPUT_MAIN_CHARGER
)
438 && !global_settings
.car_adapter_mode
439 #ifdef ATA_POWER_PLAYERSTYLE
440 && !ide_powered() /* relies on probing result from bootloader */
444 rc
= charging_screen(); /* display a "charging" screen */
445 if (rc
== 1) /* charger removed */
447 /* "On" pressed or USB connected: proceed */
448 show_logo(); /* again, to provide better visual feedback */
455 #ifdef HAVE_LCD_BITMAP
458 snprintf(str
, 31, "ATA error: %d", rc
);
460 lcd_puts(0, 3, "Press ON to debug");
462 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
465 panicf("ata: %d", rc
);
468 #ifdef HAVE_EEPROM_SETTINGS
469 eeprom_settings_init();
472 #ifndef HAVE_USBSTACK
473 usb_start_monitoring();
474 while (usb_detect() == USB_INSERTED
)
476 #ifdef HAVE_EEPROM_SETTINGS
477 firmware_settings
.disk_clean
= false;
479 /* enter USB mode early, before trying to mount */
480 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
481 #if (CONFIG_STORAGE & STORAGE_MMC)
482 if (!mmc_touched() ||
483 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
487 mounted
= true; /* mounting done @ end of USB mode */
489 #ifdef HAVE_USB_POWER
490 if (usb_powered()) /* avoid deadlock */
498 rc
= disk_mount_all();
502 lcd_puts(0, 0, "No partition");
503 lcd_puts(0, 1, "found.");
504 #ifdef HAVE_LCD_BITMAP
505 lcd_puts(0, 2, "Insert USB cable");
506 lcd_puts(0, 3, "and fix it.");
510 while(button_get(true) != SYS_USB_CONNECTED
) {};
516 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
517 (CONFIG_KEYPAD == IRIVER_H10_PAD)
518 #ifdef SETTINGS_RESET
519 /* Reset settings if holding the reset button. (Rec on Archos,
521 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
523 /* Reset settings if the hold button is turned on */
527 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
532 settings_load(SETTINGS_ALL
);
534 if (init_dircache(true) < 0)
537 remove(TAGCACHE_STATEFILE
);
542 settings_apply(true);
543 init_dircache(false);
548 #ifdef HAVE_EEPROM_SETTINGS
549 if (firmware_settings
.initialized
)
551 /* In case we crash. */
552 firmware_settings
.disk_clean
= false;
553 eeprom_settings_store();
561 #if CONFIG_CODEC == SWCODEC
563 #endif /* CONFIG_CODEC == SWCODEC */
565 #if CONFIG_CODEC != SWCODEC
566 /* No buffer allocation (see buffer.c) may take place after the call to
567 audio_init() since the mpeg thread takes the rest of the buffer space */
568 mp3_init( global_settings
.volume
,
569 global_settings
.bass
,
570 global_settings
.treble
,
571 global_settings
.balance
,
572 global_settings
.loudness
,
574 global_settings
.channel_config
,
575 global_settings
.stereo_width
,
576 global_settings
.mdb_strength
,
577 global_settings
.mdb_harmonics
,
578 global_settings
.mdb_center
,
579 global_settings
.mdb_shape
,
580 global_settings
.mdb_enable
,
581 global_settings
.superbass
);
583 /* audio_init must to know the size of voice buffer so init voice first */
585 #endif /* CONFIG_CODEC != SWCODEC */
589 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
593 /* runtime database has to be initialized after audio_init() */
597 car_adapter_mode_init();
599 #ifdef IPOD_ACCESSORY_PROTOCOL
600 iap_setup(global_settings
.serial_bitrate
);
602 #ifdef HAVE_ACCESSORY_SUPPLY
603 accessory_supply_set(global_settings
.accessory_supply
);
610 /* This is the entry point for the coprocessor
611 Anyone not running an upgraded bootloader will never reach this point,
612 so it should not be assumed that the coprocessor be usable even on
613 platforms which support it.
615 A kernel thread is initially setup on the coprocessor and immediately
616 destroyed for purposes of continuity. The cop sits idle until at least
617 one thread exists on it. */
619 /* 3G doesn't have Rolo or dual core support yet */
623 /* This should never be reached */
636 #if (CONFIG_LED == LED_REAL)
637 led(true); sleep(HZ
/10);
638 led(false); sleep(HZ
/10);