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 | ****************************************************************************/ |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 24 | #include <stdarg.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include "config.h" |
| 28 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 29 | #include "inttypes.h" |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 30 | #include "cpu.h" |
| 31 | #include "system.h" |
| 32 | #include "lcd.h" |
Michael Sevakis | 4ea4cdf | 2014-08-08 02:28:11 -0400 | [diff] [blame] | 33 | #include "../kernel-internal.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 34 | #include "storage.h" |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 35 | #include "disk.h" |
| 36 | #include "font.h" |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 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" |
Bertrik Sikken | 743dcf7 | 2009-06-23 18:11:03 +0000 | [diff] [blame] | 47 | #include "bitmaps/rockboxlogo.h" |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 48 | |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 49 | #include "i2c-s5l8700.h" |
| 50 | #include "dma-target.h" |
| 51 | #include "pcm.h" |
| 52 | #include "audiohw.h" |
| 53 | #include "rtc.h" |
Bertrik Sikken | 620982a | 2012-05-20 16:16:50 +0200 | [diff] [blame] | 54 | #include "time.h" |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 55 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 56 | #define LONG_DELAY 200000 |
| 57 | #define SHORT_DELAY 50000 |
| 58 | #define PAUSE_DELAY 50000 |
| 59 | |
| 60 | static inline void delay(int duration) |
| 61 | { |
| 62 | volatile int i; |
| 63 | for(i=0;i<duration;i++); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void bl_debug(bool bit) |
| 68 | { |
| 69 | if (bit) |
| 70 | { |
| 71 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 72 | delay(LONG_DELAY); |
| 73 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 74 | delay(LONG_DELAY); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 79 | delay(SHORT_DELAY); |
| 80 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 81 | delay(SHORT_DELAY); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void bl_debug_count(unsigned int input) |
| 86 | { |
| 87 | unsigned int i; |
| 88 | delay(SHORT_DELAY*3); |
| 89 | for (i = 0; i < input; i++) |
| 90 | { |
| 91 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 92 | delay(SHORT_DELAY); |
| 93 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 94 | delay(2*SHORT_DELAY); |
| 95 | } |
| 96 | } |
| 97 | void bl_debug_int(unsigned int input,unsigned int count) |
| 98 | { |
| 99 | unsigned int i; |
| 100 | for (i = 0; i < count; i++) |
| 101 | { |
| 102 | bl_debug(input>>i & 1); |
| 103 | } |
| 104 | delay(SHORT_DELAY*6); |
| 105 | } |
| 106 | |
Bertrik Sikken | 620982a | 2012-05-20 16:16:50 +0200 | [diff] [blame] | 107 | void post_mortem_stub(void) |
| 108 | { |
| 109 | } |
| 110 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 111 | void main(void) |
| 112 | { |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 113 | char mystring[64]; |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 114 | int i; |
| 115 | unsigned short data = 0; |
| 116 | char write_data[2], read_data[16]; |
Bertrik Sikken | 620982a | 2012-05-20 16:16:50 +0200 | [diff] [blame] | 117 | struct tm tm; |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 118 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 119 | //Set backlight pin to output and enable |
| 120 | int oldval = PCON0; |
| 121 | PCON0 = ((oldval & ~(3 << 4)) | (1 << 4)); |
| 122 | PDAT0 |= (1 << 2); |
Bertrik Sikken | 743dcf7 | 2009-06-23 18:11:03 +0000 | [diff] [blame] | 123 | |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 124 | // Set codec reset pin inactive |
| 125 | PCON5 = (PCON5 & ~0xF) | 1; |
| 126 | PDAT5 &= ~(1 << 0); |
| 127 | |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 128 | //power on |
| 129 | // oldval = PCON1; |
| 130 | // PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12)); |
| 131 | // PDAT1|=(1<<3); |
| 132 | |
| 133 | //Set PLAY to EINT4 |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 134 | oldval = PCON1; |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 135 | PCON1 = ((oldval & ~(0xf << 16)) | (2 << 16)); |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 136 | |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 137 | //Set MENU to EINT0 |
| 138 | oldval = PCON1; |
| 139 | PCON1 = (oldval & ~(0xf)) | 2; |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 140 | |
Frank Gevaerts | 49ec9ea | 2008-10-18 22:28:59 +0000 | [diff] [blame] | 141 | // enable external interrupts |
| 142 | EINTPOL = 0x11; |
| 143 | INTMSK = 0x11; |
| 144 | EINTMSK = 0x11; |
| 145 | asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts |
| 146 | |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 147 | system_init(); |
| 148 | kernel_init(); |
| 149 | |
Bertrik Sikken | 743dcf7 | 2009-06-23 18:11:03 +0000 | [diff] [blame] | 150 | backlight_init(); |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 151 | lcd_init(); |
Frank Gevaerts | 2d5e6e1 | 2008-10-05 20:01:25 +0000 | [diff] [blame] | 152 | lcd_update(); |
| 153 | |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 154 | i2c_init(); |
| 155 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 156 | init_qt1106(); |
| 157 | |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 158 | /* Calibrate the lot */ |
| 159 | qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \ |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 160 | | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_256); |
| 161 | |
| 162 | lcd_clear_display(); |
| 163 | lcd_bitmap(rockboxlogo, 0, 30, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo); |
| 164 | lcd_update(); |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 165 | |
| 166 | /* Set to maximum sensitivity */ |
| 167 | qt1106_io(QT1106_CT | (0x00 << 8) ); |
| 168 | |
| 169 | while(true) |
| 170 | { |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 171 | #if 1 /* enable this to see info about the slider touchpad */ |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 172 | qt1106_wait(); |
| 173 | |
| 174 | int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \ |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 175 | | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_256); |
| 176 | snprintf(mystring, 64, "%x %2.2x",(slider & 0x008000)>>15, slider&0xff); |
| 177 | lcd_puts(0,1,mystring); |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 178 | backlight_hw_brightness((slider & 0xFF) >> 4); |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 179 | |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 180 | /* |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 181 | if(slider & 0x008000) |
| 182 | bl_debug_count(((slider&0xff)) + 1); |
Frank Gevaerts | 68d9fb9 | 2008-10-07 21:12:03 +0000 | [diff] [blame] | 183 | */ |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 184 | #endif |
| 185 | |
| 186 | #if 1 /* enable this to see info about the RTC */ |
Bertrik Sikken | 620982a | 2012-05-20 16:16:50 +0200 | [diff] [blame] | 187 | rtc_read_datetime(&tm); |
| 188 | snprintf(mystring, 64, "%04d-%02d-%02d %02d:%02d:%02d", |
| 189 | tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, |
| 190 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 191 | lcd_puts(0, 10, mystring); |
| 192 | #endif |
| 193 | |
| 194 | #if 1 /* enable this so see info about the UDA1380 codec */ |
| 195 | memset(read_data, 0, sizeof(read_data)); |
| 196 | for (i = 0; i < 7; i++) { |
| 197 | write_data[0] = i; |
| 198 | i2c_read(0x30, i, 2, read_data); |
| 199 | data = read_data[0] << 8 | read_data[1]; |
| 200 | snprintf(mystring + 4 * i, 64, "%04X", data); |
| 201 | } |
| 202 | lcd_puts(0, 11, mystring); |
| 203 | #endif |
| 204 | |
| 205 | #if 1 /* enable this to see info about IODMA channel 0 (PCM) */ |
Bertrik Sikken | 620982a | 2012-05-20 16:16:50 +0200 | [diff] [blame] | 206 | snprintf(mystring, 64, "DMA: %08X %08X", (int)DMACADDR0, (int)DMACTCNT0); |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 207 | lcd_puts(0, 12, mystring); |
| 208 | #endif |
| 209 | #if 1 /* enable this to see info about IIS */ |
Bertrik Sikken | 620982a | 2012-05-20 16:16:50 +0200 | [diff] [blame] | 210 | snprintf(mystring, 64, "IIS: %08X", (int)I2SSTATUS); |
Bertrik Sikken | 80fbb4e | 2009-07-05 19:14:46 +0000 | [diff] [blame] | 211 | lcd_puts(0, 13, mystring); |
| 212 | #endif |
| 213 | |
| 214 | lcd_update(); |
Marcoen Hirschberg | 48e45f5 | 2008-09-17 23:22:11 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | //power off |
| 218 | PDAT1&=~(1<<3); |
| 219 | } |
| 220 | |