diff options
Diffstat (limited to 'bootloader/meizu_m6sl.c')
-rw-r--r-- | bootloader/meizu_m6sl.c | 196 |
1 files changed, 170 insertions, 26 deletions
diff --git a/bootloader/meizu_m6sl.c b/bootloader/meizu_m6sl.c index 3ee88120b5..8826abbcf0 100644 --- a/bootloader/meizu_m6sl.c +++ b/bootloader/meizu_m6sl.c | |||
@@ -47,10 +47,164 @@ | |||
47 | #include <stdarg.h> | 47 | #include <stdarg.h> |
48 | 48 | ||
49 | char version[] = APPSVERSION; | 49 | char version[] = APPSVERSION; |
50 | #define LONG_DELAY 200000 | ||
51 | #define SHORT_DELAY 50000 | ||
52 | #define PAUSE_DELAY 50000 | ||
53 | |||
54 | #define SPIDELAY(_x) void(_x); | ||
55 | #define SETMOSI() PDAT1 |= (1 << 6) | ||
56 | #define CLRMOSI() PDAT1 &= ~(1 << 6) | ||
57 | |||
58 | #define MISO ((PDAT0 >> 3) & 1) | ||
59 | #define RDY (PDAT1 & (1 << 5)) | ||
60 | |||
61 | #define SETCLK() PDAT0 |= (1 << 1) | ||
62 | #define CLRCLK() PDAT0 &= ~(1 << 1) | ||
63 | |||
64 | #define SETSS() PDAT0 |= (1 << 0) | ||
65 | #define CLRSS() PDAT0 &= ~(1 << 0) | ||
66 | |||
67 | #define SPISPEED 10000 | ||
68 | |||
69 | #define QT_CT 0x00800000 | ||
70 | |||
71 | #define QT_AKS_DISABLED 0x00000000 | ||
72 | #define QT_AKS_GLOBAL 0x00010000 | ||
73 | #define QT_AKS_MODE1 0x00020000 | ||
74 | #define QT_AKS_MODE2 0x00030000 | ||
75 | #define QT_AKS_MODE3 0x00040000 | ||
76 | #define QT_AKS_MODE4 0x00050000 | ||
77 | |||
78 | #define QT_SLD_WHEEL 0x00000000 | ||
79 | #define QT_SLD_SLIDER 0x00080000 | ||
80 | |||
81 | #define QT_KEY7_NORMAL 0x00000000 | ||
82 | #define QT_KEY7_PROX 0x00100000 | ||
83 | |||
84 | #define QT_MODE_FREE 0x00000000 | ||
85 | #define QT_MODE_LP1 0x00000100 | ||
86 | #define QT_MODE_LP2 0x00000200 | ||
87 | #define QT_MODE_LP3 0x00000300 | ||
88 | #define QT_MODE_LP4 0x00000400 | ||
89 | #define QT_MODE_SYNC 0x00000500 | ||
90 | #define QT_MODE_SLEEP 0x00000600 | ||
91 | |||
92 | #define QT_LPB 0x00000800 | ||
93 | #define QT_DI 0x00001000 | ||
94 | |||
95 | #define QT_MOD_10 0x00000000 | ||
96 | #define QT_MOD_20 0x00002000 | ||
97 | #define QT_MOD_60 0x00004000 | ||
98 | #define QT_MOD_INF 0x00006000 | ||
99 | |||
100 | #define QT_CAL_ALL 0x00000000 | ||
101 | #define QT_CAL_KEYS 0x00000008 | ||
102 | #define QT_CAL_WHEEL 0x00000010 | ||
103 | #define QT_RES_4 0x00000020 | ||
104 | #define QT_RES_8 0x00000040 | ||
105 | #define QT_RES_16 0x00000060 | ||
106 | #define QT_RES_32 0x00000080 | ||
107 | #define QT_RES_64 0x000000A0 | ||
108 | #define QT_RES_128 0x000000C0 | ||
109 | #define QT_RES_256 0x000000E0 | ||
110 | |||
111 | |||
112 | static inline void delay(int duration) | ||
113 | { | ||
114 | volatile int i; | ||
115 | for(i=0;i<duration;i++); | ||
116 | } | ||
117 | |||
118 | |||
119 | void init_qt1106(void) | ||
120 | { | ||
121 | int oldval; | ||
122 | |||
123 | oldval = PCON0; | ||
124 | //Set P0.0 and P0.1 to output, set P0.3 to input | ||
125 | PCON0 = ((oldval & ~(3 << 0 || 3 << 2 || 3 << 6)) | (1 << 0 | 1 << 2)); | ||
126 | |||
127 | oldval = PCON1; | ||
128 | //Set P1.5 to input, set P1.6 to input | ||
129 | PCON1 = ((oldval & ~(0xf << 20 || 0xf << 24)) | (1 << 24)); | ||
130 | |||
131 | SETSS(); | ||
132 | SETCLK(); | ||
133 | } | ||
134 | |||
135 | unsigned read_qt1106(unsigned int input) | ||
136 | { | ||
137 | int output = 0; | ||
138 | int i; | ||
139 | |||
140 | while(!RDY) {} | ||
141 | |||
142 | delay(10); // < 470 us | ||
143 | |||
144 | CLRSS(); | ||
145 | delay(13); // > 22 us | ||
146 | |||
147 | for (i = 0; i < 24; i++) { | ||
148 | |||
149 | CLRCLK(); | ||
150 | |||
151 | if (input & (1 << 23)) | ||
152 | SETMOSI(); | ||
153 | else | ||
154 | CLRMOSI(); | ||
155 | input <<= 1; | ||
156 | |||
157 | delay(20); // >> 6.7 us | ||
158 | |||
159 | SETCLK(); | ||
160 | |||
161 | output |= MISO; | ||
162 | output <<= 1; | ||
163 | |||
164 | delay(20); // >> 6.7 us | ||
165 | } | ||
166 | |||
167 | SETSS(); | ||
168 | |||
169 | return (output & 0x00FFFFFF); | ||
170 | } | ||
171 | |||
172 | |||
173 | void bl_debug(bool bit) | ||
174 | { | ||
175 | if (bit) | ||
176 | { | ||
177 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
178 | delay(LONG_DELAY); | ||
179 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
180 | delay(LONG_DELAY); | ||
181 | //for(i=0;i<pause_delay;i++); | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
186 | delay(SHORT_DELAY); | ||
187 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
188 | delay(SHORT_DELAY); | ||
189 | //for(i=0;i<pause_delay;i++); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | void bl_debug_int(unsigned int input) | ||
194 | { | ||
195 | unsigned int i; | ||
196 | for (i = 0; i < input; i++) | ||
197 | { | ||
198 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
199 | delay(SHORT_DELAY); | ||
200 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
201 | delay(2*SHORT_DELAY); | ||
202 | } | ||
203 | delay(SHORT_DELAY*6); | ||
204 | } | ||
50 | 205 | ||
51 | void main(void) | 206 | void main(void) |
52 | { | 207 | { |
53 | int counter=0; | ||
54 | //Set backlight pin to output and enable | 208 | //Set backlight pin to output and enable |
55 | int oldval = PCON0; | 209 | int oldval = PCON0; |
56 | PCON0 = ((oldval & ~(3 << 4)) | (1 << 4)); | 210 | PCON0 = ((oldval & ~(3 << 4)) | (1 << 4)); |
@@ -60,37 +214,27 @@ void main(void) | |||
60 | oldval = PCON1; | 214 | oldval = PCON1; |
61 | PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16)); | 215 | PCON1 = ((oldval & ~(0xf << 16)) | (0 << 16)); |
62 | 216 | ||
63 | //Set the piezo pins to output | 217 | init_qt1106(); |
64 | oldval = PCON5; | ||
65 | PCON5 = ((oldval & ~((0xf << 4) | (0xf << 8))) | ((1 << 0) | (1 << 4))); | ||
66 | PDAT5 &= ~((1 << 1) | (1 << 2)); //should not be needed | ||
67 | 218 | ||
68 | PDAT5 |= (1 << 1); //Toggle piezo + | 219 | // Wait for play to be pressed |
220 | while(!(PDAT1 & (1 << 4))); | ||
221 | // Wait for play to be released | ||
222 | while((PDAT1 & (1 << 4))); | ||
223 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
69 | 224 | ||
70 | //toggle backlight on PLAY | 225 | /* Calibrate the lot */ |
71 | while(counter<20) | 226 | read_qt1106(QT_MODE_FREE | QT_MOD_INF | QT_DI | QT_SLD_SLIDER | QT_CAL_WHEEL | QT_CAL_KEYS | QT_RES_4); |
72 | { | ||
73 | // Wait for play to be pressed | ||
74 | while(!(PDAT1 & (1 << 4))) | ||
75 | { | ||
76 | } | ||
77 | 227 | ||
78 | PDAT5 ^= (1 << 1); //Toggle piezo + | 228 | /* Set to maximum sensitivity */ |
79 | PDAT0 ^= (1 << 2); //Toggle backlight | 229 | read_qt1106(QT_CT | (0x00 << 8) ); |
80 | counter++; | ||
81 | 230 | ||
82 | // Wait for play to be released | 231 | while(true) |
83 | while(PDAT1 & (1 << 4)) | ||
84 | { | ||
85 | } | ||
86 | } | ||
87 | //toggle a few times to warn that we're done | ||
88 | for(counter=0;counter<10;counter++) | ||
89 | { | 232 | { |
90 | volatile int i; | 233 | int slider = read_qt1106(QT_MODE_FREE | QT_MOD_INF | QT_DI | QT_SLD_SLIDER | QT_RES_4); |
91 | for(i=0;i<50000;i++); | 234 | bl_debug_int(((slider&0xff)) + 1); |
92 | PDAT0 ^= (1 << 2); //Toggle backlight | ||
93 | } | 235 | } |
236 | |||
237 | //power off | ||
94 | PDAT1&=~(1<<3); | 238 | PDAT1&=~(1<<3); |
95 | } | 239 | } |
96 | 240 | ||