2007-09-20 04:46:41 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-09-22 15:43:38 +00:00
|
|
|
* $Id$
|
2007-09-20 04:46:41 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Karl Kurbjun
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-30 11:15:14 +00:00
|
|
|
/* this file also handles the touch screen driver interface */
|
|
|
|
|
2007-09-20 04:46:41 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "backlight-target.h"
|
2007-09-20 09:08:40 +00:00
|
|
|
#include "uart-target.h"
|
2007-09-30 11:15:14 +00:00
|
|
|
#include "tsc2100.h"
|
2007-10-13 14:53:34 +00:00
|
|
|
#include "string.h"
|
2007-09-20 04:46:41 +00:00
|
|
|
|
2007-09-20 08:42:06 +00:00
|
|
|
#define BUTTON_TIMEOUT 50
|
2007-09-21 02:05:02 +00:00
|
|
|
|
|
|
|
#define BUTTON_START_BYTE 0xF0
|
|
|
|
#define BUTTON_START_BYTE2 0xF4 /* not sure why, but sometimes you get F0 or F4, */
|
|
|
|
/* but always the same one for the session? */
|
2007-09-30 11:15:14 +00:00
|
|
|
static short last_x, last_y, last_z1, last_z2; /* for the touch screen */
|
|
|
|
static int last_touch;
|
2007-10-01 07:52:39 +00:00
|
|
|
|
|
|
|
static struct touch_calibration_point topleft, bottomright;
|
|
|
|
static bool using_calibration = false;
|
|
|
|
void use_calibration(bool enable)
|
|
|
|
{
|
|
|
|
using_calibration = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_calibration_points(struct touch_calibration_point *tl,
|
|
|
|
struct touch_calibration_point *br)
|
|
|
|
{
|
|
|
|
memcpy(&topleft, tl, sizeof(struct touch_calibration_point));
|
|
|
|
memcpy(&bottomright, br, sizeof(struct touch_calibration_point));
|
|
|
|
}
|
|
|
|
static int touch_to_pixels(short val_x, short val_y)
|
|
|
|
{
|
|
|
|
short x,y;
|
|
|
|
int x1,x2;
|
|
|
|
if (!using_calibration)
|
|
|
|
return (val_x<<16)|val_y;
|
|
|
|
x1 = topleft.val_x; x2 = bottomright.val_x;
|
|
|
|
x = (val_x-x1)*(bottomright.px_x - topleft.px_x) / (x2 - x1) + topleft.px_x;
|
|
|
|
x1 = topleft.val_y; x2 = bottomright.val_y;
|
|
|
|
y = (val_y-x1)*(bottomright.px_y - topleft.px_y) / (x2 - x1) + topleft.px_y;
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
return (x<<16)|y;
|
|
|
|
}
|
2007-09-20 04:46:41 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2007-09-30 11:15:14 +00:00
|
|
|
last_touch = 0;
|
2007-09-20 08:42:06 +00:00
|
|
|
/* GIO is the power button, set as input */
|
2007-09-30 08:18:46 +00:00
|
|
|
IO_GIO_DIR0 |= 0x01;
|
2007-09-30 11:15:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Enable the touchscreen interrupt */
|
|
|
|
IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */
|
|
|
|
#if 0
|
|
|
|
tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS,
|
|
|
|
TSADC_PSTCM|
|
|
|
|
(0x2<<TSADC_ADSCM_SHIFT)| /* scan x,y,z1,z2 */
|
|
|
|
(0x1<<TSADC_RESOL_SHIFT) /* 8 bit resolution */
|
|
|
|
);
|
|
|
|
/* doesnt work for some reason...
|
|
|
|
setting to 8bit would probably be better than the 12bit currently */
|
|
|
|
#endif
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool button_hold(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-09-30 11:15:14 +00:00
|
|
|
#ifdef BOOTLOADER
|
|
|
|
int button_get_last_touch(void)
|
|
|
|
{
|
|
|
|
int ret_val = last_touch;
|
|
|
|
last_touch = 0;
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-20 04:46:41 +00:00
|
|
|
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2007-09-20 08:42:06 +00:00
|
|
|
char data[5], c;
|
|
|
|
int i = 0;
|
2007-09-30 08:18:46 +00:00
|
|
|
int btn = BUTTON_NONE;
|
2007-09-20 08:42:06 +00:00
|
|
|
|
2007-09-30 11:15:14 +00:00
|
|
|
if (last_touch)
|
|
|
|
btn |= BUTTON_TOUCHPAD;
|
|
|
|
|
2007-09-23 23:08:39 +00:00
|
|
|
if ((IO_GIO_BITSET0&0x01) == 0)
|
2007-09-20 08:42:06 +00:00
|
|
|
btn |= BUTTON_POWER;
|
|
|
|
|
2007-09-30 08:18:46 +00:00
|
|
|
uart1_heartbeat();
|
2007-10-01 05:42:12 +00:00
|
|
|
while (uart1_available())
|
2007-09-20 08:42:06 +00:00
|
|
|
{
|
2007-09-30 08:18:46 +00:00
|
|
|
if (uart1_getch(&c))
|
2007-09-20 08:42:06 +00:00
|
|
|
{
|
2007-09-21 02:05:02 +00:00
|
|
|
if (i && (data[0] == BUTTON_START_BYTE || data[0] == BUTTON_START_BYTE2))
|
2007-09-20 08:42:06 +00:00
|
|
|
{
|
|
|
|
data[i++] = c;
|
|
|
|
}
|
2007-09-21 02:05:02 +00:00
|
|
|
else if (c == BUTTON_START_BYTE ||
|
|
|
|
c == BUTTON_START_BYTE2)
|
2007-09-20 08:42:06 +00:00
|
|
|
{
|
|
|
|
data[0] = c;
|
|
|
|
i = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 5)
|
|
|
|
{
|
|
|
|
if (data[1]& (1<<7))
|
|
|
|
btn |= BUTTON_RC_HEART;
|
|
|
|
if (data[1]& (1<<6))
|
|
|
|
btn |= BUTTON_RC_MODE;
|
|
|
|
if (data[1]& (1<<5))
|
|
|
|
btn |= BUTTON_RC_VOL_DOWN;
|
|
|
|
if (data[1]& (1<<4))
|
|
|
|
btn |= BUTTON_RC_VOL_UP;
|
|
|
|
if (data[1]& (1<<3))
|
|
|
|
btn |= BUTTON_RC_REW;
|
|
|
|
if (data[1]& (1<<2))
|
|
|
|
btn |= BUTTON_RC_FF;
|
|
|
|
if (data[1]& (1<<1))
|
|
|
|
btn |= BUTTON_RC_DOWN;
|
|
|
|
if (data[1]& (1<<0))
|
|
|
|
btn |= BUTTON_RC_PLAY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return btn;
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
2007-09-30 11:15:14 +00:00
|
|
|
|
|
|
|
void GIO14(void)
|
|
|
|
{
|
|
|
|
tsc2100_read_values(&last_x, &last_y,
|
|
|
|
&last_z1, &last_z2);
|
2007-10-01 07:52:39 +00:00
|
|
|
last_touch = touch_to_pixels(last_x, last_y);
|
2007-09-30 11:15:14 +00:00
|
|
|
IO_INTC_IRQ2 = (1<<3);
|
|
|
|
}
|