Manual: Small English improvement
[maemo-rb.git] / firmware / drivers / qt1106.c
blob67573fe0aecd0bdc900618744aaacf7c6f726c20
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "qt1106.h"
23 #include "cpu.h"
24 #include "system.h"
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)
45 int oldval;
47 oldval = PCON0;
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));
51 oldval = PCON1;
52 //Set P1.5 to input, set P1.6 to output
53 PCON1 = ((oldval & ~(0xf << 20 | 0xf << 24)) | (1 << 24));
56 SETSS();
57 SETCLK();
60 static inline void delay(int duration)
62 volatile int i;
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;
74 int i;
76 while(!RDY) {}
78 delay(10*100); // < 470 us
80 CLRSS();
81 delay(13*100); // > 22 us
83 for (i = 0; i < 24; i++) {
85 CLRCLK();
87 if (output & (1 << 23))
88 SETMOSI();
89 else
90 CLRMOSI();
91 output <<= 1;
93 delay(20*100); // >> 6.7 us
95 SETCLK();
97 input <<= 1;
98 input |= MISO;
100 delay(20*100); // >> 6.7 us
103 SETSS();
105 return (input);