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 */
|
2007-10-22 07:01:59 +00:00
|
|
|
static bool touch_available = false;
|
2007-10-01 07:52:39 +00:00
|
|
|
|
2008-04-15 10:35:11 +00:00
|
|
|
static enum touchpad_mode current_mode = TOUCHPAD_POINT;
|
|
|
|
static int touchpad_buttons[3][3] = {
|
|
|
|
{BUTTON_TOPLEFT, BUTTON_TOPMIDDLE, BUTTON_TOPRIGHT},
|
|
|
|
{BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
|
|
|
|
{BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT},
|
|
|
|
};
|
|
|
|
|
|
|
|
void touchpad_set_mode(enum touchpad_mode mode)
|
|
|
|
{
|
|
|
|
current_mode = mode;
|
|
|
|
}
|
|
|
|
enum touchpad_mode touchpad_get_mode(void)
|
|
|
|
{
|
|
|
|
return current_mode;
|
|
|
|
}
|
|
|
|
|
2007-10-01 07:52:39 +00:00
|
|
|
static struct touch_calibration_point topleft, bottomright;
|
2007-11-15 06:44:35 +00:00
|
|
|
|
2007-10-18 12:15:56 +00:00
|
|
|
/* Jd's tests.. These will hopefully work for everyone so we dont have to
|
2007-11-11 03:31:24 +00:00
|
|
|
* create a calibration screen.
|
|
|
|
* Portait:
|
|
|
|
* (0,0) = 200, 3900
|
|
|
|
* (480,640) = 3880, 270
|
|
|
|
* Landscape:
|
|
|
|
* (0,0) = 200, 270
|
|
|
|
* (640,480) = 3880, 3900
|
2007-10-18 12:15:56 +00:00
|
|
|
*/
|
2007-11-11 03:31:24 +00:00
|
|
|
|
2007-10-01 07:52:39 +00:00
|
|
|
static int touch_to_pixels(short val_x, short val_y)
|
|
|
|
{
|
|
|
|
short x,y;
|
2007-11-11 03:31:24 +00:00
|
|
|
|
2008-04-29 01:09:39 +00:00
|
|
|
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
|
2007-11-11 03:31:24 +00:00
|
|
|
x=val_x;
|
|
|
|
y=val_y;
|
|
|
|
#else
|
|
|
|
x=val_y;
|
|
|
|
y=val_x;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x;
|
|
|
|
y = (y-topleft.val_y)*(bottomright.px_y - topleft.px_y) / (bottomright.val_y - topleft.val_y) + topleft.px_y;
|
|
|
|
|
2007-10-01 07:52:39 +00:00
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
2007-11-15 06:44:35 +00:00
|
|
|
else if (x>=LCD_WIDTH)
|
|
|
|
x=LCD_WIDTH-1;
|
|
|
|
|
2007-10-01 07:52:39 +00:00
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
2007-11-15 06:44:35 +00:00
|
|
|
else if (y>=LCD_HEIGHT)
|
|
|
|
y=LCD_HEIGHT-1;
|
|
|
|
|
|
|
|
|
2007-10-01 07:52:39 +00:00
|
|
|
return (x<<16)|y;
|
|
|
|
}
|
2007-10-18 05:14:10 +00:00
|
|
|
|
2007-09-20 04:46:41 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2007-10-22 07:01:59 +00:00
|
|
|
touch_available = false;
|
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-11-11 03:31:24 +00:00
|
|
|
|
2008-04-29 01:09:39 +00:00
|
|
|
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
|
2007-11-11 03:31:24 +00:00
|
|
|
topleft.val_x = 200;
|
|
|
|
topleft.val_y = 3900;
|
|
|
|
|
|
|
|
bottomright.val_x = 3880;
|
|
|
|
bottomright.val_y = 270;
|
2007-11-11 04:48:33 +00:00
|
|
|
#else
|
2007-11-11 03:31:24 +00:00
|
|
|
topleft.val_x = 270;
|
|
|
|
topleft.val_y = 200;
|
2007-09-30 11:15:14 +00:00
|
|
|
|
2007-11-11 03:31:24 +00:00
|
|
|
bottomright.val_x = 3900;
|
|
|
|
bottomright.val_y = 3880;
|
|
|
|
#endif
|
|
|
|
|
2007-11-15 06:44:35 +00:00
|
|
|
topleft.px_x = 0;
|
2007-11-11 03:31:24 +00:00
|
|
|
topleft.px_y = 0;
|
2007-11-15 06:44:35 +00:00
|
|
|
|
|
|
|
bottomright.px_x = LCD_WIDTH;
|
2007-11-11 03:31:24 +00:00
|
|
|
bottomright.px_y = LCD_HEIGHT;
|
|
|
|
|
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-10-18 12:15:56 +00:00
|
|
|
|
2007-10-18 05:14:10 +00:00
|
|
|
static void remote_heartbeat(void)
|
|
|
|
{
|
|
|
|
char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'};
|
2007-11-15 06:44:35 +00:00
|
|
|
uart1_puts(data, 5);
|
2007-10-18 05:14:10 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 07:01:59 +00:00
|
|
|
#define TOUCH_MARGIN 8
|
2007-11-15 06:44:35 +00:00
|
|
|
char r_buffer[5];
|
|
|
|
int r_button = BUTTON_NONE;
|
2007-10-22 07:01:59 +00:00
|
|
|
int button_read_device(int *data)
|
2007-09-20 04:46:41 +00:00
|
|
|
{
|
2007-11-15 06:44:35 +00:00
|
|
|
int retval, calbuf;
|
2007-11-10 22:12:54 +00:00
|
|
|
static int oldbutton = BUTTON_NONE;
|
2007-11-15 06:44:35 +00:00
|
|
|
|
|
|
|
r_button=BUTTON_NONE;
|
2007-10-22 07:01:59 +00:00
|
|
|
*data = 0;
|
2007-11-10 22:12:54 +00:00
|
|
|
|
2007-10-22 07:01:59 +00:00
|
|
|
if (touch_available)
|
|
|
|
{
|
|
|
|
short x,y;
|
|
|
|
static long last_touch = 0;
|
|
|
|
bool send_touch = false;
|
|
|
|
tsc2100_read_values(&x, &y, &last_z1, &last_z2);
|
|
|
|
if (TIME_BEFORE(last_touch + HZ/5, current_tick))
|
|
|
|
{
|
|
|
|
if ((x > last_x + TOUCH_MARGIN) ||
|
|
|
|
(x < last_x - TOUCH_MARGIN) ||
|
|
|
|
(y > last_y + TOUCH_MARGIN) ||
|
|
|
|
(y < last_y - TOUCH_MARGIN))
|
|
|
|
{
|
|
|
|
send_touch = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
send_touch = true;
|
|
|
|
if (send_touch)
|
|
|
|
{
|
|
|
|
last_x = x;
|
|
|
|
last_y = y;
|
|
|
|
*data = touch_to_pixels(x, y);
|
2008-04-15 10:35:11 +00:00
|
|
|
switch (current_mode)
|
|
|
|
{
|
|
|
|
case TOUCHPAD_POINT:
|
|
|
|
r_button |= BUTTON_TOUCHPAD;
|
|
|
|
break;
|
|
|
|
case TOUCHPAD_BUTTON:
|
|
|
|
{
|
|
|
|
int px_x = ((*data&0xffff0000)>>16), px_y = ((*data&0x0000ffff));
|
|
|
|
r_button |= touchpad_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)];
|
|
|
|
oldbutton = r_button;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-22 07:01:59 +00:00
|
|
|
}
|
|
|
|
last_touch = current_tick;
|
|
|
|
touch_available = false;
|
|
|
|
}
|
2007-10-18 05:14:10 +00:00
|
|
|
remote_heartbeat();
|
2007-11-10 22:12:54 +00:00
|
|
|
|
|
|
|
if ((IO_GIO_BITSET0&0x01) == 0)
|
2007-11-15 06:44:35 +00:00
|
|
|
{
|
|
|
|
r_button |= BUTTON_POWER;
|
|
|
|
oldbutton=r_button;
|
|
|
|
}
|
2007-11-10 22:12:54 +00:00
|
|
|
|
2007-11-15 06:44:35 +00:00
|
|
|
retval=uart1_gets_queue(r_buffer, 5);
|
2007-11-10 22:12:54 +00:00
|
|
|
do
|
2007-09-20 08:42:06 +00:00
|
|
|
{
|
2007-11-15 06:44:35 +00:00
|
|
|
for(calbuf=0;calbuf<4;calbuf++)
|
|
|
|
{
|
|
|
|
if((r_buffer[calbuf]&0xF0)==0xF0 && (r_buffer[calbuf+1]&0xF0)!=0xF0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
calbuf++;
|
|
|
|
if(calbuf==5)
|
|
|
|
calbuf=0;
|
2007-11-10 22:12:54 +00:00
|
|
|
if(retval>=0)
|
2007-09-20 08:42:06 +00:00
|
|
|
{
|
2007-11-15 06:44:35 +00:00
|
|
|
r_button |= r_buffer[calbuf];
|
|
|
|
oldbutton=r_button;
|
2007-10-18 05:14:10 +00:00
|
|
|
}
|
2007-11-10 22:12:54 +00:00
|
|
|
else
|
2007-10-18 05:14:10 +00:00
|
|
|
{
|
2007-11-15 06:44:35 +00:00
|
|
|
r_button=oldbutton;
|
2007-09-20 08:42:06 +00:00
|
|
|
}
|
2007-11-15 06:44:35 +00:00
|
|
|
} while((retval=uart1_gets_queue(r_buffer, 5))>=5);
|
2007-11-10 22:12:54 +00:00
|
|
|
|
2007-11-15 06:44:35 +00:00
|
|
|
return r_button;
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
2007-10-22 07:01:59 +00:00
|
|
|
|
|
|
|
/* Touchpad data available interupt */
|
2007-10-22 15:28:40 +00:00
|
|
|
void read_battery_inputs(void);
|
2007-09-30 11:15:14 +00:00
|
|
|
void GIO14(void)
|
|
|
|
{
|
2007-10-22 15:28:40 +00:00
|
|
|
short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
|
|
|
|
short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
|
|
|
|
switch (adscm)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
touch_available = true;
|
|
|
|
break;
|
|
|
|
case 0xb:
|
|
|
|
read_battery_inputs();
|
|
|
|
break;
|
|
|
|
}
|
2008-04-15 10:35:11 +00:00
|
|
|
//touch_available = true;
|
2007-10-22 07:01:59 +00:00
|
|
|
IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */
|
2007-09-30 11:15:14 +00:00
|
|
|
}
|