Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Greg White |
| 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 | #include "config.h" |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | #include "inttypes.h" |
| 26 | #include "string.h" |
| 27 | #include "cpu.h" |
| 28 | #include "system.h" |
| 29 | #include "lcd.h" |
| 30 | #include "kernel.h" |
| 31 | #include "thread.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 32 | #include "storage.h" |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 33 | #include "fat.h" |
| 34 | #include "disk.h" |
| 35 | #include "font.h" |
| 36 | #include "adc.h" |
| 37 | #include "backlight.h" |
| 38 | #include "backlight-target.h" |
| 39 | #include "button.h" |
| 40 | #include "panic.h" |
| 41 | #include "power.h" |
| 42 | #include "file.h" |
| 43 | #include "common.h" |
| 44 | #include "rbunicode.h" |
| 45 | #include "usb.h" |
| 46 | #include "qt1106.h" |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 47 | #include "rockboxlogo.h" |
| 48 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 49 | |
| 50 | #include <stdarg.h> |
| 51 | |
| 52 | char version[] = APPSVERSION; |
| 53 | #define LONG_DELAY 200000 |
| 54 | #define SHORT_DELAY 50000 |
| 55 | #define PAUSE_DELAY 50000 |
| 56 | |
| 57 | static inline void delay(int duration) |
| 58 | { |
| 59 | volatile int i; |
| 60 | for(i=0;i<duration;i++); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | void bl_debug(bool bit) |
| 65 | { |
| 66 | if (bit) |
| 67 | { |
| 68 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 69 | delay(LONG_DELAY); |
| 70 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 71 | delay(LONG_DELAY); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 76 | delay(SHORT_DELAY); |
| 77 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 78 | delay(SHORT_DELAY); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void bl_debug_count(unsigned int input) |
| 83 | { |
| 84 | unsigned int i; |
| 85 | delay(SHORT_DELAY*3); |
| 86 | for (i = 0; i < input; i++) |
| 87 | { |
| 88 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 89 | delay(SHORT_DELAY); |
| 90 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 91 | delay(2*SHORT_DELAY); |
| 92 | } |
| 93 | } |
| 94 | void bl_debug_int(unsigned int input,unsigned int count) |
| 95 | { |
| 96 | unsigned int i; |
| 97 | for (i = 0; i < count; i++) |
| 98 | { |
| 99 | bl_debug(input>>i & 1); |
| 100 | } |
| 101 | delay(SHORT_DELAY*6); |
| 102 | } |
| 103 | |
| 104 | void main(void) |
| 105 | { |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 106 | char mystring[64]; |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 107 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 108 | //Set backlight pin to output and enable |
| 109 | int oldval = PCON0; |
| 110 | PCON0 = ((oldval & ~(3 << 4)) | (1 << 4)); |
| 111 | PDAT0 |= (1 << 2); |
| 112 | |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 113 | //power on |
| 114 | // oldval = PCON1; |
| 115 | // PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12)); |
| 116 | // PDAT1|=(1<<3); |
| 117 | |
| 118 | //Set PLAY to EINT4 |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 119 | oldval = PCON1; |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 120 | PCON1 = ((oldval & ~(0xf << 16)) | (2 << 16)); |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 121 | |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 122 | //Set MENU to EINT0 |
| 123 | oldval = PCON1; |
| 124 | PCON1 = (oldval & ~(0xf)) | 2; |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 125 | |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 126 | // enable external interrupts |
| 127 | EINTPOL = 0x11; |
| 128 | INTMSK = 0x11; |
| 129 | EINTMSK = 0x11; |
| 130 | asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts |
| 131 | |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 132 | lcd_init(); |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 133 | lcd_update(); |
| 134 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 135 | init_qt1106(); |
| 136 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 137 | /* Calibrate the lot */ |
| 138 | qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \ |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 139 | | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_256); |
| 140 | |
| 141 | lcd_clear_display(); |
| 142 | lcd_bitmap(rockboxlogo, 0, 30, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo); |
| 143 | lcd_update(); |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 144 | |
| 145 | /* Set to maximum sensitivity */ |
| 146 | qt1106_io(QT1106_CT | (0x00 << 8) ); |
| 147 | |
| 148 | while(true) |
| 149 | { |
| 150 | qt1106_wait(); |
| 151 | |
| 152 | int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \ |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 153 | | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_256); |
| 154 | snprintf(mystring, 64, "%x %2.2x",(slider & 0x008000)>>15, slider&0xff); |
| 155 | lcd_puts(0,1,mystring); |
| 156 | lcd_update(); |
| 157 | /* |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 158 | if(slider & 0x008000) |
| 159 | bl_debug_count(((slider&0xff)) + 1); |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 160 | */ |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | //power off |
| 164 | PDAT1&=~(1<<3); |
| 165 | } |
| 166 | |