Put the quickscreen viewports onto the stack (saving a tiny bit of ram), and simplify...
[kugel-rb.git] / bootloader / meizu_m3.c
blob61aa3cecbe00a4180c254f126b358460a34e283f
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 char version[] = APPSVERSION;
58 #define LONG_DELAY 200000
59 #define SHORT_DELAY 50000
60 #define PAUSE_DELAY 50000
62 static inline void delay(int duration)
64 volatile int i;
65 for(i=0;i<duration;i++);
69 void bl_debug(bool bit)
71 if (bit)
73 PDAT0 ^= (1 << 2); //Toggle backlight
74 delay(LONG_DELAY);
75 PDAT0 ^= (1 << 2); //Toggle backlight
76 delay(LONG_DELAY);
78 else
80 PDAT0 ^= (1 << 2); //Toggle backlight
81 delay(SHORT_DELAY);
82 PDAT0 ^= (1 << 2); //Toggle backlight
83 delay(SHORT_DELAY);
87 void bl_debug_count(unsigned int input)
89 unsigned int i;
90 delay(SHORT_DELAY*3);
91 for (i = 0; i < input; i++)
93 PDAT0 ^= (1 << 2); //Toggle backlight
94 delay(SHORT_DELAY);
95 PDAT0 ^= (1 << 2); //Toggle backlight
96 delay(2*SHORT_DELAY);
99 void bl_debug_int(unsigned int input,unsigned int count)
101 unsigned int i;
102 for (i = 0; i < count; i++)
104 bl_debug(input>>i & 1);
106 delay(SHORT_DELAY*6);
109 void main(void)
111 char mystring[64];
112 int i;
113 unsigned short data = 0;
114 char write_data[2], read_data[16];
116 //Set backlight pin to output and enable
117 int oldval = PCON0;
118 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
119 PDAT0 |= (1 << 2);
121 // Set codec reset pin inactive
122 PCON5 = (PCON5 & ~0xF) | 1;
123 PDAT5 &= ~(1 << 0);
125 //power on
126 // oldval = PCON1;
127 // PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12));
128 // PDAT1|=(1<<3);
130 //Set PLAY to EINT4
131 oldval = PCON1;
132 PCON1 = ((oldval & ~(0xf << 16)) | (2 << 16));
134 //Set MENU to EINT0
135 oldval = PCON1;
136 PCON1 = (oldval & ~(0xf)) | 2;
138 // enable external interrupts
139 EINTPOL = 0x11;
140 INTMSK = 0x11;
141 EINTMSK = 0x11;
142 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
144 system_init();
145 kernel_init();
147 backlight_init();
148 lcd_init();
149 lcd_update();
151 i2c_init();
153 init_qt1106();
155 /* Calibrate the lot */
156 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \
157 | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_256);
159 lcd_clear_display();
160 lcd_bitmap(rockboxlogo, 0, 30, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
161 lcd_update();
163 /* Set to maximum sensitivity */
164 qt1106_io(QT1106_CT | (0x00 << 8) );
166 while(true)
168 #if 1 /* enable this to see info about the slider touchpad */
169 qt1106_wait();
171 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \
172 | 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);
175 _backlight_set_brightness((slider & 0xFF) >> 4);
178 if(slider & 0x008000)
179 bl_debug_count(((slider&0xff)) + 1);
181 #endif
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]);
188 lcd_puts(0, 10, mystring);
189 #endif
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);
199 lcd_puts(0, 11, mystring);
200 #endif
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
211 lcd_update();
214 //power off
215 PDAT1&=~(1<<3);