diff options
Diffstat (limited to 'firmware/drivers/tsc2100.c')
-rw-r--r-- | firmware/drivers/tsc2100.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/firmware/drivers/tsc2100.c b/firmware/drivers/tsc2100.c new file mode 100644 index 0000000000..19da33e377 --- /dev/null +++ b/firmware/drivers/tsc2100.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Jonathan Gordon | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "config.h" | ||
21 | #include "cpu.h" | ||
22 | #include "system.h" | ||
23 | #include "spi.h" | ||
24 | #include "tsc2100.h" | ||
25 | |||
26 | /* Read X, Y, Z1, Z2 touchscreen coordinates. */ | ||
27 | void tsc2100_read_values(short *x, short* y, short *z1, short *z2) | ||
28 | { | ||
29 | int page = 0, address = 0; | ||
30 | unsigned short command = 0x8000|(page << 11)|(address << 5); | ||
31 | unsigned char out[] = {command >> 8, command & 0xff}; | ||
32 | unsigned char in[8]; | ||
33 | spi_block_transfer(out, sizeof(out), in, sizeof(in)); | ||
34 | |||
35 | *x = (in[0]<<8)|in[1]; | ||
36 | *y = (in[2]<<8)|in[3]; | ||
37 | *z1 = (in[4]<<8)|in[5]; | ||
38 | *z2 = (in[6]<<8)|in[7]; | ||
39 | } | ||
40 | |||
41 | short tsc2100_readreg(int page, int address) | ||
42 | { | ||
43 | unsigned short command = 0x8000|(page << 11)|(address << 5); | ||
44 | unsigned char out[] = {command >> 8, command & 0xff}; | ||
45 | unsigned char in[2]; | ||
46 | spi_block_transfer(out, sizeof(out), in, sizeof(in)); | ||
47 | return (in[0]<<8)|in[1]; | ||
48 | } | ||
49 | |||
50 | |||
51 | void tsc2100_writereg(int page, int address, short value) | ||
52 | { | ||
53 | unsigned short command = 0x8000|(page << 11)|(address << 5); | ||
54 | unsigned char out[4] = {command >> 8, command & 0xff, | ||
55 | value >> 8, value & 0xff}; | ||
56 | spi_block_transfer(out, sizeof(out), NULL, 0); | ||
57 | } | ||
58 | |||
59 | void tsc2100_keyclick(void) | ||
60 | { | ||
61 | // 1100 0100 0001 0000 | ||
62 | short val = 0xC410; | ||
63 | tsc2100_writereg(TSAC2_PAGE, TSAC2_ADDRESS, val); | ||
64 | } | ||