Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +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 | * 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 Gordon | d7c3d80 | 2007-09-20 14:16:25 +0000 | [diff] [blame] | 20 | #include "inttypes.h"
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 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"
|
Jonathan Gordon | d331d00 | 2007-09-22 14:21:07 +0000 | [diff] [blame] | 41 | #include "spi.h"
|
Catalin Patulea | 8664a4d | 2007-09-21 09:09:59 +0000 | [diff] [blame] | 42 | #include "uart-target.h"
|
Jonathan Gordon | d331d00 | 2007-09-22 14:21:07 +0000 | [diff] [blame] | 43 | #include "tsc2100.h"
|
Jonathan Gordon | 274c2b8 | 2007-10-01 07:52:39 +0000 | [diff] [blame] | 44 | #include "time.h"
|
Karl Kurbjun | 0a63268 | 2007-10-26 05:17:15 +0000 | [diff] [blame] | 45 | #include "system-arm.h"
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 46 |
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 47 | #define MRDEBUG
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 48 |
|
| 49 | #if defined(MRDEBUG)
|
| 50 |
|
Karl Kurbjun | 4a42723 | 2007-09-22 06:04:14 +0000 | [diff] [blame] | 51 | extern int line;
|
Jonathan Gordon | 12d1ff9 | 2007-10-22 07:01:59 +0000 | [diff] [blame] | 52 | #if 0
|
Jonathan Gordon | 274c2b8 | 2007-10-01 07:52:39 +0000 | [diff] [blame] | 53 | struct touch_calibration_point tl, br;
|
| 54 |
|
| 55 | void 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
|
| 75 | void 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 Gordon | 12d1ff9 | 2007-10-22 07:01:59 +0000 | [diff] [blame] | 100 | #endif
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 101 | void mrdebug(void)
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 102 | {
|
| 103 | int button=0, *address=0x0;
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 104 | #if 0
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 105 | use_calibration(false);
|
| 106 | touchpad_calibrate_screen();
|
| 107 | use_calibration(true);
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 108 | #endif
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 109 | while(true)
|
| 110 | {
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 111 | #if 0
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 112 | struct tm *t = get_time();
|
| 113 | 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);
|
| 114 | printf("time: %d", mktime(t));
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 115 | #endif
|
Jonathan Gordon | d8667df | 2007-10-18 12:15:56 +0000 | [diff] [blame] | 116 | button = button_get(false);
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 117 | if (button == BUTTON_POWER)
|
| 118 | {
|
| 119 | printf("reset");
|
| 120 | IO_GIO_BITSET1|=1<<10;
|
| 121 | }
|
| 122 | if(button==BUTTON_RC_PLAY)
|
| 123 | address+=0x02;
|
| 124 | else if (button==BUTTON_RC_DOWN)
|
| 125 | address-=0x02;
|
| 126 | else if (button==BUTTON_RC_FF)
|
| 127 | address+=0x1000;
|
| 128 | else if (button==BUTTON_RC_REW)
|
| 129 | address-=0x1000;
|
Jonathan Gordon | 12d1ff9 | 2007-10-22 07:01:59 +0000 | [diff] [blame] | 130 | // {
|
| 131 | // short x,y,z1,z2;
|
| 132 | // tsc2100_read_values(&x, &y, &z1, &z2);
|
| 133 | // printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
|
| 134 | // printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
|
| 135 | // printf("current tick: %04x", current_tick);
|
| 136 | // printf("Address: 0x%08x Data: 0x%08x", address, *address);
|
| 137 | // printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
|
| 138 | // printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
|
| 139 | // // tsc2100_keyclick(); /* doesnt work :( */
|
| 140 | // line -= 6;
|
| 141 | // }
|
Jonathan Gordon | d8667df | 2007-10-18 12:15:56 +0000 | [diff] [blame] | 142 | #if 1
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 143 | if (button&BUTTON_TOUCHPAD)
|
| 144 | {
|
Jonathan Gordon | 12d1ff9 | 2007-10-22 07:01:59 +0000 | [diff] [blame] | 145 | if (button&BUTTON_REL)
|
| 146 | continue;
|
Jonathan Gordon | d8667df | 2007-10-18 12:15:56 +0000 | [diff] [blame] | 147 | unsigned int data = button_get_data();
|
| 148 | int x = (data&0xffff0000)>>16, y = data&0x0000ffff;
|
| 149 | reset_screen();
|
Jonathan Gordon | 12d1ff9 | 2007-10-22 07:01:59 +0000 | [diff] [blame] | 150 | line = 9;
|
| 151 | printf("%x %d %d\n", button, x,y);
|
Jonathan Gordon | d8667df | 2007-10-18 12:15:56 +0000 | [diff] [blame] | 152 | lcd_hline(x-5, x+5, y);
|
| 153 | lcd_vline(x, y-5, y+5);
|
| 154 | lcd_update();
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 155 | }
|
Karl Kurbjun | fa1a38e | 2007-10-18 05:14:10 +0000 | [diff] [blame] | 156 | #endif
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 157 | }
|
| 158 | }
|
| 159 | #endif
|
Jonathan Gordon | 274c2b8 | 2007-10-01 07:52:39 +0000 | [diff] [blame] | 160 |
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 161 | void main(void)
|
| 162 | {
|
Karl Kurbjun | 9ac9cc6 | 2007-09-23 23:08:39 +0000 | [diff] [blame] | 163 | unsigned char* loadbuffer;
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 164 | int buffer_size;
|
| 165 | int rc;
|
| 166 | int(*kernel_entry)(void);
|
Karl Kurbjun | 9ac9cc6 | 2007-09-23 23:08:39 +0000 | [diff] [blame] | 167 |
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 168 | power_init();
|
Karl Kurbjun | 9ac9cc6 | 2007-09-23 23:08:39 +0000 | [diff] [blame] | 169 | lcd_init();
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 170 | system_init();
|
| 171 | kernel_init();
|
Karl Kurbjun | 0a63268 | 2007-10-26 05:17:15 +0000 | [diff] [blame] | 172 |
|
| 173 | set_irq_level(0);
|
| 174 | set_fiq_status(FIQ_ENABLED);
|
| 175 |
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 176 | adc_init();
|
| 177 | button_init();
|
| 178 | backlight_init();
|
Karl Kurbjun | 9ac9cc6 | 2007-09-23 23:08:39 +0000 | [diff] [blame] | 179 |
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 180 | font_init();
|
| 181 |
|
| 182 | lcd_setfont(FONT_SYSFIXED);
|
| 183 |
|
| 184 | /* Show debug messages if button is pressed */
|
| 185 | // if(button_read_device())
|
| 186 | verbose = true;
|
| 187 |
|
| 188 | printf("Rockbox boot loader");
|
| 189 | printf("Version %s", APPSVERSION);
|
| 190 |
|
| 191 | usb_init();
|
| 192 |
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 193 | /* Enter USB mode without USB thread */
|
| 194 | if(usb_detect())
|
| 195 | {
|
| 196 | const char msg[] = "Bootloader USB mode";
|
| 197 | reset_screen();
|
| 198 | lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
|
| 199 | (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
|
| 200 | lcd_update();
|
| 201 |
|
| 202 | ide_power_enable(true);
|
| 203 | ata_enable(false);
|
| 204 | sleep(HZ/20);
|
| 205 | usb_enable(true);
|
| 206 |
|
| 207 | while (usb_detect())
|
| 208 | {
|
| 209 | ata_spin(); /* Prevent the drive from spinning down */
|
| 210 | sleep(HZ);
|
| 211 | }
|
| 212 |
|
| 213 | usb_enable(false);
|
| 214 |
|
| 215 | reset_screen();
|
| 216 | lcd_update();
|
| 217 | }
|
Karl Kurbjun | f96fc52 | 2007-10-13 16:27:41 +0000 | [diff] [blame] | 218 | #if defined(MRDEBUG)
|
| 219 | mrdebug();
|
Karl Kurbjun | 968ba0a | 2007-09-25 01:44:57 +0000 | [diff] [blame] | 220 | #endif
|
Karl Kurbjun | 9ac9cc6 | 2007-09-23 23:08:39 +0000 | [diff] [blame] | 221 | printf("ATA");
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 222 | rc = ata_init();
|
| 223 | if(rc)
|
| 224 | {
|
| 225 | reset_screen();
|
| 226 | error(EATA, rc);
|
| 227 | }
|
| 228 |
|
| 229 | printf("disk");
|
| 230 | disk_init();
|
| 231 |
|
| 232 | printf("mount");
|
| 233 | rc = disk_mount_all();
|
| 234 | if (rc<=0)
|
| 235 | {
|
| 236 | error(EDISK,rc);
|
| 237 | }
|
| 238 |
|
| 239 | printf("Loading firmware");
|
| 240 |
|
| 241 | loadbuffer = (unsigned char*) 0x00900000;
|
Karl Kurbjun | f6bc191 | 2007-10-17 05:19:20 +0000 | [diff] [blame] | 242 | buffer_size = (unsigned char*)0x01900000 - loadbuffer;
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 243 |
|
| 244 | rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
|
| 245 | if(rc < 0)
|
| 246 | error(EBOOTFILE, rc);
|
| 247 |
|
| 248 | if (rc == EOK)
|
| 249 | {
|
| 250 | kernel_entry = (void*) loadbuffer;
|
| 251 | rc = kernel_entry();
|
| 252 | }
|
Karl Kurbjun | 7b97fe2 | 2007-09-20 04:46:41 +0000 | [diff] [blame] | 253 | }
|