1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Jonas Aaberg, Rob Purchase
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 ****************************************************************************/
26 #define TSC_SLAVE_ADDR 0x90
27 #define TSC_REG_READ_X 0x80
28 #define TSC_REG_READ_Y 0x90
31 #define TSCPRES_GPIO GPIOC
32 #define TSCPRES_GPIO_DIR GPIOC_DIR
33 #define TSCPRES_BIT (1<<26)
36 void tsc200x_init(void)
38 /* Configure GPIOC 26 (TSC pressed) for input */
39 TSCPRES_GPIO_DIR
&= ~TSCPRES_BIT
;
42 bool tsc200x_is_pressed(void)
44 return !(TSCPRES_GPIO
& TSCPRES_BIT
);
47 bool tsc200x_read_coords(short* x
, short* y
)
50 unsigned char x_val
[2], y_val
[2];
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);
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;