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"
68 #include "eeprom_settings.h"
70 #if (CONFIG_CODEC == SWCODEC)
76 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
77 #include "pcm_record.h"
78 #define SETTINGS_RESET BUTTON_REC
88 #ifdef HAVE_REMOTE_LCD
89 #include "lcd-remote.h"
92 #if CONFIG_USBOTG == USBOTG_ISP1362
96 #if CONFIG_USBOTG == USBOTG_M5636
100 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
102 const char appsversion
[]=APPSVERSION
;
112 int init_dircache(bool preinit
)
121 if (global_settings
.dircache
)
123 # ifdef HAVE_EEPROM_SETTINGS
124 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
127 result
= dircache_load(DIRCACHE_FILE
);
128 remove(DIRCACHE_FILE
);
131 firmware_settings
.disk_clean
= false;
132 if (global_settings
.dircache_size
>= 0)
133 dircache_build(global_settings
.dircache_size
);
143 if (!dircache_is_enabled()
144 && !dircache_is_initializing())
146 if (global_settings
.dircache_size
<= 0)
148 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING
));
151 result
= dircache_build(global_settings
.dircache_size
);
155 gui_syncsplash(0, true, "Failed! Result: %d", result
);
171 void init_tagcache(void)
177 while (!tagcache_is_initialized())
179 #ifdef HAVE_LCD_CHARCELLS
182 int ret
= tagcache_get_commit_step();
186 #ifdef HAVE_LCD_BITMAP
187 gui_syncsplash(0, true, "%s [%d/%d]",
188 str(LANG_TAGCACHE_INIT
), ret
, TAG_COUNT
);
190 lcd_double_height(false);
191 snprintf(buf
, sizeof(buf
), " TC [%d/%d]", ret
, TAG_COUNT
);
214 #ifdef HAVE_REMOTE_LCD
222 /* Must be done before any code uses the multi-screen APi */
223 screen_access_init();
224 gui_syncstatusbar_init(&statusbars
);
226 settings_calc_config_sector();
227 settings_load(SETTINGS_ALL
);
231 init_dircache(false);
236 mp3_init( global_settings
.volume
,
237 global_settings
.bass
,
238 global_settings
.treble
,
239 global_settings
.balance
,
240 global_settings
.loudness
,
242 global_settings
.channel_config
,
243 global_settings
.stereo_width
,
244 global_settings
.mdb_strength
,
245 global_settings
.mdb_harmonics
,
246 global_settings
.mdb_center
,
247 global_settings
.mdb_shape
,
248 global_settings
.mdb_enable
,
249 global_settings
.superbass
);
251 #if CONFIG_CODEC == SWCODEC
255 /* audio_init must to know the size of voice buffer so init voice first */
256 #if CONFIG_CODEC == SWCODEC
261 button_clear_queue(); /* Empty the keyboard buffer */
269 bool mounted
= false;
270 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
271 /* if nobody initialized ATA before, I consider this a cold start */
272 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
277 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
278 set_cpu_frequency(CPUFREQ_NORMAL
);
290 #ifdef HAVE_REMOTE_LCD
300 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
301 * (do debug builds on the Ondio make sense?) */
312 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
318 #if CONFIG_USBOTG == USBOTG_ISP1362
320 #elif CONFIG_USBOTG == USBOTG_M5636
330 #if CONFIG_CODEC == SWCODEC
338 /* Must be done before any code uses the multi-screen APi */
339 screen_access_init();
340 gui_syncstatusbar_init(&statusbars
);
342 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
343 if (coldstart
&& charger_inserted()
344 && !global_settings
.car_adapter_mode
345 #ifdef ATA_POWER_PLAYERSTYLE
346 && !ide_powered() /* relies on probing result from bootloader */
350 rc
= charging_screen(); /* display a "charging" screen */
351 if (rc
== 1) /* charger removed */
353 /* "On" pressed or USB connected: proceed */
354 show_logo(); /* again, to provide better visual feedback */
361 #ifdef HAVE_LCD_BITMAP
364 snprintf(str
, 31, "ATA error: %d", rc
);
366 lcd_puts(0, 3, "Press ON to debug");
368 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
371 panicf("ata: %d", rc
);
374 #ifdef HAVE_EEPROM_SETTINGS
375 eeprom_settings_init();
378 usb_start_monitoring();
381 #ifdef HAVE_EEPROM_SETTINGS
382 firmware_settings
.disk_clean
= false;
384 /* enter USB mode early, before trying to mount */
385 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
387 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
391 mounted
= true; /* mounting done @ end of USB mode */
393 #ifdef HAVE_USB_POWER
394 if (usb_powered()) /* avoid deadlock */
401 rc
= disk_mount_all();
405 lcd_puts(0, 0, "No partition");
406 lcd_puts(0, 1, "found.");
407 #ifdef HAVE_LCD_BITMAP
408 lcd_puts(0, 2, "Insert USB cable");
409 lcd_puts(0, 3, "and fix it.");
412 while(button_get(true) != SYS_USB_CONNECTED
) {};
418 settings_calc_config_sector();
420 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD)
421 #ifdef SETTINGS_RESET
422 /* Reset settings if holding the rec button. */
423 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
425 /* Reset settings if the hold button is turned on */
429 gui_syncsplash(HZ
*2, true, str(LANG_RESET_DONE_CLEAR
));
434 settings_load(SETTINGS_ALL
);
437 if (init_dircache(true) < 0)
439 remove(TAGCACHE_STATEFILE
);
444 init_dircache(false);
447 #ifdef HAVE_EEPROM_SETTINGS
448 if (firmware_settings
.initialized
)
450 /* In case we crash. */
451 firmware_settings
.disk_clean
= false;
452 eeprom_settings_store();
459 /* No buffer allocation (see buffer.c) may take place after the call to
460 audio_init() since the mpeg thread takes the rest of the buffer space */
461 mp3_init( global_settings
.volume
,
462 global_settings
.bass
,
463 global_settings
.treble
,
464 global_settings
.balance
,
465 global_settings
.loudness
,
467 global_settings
.channel_config
,
468 global_settings
.stereo_width
,
469 global_settings
.mdb_strength
,
470 global_settings
.mdb_harmonics
,
471 global_settings
.mdb_center
,
472 global_settings
.mdb_shape
,
473 global_settings
.mdb_enable
,
474 global_settings
.superbass
);
476 /* audio_init must to know the size of voice buffer so init voice first */
480 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
484 /* runtime database has to be initialized after audio_init() */
490 static const char filename
[] = PLUGIN_DIR
"/autostart.rock";
492 fd
= open(filename
, O_RDONLY
);
493 if(fd
>= 0) /* no complaint if it doesn't exist */
496 plugin_load((char*)filename
, NULL
); /* start if it does */
499 #endif /* #ifdef AUTOROCK */
501 #ifdef CONFIG_CHARGING
502 car_adapter_mode_init();
509 /* This is the entry point for the coprocessor
510 Anyone not running an upgraded bootloader will never reach this point,
511 so it should not be assumed that the coprocessor be usable even on
512 platforms which support it.
514 At present all we do is send the COP to sleep if anything wakes it. */
516 COP_CTL
= PROC_SLEEP
;
526 #if CONFIG_LED == LED_REAL
527 led(true); sleep(HZ
/10);
528 led(false); sleep(HZ
/10);