Theme Editor: Added column number to parser error messages
[kugel-rb.git] / bootloader / meizu_m3.c
blob7c0a5bca2df3a3308c5a8e61cf6cd80616231923
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Greg White
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <string.h>
27 #include "config.h"
29 #include "inttypes.h"
30 #include "cpu.h"
31 #include "system.h"
32 #include "lcd.h"
33 #include "kernel.h"
34 #include "thread.h"
35 #include "storage.h"
36 #include "fat.h"
37 #include "disk.h"
38 #include "font.h"
39 #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"
49 #include "bitmaps/rockboxlogo.h"
51 #include "i2c-s5l8700.h"
52 #include "dma-target.h"
53 #include "pcm.h"
54 #include "audiohw.h"
55 #include "rtc.h"
57 #define LONG_DELAY 200000
58 #define SHORT_DELAY 50000
59 #define PAUSE_DELAY 50000
61 static inline void delay(int duration)
63 volatile int i;
64 for(i=0;i<duration;i++);
68 void bl_debug(bool bit)
70 if (bit)
72 PDAT0 ^= (1 << 2); //Toggle backlight
73 delay(LONG_DELAY);
74 PDAT0 ^= (1 << 2); //Toggle backlight
75 delay(LONG_DELAY);
77 else
79 PDAT0 ^= (1 << 2); //Toggle backlight
80 delay(SHORT_DELAY);
81 PDAT0 ^= (1 << 2); //Toggle backlight
82 delay(SHORT_DELAY);
86 void bl_debug_count(unsigned int input)
88 unsigned int i;
89 delay(SHORT_DELAY*3);
90 for (i = 0; i < input; i++)
92 PDAT0 ^= (1 << 2); //Toggle backlight
93 delay(SHORT_DELAY);
94 PDAT0 ^= (1 << 2); //Toggle backlight
95 delay(2*SHORT_DELAY);
98 void bl_debug_int(unsigned int input,unsigned int count)
100 unsigned int i;
101 for (i = 0; i < count; i++)
103 bl_debug(input>>i & 1);
105 delay(SHORT_DELAY*6);
108 void main(void)
110 char mystring[64];
111 int i;
112 unsigned short data = 0;
113 char write_data[2], read_data[16];
115 //Set backlight pin to output and enable
116 int oldval = PCON0;
117 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
118 PDAT0 |= (1 << 2);
120 // Set codec reset pin inactive
121 PCON5 = (PCON5 & ~0xF) | 1;
122 PDAT5 &= ~(1 << 0);
124 //power on
125 // oldval = PCON1;
126 // PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12));
127 // PDAT1|=(1<<3);
129 //Set PLAY to EINT4
130 oldval = PCON1;
131 PCON1 = ((oldval & ~(0xf << 16)) | (2 << 16));
133 //Set MENU to EINT0
134 oldval = PCON1;
135 PCON1 = (oldval & ~(0xf)) | 2;
137 // enable external interrupts
138 EINTPOL = 0x11;
139 INTMSK = 0x11;
140 EINTMSK = 0x11;
141 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
143 system_init();
144 kernel_init();
146 backlight_init();
147 lcd_init();
148 lcd_update();
150 i2c_init();
152 init_qt1106();
154 /* Calibrate the lot */
155 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \
156 | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_256);
158 lcd_clear_display();
159 lcd_bitmap(rockboxlogo, 0, 30, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
160 lcd_update();
162 /* Set to maximum sensitivity */
163 qt1106_io(QT1106_CT | (0x00 << 8) );
165 while(true)
167 #if 1 /* enable this to see info about the slider touchpad */
168 qt1106_wait();
170 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \
171 | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_256);
172 snprintf(mystring, 64, "%x %2.2x",(slider & 0x008000)>>15, slider&0xff);
173 lcd_puts(0,1,mystring);
174 _backlight_set_brightness((slider & 0xFF) >> 4);
177 if(slider & 0x008000)
178 bl_debug_count(((slider&0xff)) + 1);
180 #endif
182 #if 1 /* enable this to see info about the RTC */
183 rtc_read_datetime(read_data);
184 for (i = 0; i < 7; i++) {
185 snprintf(mystring + 2 * i, 64, "%02X", read_data[i]);
187 lcd_puts(0, 10, mystring);
188 #endif
190 #if 1 /* enable this so see info about the UDA1380 codec */
191 memset(read_data, 0, sizeof(read_data));
192 for (i = 0; i < 7; i++) {
193 write_data[0] = i;
194 i2c_read(0x30, i, 2, read_data);
195 data = read_data[0] << 8 | read_data[1];
196 snprintf(mystring + 4 * i, 64, "%04X", data);
198 lcd_puts(0, 11, mystring);
199 #endif
201 #if 1 /* enable this to see info about IODMA channel 0 (PCM) */
202 snprintf(mystring, 64, "DMA: %08X %08X", DMACADDR0, DMACTCNT0);
203 lcd_puts(0, 12, mystring);
204 #endif
205 #if 1 /* enable this to see info about IIS */
206 snprintf(mystring, 64, "IIS: %08X", I2SSTATUS);
207 lcd_puts(0, 13, mystring);
208 #endif
210 lcd_update();
213 //power off
214 PDAT1&=~(1<<3);