blob: 0b335bec8aa601c4808e26268f439fa544f34e3b [file] [log] [blame]
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Greg White
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Hirschberg7b10ef92008-06-27 23:24:34 +000016 *
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 Gevaerts2f8a0082008-11-01 16:14:28 +000032#include "storage.h"
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +000033#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"
Frank Gevaerts1898ff72008-09-11 18:18:40 +000046#include "qt1106.h"
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +000047
48#include <stdarg.h>
49
50char version[] = APPSVERSION;
Frank Gevaerts3637ef92008-09-10 19:08:46 +000051#define LONG_DELAY 200000
52#define SHORT_DELAY 50000
53#define PAUSE_DELAY 50000
54
Frank Gevaerts3637ef92008-09-10 19:08:46 +000055static inline void delay(int duration)
56{
57 volatile int i;
58 for(i=0;i<duration;i++);
59}
60
61
Frank Gevaerts3637ef92008-09-10 19:08:46 +000062void bl_debug(bool bit)
63{
64 if (bit)
65 {
66 PDAT0 ^= (1 << 2); //Toggle backlight
67 delay(LONG_DELAY);
68 PDAT0 ^= (1 << 2); //Toggle backlight
69 delay(LONG_DELAY);
Frank Gevaerts3637ef92008-09-10 19:08:46 +000070 }
71 else
72 {
73 PDAT0 ^= (1 << 2); //Toggle backlight
74 delay(SHORT_DELAY);
75 PDAT0 ^= (1 << 2); //Toggle backlight
76 delay(SHORT_DELAY);
Frank Gevaerts3637ef92008-09-10 19:08:46 +000077 }
78}
79
Frank Gevaertsc0e898a2008-09-16 16:51:25 +000080void bl_debug_count(unsigned int input)
Frank Gevaerts3637ef92008-09-10 19:08:46 +000081{
82 unsigned int i;
Frank Gevaertsc0e898a2008-09-16 16:51:25 +000083 delay(SHORT_DELAY*3);
Frank Gevaerts3637ef92008-09-10 19:08:46 +000084 for (i = 0; i < input; i++)
85 {
86 PDAT0 ^= (1 << 2); //Toggle backlight
87 delay(SHORT_DELAY);
88 PDAT0 ^= (1 << 2); //Toggle backlight
89 delay(2*SHORT_DELAY);
90 }
Frank Gevaertsc0e898a2008-09-16 16:51:25 +000091}
92void bl_debug_int(unsigned int input,unsigned int count)
93{
94 unsigned int i;
95 for (i = 0; i < count; i++)
96 {
97 bl_debug(input>>i & 1);
98 }
Frank Gevaerts3637ef92008-09-10 19:08:46 +000099 delay(SHORT_DELAY*6);
100}
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000101
Frank Gevaertsc0e898a2008-09-16 16:51:25 +0000102/* These functions are supposed to be static in lcd-m6sl.c, but
103 we use them here for testing */
104void init_lcd_spi(void);
105unsigned int lcd_read_id(void);
106
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000107void main(void)
108{
109 //Set backlight pin to output and enable
Frank Gevaertsc0e898a2008-09-16 16:51:25 +0000110 unsigned int model;
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000111 int oldval = PCON0;
112 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
113 PDAT0 |= (1 << 2);
114
115 //Set PLAY to input
116 oldval = PCON1;
117 PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16));
118
Frank Gevaerts3637ef92008-09-10 19:08:46 +0000119 init_qt1106();
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000120
Frank Gevaerts3637ef92008-09-10 19:08:46 +0000121 // Wait for play to be pressed
122 while(!(PDAT1 & (1 << 4)));
123 // Wait for play to be released
124 while((PDAT1 & (1 << 4)));
125 PDAT0 ^= (1 << 2); //Toggle backlight
Frank Gevaertsc0e898a2008-09-16 16:51:25 +0000126 delay(LONG_DELAY);
127
128 init_lcd_spi();
129 model=lcd_read_id();
130 bl_debug_count((model&0xf000)>>12);
131 bl_debug_count((model&0xf00)>>8);
132 bl_debug_count((model&0xf0)>>4);
133 bl_debug_count(model&0xf);
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000134
Frank Gevaerts3637ef92008-09-10 19:08:46 +0000135 /* Calibrate the lot */
Frank Gevaertsc0e898a2008-09-16 16:51:25 +0000136 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \
137 | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_4);
Frank Gevaerts3637ef92008-09-10 19:08:46 +0000138
139 /* Set to maximum sensitivity */
Frank Gevaerts1898ff72008-09-11 18:18:40 +0000140 qt1106_io(QT1106_CT | (0x00 << 8) );
Frank Gevaerts3637ef92008-09-10 19:08:46 +0000141
142 while(true)
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000143 {
Frank Gevaerts1898ff72008-09-11 18:18:40 +0000144 qt1106_wait();
145
Frank Gevaertsc0e898a2008-09-16 16:51:25 +0000146 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \
147 | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_4);
148 if(slider & 0x008000)
149 bl_debug_count(((slider&0xff)) + 1);
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000150 }
Frank Gevaerts3637ef92008-09-10 19:08:46 +0000151
152 //power off
Frank Gevaertse278b4f2008-09-02 20:19:58 +0000153 PDAT1&=~(1<<3);
Marcoen Hirschberg7b10ef92008-06-27 23:24:34 +0000154}
155