summaryrefslogtreecommitdiff
path: root/firmware/drivers/tsc200x.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/tsc200x.c')
-rw-r--r--firmware/drivers/tsc200x.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/firmware/drivers/tsc200x.c b/firmware/drivers/tsc200x.c
new file mode 100644
index 0000000000..4af8118d26
--- /dev/null
+++ b/firmware/drivers/tsc200x.c
@@ -0,0 +1,64 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Jonas Aaberg, Rob Purchase
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "tsc200x.h"
23#include "cpu.h"
24#include "i2c.h"
25
26#define TSC_SLAVE_ADDR 0x90
27#define TSC_REG_READ_X 0x80
28#define TSC_REG_READ_Y 0x90
29
30#ifdef COWON_D2
31#define TSCPRES_GPIO GPIOC
32#define TSCPRES_GPIO_DIR GPIOC_DIR
33#define TSCPRES_BIT (1<<26)
34#endif
35
36void tsc200x_init(void)
37{
38 /* Configure GPIOC 26 (TSC pressed) for input */
39 TSCPRES_GPIO_DIR &= ~TSCPRES_BIT;
40}
41
42bool tsc200x_is_pressed(void)
43{
44 return !(TSCPRES_GPIO & TSCPRES_BIT);
45}
46
47bool tsc200x_read_coords(short* x, short* y)
48{
49 int rc = 0;
50 unsigned char x_val[2], y_val[2];
51
52 rc |= i2c_readmem(TSC_SLAVE_ADDR, TSC_REG_READ_Y, y_val, 2);
53 rc |= i2c_readmem(TSC_SLAVE_ADDR, TSC_REG_READ_X, x_val, 2);
54
55 if (rc >= 0)
56 {
57 /* Keep the 10 most significant bits */
58 *x = ((((short)x_val[0]) << 8) | x_val[1]) >> 6;
59 *y = ((((short)y_val[0]) << 8) | y_val[1]) >> 6;
60 return true;
61 }
62
63 return false;
64}