fix off-by-one error when reading spi data
[kugel-rb.git] / bootloader / meizu_m6sl.c
blob442a0f9e18bdeb32e36dfbc35150d1567ba69027
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 "ata.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 char version[] = APPSVERSION;
51 #define LONG_DELAY 200000
52 #define SHORT_DELAY 50000
53 #define PAUSE_DELAY 50000
55 static inline void delay(int duration)
57 volatile int i;
58 for(i=0;i<duration;i++);
62 void bl_debug(bool bit)
64 if (bit)
66 PDAT0 ^= (1 << 2); //Toggle backlight
67 delay(LONG_DELAY);
68 PDAT0 ^= (1 << 2); //Toggle backlight
69 delay(LONG_DELAY);
71 else
73 PDAT0 ^= (1 << 2); //Toggle backlight
74 delay(SHORT_DELAY);
75 PDAT0 ^= (1 << 2); //Toggle backlight
76 delay(SHORT_DELAY);
80 void bl_debug_int(unsigned int input)
82 unsigned int i;
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);
90 delay(SHORT_DELAY*6);
93 void main(void)
95 //Set backlight pin to output and enable
96 int oldval = PCON0;
97 PCON0 = ((oldval & ~(3 << 4)) | (1 << 4));
98 PDAT0 |= (1 << 2);
100 //Set PLAY to input
101 oldval = PCON1;
102 PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16));
104 init_qt1106();
106 // Wait for play to be pressed
107 while(!(PDAT1 & (1 << 4)));
108 // Wait for play to be released
109 while((PDAT1 & (1 << 4)));
110 PDAT0 ^= (1 << 2); //Toggle backlight
112 /* Calibrate the lot */
113 qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI | QT1106_SLD_SLIDER | QT1106_CAL_WHEEL | QT1106_CAL_KEYS | QT1106_RES_4);
115 /* Set to maximum sensitivity */
116 qt1106_io(QT1106_CT | (0x00 << 8) );
118 while(true)
120 qt1106_wait();
122 int slider = qt1106_io(QT1106_MODE_FREE | QT1106_MOD_INF | QT1106_DI | QT1106_SLD_SLIDER | QT1106_RES_4);
123 bl_debug_int(((slider&0xff)) + 1);
126 //power off
127 PDAT1&=~(1<<3);