1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
35 #include "powermgmt.h"
42 #include "mp3_playback.h"
45 #include "backlight.h"
47 #include "debug_menu.h"
70 #include "eeprom_settings.h"
71 #include "scrobbler.h"
73 #if (CONFIG_CODEC == SWCODEC)
79 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
80 #include "pcm_record.h"
81 #define SETTINGS_RESET BUTTON_REC
91 #ifdef HAVE_REMOTE_LCD
92 #include "lcd-remote.h"
95 #if CONFIG_USBOTG == USBOTG_ISP1362
99 #if CONFIG_USBOTG == USBOTG_M5636
103 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
105 const char appsversion
[]=APPSVERSION
;
115 int init_dircache(bool preinit
)
124 if (global_settings
.dircache
)
126 # ifdef HAVE_EEPROM_SETTINGS
127 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
130 result
= dircache_load(DIRCACHE_FILE
);
131 remove(DIRCACHE_FILE
);
134 firmware_settings
.disk_clean
= false;
135 if (global_settings
.dircache_size
>= 0)
136 dircache_build(global_settings
.dircache_size
);
146 if (!dircache_is_enabled()
147 && !dircache_is_initializing())
149 if (global_settings
.dircache_size
<= 0)
151 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING
));
154 result
= dircache_build(global_settings
.dircache_size
);
158 gui_syncsplash(0, true, "Failed! Result: %d", result
);
175 void init_tagcache(void)
181 while (!tagcache_is_initialized())
183 #ifdef HAVE_LCD_CHARCELLS
186 int ret
= tagcache_get_commit_step();
190 #ifdef HAVE_LCD_BITMAP
191 gui_syncsplash(0, true, "%s [%d/%d]",
192 str(LANG_TAGCACHE_INIT
), ret
, 7);
194 lcd_double_height(false);
195 snprintf(buf
, sizeof(buf
), " TC [%d/%d]", ret
, 7);
219 #ifdef HAVE_REMOTE_LCD
227 /* Must be done before any code uses the multi-screen APi */
228 screen_access_init();
229 gui_syncstatusbar_init(&statusbars
);
231 settings_calc_config_sector();
232 settings_load(SETTINGS_ALL
);
236 init_dircache(false);
243 mp3_init( global_settings
.volume
,
244 global_settings
.bass
,
245 global_settings
.treble
,
246 global_settings
.balance
,
247 global_settings
.loudness
,
249 global_settings
.channel_config
,
250 global_settings
.stereo_width
,
251 global_settings
.mdb_strength
,
252 global_settings
.mdb_harmonics
,
253 global_settings
.mdb_center
,
254 global_settings
.mdb_shape
,
255 global_settings
.mdb_enable
,
256 global_settings
.superbass
);
258 #if CONFIG_CODEC == SWCODEC
264 /* audio_init must to know the size of voice buffer so init voice first */
265 #if CONFIG_CODEC == SWCODEC
270 button_clear_queue(); /* Empty the keyboard buffer */
278 bool mounted
= false;
279 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
280 /* if nobody initialized ATA before, I consider this a cold start */
281 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
286 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
287 set_cpu_frequency(CPUFREQ_NORMAL
);
288 cpu_boost_id(true, CPUBOOSTID_MAININIT
);
299 #ifdef HAVE_REMOTE_LCD
309 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
310 * (do debug builds on the Ondio make sense?) */
321 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
327 #if CONFIG_USBOTG == USBOTG_ISP1362
329 #elif CONFIG_USBOTG == USBOTG_M5636
339 #if CONFIG_CODEC == SWCODEC
347 /* Must be done before any code uses the multi-screen APi */
348 screen_access_init();
349 gui_syncstatusbar_init(&statusbars
);
351 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
352 if (coldstart
&& charger_inserted()
353 && !global_settings
.car_adapter_mode
354 #ifdef ATA_POWER_PLAYERSTYLE
355 && !ide_powered() /* relies on probing result from bootloader */
359 rc
= charging_screen(); /* display a "charging" screen */
360 if (rc
== 1) /* charger removed */
362 /* "On" pressed or USB connected: proceed */
363 show_logo(); /* again, to provide better visual feedback */
370 #ifdef HAVE_LCD_BITMAP
373 snprintf(str
, 31, "ATA error: %d", rc
);
375 lcd_puts(0, 3, "Press ON to debug");
377 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
380 panicf("ata: %d", rc
);
383 #ifdef HAVE_EEPROM_SETTINGS
384 eeprom_settings_init();
387 usb_start_monitoring();
390 #ifdef HAVE_EEPROM_SETTINGS
391 firmware_settings
.disk_clean
= false;
393 /* enter USB mode early, before trying to mount */
394 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
396 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
400 mounted
= true; /* mounting done @ end of USB mode */
402 #ifdef HAVE_USB_POWER
403 if (usb_powered()) /* avoid deadlock */
410 rc
= disk_mount_all();
414 lcd_puts(0, 0, "No partition");
415 lcd_puts(0, 1, "found.");
416 #ifdef HAVE_LCD_BITMAP
417 lcd_puts(0, 2, "Insert USB cable");
418 lcd_puts(0, 3, "and fix it.");
421 while(button_get(true) != SYS_USB_CONNECTED
) {};
427 settings_calc_config_sector();
429 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IRIVER_H10_PAD)
430 #ifdef SETTINGS_RESET
431 /* Reset settings if holding the rec button. */
432 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
434 /* Reset settings if the hold button is turned on */
438 gui_syncsplash(HZ
*2, true, str(LANG_RESET_DONE_CLEAR
));
443 settings_load(SETTINGS_ALL
);
445 if (init_dircache(true) < 0)
448 remove(TAGCACHE_STATEFILE
);
454 init_dircache(false);
459 #ifdef HAVE_EEPROM_SETTINGS
460 if (firmware_settings
.initialized
)
462 /* In case we crash. */
463 firmware_settings
.disk_clean
= false;
464 eeprom_settings_store();
472 /* No buffer allocation (see buffer.c) may take place after the call to
473 audio_init() since the mpeg thread takes the rest of the buffer space */
474 mp3_init( global_settings
.volume
,
475 global_settings
.bass
,
476 global_settings
.treble
,
477 global_settings
.balance
,
478 global_settings
.loudness
,
480 global_settings
.channel_config
,
481 global_settings
.stereo_width
,
482 global_settings
.mdb_strength
,
483 global_settings
.mdb_harmonics
,
484 global_settings
.mdb_center
,
485 global_settings
.mdb_shape
,
486 global_settings
.mdb_enable
,
487 global_settings
.superbass
);
489 /* audio_init must to know the size of voice buffer so init voice first */
493 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
497 /* runtime database has to be initialized after audio_init() */
498 cpu_boost_id(false, CPUBOOSTID_MAININIT
);
503 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
505 fd
= open(filename
, O_RDONLY
);
506 if(fd
>= 0) /* no complaint if it doesn't exist */
509 plugin_load((char*)filename
, NULL
); /* start if it does */
512 #endif /* #ifdef AUTOROCK */
514 #ifdef CONFIG_CHARGING
515 car_adapter_mode_init();
522 /* This is the entry point for the coprocessor
523 Anyone not running an upgraded bootloader will never reach this point,
524 so it should not be assumed that the coprocessor be usable even on
525 platforms which support it.
527 At present all we do is send the COP to sleep if anything wakes it. */
529 COP_CTL
= PROC_SLEEP
;
539 #if CONFIG_LED == LED_REAL
540 led(true); sleep(HZ
/10);
541 led(false); sleep(HZ
/10);