Split off target-specific parts from firmware/drivers/serial.c
[kugel-rb.git] / firmware / drivers / tsc200x.c
blob4af8118d26c35915ef1daaceffd404de4bbf188f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "tsc200x.h"
23 #include "cpu.h"
24 #include "i2c.h"
26 #define TSC_SLAVE_ADDR 0x90
27 #define TSC_REG_READ_X 0x80
28 #define TSC_REG_READ_Y 0x90
30 #ifdef COWON_D2
31 #define TSCPRES_GPIO GPIOC
32 #define TSCPRES_GPIO_DIR GPIOC_DIR
33 #define TSCPRES_BIT (1<<26)
34 #endif
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)
49 int rc = 0;
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);
55 if (rc >= 0)
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;
63 return false;