Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Karl Kurbjun |
| 11 | * |
| 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. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 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" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 29 | #include "storage.h" |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 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" |
| 48 | |
| 49 | #define MRDEBUG |
| 50 | |
| 51 | #if defined(MRDEBUG) |
| 52 | |
| 53 | extern int line; |
| 54 | #if 0 |
| 55 | struct touch_calibration_point tl, br; |
| 56 | |
| 57 | void touchscreen_get_one_point(struct touch_calibration_point *p) |
| 58 | { |
| 59 | int data = 0; |
| 60 | int start = current_tick; |
| 61 | while (TIME_AFTER(start+(HZ/3), current_tick)) |
| 62 | { |
| 63 | if (button_read_device()&BUTTON_TOUCHSCREEN) |
| 64 | { |
| 65 | data = button_get_last_touch(); |
| 66 | p->val_x = data>>16; |
| 67 | p->val_y = data&0xffff; |
| 68 | start = current_tick; |
| 69 | } |
| 70 | else if (data == 0) |
| 71 | start = current_tick; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | #define MARGIN 25 |
| 76 | #define LEN 7 |
| 77 | void touchscreen_calibrate_screen(void) |
| 78 | { |
| 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); |
| 101 | } |
| 102 | #endif |
| 103 | static uint8_t bl_command[] = {0xa4, 0x00, 0x00, 0xbb}; |
| 104 | int brightness = 0; |
| 105 | |
| 106 | void mrdebug(void) |
| 107 | { |
| 108 | int button=0; |
| 109 | #if 0 |
| 110 | use_calibration(false); |
| 111 | touchscreen_calibrate_screen(); |
| 112 | use_calibration(true); |
| 113 | #endif |
| 114 | |
| 115 | while(true) |
| 116 | { |
| 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) |
| 124 | { |
| 125 | printf("reset"); |
| 126 | IO_GIO_BITSET1|=1<<10; |
| 127 | } |
| 128 | if (button==BUTTON_RC_VOL_DOWN) |
| 129 | { |
| 130 | brightness = (brightness - 5) & 0x7f; |
| 131 | bl_command[2] = brightness; |
| 132 | spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0); |
| 133 | } |
| 134 | else if (button==BUTTON_RC_VOL_UP) |
| 135 | { |
| 136 | brightness = (brightness + 5) & 0x7f; |
| 137 | bl_command[2] = brightness; |
| 138 | spi_block_transfer(SPI_target_BACKLIGHT, bl_command, 4, 0, 0); |
| 139 | } |
| 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) |
| 149 | { |
| 150 | printf("POINT"); |
| 151 | touchscreen_set_mode(TOUCHSCREEN_POINT); |
| 152 | } |
| 153 | else if (button == BUTTON_RC_MODE) |
| 154 | { |
| 155 | printf("BUTTON"); |
| 156 | touchscreen_set_mode(TOUCHSCREEN_BUTTON); |
| 157 | } |
| 158 | #if 1 |
| 159 | else if (button&BUTTON_TOUCHSCREEN) |
| 160 | { |
| 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(); |
| 171 | } |
| 172 | else if (button == BUTTON_RC_PLAY) |
| 173 | { |
| 174 | reset_screen(); |
| 175 | } |
| 176 | |
| 177 | else if (button) |
| 178 | { |
| 179 | // if (button&BUTTON_REL) |
| 180 | { |
| 181 | printf("%08x %s\n", button, (button&BUTTON_REL)?"yes":"no"); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | #endif |
| 186 | } |
| 187 | } |
| 188 | #endif |
| 189 | |
| 190 | void main(void) |
| 191 | { |
| 192 | unsigned char* loadbuffer; |
| 193 | int buffer_size; |
| 194 | int rc; |
| 195 | int(*kernel_entry)(void); |
| 196 | |
| 197 | power_init(); |
| 198 | lcd_init(); |
| 199 | system_init(); |
| 200 | kernel_init(); |
| 201 | |
| 202 | enable_irq(); |
| 203 | enable_fiq(); |
| 204 | |
| 205 | adc_init(); |
| 206 | button_init(); |
| 207 | backlight_init(); |
| 208 | |
| 209 | font_init(); |
| 210 | |
| 211 | lcd_setfont(FONT_SYSFIXED); |
| 212 | |
| 213 | /* Show debug messages if button is pressed */ |
| 214 | // if(button_read_device()) |
| 215 | verbose = true; |
| 216 | |
| 217 | printf("Rockbox boot loader"); |
| 218 | printf("Version %s", APPSVERSION); |
| 219 | |
| 220 | usb_init(); |
| 221 | |
| 222 | /* Enter USB mode without USB thread */ |
| 223 | if(usb_detect() == USB_INSERTED) |
| 224 | { |
| 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(); |
| 230 | |
| 231 | ide_power_enable(true); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 232 | storage_enable(false); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 233 | sleep(HZ/20); |
| 234 | usb_enable(true); |
| 235 | |
| 236 | while (usb_detect() == USB_INSERTED) |
| 237 | { |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 238 | storage_spin(); /* Prevent the drive from spinning down */ |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 239 | sleep(HZ); |
| 240 | } |
| 241 | |
| 242 | usb_enable(false); |
| 243 | |
| 244 | reset_screen(); |
| 245 | lcd_update(); |
| 246 | } |
| 247 | #if defined(MRDEBUG) |
| 248 | mrdebug(); |
| 249 | #endif |
| 250 | printf("ATA"); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 251 | rc = storage_init(); |
Maurus Cuelenaere | 1ff9ce2 | 2008-09-10 19:35:15 +0000 | [diff] [blame] | 252 | if(rc) |
| 253 | { |
| 254 | reset_screen(); |
| 255 | error(EATA, rc); |
| 256 | } |
| 257 | |
| 258 | printf("disk"); |
| 259 | disk_init(); |
| 260 | |
| 261 | printf("mount"); |
| 262 | rc = disk_mount_all(); |
| 263 | if (rc<=0) |
| 264 | { |
| 265 | error(EDISK,rc); |
| 266 | } |
| 267 | |
| 268 | printf("Loading firmware"); |
| 269 | |
| 270 | loadbuffer = (unsigned char*) 0x00900000; |
| 271 | buffer_size = (unsigned char*)0x01900000 - loadbuffer; |
| 272 | |
| 273 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); |
| 274 | if(rc < 0) |
| 275 | error(EBOOTFILE, rc); |
| 276 | |
| 277 | if (rc == EOK) |
| 278 | { |
| 279 | kernel_entry = (void*) loadbuffer; |
| 280 | rc = kernel_entry(); |
| 281 | } |
| 282 | } |