Fix for ff/rw in long MP3 files.
[kugel-rb.git] / apps / main.c
blob90be703c6b93bc4baf352ad86dad96fa900bf68d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
19 #include "config.h"
21 #include "ata.h"
22 #include "disk.h"
23 #include "fat.h"
24 #include "lcd.h"
25 #include "rtc.h"
26 #include "debug.h"
27 #include "led.h"
28 #include "kernel.h"
29 #include "button.h"
30 #include "tree.h"
31 #include "panic.h"
32 #include "menu.h"
33 #include "system.h"
34 #include "usb.h"
35 #include "powermgmt.h"
36 #include "adc.h"
37 #include "i2c.h"
38 #ifndef DEBUG
39 #include "serial.h"
40 #endif
41 #include "audio.h"
42 #include "mp3_playback.h"
43 #include "main_menu.h"
44 #include "thread.h"
45 #include "settings.h"
46 #include "backlight.h"
47 #include "status.h"
48 #include "debug_menu.h"
49 #include "version.h"
50 #include "sprintf.h"
51 #include "font.h"
52 #include "language.h"
53 #include "wps-display.h"
54 #include "playlist.h"
55 #include "buffer.h"
56 #include "rolo.h"
57 #include "screens.h"
58 #include "power.h"
59 #include "talk.h"
60 #include "plugin.h"
61 #include "misc.h"
62 #include "database.h"
64 #if (CONFIG_HWCODEC == MASNONE)
65 #include "pcmbuf.h"
66 #else
67 #define pcmbuf_init()
68 #endif
69 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
70 #include "pcm_record.h"
71 #endif
73 #ifdef CONFIG_TUNER
74 #include "radio.h"
75 #endif
76 #ifdef HAVE_MMC
77 #include "ata_mmc.h"
78 #endif
80 #ifdef HAVE_REMOTE_LCD
81 #include "lcd-remote.h"
82 #endif
84 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
86 const char appsversion[]=APPSVERSION;
88 void init(void);
90 void app_main(void)
92 init();
93 browse_root();
96 #ifdef SIMULATOR
98 void init(void)
100 init_threads();
101 buffer_init();
102 lcd_init();
103 #ifdef HAVE_REMOTE_LCD
104 lcd_remote_init();
105 #endif
106 font_init();
107 show_logo();
108 lang_init();
109 audio_init();
110 settings_reset();
111 settings_calc_config_sector();
112 settings_load(SETTINGS_ALL);
113 settings_apply();
114 sleep(HZ/2);
115 tree_init();
116 playlist_init();
117 mp3_init( global_settings.volume,
118 global_settings.bass,
119 global_settings.treble,
120 global_settings.balance,
121 global_settings.loudness,
122 global_settings.avc,
123 global_settings.channel_config,
124 global_settings.stereo_width,
125 global_settings.mdb_strength,
126 global_settings.mdb_harmonics,
127 global_settings.mdb_center,
128 global_settings.mdb_shape,
129 global_settings.mdb_enable,
130 global_settings.superbass);
131 button_clear_queue(); /* Empty the keyboard buffer */
134 #else
136 void init(void)
138 int rc;
139 bool mounted = false;
140 #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
141 /* if nobody initialized ATA before, I consider this a cold start */
142 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
143 #endif
144 system_init();
145 kernel_init();
147 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
148 set_cpu_frequency(CPUFREQ_NORMAL);
149 #endif
151 buffer_init();
153 settings_reset();
155 lcd_init();
156 #ifdef HAVE_REMOTE_LCD
157 lcd_remote_init();
158 #endif
159 font_init();
160 show_logo();
161 lang_init();
163 set_irq_level(0);
164 #ifdef DEBUG
165 debug_init();
166 #else
167 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
168 * (do debug builds on the Ondio make sense?) */
169 serial_setup();
170 #endif
171 #endif
173 i2c_init();
175 #ifdef HAVE_RTC
176 rtc_init();
177 settings_load(SETTINGS_RTC); /* early load parts of global_settings */
178 #endif
180 adc_init();
182 usb_init();
184 backlight_init();
186 button_init();
188 powermgmt_init();
190 #ifdef CONFIG_TUNER
191 radio_init();
192 #endif
194 #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
195 if (coldstart && charger_inserted()
196 && !global_settings.car_adapter_mode
197 #ifdef ATA_POWER_PLAYERSTYLE
198 && !ide_powered() /* relies on probing result from bootloader */
199 #endif
202 rc = charging_screen(); /* display a "charging" screen */
203 if (rc == 1) /* charger removed */
204 power_off();
205 /* "On" pressed or USB connected: proceed */
206 show_logo(); /* again, to provide better visual feedback */
208 #endif
210 rc = ata_init();
211 if(rc)
213 #ifdef HAVE_LCD_BITMAP
214 char str[32];
215 lcd_clear_display();
216 snprintf(str, 31, "ATA error: %d", rc);
217 lcd_puts(0, 1, str);
218 lcd_puts(0, 3, "Press ON to debug");
219 lcd_update();
220 while(!(button_get(true) & BUTTON_REL));
221 dbg_ports();
222 #endif
223 panicf("ata: %d", rc);
226 usb_start_monitoring();
227 while (usb_detect())
228 { /* enter USB mode early, before trying to mount */
229 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
230 #ifdef HAVE_MMC
231 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
232 #endif
234 usb_screen();
235 mounted = true; /* mounting done @ end of USB mode */
237 #ifdef HAVE_USB_POWER
238 if (usb_powered()) /* avoid deadlock */
239 break;
240 #endif
243 if (!mounted)
245 rc = disk_mount_all();
246 if (rc<=0)
248 lcd_clear_display();
249 lcd_puts(0, 0, "No partition");
250 lcd_puts(0, 1, "found.");
251 #ifdef HAVE_LCD_BITMAP
252 lcd_puts(0, 2, "Insert USB cable");
253 lcd_puts(0, 3, "and fix it.");
254 lcd_update();
255 #endif
256 while(button_get(true) != SYS_USB_CONNECTED) {};
257 usb_screen();
258 system_reboot();
262 /* On software codec platforms we have to init audio before
263 calling audio_set_buffer_margin(). */
264 #if (CONFIG_HWCODEC == MASNONE)
265 audio_init();
266 #endif
267 settings_calc_config_sector();
268 settings_load(SETTINGS_ALL);
269 settings_apply();
271 status_init();
272 playlist_init();
273 tree_init();
275 /* No buffer allocation (see buffer.c) may take place after the call to
276 audio_init() since the mpeg thread takes the rest of the buffer space */
277 mp3_init( global_settings.volume,
278 global_settings.bass,
279 global_settings.treble,
280 global_settings.balance,
281 global_settings.loudness,
282 global_settings.avc,
283 global_settings.channel_config,
284 global_settings.stereo_width,
285 global_settings.mdb_strength,
286 global_settings.mdb_harmonics,
287 global_settings.mdb_center,
288 global_settings.mdb_shape,
289 global_settings.mdb_enable,
290 global_settings.superbass);
291 #if (CONFIG_HWCODEC == MASNONE)
292 sound_settings_apply();
293 #else
294 audio_init();
295 #endif
296 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
297 pcm_init_recording();
298 #endif
299 talk_init();
300 /* runtime database has to be initialized after audio_init() */
301 rundb_init();
304 #ifdef AUTOROCK
306 int fd;
307 static const char filename[] = PLUGIN_DIR "/autostart.rock";
309 fd = open(filename, O_RDONLY);
310 if(fd >= 0) /* no complaint if it doesn't exist */
312 close(fd);
313 plugin_load((char*)filename, NULL); /* start if it does */
316 #endif /* #ifdef AUTOROCK */
318 #ifdef HAVE_CHARGING
319 car_adapter_mode_init();
320 #endif
323 int main(void)
325 app_main();
327 while(1) {
328 #if CONFIG_LED == LED_REAL
329 led(true); sleep(HZ/10);
330 led(false); sleep(HZ/10);
331 #endif
333 return 0;
335 #endif