1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Frank Gevaerts
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 ****************************************************************************/
27 #define SPIDELAY(_x) void(_x);
28 #define SETMOSI() (PDAT1 |= (1 << 6))
29 #define CLRMOSI() (PDAT1 &= ~(1 << 6))
31 #define MISO ((PDAT0 >> 3) & 1)
32 #define RDY (PDAT1 & (1 << 5))
34 #define SETCLK() (PDAT0 |= (1 << 1))
35 #define CLRCLK() (PDAT0 &= ~(1 << 1))
37 #define SETSS() (PDAT0 |= (1 << 0))
38 #define CLRSS() (PDAT0 &= ~(1 << 0))
40 #define CHANGE (PDAT0 & (1 << 4))
43 void init_qt1106(void)
48 //Set P0.0 and P0.1 to output, set P0.3 and P0.4 to input
49 PCON0
= ((oldval
& ~(3 << 0 | 3 << 2 | 3 << 6 | 3 << 8)) | (1 << 0 | 1 << 2));
52 //Set P1.5 to input, set P1.6 to output
53 PCON1
= ((oldval
& ~(0xf << 20 | 0xf << 24)) | (1 << 24));
60 static inline void delay(int duration
)
63 for(i
=0;i
<duration
;i
++);
66 void qt1106_wait(void)
68 while(!(PDAT0
& (1 << 4))) {}
71 unsigned int qt1106_io(unsigned int output
)
73 unsigned int input
= 0;
78 delay(10*100); // < 470 us
81 delay(13*100); // > 22 us
83 for (i
= 0; i
< 24; i
++) {
87 if (output
& (1 << 23))
93 delay(20*100); // >> 6.7 us
100 delay(20*100); // >> 6.7 us