slightly better touchpad driver. Still not brilliant, but the bootloader/debugger...
[Rockbox.git] / bootloader / mrobe500.c
blobc051e54fb6344e9ee8e2c4907de557cbe9e3e44b
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"
44 #include "time.h"
46 #define MRDEBUG
48 #if defined(MRDEBUG)
50 extern int line;
52 struct touch_calibration_point tl, br;
54 void touchpad_get_one_point(struct touch_calibration_point *p)
56 int data = 0;
57 int start = current_tick;
58 while (TIME_AFTER(start+(HZ/3), current_tick))
60 if (button_read_device()&BUTTON_TOUCHPAD)
62 data = button_get_last_touch();
63 p->val_x = data>>16;
64 p->val_y = data&0xffff;
65 start = current_tick;
67 else if (data == 0)
68 start = current_tick;
72 #define MARGIN 25
73 #define LEN 7
74 void touchpad_calibrate_screen(void)
76 reset_screen();
77 printf("touch the center of the crosshairs to calibrate");
78 /* get the topleft value */
79 lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN);
80 lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN);
81 lcd_update();
82 tl.px_x = MARGIN; tl.px_y = MARGIN;
83 touchpad_get_one_point(&tl);
84 reset_screen();
85 printf("touch the center of the crosshairs to calibrate");
86 /* get the topright value */
87 lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN);
88 lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN);
89 lcd_update();
90 br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN;
91 touchpad_get_one_point(&br);
92 reset_screen();
93 line++;
94 printf("tl %d %d", tl.val_x, tl.val_y);
95 printf("br %d %d", br.val_x, br.val_y);
96 line++;
97 set_calibration_points(&tl, &br);
100 void mrdebug(void)
102 int button=0, *address=0x0;
103 #if 0
104 use_calibration(false);
105 touchpad_calibrate_screen();
106 use_calibration(true);
107 #endif
108 while(true)
110 #if 0
111 struct tm *t = get_time();
112 printf("%d:%d:%d %d %d %d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon, t->tm_year);
113 printf("time: %d", mktime(t));
114 #endif
115 button = button_get(false);
116 if (button == BUTTON_POWER)
118 printf("reset");
119 IO_GIO_BITSET1|=1<<10;
121 if(button==BUTTON_RC_PLAY)
122 address+=0x02;
123 else if (button==BUTTON_RC_DOWN)
124 address-=0x02;
125 else if (button==BUTTON_RC_FF)
126 address+=0x1000;
127 else if (button==BUTTON_RC_REW)
128 address-=0x1000;
130 short x,y,z1,z2;
131 tsc2100_read_values(&x, &y, &z1, &z2);
132 printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
133 printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
134 printf("current tick: %04x", current_tick);
135 printf("Address: 0x%08x Data: 0x%08x", address, *address);
136 printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
137 printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
138 // tsc2100_keyclick(); /* doesnt work :( */
139 line -= 6;
141 #if 1
142 if (button&BUTTON_TOUCHPAD)
144 unsigned int data = button_get_data();
145 int x = (data&0xffff0000)>>16, y = data&0x0000ffff;
146 reset_screen();
147 lcd_hline(x-5, x+5, y);
148 lcd_vline(x, y-5, y+5);
149 lcd_update();
151 #endif
154 #endif
156 void main(void)
158 unsigned char* loadbuffer;
159 int buffer_size;
160 int rc;
161 int(*kernel_entry)(void);
163 power_init();
164 lcd_init();
165 system_init();
166 kernel_init();
167 adc_init();
168 button_init();
169 backlight_init();
170 uart_init();
172 font_init();
173 spi_init();
175 lcd_setfont(FONT_SYSFIXED);
177 /* Show debug messages if button is pressed */
178 // if(button_read_device())
179 verbose = true;
181 printf("Rockbox boot loader");
182 printf("Version %s", APPSVERSION);
184 usb_init();
186 /* Enter USB mode without USB thread */
187 if(usb_detect())
189 const char msg[] = "Bootloader USB mode";
190 reset_screen();
191 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
192 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
193 lcd_update();
195 ide_power_enable(true);
196 ata_enable(false);
197 sleep(HZ/20);
198 usb_enable(true);
200 while (usb_detect())
202 ata_spin(); /* Prevent the drive from spinning down */
203 sleep(HZ);
206 usb_enable(false);
208 reset_screen();
209 lcd_update();
211 #if defined(MRDEBUG)
212 mrdebug();
213 #endif
214 printf("ATA");
215 rc = ata_init();
216 if(rc)
218 reset_screen();
219 error(EATA, rc);
222 printf("disk");
223 disk_init();
225 printf("mount");
226 rc = disk_mount_all();
227 if (rc<=0)
229 error(EDISK,rc);
232 printf("Loading firmware");
234 loadbuffer = (unsigned char*) 0x00900000;
235 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
237 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
238 if(rc < 0)
239 error(EBOOTFILE, rc);
241 if (rc == EOK)
243 kernel_entry = (void*) loadbuffer;
244 rc = kernel_entry();