Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +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 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 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 | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 33 | #include "disk.h" |
| 34 | #include "font.h" |
| 35 | #include "adc.h" |
| 36 | #include "backlight.h" |
| 37 | #include "backlight-target.h" |
| 38 | #include "button.h" |
| 39 | #include "panic.h" |
| 40 | #include "power.h" |
| 41 | #include "file.h" |
| 42 | #include "common.h" |
| 43 | #include "rbunicode.h" |
| 44 | #include "usb.h" |
Frank Gevaerts | 1898ff7 | 2008-09-11 18:18:40 +0000 | [diff] [blame] | 45 | #include "qt1106.h" |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 46 | |
| 47 | #include <stdarg.h> |
| 48 | |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 49 | #define LONG_DELAY 200000 |
| 50 | #define SHORT_DELAY 50000 |
| 51 | #define PAUSE_DELAY 50000 |
| 52 | |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 53 | static inline void delay(int duration) |
| 54 | { |
| 55 | volatile int i; |
| 56 | for(i=0;i<duration;i++); |
| 57 | } |
| 58 | |
| 59 | |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 60 | void bl_debug(bool bit) |
| 61 | { |
| 62 | if (bit) |
| 63 | { |
| 64 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 65 | delay(LONG_DELAY); |
| 66 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 67 | delay(LONG_DELAY); |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 68 | } |
| 69 | else |
| 70 | { |
| 71 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 72 | delay(SHORT_DELAY); |
| 73 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 74 | delay(SHORT_DELAY); |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 78 | void bl_debug_count(unsigned int input) |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 79 | { |
| 80 | unsigned int i; |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 81 | delay(SHORT_DELAY*3); |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 82 | for (i = 0; i < input; i++) |
| 83 | { |
| 84 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 85 | delay(SHORT_DELAY); |
| 86 | PDAT0 ^= (1 << 2); //Toggle backlight |
| 87 | delay(2*SHORT_DELAY); |
| 88 | } |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 89 | } |
| 90 | void bl_debug_int(unsigned int input,unsigned int count) |
| 91 | { |
| 92 | unsigned int i; |
| 93 | for (i = 0; i < count; i++) |
| 94 | { |
| 95 | bl_debug(input>>i & 1); |
| 96 | } |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 97 | delay(SHORT_DELAY*6); |
| 98 | } |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 99 | |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 100 | /* These functions are supposed to be static in lcd-m6sl.c, but |
| 101 | we use them here for testing */ |
| 102 | void init_lcd_spi(void); |
| 103 | unsigned int lcd_read_id(void); |
| 104 | |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 105 | void main(void) |
| 106 | { |
| 107 | //Set backlight pin to output and enable |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 108 | unsigned int model; |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 109 | int oldval = PCON0; |
| 110 | PCON0 = ((oldval & ~(3 << 4)) | (1 << 4)); |
| 111 | PDAT0 |= (1 << 2); |
| 112 | |
| 113 | //Set PLAY to input |
| 114 | oldval = PCON1; |
| 115 | PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16)); |
| 116 | |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 117 | init_qt1106(); |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 118 | |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 119 | // Wait for play to be pressed |
| 120 | while(!(PDAT1 & (1 << 4))); |
| 121 | // Wait for play to be released |
| 122 | while((PDAT1 & (1 << 4))); |
| 123 | PDAT0 ^= (1 << 2); //Toggle backlight |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 124 | delay(LONG_DELAY); |
| 125 | |
| 126 | init_lcd_spi(); |
| 127 | model=lcd_read_id(); |
| 128 | bl_debug_count((model&0xf000)>>12); |
| 129 | bl_debug_count((model&0xf00)>>8); |
| 130 | bl_debug_count((model&0xf0)>>4); |
| 131 | bl_debug_count(model&0xf); |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 132 | |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 133 | /* Calibrate the lot */ |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 134 | qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \ |
| 135 | | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_4); |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 136 | |
| 137 | /* Set to maximum sensitivity */ |
Frank Gevaerts | 1898ff7 | 2008-09-11 18:18:40 +0000 | [diff] [blame] | 138 | qt1106_io(QT1106_CT | (0x00 << 8) ); |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 139 | |
| 140 | while(true) |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 141 | { |
Frank Gevaerts | 1898ff7 | 2008-09-11 18:18:40 +0000 | [diff] [blame] | 142 | qt1106_wait(); |
| 143 | |
Frank Gevaerts | c0e898a | 2008-09-16 16:51:25 +0000 | [diff] [blame] | 144 | int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \ |
| 145 | | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_4); |
| 146 | if(slider & 0x008000) |
| 147 | bl_debug_count(((slider&0xff)) + 1); |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 148 | } |
Frank Gevaerts | 3637ef9 | 2008-09-10 19:08:46 +0000 | [diff] [blame] | 149 | |
| 150 | //power off |
Frank Gevaerts | e278b4f | 2008-09-02 20:19:58 +0000 | [diff] [blame] | 151 | PDAT1&=~(1<<3); |
Marcoen Hirschberg | 7b10ef9 | 2008-06-27 23:24:34 +0000 | [diff] [blame] | 152 | } |
| 153 | |