blob: 61aa3cecbe00a4180c254f126b358460a34e283f [file] [log] [blame]
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +00001/***************************************************************************
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 Hirschberg48e45f52008-09-17 23:22:11 +000021
22#include <stdlib.h>
23#include <stdio.h>
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +000024#include <stdarg.h>
25#include <string.h>
26
27#include "config.h"
28
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000029#include "inttypes.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000030#include "cpu.h"
31#include "system.h"
32#include "lcd.h"
33#include "kernel.h"
34#include "thread.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000035#include "storage.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000036#include "fat.h"
37#include "disk.h"
38#include "font.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000039#include "backlight.h"
40#include "backlight-target.h"
41#include "button.h"
42#include "panic.h"
43#include "power.h"
44#include "file.h"
45#include "common.h"
46#include "rbunicode.h"
47#include "usb.h"
48#include "qt1106.h"
Bertrik Sikken743dcf72009-06-23 18:11:03 +000049#include "bitmaps/rockboxlogo.h"
Frank Gevaerts68d9fb92008-10-07 21:12:03 +000050
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +000051#include "i2c-s5l8700.h"
52#include "dma-target.h"
53#include "pcm.h"
54#include "audiohw.h"
55#include "rtc.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000056
57char version[] = APPSVERSION;
58#define LONG_DELAY 200000
59#define SHORT_DELAY 50000
60#define PAUSE_DELAY 50000
61
62static inline void delay(int duration)
63{
64 volatile int i;
65 for(i=0;i<duration;i++);
66}
67
68
69void bl_debug(bool bit)
70{
71 if (bit)
72 {
73 PDAT0 ^= (1 << 2); //Toggle backlight
74 delay(LONG_DELAY);
75 PDAT0 ^= (1 << 2); //Toggle backlight
76 delay(LONG_DELAY);
77 }
78 else
79 {
80 PDAT0 ^= (1 << 2); //Toggle backlight
81 delay(SHORT_DELAY);
82 PDAT0 ^= (1 << 2); //Toggle backlight
83 delay(SHORT_DELAY);
84 }
85}
86
87void bl_debug_count(unsigned int input)
88{
89 unsigned int i;
90 delay(SHORT_DELAY*3);
91 for (i = 0; i < input; i++)
92 {
93 PDAT0 ^= (1 << 2); //Toggle backlight
94 delay(SHORT_DELAY);
95 PDAT0 ^= (1 << 2); //Toggle backlight
96 delay(2*SHORT_DELAY);
97 }
98}
99void bl_debug_int(unsigned int input,unsigned int count)
100{
101 unsigned int i;
102 for (i = 0; i < count; i++)
103 {
104 bl_debug(input>>i & 1);
105 }
106 delay(SHORT_DELAY*6);
107}
108
109void main(void)
110{
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000111 char mystring[64];
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000112 int i;
113 unsigned short data = 0;
114 char write_data[2], read_data[16];
115
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000116 //Set backlight pin to output and enable
117 int oldval = PCON0;
118 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
119 PDAT0 |= (1 << 2);
Bertrik Sikken743dcf72009-06-23 18:11:03 +0000120
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000121 // Set codec reset pin inactive
122 PCON5 = (PCON5 & ~0xF) | 1;
123 PDAT5 &= ~(1 << 0);
124
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000125 //power on
126// oldval = PCON1;
127// PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12));
128// PDAT1|=(1<<3);
129
130 //Set PLAY to EINT4
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000131 oldval = PCON1;
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000132 PCON1 = ((oldval & ~(0xf << 16)) | (2 << 16));
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000133
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000134 //Set MENU to EINT0
135 oldval = PCON1;
136 PCON1 = (oldval & ~(0xf)) | 2;
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000137
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000138 // enable external interrupts
139 EINTPOL = 0x11;
140 INTMSK = 0x11;
141 EINTMSK = 0x11;
142 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
143
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000144 system_init();
145 kernel_init();
146
Bertrik Sikken743dcf72009-06-23 18:11:03 +0000147 backlight_init();
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000148 lcd_init();
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000149 lcd_update();
150
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000151 i2c_init();
152
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000153 init_qt1106();
154
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000155 /* Calibrate the lot */
156 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000157 | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_256);
158
159 lcd_clear_display();
160 lcd_bitmap(rockboxlogo, 0, 30, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
161 lcd_update();
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000162
163 /* Set to maximum sensitivity */
164 qt1106_io(QT1106_CT | (0x00 << 8) );
165
166 while(true)
167 {
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000168#if 1 /* enable this to see info about the slider touchpad */
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000169 qt1106_wait();
170
171 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000172 | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_256);
173 snprintf(mystring, 64, "%x %2.2x",(slider & 0x008000)>>15, slider&0xff);
174 lcd_puts(0,1,mystring);
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000175 _backlight_set_brightness((slider & 0xFF) >> 4);
176
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000177 /*
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000178 if(slider & 0x008000)
179 bl_debug_count(((slider&0xff)) + 1);
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000180 */
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000181#endif
182
183#if 1 /* enable this to see info about the RTC */
184 rtc_read_datetime(read_data);
185 for (i = 0; i < 7; i++) {
186 snprintf(mystring + 2 * i, 64, "%02X", read_data[i]);
187 }
188 lcd_puts(0, 10, mystring);
189#endif
190
191#if 1 /* enable this so see info about the UDA1380 codec */
192 memset(read_data, 0, sizeof(read_data));
193 for (i = 0; i < 7; i++) {
194 write_data[0] = i;
195 i2c_read(0x30, i, 2, read_data);
196 data = read_data[0] << 8 | read_data[1];
197 snprintf(mystring + 4 * i, 64, "%04X", data);
198 }
199 lcd_puts(0, 11, mystring);
200#endif
201
202#if 1 /* enable this to see info about IODMA channel 0 (PCM) */
203 snprintf(mystring, 64, "DMA: %08X %08X", DMACADDR0, DMACTCNT0);
204 lcd_puts(0, 12, mystring);
205#endif
206#if 1 /* enable this to see info about IIS */
207 snprintf(mystring, 64, "IIS: %08X", I2SSTATUS);
208 lcd_puts(0, 13, mystring);
209#endif
210
211 lcd_update();
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000212 }
213
214 //power off
215 PDAT1&=~(1<<3);
216}
217