Fix APE 16-bit mono output: mono signals need to be scaled for rockbox.
[kugel-rb.git] / bootloader / mrobe500.c
blobf92ff4bf843a66e4fe2954de1bdc4c45a1472662
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Karl Kurbjun
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "inttypes.h"
23 #include "string.h"
24 #include "cpu.h"
25 #include "system.h"
26 #include "lcd.h"
27 #include "kernel.h"
28 #include "thread.h"
29 #include "storage.h"
30 #include "fat.h"
31 #include "disk.h"
32 #include "font.h"
33 #include "adc.h"
34 #include "backlight.h"
35 #include "backlight-target.h"
36 #include "button.h"
37 #include "panic.h"
38 #include "power.h"
39 #include "file.h"
40 #include "common.h"
41 #include "rbunicode.h"
42 #include "usb.h"
43 #include "spi.h"
44 #include "uart-target.h"
45 #include "tsc2100.h"
46 #include "time.h"
47 #include "system-arm.h"
49 #define MRDEBUG
51 #if defined(MRDEBUG)
53 extern int line;
54 #if 0
55 struct touch_calibration_point tl, br;
57 void touchscreen_get_one_point(struct touch_calibration_point *p)
59 int data = 0;
60 int start = current_tick;
61 while (TIME_AFTER(start+(HZ/3), current_tick))
63 if (button_read_device()&BUTTON_TOUCHSCREEN)
65 data = button_get_last_touch();
66 p->val_x = data>>16;
67 p->val_y = data&0xffff;
68 start = current_tick;
70 else if (data == 0)
71 start = current_tick;
75 #define MARGIN 25
76 #define LEN 7
77 void touchscreen_calibrate_screen(void)
79 reset_screen();
80 printf("touch the center of the crosshairs to calibrate");
81 /* get the topleft value */
82 lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN);
83 lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN);
84 lcd_update();
85 tl.px_x = MARGIN; tl.px_y = MARGIN;
86 touchscreen_get_one_point(&tl);
87 reset_screen();
88 printf("touch the center of the crosshairs to calibrate");
89 /* get the topright value */
90 lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN);
91 lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN);
92 lcd_update();
93 br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN;
94 touchscreen_get_one_point(&br);
95 reset_screen();
96 line++;
97 printf("tl %d %d", tl.val_x, tl.val_y);
98 printf("br %d %d", br.val_x, br.val_y);
99 line++;
100 set_calibration_points(&tl, &br);
102 #endif
103 static uint8_t bl_command[] = {0xa4, 0x00, 0x00, 0xbb};
104 int brightness = 0;
106 void mrdebug(void)
108 int button=0;
109 #if 0
110 use_calibration(false);
111 touchscreen_calibrate_screen();
112 use_calibration(true);
113 #endif
115 while(true)
117 #if 0
118 struct tm *t = get_time();
119 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);
120 printf("time: %d", mktime(t));
121 #endif
122 button = button_get(false);
123 if (button == BUTTON_POWER)
125 printf("reset");
126 IO_GIO_BITSET1|=1<<10;
128 if (button==BUTTON_RC_VOL_DOWN)
130 brightness = (brightness - 5) & 0x7f;
131 bl_command[2] = brightness;
132 spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
134 else if (button==BUTTON_RC_VOL_UP)
136 brightness = (brightness + 5) & 0x7f;
137 bl_command[2] = brightness;
138 spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
140 // {
141 // short x,y,z1,z2;
142 // tsc2100_read_values(&x, &y, &z1, &z2);
143 // printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
144 // printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
145 // // tsc2100_keyclick(); /* doesnt work :( */
146 // line -= 6;
147 // }
148 else if (button == BUTTON_RC_HEART)
150 printf("POINT");
151 touchscreen_set_mode(TOUCHSCREEN_POINT);
153 else if (button == BUTTON_RC_MODE)
155 printf("BUTTON");
156 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
158 #if 1
159 else if (button&BUTTON_TOUCHSCREEN)
161 if (button&BUTTON_REL)
162 continue;
163 unsigned int data = button_get_data();
164 int x = (data&0xffff0000)>>16, y = data&0x0000ffff;
165 reset_screen();
166 line = 9;
167 printf("BB: %x %d %d", button, x,y);
168 lcd_hline(x-5, x+5, y);
169 lcd_vline(x, y-5, y+5);
170 lcd_update();
172 else if (button == BUTTON_RC_PLAY)
174 reset_screen();
177 else if (button)
179 // if (button&BUTTON_REL)
181 printf("%08x %s\n", button, (button&BUTTON_REL)?"yes":"no");
185 #endif
188 #endif
190 void main(void)
192 unsigned char* loadbuffer;
193 int buffer_size;
194 int rc;
195 int(*kernel_entry)(void);
197 power_init();
198 lcd_init();
199 system_init();
200 kernel_init();
202 enable_irq();
203 enable_fiq();
205 adc_init();
206 button_init();
207 backlight_init();
209 font_init();
211 lcd_setfont(FONT_SYSFIXED);
213 /* Show debug messages if button is pressed */
214 // if(button_read_device())
215 verbose = true;
217 printf("Rockbox boot loader");
218 printf("Version %s", APPSVERSION);
220 usb_init();
222 /* Enter USB mode without USB thread */
223 if(usb_detect() == USB_INSERTED)
225 const char msg[] = "Bootloader USB mode";
226 reset_screen();
227 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
228 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
229 lcd_update();
231 ide_power_enable(true);
232 storage_enable(false);
233 sleep(HZ/20);
234 usb_enable(true);
236 while (usb_detect() == USB_INSERTED)
238 storage_spin(); /* Prevent the drive from spinning down */
239 sleep(HZ);
242 usb_enable(false);
244 reset_screen();
245 lcd_update();
247 #if defined(MRDEBUG)
248 mrdebug();
249 #endif
250 printf("ATA");
251 rc = storage_init();
252 if(rc)
254 reset_screen();
255 error(EATA, rc);
258 printf("disk");
259 disk_init();
261 printf("mount");
262 rc = disk_mount_all();
263 if (rc<=0)
265 error(EDISK,rc);
268 printf("Loading firmware");
270 loadbuffer = (unsigned char*) 0x00900000;
271 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
273 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
274 if(rc < 0)
275 error(EBOOTFILE, rc);
277 if (rc == EOK)
279 kernel_entry = (void*) loadbuffer;
280 rc = kernel_entry();