blob: 61308349f6f37bad0f7941645f66cc60fd52824a [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"
Michael Sevakis4ea4cdf2014-08-08 02:28:11 -040033#include "../kernel-internal.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000034#include "storage.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000035#include "disk.h"
36#include "font.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000037#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 Sikken743dcf72009-06-23 18:11:03 +000047#include "bitmaps/rockboxlogo.h"
Frank Gevaerts68d9fb92008-10-07 21:12:03 +000048
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +000049#include "i2c-s5l8700.h"
50#include "dma-target.h"
51#include "pcm.h"
52#include "audiohw.h"
53#include "rtc.h"
Bertrik Sikken620982a2012-05-20 16:16:50 +020054#include "time.h"
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000055
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +000056#define LONG_DELAY 200000
57#define SHORT_DELAY 50000
58#define PAUSE_DELAY 50000
59
60static inline void delay(int duration)
61{
62 volatile int i;
63 for(i=0;i<duration;i++);
64}
65
66
67void 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
85void 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}
97void 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 Sikken620982a2012-05-20 16:16:50 +0200107void post_mortem_stub(void)
108{
109}
110
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000111void main(void)
112{
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000113 char mystring[64];
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000114 int i;
115 unsigned short data = 0;
116 char write_data[2], read_data[16];
Bertrik Sikken620982a2012-05-20 16:16:50 +0200117 struct tm tm;
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000118
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000119 //Set backlight pin to output and enable
120 int oldval = PCON0;
121 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
122 PDAT0 |= (1 << 2);
Bertrik Sikken743dcf72009-06-23 18:11:03 +0000123
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000124 // Set codec reset pin inactive
125 PCON5 = (PCON5 & ~0xF) | 1;
126 PDAT5 &= ~(1 << 0);
127
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000128 //power on
129// oldval = PCON1;
130// PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12));
131// PDAT1|=(1<<3);
132
133 //Set PLAY to EINT4
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000134 oldval = PCON1;
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000135 PCON1 = ((oldval & ~(0xf << 16)) | (2 << 16));
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000136
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000137 //Set MENU to EINT0
138 oldval = PCON1;
139 PCON1 = (oldval & ~(0xf)) | 2;
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000140
Frank Gevaerts49ec9ea2008-10-18 22:28:59 +0000141 // 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 Sikken80fbb4e2009-07-05 19:14:46 +0000147 system_init();
148 kernel_init();
149
Bertrik Sikken743dcf72009-06-23 18:11:03 +0000150 backlight_init();
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000151 lcd_init();
Frank Gevaerts2d5e6e12008-10-05 20:01:25 +0000152 lcd_update();
153
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000154 i2c_init();
155
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000156 init_qt1106();
157
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000158 /* Calibrate the lot */
159 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000160 | 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 Hirschberg48e45f52008-09-17 23:22:11 +0000165
166 /* Set to maximum sensitivity */
167 qt1106_io(QT1106_CT | (0x00 << 8) );
168
169 while(true)
170 {
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000171#if 1 /* enable this to see info about the slider touchpad */
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000172 qt1106_wait();
173
174 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000175 | 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 Bukat89ba7e82015-01-09 00:22:40 +0100178 backlight_hw_brightness((slider & 0xFF) >> 4);
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000179
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000180 /*
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000181 if(slider & 0x008000)
182 bl_debug_count(((slider&0xff)) + 1);
Frank Gevaerts68d9fb92008-10-07 21:12:03 +0000183 */
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000184#endif
185
186#if 1 /* enable this to see info about the RTC */
Bertrik Sikken620982a2012-05-20 16:16:50 +0200187 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 Sikken80fbb4e2009-07-05 19:14:46 +0000191 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 Sikken620982a2012-05-20 16:16:50 +0200206 snprintf(mystring, 64, "DMA: %08X %08X", (int)DMACADDR0, (int)DMACTCNT0);
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000207 lcd_puts(0, 12, mystring);
208#endif
209#if 1 /* enable this to see info about IIS */
Bertrik Sikken620982a2012-05-20 16:16:50 +0200210 snprintf(mystring, 64, "IIS: %08X", (int)I2SSTATUS);
Bertrik Sikken80fbb4e2009-07-05 19:14:46 +0000211 lcd_puts(0, 13, mystring);
212#endif
213
214 lcd_update();
Marcoen Hirschberg48e45f52008-09-17 23:22:11 +0000215 }
216
217 //power off
218 PDAT1&=~(1<<3);
219}
220