Fix building the manual on ubuntu (dash issue again). Also, make credits file generat...
[Rockbox.git] / bootloader / telechips.c
blob4c8b6ef5fdc89611083d475ae6f496857a106b90
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.h"
39 #include "backlight-target.h"
40 #include "panic.h"
41 #include "power.h"
42 #include "file.h"
43 #include "common.h"
45 #if defined(COWON_D2)
46 #include "i2c.h"
47 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
48 #endif
50 char version[] = APPSVERSION;
52 extern int line;
54 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
56 void show_debug_screen(void)
58 int button;
59 int power_count = 0;
60 int count = 0;
61 bool do_power_off = false;
63 while(!do_power_off) {
64 line = 0;
65 printf("Hello World!");
67 button = button_read_device();
69 /* Power-off if POWER button has been held for a long time
70 This loop is currently running at about 100 iterations/second
72 if (button & POWEROFF_BUTTON) {
73 power_count++;
74 if (power_count > 200)
75 do_power_off = true;
76 } else {
77 power_count = 0;
80 printf("Btn: 0x%08x",button);
82 #if defined(COWON_D2)
83 int i;
85 printf("GPIOA: 0x%08x",GPIOA);
86 printf("GPIOB: 0x%08x",GPIOB);
87 printf("GPIOC: 0x%08x",GPIOC);
88 printf("GPIOD: 0x%08x",GPIOD);
89 printf("GPIOE: 0x%08x",GPIOE);
91 for (i = 0; i<4; i++)
93 printf("ADC%d: 0x%04x",i,adc_read(i));
96 /* TODO: Move this stuff out to a touchscreen driver and establish
97 how such a beast is going to work. Since it needs I2C read/write,
98 it can't easily go on an interrupt-based tick task. */
100 unsigned char buf[] = { 0x2f, (0xE<<1) | 1, /* ADC start for X+Y */
101 0, 0, 0 };
102 int x,y;
103 i2c_write(0x10, buf, 2);
104 i2c_readmem(0x10, 0x2e, buf, 5);
105 x = (buf[2] << 2) | (buf[3] & 3);
106 y = (buf[4] << 2) | ((buf[3] & 0xC) >> 2);
107 printf("X: 0x%03x Y: 0x%03x",x,y);
109 x = (x*LCD_WIDTH) / 1024;
110 y = (y*LCD_HEIGHT) / 1024;
111 lcd_hline(x-5, x+5, y);
112 lcd_vline(x, y-5, y+5);
114 buf[0] = 0x2f;
115 buf[1] = (0xF<<1) | 1; /* ADC start for P1+P2 */
116 i2c_write(0x10, buf, 2);
117 i2c_readmem(0x10, 0x2e, buf, 5);
118 x = (buf[2] << 2) | (buf[3] & 3);
119 y = (buf[4] << 2) | ((buf[3] & 0xC) >> 2);
120 printf("P1: 0x%03x P2: 0x%03x",x,y);
122 #endif
124 count++;
125 printf("Count: %d",count);
128 lcd_clear_display();
129 line = 0;
130 printf("POWER-OFF");
132 /* Power-off */
133 power_off();
135 printf("(NOT) POWERED OFF");
136 while (true);
140 void* main(void)
142 #if defined(COWON_D2) && defined(TCCBOOT)
143 int rc;
144 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
145 #endif
147 power_init();
148 system_init();
149 lcd_init();
151 adc_init();
152 button_init();
153 backlight_init();
155 font_init();
156 lcd_setfont(FONT_SYSFIXED);
158 _backlight_on();
160 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
161 available for loading the firmware. Otherwise display the debug screen. */
162 #if defined(COWON_D2) && defined(TCCBOOT)
163 printf("Rockbox boot loader");
164 printf("Version %s", version);
166 printf("ATA");
167 rc = ata_init();
168 if(rc)
170 reset_screen();
171 error(EATA, rc);
174 printf("mount");
175 rc = disk_mount_all();
176 if (rc<=0)
178 error(EDISK,rc);
181 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
183 if (rc < 0)
185 error(EBOOTFILE,rc);
187 else if (rc == EOK)
189 int(*kernel_entry)(void);
191 /* wait for button release to allow debug statememts to be read */
192 while (button_read_device()) {};
194 kernel_entry = (void*) loadbuffer;
196 /* allow entry to the debug screen if hold is on */
197 if (!button_hold()) rc = kernel_entry();
199 #endif
200 show_debug_screen();
202 return 0;
205 /* These functions are present in the firmware library, but we reimplement
206 them here because the originals do a lot more than we want */
207 void usb_acknowledge(void)
211 void usb_wait_for_disconnect(void)