Use DBOP to check for left button on C200v2 like we are supposed to instead of right...
[kugel-rb.git] / bootloader / telechips.c
blobadf3e634838e315c7ace265e801cf4dbd122588d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Dave Chapman
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "config.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include "cpu.h"
29 #include "system.h"
30 #include "lcd.h"
31 #include "kernel.h"
32 #include "thread.h"
33 #include "storage.h"
34 #include "fat.h"
35 #include "disk.h"
36 #include "font.h"
37 #include "button.h"
38 #include "adc.h"
39 #include "adc-target.h"
40 #include "backlight.h"
41 #include "backlight-target.h"
42 #include "panic.h"
43 #include "power.h"
44 #include "file.h"
45 #include "common.h"
46 #include "version.h"
48 /* Show the Rockbox logo - in show_logo.c */
49 extern int show_logo(void);
51 /* Address to load main Rockbox image to */
52 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
54 extern int line;
56 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
58 /* The following function is just test/development code */
59 void show_debug_screen(void)
61 int button;
62 int power_count = 0;
63 int count = 0;
64 bool do_power_off = false;
66 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
67 while (!do_power_off) {
68 line = 1;
69 button = button_get(false);
71 /* Power-off if POWER button has been held for a time
72 This loop is currently running at about 100 iterations/second
74 if (button & POWEROFF_BUTTON) {
75 power_count++;
76 if (power_count > 100)
77 do_power_off = true;
78 } else {
79 power_count = 0;
81 #if 0
82 if (button & BUTTON_SELECT){
83 _backlight_off();
85 else{
86 _backlight_on();
88 #endif
89 printf("Btn: 0x%08x",button);
90 #if 0
91 printf("Tick: %d",current_tick);
92 printf("GPIOA: 0x%08x",GPIOA);
93 printf("GPIOB: 0x%08x",GPIOB);
94 printf("GPIOC: 0x%08x",GPIOC);
95 printf("GPIOD: 0x%08x",GPIOD);
96 printf("GPIOE: 0x%08x",GPIOE);
97 #endif
99 #if 0
100 int i;
101 for (i = 0; i<4; i++)
103 printf("ADC%d: 0x%04x",i,adc_read(i));
105 #endif
106 count++;
107 printf("Count: %d",count);
108 lcd_update();
109 sleep(HZ/10);
113 lcd_clear_display();
114 line = 0;
115 printf("POWER-OFF");
117 /* Power-off */
118 power_off();
120 printf("(NOT) POWERED OFF");
121 while (true);
124 void* main(void)
126 #ifdef TCCBOOT
127 int rc;
128 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
129 #endif
131 system_init();
132 power_init();
134 kernel_init();
135 enable_irq();
137 lcd_init();
139 adc_init();
140 button_init();
141 backlight_init();
143 font_init();
144 lcd_setfont(FONT_SYSFIXED);
146 show_logo();
148 _backlight_on();
150 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
151 available for loading the firmware. Otherwise display the debug screen. */
152 #ifdef TCCBOOT
153 printf("Rockbox boot loader");
154 printf("Version " RBVERSION);
156 printf("ATA");
157 rc = storage_init();
158 if(rc)
160 reset_screen();
161 error(EATA, rc, true);
164 printf("mount");
165 rc = disk_mount_all();
166 if (rc<=0)
168 error(EDISK,rc, true);
171 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
173 if (rc < 0)
175 error(EBOOTFILE,rc, true);
177 else if (rc == EOK)
179 int(*kernel_entry)(void) = (void *) loadbuffer;
181 disable_irq();
182 rc = kernel_entry();
185 panicf("Boot failed!");
186 #else
187 show_debug_screen();
188 #endif
190 return 0;