doom: fix types mismatch spotted by gcc 4.5.1
[kugel-rb.git] / bootloader / meizu_m6sl.c
blobc230ec3c0886b4158df7f2ec35c6626dafa034db
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 ****************************************************************************/
21 #include "config.h"
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"
32 #include "storage.h"
33 #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"
46 #include "qt1106.h"
48 #include <stdarg.h>
50 #define LONG_DELAY 200000
51 #define SHORT_DELAY 50000
52 #define PAUSE_DELAY 50000
54 static inline void delay(int duration)
56 volatile int i;
57 for(i=0;i<duration;i++);
61 void bl_debug(bool bit)
63 if (bit)
65 PDAT0 ^= (1 << 2); //Toggle backlight
66 delay(LONG_DELAY);
67 PDAT0 ^= (1 << 2); //Toggle backlight
68 delay(LONG_DELAY);
70 else
72 PDAT0 ^= (1 << 2); //Toggle backlight
73 delay(SHORT_DELAY);
74 PDAT0 ^= (1 << 2); //Toggle backlight
75 delay(SHORT_DELAY);
79 void bl_debug_count(unsigned int input)
81 unsigned int i;
82 delay(SHORT_DELAY*3);
83 for (i = 0; i < input; i++)
85 PDAT0 ^= (1 << 2); //Toggle backlight
86 delay(SHORT_DELAY);
87 PDAT0 ^= (1 << 2); //Toggle backlight
88 delay(2*SHORT_DELAY);
91 void bl_debug_int(unsigned int input,unsigned int count)
93 unsigned int i;
94 for (i = 0; i < count; i++)
96 bl_debug(input>>i & 1);
98 delay(SHORT_DELAY*6);
101 /* These functions are supposed to be static in lcd-m6sl.c, but
102 we use them here for testing */
103 void init_lcd_spi(void);
104 unsigned int lcd_read_id(void);
106 void main(void)
108 //Set backlight pin to output and enable
109 unsigned int model;
110 int oldval = PCON0;
111 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
112 PDAT0 |= (1 << 2);
114 //Set PLAY to input
115 oldval = PCON1;
116 PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16));
118 init_qt1106();
120 // Wait for play to be pressed
121 while(!(PDAT1 & (1 << 4)));
122 // Wait for play to be released
123 while((PDAT1 & (1 << 4)));
124 PDAT0 ^= (1 << 2); //Toggle backlight
125 delay(LONG_DELAY);
127 init_lcd_spi();
128 model=lcd_read_id();
129 bl_debug_count((model&0xf000)>>12);
130 bl_debug_count((model&0xf00)>>8);
131 bl_debug_count((model&0xf0)>>4);
132 bl_debug_count(model&0xf);
134 /* Calibrate the lot */
135 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI \
136 | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_4);
138 /* Set to maximum sensitivity */
139 qt1106_io(QT1106_CT | (0x00 << 8) );
141 while(true)
143 qt1106_wait();
145 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF \
146 | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_4);
147 if(slider & 0x008000)
148 bl_debug_count(((slider&0xff)) + 1);
151 //power off
152 PDAT1&=~(1<<3);