IRQ driven touchpad driver, crude but working
[Rockbox.git] / bootloader / mrobe500.c
blobb92096ada23f6a513d33f8057a26e658e8d754ba
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
10 * Copyright (C) 2007 by Karl Kurbjun
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 ****************************************************************************/
20 #include "inttypes.h"
21 #include "string.h"
22 #include "cpu.h"
23 #include "system.h"
24 #include "lcd.h"
25 #include "kernel.h"
26 #include "thread.h"
27 #include "ata.h"
28 #include "fat.h"
29 #include "disk.h"
30 #include "font.h"
31 #include "adc.h"
32 #include "backlight.h"
33 #include "backlight-target.h"
34 #include "button.h"
35 #include "panic.h"
36 #include "power.h"
37 #include "file.h"
38 #include "common.h"
39 #include "rbunicode.h"
40 #include "usb.h"
41 #include "spi.h"
42 #include "uart-target.h"
43 #include "tsc2100.h"
45 extern int line;
47 void main(void)
49 unsigned char* loadbuffer;
50 int buffer_size;
51 int rc;
52 int(*kernel_entry)(void);
54 power_init();
55 lcd_init();
56 system_init();
57 kernel_init();
58 adc_init();
59 button_init();
60 backlight_init();
61 uart_init();
63 font_init();
64 spi_init();
66 lcd_setfont(FONT_SYSFIXED);
68 /* Show debug messages if button is pressed */
69 // if(button_read_device())
70 verbose = true;
72 printf("Rockbox boot loader");
73 printf("Version %s", APPSVERSION);
75 usb_init();
77 /* Enter USB mode without USB thread */
78 if(usb_detect())
80 const char msg[] = "Bootloader USB mode";
81 reset_screen();
82 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
83 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
84 lcd_update();
86 ide_power_enable(true);
87 ata_enable(false);
88 sleep(HZ/20);
89 usb_enable(true);
91 while (usb_detect())
93 ata_spin(); /* Prevent the drive from spinning down */
94 sleep(HZ);
97 usb_enable(false);
99 reset_screen();
100 lcd_update();
102 #if 0
103 int button=0, *address=0x0, count=0;
104 while(true)
106 button = button_read_device();
107 if (button == BUTTON_POWER)
109 printf("reset");
110 IO_GIO_BITSET1|=1<<10;
112 if(button==BUTTON_RC_PLAY)
113 address+=0x02;
114 else if (button==BUTTON_RC_DOWN)
115 address-=0x02;
116 else if (button==BUTTON_RC_FF)
117 address+=0x1000;
118 else if (button==BUTTON_RC_REW)
119 address-=0x1000;
120 if (button&BUTTON_TOUCHPAD)
122 int touch = button_get_last_touch();
123 printf("x: %d, y: %d", (touch>>16), touch&0xffff);
124 line--;
126 // if ((IO_GIO_BITSET0&(1<<14) == 0)
127 // {
128 // short x,y,z1,z2, reg;
129 // extern int uart1count;
130 // tsc2100_read_values(&x, &y, &z1, &z2);
131 // printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
132 // printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
133 // printf("current tick: %04x", current_tick);
134 // printf("Address: 0x%08x Data: 0x%08x", address, *address);
135 // printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
136 // printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
137 // printf("uart1count: %d", uart1count);
138 // printf("%x %x", IO_UART1_RFCR & 0x3f, IO_UART1_DTRR & 0xff);
139 // tsc2100_keyclick(); /* doesnt work :( */
140 // line -= 8;
141 // }
143 #endif
144 printf("ATA");
145 rc = ata_init();
146 if(rc)
148 reset_screen();
149 error(EATA, rc);
152 printf("disk");
153 disk_init();
155 printf("mount");
156 rc = disk_mount_all();
157 if (rc<=0)
159 error(EDISK,rc);
162 printf("Loading firmware");
164 loadbuffer = (unsigned char*) 0x00900000;
165 buffer_size = (unsigned char*)0x00100000 - loadbuffer;
167 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
168 if(rc < 0)
169 error(EBOOTFILE, rc);
171 if (rc == EOK)
173 kernel_entry = (void*) loadbuffer;
174 rc = kernel_entry();