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 #ifdef IPOD_ACCESSORY_PROTOCOL
80 #if (CONFIG_CODEC == SWCODEC)
83 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
84 #include "pcm_record.h"
88 #define SETTINGS_RESET BUTTON_REC
89 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
90 #define SETTINGS_RESET BUTTON_A
96 #if (CONFIG_STORAGE & STORAGE_MMC)
100 #ifdef HAVE_REMOTE_LCD
101 #include "lcd-remote.h"
104 #if CONFIG_USBOTG == USBOTG_ISP1362
108 #if CONFIG_USBOTG == USBOTG_M5636
112 #include "cuesheet.h"
115 #include "system-sdl.h"
118 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
120 const char appsversion
[]=APPSVERSION
;
122 static void init(void);
124 static void fourhertz_tick_task(void)
126 static long last_fire
= 0;
127 if (TIME_AFTER(current_tick
, last_fire
+HZ
/4))
129 queue_post(&button_queue
, SYS_FOURHERTZ
, 0);
130 last_fire
= current_tick
;
137 static void app_main(void)
144 screens
[i
].clear_display();
148 #ifdef HAVE_TOUCHSCREEN
149 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
151 tick_add_task(fourhertz_tick_task
);
152 viewportmanager_set_statusbar(true);
153 add_event(GUI_EVENT_STATUSBAR_TOGGLE
, false,
154 viewportmanager_statusbar_changed
);
158 static int init_dircache(bool preinit
)
167 if (!global_settings
.dircache
)
170 # ifdef HAVE_EEPROM_SETTINGS
171 if (firmware_settings
.initialized
&& firmware_settings
.disk_clean
174 result
= dircache_load();
178 firmware_settings
.disk_clean
= false;
179 if (global_status
.dircache_size
<= 0)
181 /* This will be in default language, settings are not
182 applied yet. Not really any easy way to fix that. */
183 splash(0, str(LANG_SCANNING_DISK
));
187 dircache_build(global_status
.dircache_size
);
196 if (!dircache_is_enabled()
197 && !dircache_is_initializing())
199 if (global_status
.dircache_size
<= 0)
201 splash(0, str(LANG_SCANNING_DISK
));
204 result
= dircache_build(global_status
.dircache_size
);
209 /* Initialization of dircache failed. Manual action is
210 * necessary to enable dircache again.
212 splashf(0, "Dircache failed, disabled. Result: %d", result
);
213 global_settings
.dircache
= false;
222 global_status
.dircache_size
= dircache_get_cache_size();
234 static void init_tagcache(void)
240 while (!tagcache_is_initialized())
242 #ifdef HAVE_LCD_CHARCELLS
245 int ret
= tagcache_get_commit_step();
249 #if CONFIG_CODEC == SWCODEC
250 /* hwcodec can't use voice here, as the database commit
251 * uses the audio buffer. */
252 static long talked_tick
= 0;
253 if(global_settings
.talk_menu
255 || TIME_AFTER(current_tick
, talked_tick
+7*HZ
)))
257 talked_tick
= current_tick
;
258 talk_id(LANG_TAGCACHE_INIT
, false);
259 talk_number(ret
, true);
260 talk_id(VOICE_OF
, true);
261 talk_number(tagcache_get_max_commit_step(), true);
264 #ifdef HAVE_LCD_BITMAP
265 splashf(0, "%s [%d/%d]",
266 str(LANG_TAGCACHE_INIT
), ret
,
267 tagcache_get_max_commit_step());
269 lcd_double_height(false);
270 snprintf(buf
, sizeof(buf
), " DB [%d/%d]", ret
,
271 tagcache_get_max_commit_step());
291 static void init(void)
297 #ifdef HAVE_REMOTE_LCD
308 /* Must be done before any code uses the multi-screen APi */
309 gui_syncstatusbar_init(&statusbars
);
312 settings_load(SETTINGS_ALL
);
314 settings_apply(true);
316 init_dircache(false);
325 #if CONFIG_CODEC != SWCODEC
326 mp3_init( global_settings
.volume
,
327 global_settings
.bass
,
328 global_settings
.treble
,
329 global_settings
.balance
,
330 global_settings
.loudness
,
332 global_settings
.channel_config
,
333 global_settings
.stereo_width
,
334 global_settings
.mdb_strength
,
335 global_settings
.mdb_harmonics
,
336 global_settings
.mdb_center
,
337 global_settings
.mdb_shape
,
338 global_settings
.mdb_enable
,
339 global_settings
.superbass
);
341 /* audio_init must to know the size of voice buffer so init voice first */
343 #endif /* CONFIG_CODEC != SWCODEC */
349 button_clear_queue(); /* Empty the keyboard buffer */
354 static void init(void)
357 bool mounted
= false;
358 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
359 /* if nobody initialized ATA before, I consider this a cold start */
360 bool coldstart
= (PACR2
& 0x4000) != 0; /* starting from Flash */
366 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
367 set_cpu_frequency(CPUFREQ_NORMAL
);
369 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS
);
387 #ifdef HAVE_REMOTE_LCD
398 #if !defined(HAVE_FMADC) && !(CONFIG_STORAGE & STORAGE_MMC)
407 settings_load(SETTINGS_RTC
); /* early load parts of global_settings */
413 #if CONFIG_USBOTG == USBOTG_ISP1362
415 #elif CONFIG_USBOTG == USBOTG_M5636
429 /* Must be done before any code uses the multi-screen APi */
430 gui_syncstatusbar_init(&statusbars
);
432 #if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
433 if (coldstart
&& charger_inserted()
434 && !global_settings
.car_adapter_mode
435 #ifdef ATA_POWER_PLAYERSTYLE
436 && !ide_powered() /* relies on probing result from bootloader */
440 rc
= charging_screen(); /* display a "charging" screen */
441 if (rc
== 1) /* charger removed */
443 /* "On" pressed or USB connected: proceed */
444 show_logo(); /* again, to provide better visual feedback */
451 #ifdef HAVE_LCD_BITMAP
454 snprintf(str
, 31, "ATA error: %d", rc
);
456 lcd_puts(0, 3, "Press ON to debug");
458 while(!(button_get(true) & BUTTON_REL
)); /*DO NOT CHANGE TO ACTION SYSTEM */
461 panicf("ata: %d", rc
);
464 #ifdef HAVE_EEPROM_SETTINGS
465 eeprom_settings_init();
468 usb_start_monitoring();
469 #ifndef HAVE_USBSTACK
470 while (usb_detect() == USB_INSERTED
)
472 #ifdef HAVE_EEPROM_SETTINGS
473 firmware_settings
.disk_clean
= false;
475 /* enter USB mode early, before trying to mount */
476 if (button_get_w_tmo(HZ
/10) == SYS_USB_CONNECTED
)
477 #if (CONFIG_STORAGE & STORAGE_MMC)
478 if (!mmc_touched() ||
479 (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED
))
483 mounted
= true; /* mounting done @ end of USB mode */
485 #ifdef HAVE_USB_POWER
486 if (usb_powered()) /* avoid deadlock */
494 rc
= disk_mount_all();
498 lcd_puts(0, 0, "No partition");
499 lcd_puts(0, 1, "found.");
500 #ifdef HAVE_LCD_BITMAP
501 lcd_puts(0, 2, "Insert USB cable");
502 lcd_puts(0, 3, "and fix it.");
506 while(button_get(true) != SYS_USB_CONNECTED
) {};
512 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \
513 (CONFIG_KEYPAD == IRIVER_H10_PAD)
514 #ifdef SETTINGS_RESET
515 /* Reset settings if holding the reset button. (Rec on Archos,
517 if ((button_status() & SETTINGS_RESET
) == SETTINGS_RESET
)
519 /* Reset settings if the hold button is turned on */
523 splash(HZ
*2, str(LANG_RESET_DONE_CLEAR
));
528 settings_load(SETTINGS_ALL
);
530 if (init_dircache(true) < 0)
533 remove(TAGCACHE_STATEFILE
);
538 settings_apply(true);
539 init_dircache(false);
544 #ifdef HAVE_EEPROM_SETTINGS
545 if (firmware_settings
.initialized
)
547 /* In case we crash. */
548 firmware_settings
.disk_clean
= false;
549 eeprom_settings_store();
559 #if CONFIG_CODEC != SWCODEC
560 /* No buffer allocation (see buffer.c) may take place after the call to
561 audio_init() since the mpeg thread takes the rest of the buffer space */
562 mp3_init( global_settings
.volume
,
563 global_settings
.bass
,
564 global_settings
.treble
,
565 global_settings
.balance
,
566 global_settings
.loudness
,
568 global_settings
.channel_config
,
569 global_settings
.stereo_width
,
570 global_settings
.mdb_strength
,
571 global_settings
.mdb_harmonics
,
572 global_settings
.mdb_center
,
573 global_settings
.mdb_shape
,
574 global_settings
.mdb_enable
,
575 global_settings
.superbass
);
577 /* audio_init must to know the size of voice buffer so init voice first */
579 #endif /* CONFIG_CODEC != SWCODEC */
583 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR)
587 /* runtime database has to be initialized after audio_init() */
592 static const char filename
[] = PLUGIN_APPS_DIR
"/autostart.rock";
594 if(file_exists(filename
)) /* no complaint if it doesn't exist */
596 plugin_load((char*)filename
, NULL
); /* start if it does */
599 #endif /* #ifdef AUTOROCK */
602 car_adapter_mode_init();
604 #ifdef IPOD_ACCESSORY_PROTOCOL
605 iap_setup(global_settings
.serial_bitrate
);
607 #ifdef HAVE_ACCESSORY_SUPPLY
608 accessory_supply_set(global_settings
.accessory_supply
);
615 /* This is the entry point for the coprocessor
616 Anyone not running an upgraded bootloader will never reach this point,
617 so it should not be assumed that the coprocessor be usable even on
618 platforms which support it.
620 A kernel thread is initially setup on the coprocessor and immediately
621 destroyed for purposes of continuity. The cop sits idle until at least
622 one thread exists on it. */
624 /* 3G doesn't have Rolo or dual core support yet */
628 /* This should never be reached */
641 #if (CONFIG_LED == LED_REAL)
642 led(true); sleep(HZ
/10);
643 led(false); sleep(HZ
/10);