blob: 1dbe7b8edb9ed70ffbf1e15e33242ef6f5e5c81d [file] [log] [blame]
Karl Kurbjun7b97fe22007-09-20 04:46:41 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
Jonathan Gordond7c3d802007-09-20 14:16:25 +000020#include "inttypes.h"
Karl Kurbjun7b97fe22007-09-20 04:46:41 +000021#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"
Jonathan Gordond331d002007-09-22 14:21:07 +000041#include "spi.h"
Catalin Patulea8664a4d2007-09-21 09:09:59 +000042#include "uart-target.h"
Jonathan Gordond331d002007-09-22 14:21:07 +000043#include "tsc2100.h"
Jonathan Gordon274c2b82007-10-01 07:52:39 +000044#include "time.h"
Karl Kurbjun0a632682007-10-26 05:17:15 +000045#include "system-arm.h"
Karl Kurbjun7b97fe22007-09-20 04:46:41 +000046
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +000047#define MRDEBUG
Karl Kurbjunf96fc522007-10-13 16:27:41 +000048
49#if defined(MRDEBUG)
50
Karl Kurbjun4a427232007-09-22 06:04:14 +000051extern int line;
Jonathan Gordon12d1ff92007-10-22 07:01:59 +000052#if 0
Jonathan Gordon274c2b82007-10-01 07:52:39 +000053struct touch_calibration_point tl, br;
54
55void touchpad_get_one_point(struct touch_calibration_point *p)
56{
57 int data = 0;
58 int start = current_tick;
59 while (TIME_AFTER(start+(HZ/3), current_tick))
60 {
61 if (button_read_device()&BUTTON_TOUCHPAD)
62 {
63 data = button_get_last_touch();
64 p->val_x = data>>16;
65 p->val_y = data&0xffff;
66 start = current_tick;
67 }
68 else if (data == 0)
69 start = current_tick;
70 }
71}
72
73#define MARGIN 25
74#define LEN 7
75void touchpad_calibrate_screen(void)
76{
77 reset_screen();
78 printf("touch the center of the crosshairs to calibrate");
79 /* get the topleft value */
80 lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN);
81 lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN);
82 lcd_update();
83 tl.px_x = MARGIN; tl.px_y = MARGIN;
84 touchpad_get_one_point(&tl);
85 reset_screen();
86 printf("touch the center of the crosshairs to calibrate");
87 /* get the topright value */
88 lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN);
89 lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN);
90 lcd_update();
91 br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN;
92 touchpad_get_one_point(&br);
93 reset_screen();
94 line++;
95 printf("tl %d %d", tl.val_x, tl.val_y);
96 printf("br %d %d", br.val_x, br.val_y);
97 line++;
98 set_calibration_points(&tl, &br);
99}
Jonathan Gordon12d1ff92007-10-22 07:01:59 +0000100#endif
Catalin Patuleaf57ea9a2007-11-02 06:13:43 +0000101static uint8_t bl_command[] = {0xa4, 0x00, 0x00, 0xbb};
102int brightness = 0;
Catalin Patulea574b1002007-11-02 05:07:52 +0000103
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +0000104void mrdebug(void)
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000105{
Karl Kurbjun59a28622007-11-11 03:31:24 +0000106 int button=0;
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +0000107#if 0
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000108 use_calibration(false);
109 touchpad_calibrate_screen();
110 use_calibration(true);
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +0000111#endif
Karl Kurbjun5db6b512007-11-07 05:30:31 +0000112
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000113 while(true)
114 {
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +0000115#if 0
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000116 struct tm *t = get_time();
117 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);
118 printf("time: %d", mktime(t));
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +0000119#endif
Jonathan Gordond8667df2007-10-18 12:15:56 +0000120 button = button_get(false);
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000121 if (button == BUTTON_POWER)
122 {
123 printf("reset");
124 IO_GIO_BITSET1|=1<<10;
125 }
Karl Kurbjun59a28622007-11-11 03:31:24 +0000126 if (button==BUTTON_RC_VOL_DOWN)
127 {
Catalin Patuleaf57ea9a2007-11-02 06:13:43 +0000128 brightness = (brightness - 5) & 0x7f;
129 bl_command[2] = brightness;
130 spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
Karl Kurbjun59a28622007-11-11 03:31:24 +0000131 }
132 else if (button==BUTTON_RC_VOL_UP)
133 {
Catalin Patuleaf57ea9a2007-11-02 06:13:43 +0000134 brightness = (brightness + 5) & 0x7f;
135 bl_command[2] = brightness;
136 spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0);
137 }
Jonathan Gordon12d1ff92007-10-22 07:01:59 +0000138// {
139// short x,y,z1,z2;
140// tsc2100_read_values(&x, &y, &z1, &z2);
141// printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
142// printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
Jonathan Gordon12d1ff92007-10-22 07:01:59 +0000143// // tsc2100_keyclick(); /* doesnt work :( */
144// line -= 6;
145// }
Karl Kurbjun59a28622007-11-11 03:31:24 +0000146#if 1
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000147 if (button&BUTTON_TOUCHPAD)
148 {
Jonathan Gordon12d1ff92007-10-22 07:01:59 +0000149 if (button&BUTTON_REL)
150 continue;
Jonathan Gordond8667df2007-10-18 12:15:56 +0000151 unsigned int data = button_get_data();
152 int x = (data&0xffff0000)>>16, y = data&0x0000ffff;
153 reset_screen();
Jonathan Gordon12d1ff92007-10-22 07:01:59 +0000154 line = 9;
155 printf("%x %d %d\n", button, x,y);
Jonathan Gordond8667df2007-10-18 12:15:56 +0000156 lcd_hline(x-5, x+5, y);
157 lcd_vline(x, y-5, y+5);
158 lcd_update();
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000159 }
Karl Kurbjunfa1a38e2007-10-18 05:14:10 +0000160#endif
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000161 }
162}
163#endif
Jonathan Gordon274c2b82007-10-01 07:52:39 +0000164
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000165void main(void)
166{
Karl Kurbjun9ac9cc62007-09-23 23:08:39 +0000167 unsigned char* loadbuffer;
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000168 int buffer_size;
169 int rc;
170 int(*kernel_entry)(void);
Karl Kurbjun9ac9cc62007-09-23 23:08:39 +0000171
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000172 power_init();
Karl Kurbjun9ac9cc62007-09-23 23:08:39 +0000173 lcd_init();
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000174 system_init();
175 kernel_init();
Karl Kurbjun0a632682007-10-26 05:17:15 +0000176
177 set_irq_level(0);
178 set_fiq_status(FIQ_ENABLED);
179
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000180 adc_init();
181 button_init();
182 backlight_init();
Karl Kurbjun9ac9cc62007-09-23 23:08:39 +0000183
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000184 font_init();
185
186 lcd_setfont(FONT_SYSFIXED);
187
188 /* Show debug messages if button is pressed */
189// if(button_read_device())
190 verbose = true;
191
192 printf("Rockbox boot loader");
193 printf("Version %s", APPSVERSION);
194
195 usb_init();
196
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000197 /* Enter USB mode without USB thread */
198 if(usb_detect())
199 {
200 const char msg[] = "Bootloader USB mode";
201 reset_screen();
202 lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
203 (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
204 lcd_update();
205
206 ide_power_enable(true);
207 ata_enable(false);
208 sleep(HZ/20);
209 usb_enable(true);
210
211 while (usb_detect())
212 {
213 ata_spin(); /* Prevent the drive from spinning down */
214 sleep(HZ);
215 }
216
217 usb_enable(false);
218
219 reset_screen();
220 lcd_update();
221 }
Karl Kurbjunf96fc522007-10-13 16:27:41 +0000222#if defined(MRDEBUG)
223 mrdebug();
Karl Kurbjun968ba0a2007-09-25 01:44:57 +0000224#endif
Karl Kurbjun9ac9cc62007-09-23 23:08:39 +0000225 printf("ATA");
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000226 rc = ata_init();
227 if(rc)
228 {
229 reset_screen();
230 error(EATA, rc);
231 }
232
233 printf("disk");
234 disk_init();
235
236 printf("mount");
237 rc = disk_mount_all();
238 if (rc<=0)
239 {
240 error(EDISK,rc);
241 }
242
243 printf("Loading firmware");
244
245 loadbuffer = (unsigned char*) 0x00900000;
Karl Kurbjunf6bc1912007-10-17 05:19:20 +0000246 buffer_size = (unsigned char*)0x01900000 - loadbuffer;
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000247
248 rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
249 if(rc < 0)
250 error(EBOOTFILE, rc);
251
252 if (rc == EOK)
253 {
254 kernel_entry = (void*) loadbuffer;
255 rc = kernel_entry();
256 }
Karl Kurbjun7b97fe22007-09-20 04:46:41 +0000257}