Fix b&w LCD targets.
[maemo-rb.git] / apps / main.c
blob7bfc438cfda952b6f2e92c48f87d5c14a38d6f20
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 "thread.h"
44 #include "settings.h"
45 #include "backlight.h"
46 #include "status.h"
47 #include "debug_menu.h"
48 #include "version.h"
49 #include "sprintf.h"
50 #include "font.h"
51 #include "language.h"
52 #include "gwps.h"
53 #include "playlist.h"
54 #include "buffer.h"
55 #include "rolo.h"
56 #include "screens.h"
57 #include "power.h"
58 #include "talk.h"
59 #include "plugin.h"
60 #include "misc.h"
61 #include "database.h"
62 #include "dircache.h"
63 #include "tagcache.h"
64 #include "tagtree.h"
65 #include "lang.h"
66 #include "string.h"
67 #include "splash.h"
69 #if (CONFIG_CODEC == SWCODEC)
70 #include "playback.h"
71 #include "pcmbuf.h"
72 #else
73 #define pcmbuf_init()
74 #endif
75 #if (defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)) && !defined(SIMULATOR)
76 #include "pcm_record.h"
77 #define SETTINGS_RESET BUTTON_REC
78 #endif
80 #ifdef CONFIG_TUNER
81 #include "radio.h"
82 #endif
83 #ifdef HAVE_MMC
84 #include "ata_mmc.h"
85 #endif
87 #ifdef HAVE_REMOTE_LCD
88 #include "lcd-remote.h"
89 #endif
91 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
93 const char appsversion[]=APPSVERSION;
95 void init(void);
97 void app_main(void)
99 init();
100 browse_root();
103 #ifdef HAVE_DIRCACHE
104 void init_dircache(void)
106 int result;
107 bool clear = false;
109 dircache_init();
110 if (global_settings.dircache)
112 if (global_settings.dircache_size == 0)
114 gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING));
115 clear = true;
118 result = dircache_build(global_settings.dircache_size);
119 if (result < 0)
120 gui_syncsplash(0, true, "Failed! Result: %d", result);
122 if (clear)
124 backlight_on();
125 show_logo();
129 #else
130 # define init_dircache(...)
131 #endif
133 void init_tagcache(void)
135 bool clear = false;
137 tagcache_init();
139 while (!tagcache_is_initialized())
141 #ifdef HAVE_LCD_CHARCELLS
142 char buf[32];
143 #endif
144 int ret = tagcache_get_commit_step();
146 if (ret > 0)
148 #ifdef HAVE_LCD_BITMAP
149 gui_syncsplash(0, true, "%s [%d/%d]",
150 str(LANG_TAGCACHE_INIT), ret, TAG_COUNT);
151 #else
152 lcd_double_height(false);
153 snprintf(buf, sizeof(buf), " TC [%d/%d]", ret, TAG_COUNT);
154 lcd_puts(0, 1, buf);
155 #endif
156 clear = true;
158 sleep(HZ/4);
160 tagtree_init();
162 if (clear)
164 backlight_on();
165 show_logo();
169 #ifdef SIMULATOR
171 void init(void)
173 init_threads();
174 buffer_init();
175 lcd_init();
176 #ifdef HAVE_REMOTE_LCD
177 lcd_remote_init();
178 #endif
179 font_init();
180 show_logo();
181 button_init();
182 backlight_init();
183 lang_init();
184 /* Must be done before any code uses the multi-screen APi */
185 screen_access_init();
186 gui_syncstatusbar_init(&statusbars);
187 settings_reset();
188 settings_calc_config_sector();
189 settings_load(SETTINGS_ALL);
190 gui_sync_wps_init();
191 settings_apply();
192 init_dircache();
193 init_tagcache();
194 sleep(HZ/2);
195 tree_init();
196 playlist_init();
197 mp3_init( global_settings.volume,
198 global_settings.bass,
199 global_settings.treble,
200 global_settings.balance,
201 global_settings.loudness,
202 global_settings.avc,
203 global_settings.channel_config,
204 global_settings.stereo_width,
205 global_settings.mdb_strength,
206 global_settings.mdb_harmonics,
207 global_settings.mdb_center,
208 global_settings.mdb_shape,
209 global_settings.mdb_enable,
210 global_settings.superbass);
212 #if CONFIG_CODEC == SWCODEC
213 audio_preinit();
214 #endif
216 /* audio_init must to know the size of voice buffer so init voice first */
217 #if CONFIG_CODEC == SWCODEC
218 talk_init();
219 #endif
221 audio_init();
222 button_clear_queue(); /* Empty the keyboard buffer */
225 #else
227 void init(void)
229 int rc;
230 bool mounted = false;
231 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
232 /* if nobody initialized ATA before, I consider this a cold start */
233 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
234 #endif
235 system_init();
236 kernel_init();
238 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
239 set_cpu_frequency(CPUFREQ_NORMAL);
240 cpu_boost(true);
241 #endif
243 buffer_init();
245 settings_reset();
247 power_init();
249 set_irq_level(0);
250 lcd_init();
251 #ifdef HAVE_REMOTE_LCD
252 lcd_remote_init();
253 #endif
254 font_init();
255 show_logo();
256 lang_init();
258 #ifdef DEBUG
259 debug_init();
260 #else
261 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
262 * (do debug builds on the Ondio make sense?) */
263 serial_setup();
264 #endif
265 #endif
267 i2c_init();
269 #ifdef CONFIG_RTC
270 rtc_init();
271 #endif
272 #ifdef HAVE_RTC_RAM
273 settings_load(SETTINGS_RTC); /* early load parts of global_settings */
274 #endif
276 adc_init();
278 usb_init();
280 backlight_init();
282 button_init();
284 powermgmt_init();
286 #if CONFIG_CODEC == SWCODEC
287 audio_preinit();
288 #endif
290 #ifdef CONFIG_TUNER
291 radio_init();
292 #endif
294 /* Must be done before any code uses the multi-screen APi */
295 screen_access_init();
296 gui_syncstatusbar_init(&statusbars);
298 #if defined(CONFIG_CHARGING) && (CONFIG_CPU == SH7034)
299 if (coldstart && charger_inserted()
300 && !global_settings.car_adapter_mode
301 #ifdef ATA_POWER_PLAYERSTYLE
302 && !ide_powered() /* relies on probing result from bootloader */
303 #endif
306 rc = charging_screen(); /* display a "charging" screen */
307 if (rc == 1) /* charger removed */
308 power_off();
309 /* "On" pressed or USB connected: proceed */
310 show_logo(); /* again, to provide better visual feedback */
312 #endif
314 rc = ata_init();
315 if(rc)
317 #ifdef HAVE_LCD_BITMAP
318 char str[32];
319 lcd_clear_display();
320 snprintf(str, 31, "ATA error: %d", rc);
321 lcd_puts(0, 1, str);
322 lcd_puts(0, 3, "Press ON to debug");
323 lcd_update();
324 while(!(button_get(true) & BUTTON_REL));
325 dbg_ports();
326 #endif
327 panicf("ata: %d", rc);
330 usb_start_monitoring();
331 while (usb_detect())
332 { /* enter USB mode early, before trying to mount */
333 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
334 #ifdef HAVE_MMC
335 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
336 #endif
338 usb_screen();
339 mounted = true; /* mounting done @ end of USB mode */
341 #ifdef HAVE_USB_POWER
342 if (usb_powered()) /* avoid deadlock */
343 break;
344 #endif
347 if (!mounted)
349 rc = disk_mount_all();
350 if (rc<=0)
352 lcd_clear_display();
353 lcd_puts(0, 0, "No partition");
354 lcd_puts(0, 1, "found.");
355 #ifdef HAVE_LCD_BITMAP
356 lcd_puts(0, 2, "Insert USB cable");
357 lcd_puts(0, 3, "and fix it.");
358 lcd_update();
359 #endif
360 while(button_get(true) != SYS_USB_CONNECTED) {};
361 usb_screen();
362 system_reboot();
366 settings_calc_config_sector();
368 #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD)
369 #ifdef SETTINGS_RESET
370 /* Reset settings if holding the rec button. */
371 if ((button_status() & SETTINGS_RESET) == SETTINGS_RESET)
372 #else
373 /* Reset settings if the hold button is turned on */
374 if (button_hold())
375 #endif
377 gui_syncsplash(HZ*2, true, str(LANG_RESET_DONE_CLEAR));
378 settings_reset();
380 else
381 #endif
382 settings_load(SETTINGS_ALL);
385 gui_sync_wps_init();
386 settings_apply();
387 init_dircache();
388 init_tagcache();
390 status_init();
391 playlist_init();
392 tree_init();
394 /* No buffer allocation (see buffer.c) may take place after the call to
395 audio_init() since the mpeg thread takes the rest of the buffer space */
396 mp3_init( global_settings.volume,
397 global_settings.bass,
398 global_settings.treble,
399 global_settings.balance,
400 global_settings.loudness,
401 global_settings.avc,
402 global_settings.channel_config,
403 global_settings.stereo_width,
404 global_settings.mdb_strength,
405 global_settings.mdb_harmonics,
406 global_settings.mdb_center,
407 global_settings.mdb_shape,
408 global_settings.mdb_enable,
409 global_settings.superbass);
411 /* audio_init must to know the size of voice buffer so init voice first */
412 talk_init();
414 audio_init();
415 #if (defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)) && !defined(SIMULATOR)
416 pcm_rec_init();
417 #endif
419 /* runtime database has to be initialized after audio_init() */
420 cpu_boost(false);
422 #ifdef AUTOROCK
424 int fd;
425 static const char filename[] = PLUGIN_DIR "/autostart.rock";
427 fd = open(filename, O_RDONLY);
428 if(fd >= 0) /* no complaint if it doesn't exist */
430 close(fd);
431 plugin_load((char*)filename, NULL); /* start if it does */
434 #endif /* #ifdef AUTOROCK */
436 #ifdef CONFIG_CHARGING
437 car_adapter_mode_init();
438 #endif
441 int main(void)
443 app_main();
445 while(1) {
446 #if CONFIG_LED == LED_REAL
447 led(true); sleep(HZ/10);
448 led(false); sleep(HZ/10);
449 #endif
451 return 0;
453 #endif