fix themes not being fully applied to the menu on load (Hopefully fixes FS#8808)
[Rockbox.git] / bootloader / telechips.c
blob305bdf3081cfa9de85124bc2f4dcd39aa03aae01
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 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "cpu.h"
27 #include "system.h"
28 #include "lcd.h"
29 #include "kernel.h"
30 #include "thread.h"
31 #include "ata.h"
32 #include "fat.h"
33 #include "disk.h"
34 #include "font.h"
35 #include "button.h"
36 #include "adc.h"
37 #include "adc-target.h"
38 #include "backlight-target.h"
39 #include "panic.h"
40 #include "power.h"
41 #include "file.h"
42 #include "common.h"
44 #if defined(COWON_D2)
45 #include "i2c.h"
46 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
47 #endif
49 char version[] = APPSVERSION;
51 extern int line;
53 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
55 void* main(void)
57 int button;
58 int power_count = 0;
59 int count = 0;
60 bool do_power_off = false;
62 #if defined(COWON_D2) && defined(TCCBOOT)
63 int rc;
64 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
65 #endif
67 power_init();
68 system_init();
69 lcd_init();
71 adc_init();
72 button_init();
73 backlight_init();
75 font_init();
76 lcd_setfont(FONT_SYSFIXED);
78 _backlight_on();
80 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
81 available for loading the firmware. Otherwise display the debug screen. */
82 #if defined(COWON_D2) && defined(TCCBOOT)
83 printf("Rockbox boot loader");
84 printf("Version %s", version);
86 printf("ATA");
87 rc = ata_init();
88 if(rc)
90 reset_screen();
91 error(EATA, rc);
94 printf("mount");
95 rc = disk_mount_all();
96 if (rc<=0)
98 error(EDISK,rc);
101 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
103 if (rc < 0)
105 error(EBOOTFILE,rc);
107 else if (rc == EOK)
109 int(*kernel_entry)(void);
111 kernel_entry = (void*) loadbuffer;
112 rc = kernel_entry();
114 #else
116 while(!do_power_off) {
117 line = 0;
118 printf("Hello World!");
120 button = button_read_device();
122 /* Power-off if POWER button has been held for a long time
123 This loop is currently running at about 100 iterations/second
125 if (button & POWEROFF_BUTTON) {
126 power_count++;
127 if (power_count > 200)
128 do_power_off = true;
129 } else {
130 power_count = 0;
133 printf("Btn: 0x%08x",button);
135 #if defined(COWON_D2)
136 int i;
138 printf("GPIOA: 0x%08x",GPIOA);
139 printf("GPIOB: 0x%08x",GPIOB);
140 printf("GPIOC: 0x%08x",GPIOC);
141 printf("GPIOD: 0x%08x",GPIOD);
142 printf("GPIOE: 0x%08x",GPIOE);
144 for (i = 0; i<4; i++)
146 printf("ADC%d: 0x%04x",i,adc_read(i));
149 /* TODO: Move this stuff out to a touchscreen driver and establish
150 how such a beast is going to work. Since it needs I2C read/write,
151 it can't easily go on an interrupt-based tick task. */
153 unsigned char buf[] = { 0x2f, (0xE<<1) | 1, /* ADC start for X+Y */
154 0, 0, 0 };
155 int x,y;
156 i2c_write(0x10, buf, 2);
157 i2c_readmem(0x10, 0x2e, buf, 5);
158 x = (buf[2] << 2) | (buf[3] & 3);
159 y = (buf[4] << 2) | ((buf[3] & 0xC) >> 2);
160 printf("X: 0x%03x Y: 0x%03x",x,y);
162 x = (x*LCD_WIDTH) / 1024;
163 y = (y*LCD_HEIGHT) / 1024;
164 lcd_hline(x-5, x+5, y);
165 lcd_vline(x, y-5, y+5);
167 buf[0] = 0x2f;
168 buf[1] = (0xF<<1) | 1; /* ADC start for P1+P2 */
169 i2c_write(0x10, buf, 2);
170 i2c_readmem(0x10, 0x2e, buf, 5);
171 x = (buf[2] << 2) | (buf[3] & 3);
172 y = (buf[4] << 2) | ((buf[3] & 0xC) >> 2);
173 printf("P1: 0x%03x P2: 0x%03x",x,y);
175 #endif
177 count++;
178 printf("Count: %d",count);
181 lcd_clear_display();
182 line = 0;
183 printf("POWER-OFF");
185 /* Power-off */
186 power_off();
188 printf("(NOT) POWERED OFF");
189 #endif
191 return 0;
194 /* These functions are present in the firmware library, but we reimplement
195 them here because the originals do a lot more than we want */
196 void usb_acknowledge(void)
200 void usb_wait_for_disconnect(void)