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
|
|
|
*
|
2009-04-16 03:10:01 +00:00
|
|
|
* Copyright (C) 2007, 2009 by Karl Kurbjun
|
2007-09-20 04:46:41 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-20 04:46:41 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "backlight-target.h"
|
2009-04-18 06:38:55 +00:00
|
|
|
#include "lcd-remote-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"
|
2009-02-19 22:55:14 +00:00
|
|
|
#include "touchscreen.h"
|
2007-09-20 04:46:41 +00:00
|
|
|
|
2009-04-28 05:07:25 +00:00
|
|
|
static bool hold_button = false;
|
|
|
|
|
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
|
|
|
|
2009-04-28 05:07:25 +00:00
|
|
|
static int touch_to_pixels(short *val_x, short *val_y)
|
2007-10-01 07:52:39 +00:00
|
|
|
{
|
|
|
|
short x,y;
|
2007-11-11 03:31:24 +00:00
|
|
|
|
2008-04-29 01:09:39 +00:00
|
|
|
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
|
2009-04-28 05:07:25 +00:00
|
|
|
x=*val_x;
|
|
|
|
y=*val_y;
|
2007-11-11 03:31:24 +00:00
|
|
|
#else
|
2009-04-28 05:07:25 +00:00
|
|
|
x=*val_y;
|
|
|
|
y=*val_x;
|
2007-11-11 03:31:24 +00:00
|
|
|
#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;
|
|
|
|
|
2009-04-28 05:07:25 +00:00
|
|
|
*val_x=x;
|
|
|
|
*val_y=y;
|
2007-11-15 06:44:35 +00:00
|
|
|
|
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-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-20 04:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool button_hold(void)
|
|
|
|
{
|
2009-04-16 03:10:01 +00:00
|
|
|
return hold_button;
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
2007-10-18 12:15:56 +00:00
|
|
|
|
2012-01-07 19:44:30 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
static bool remote_hold_button;
|
|
|
|
static int remote_read_buttons(void)
|
|
|
|
{
|
|
|
|
static char read_buffer[5];
|
|
|
|
int read_button = BUTTON_NONE;
|
|
|
|
|
|
|
|
static int oldbutton=BUTTON_NONE;
|
|
|
|
|
|
|
|
/* Handle remote buttons */
|
|
|
|
if(uart1_gets_queue(read_buffer, 5)>=0)
|
|
|
|
{
|
|
|
|
int button_location;
|
|
|
|
|
|
|
|
for(button_location=0;button_location<4;button_location++)
|
|
|
|
{
|
|
|
|
if((read_buffer[button_location]&0xF0)==0xF0
|
|
|
|
&& (read_buffer[button_location+1]&0xF0)!=0xF0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(button_location==4)
|
|
|
|
button_location=0;
|
|
|
|
|
|
|
|
button_location++;
|
|
|
|
|
|
|
|
read_button |= read_buffer[button_location];
|
|
|
|
|
|
|
|
/* Find the hold status location */
|
|
|
|
if(button_location==4)
|
|
|
|
button_location=0;
|
|
|
|
else
|
|
|
|
button_location++;
|
|
|
|
|
|
|
|
remote_hold_button=((read_buffer[button_location]&0x80)?true:false);
|
|
|
|
|
|
|
|
uart1_clear_queue();
|
|
|
|
oldbutton=read_button;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
read_button=oldbutton;
|
|
|
|
|
|
|
|
return read_button;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-14 23:08:50 +00:00
|
|
|
/* Since this is a touchscreen, the expectation in higher levels is that the
|
|
|
|
* previous touch location is maintained when a release occurs. This is
|
|
|
|
* intended to mimic a mouse or other similar pointing device.
|
|
|
|
*/
|
2007-10-22 07:01:59 +00:00
|
|
|
int button_read_device(int *data)
|
2007-09-20 04:46:41 +00:00
|
|
|
{
|
2009-08-14 23:08:50 +00:00
|
|
|
static int old_data = 0;
|
2009-04-18 06:38:55 +00:00
|
|
|
int button_read = BUTTON_NONE;
|
2009-05-02 23:25:55 +00:00
|
|
|
short touch_x, touch_y, touch_z1, touch_z2;
|
2012-03-16 20:57:30 +00:00
|
|
|
#ifndef BOOTLOADER
|
2009-04-18 06:38:55 +00:00
|
|
|
static bool hold_button_old = false;
|
2012-03-16 20:57:30 +00:00
|
|
|
#endif
|
2009-08-02 07:05:30 +00:00
|
|
|
*data = old_data;
|
2007-11-10 22:12:54 +00:00
|
|
|
|
2009-04-17 03:56:06 +00:00
|
|
|
/* Handle touchscreen */
|
2009-05-02 23:25:55 +00:00
|
|
|
if (tsc2100_read_touch(&touch_x, &touch_y, &touch_z1, &touch_z2))
|
2007-10-22 07:01:59 +00:00
|
|
|
{
|
2009-08-02 07:05:30 +00:00
|
|
|
old_data = *data = touch_to_pixels(&touch_x, &touch_y);
|
2009-04-28 05:07:25 +00:00
|
|
|
button_read |= touchscreen_to_pixels(touch_x, touch_y, data);
|
2007-10-22 07:01:59 +00:00
|
|
|
}
|
2007-11-10 22:12:54 +00:00
|
|
|
|
2009-12-12 18:36:52 +00:00
|
|
|
tsc2100_set_mode(true, 0x02);
|
2009-05-02 23:25:55 +00:00
|
|
|
|
2009-04-17 03:56:06 +00:00
|
|
|
/* Handle power button */
|
2009-05-02 23:25:55 +00:00
|
|
|
if ((IO_GIO_BITSET0&0x01) == 0) {
|
2009-04-18 06:38:55 +00:00
|
|
|
button_read |= BUTTON_POWER;
|
2007-11-15 06:44:35 +00:00
|
|
|
}
|
2007-11-10 22:12:54 +00:00
|
|
|
|
2009-05-15 13:43:30 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD)
|
2009-04-18 06:38:55 +00:00
|
|
|
/* Read data from the remote */
|
2012-01-07 19:44:30 +00:00
|
|
|
button_read |= remote_read_buttons();
|
|
|
|
hold_button=remote_hold_button;
|
2009-05-15 13:43:30 +00:00
|
|
|
#endif
|
2009-04-18 06:38:55 +00:00
|
|
|
|
|
|
|
/* Take care of hold notifications */
|
2009-04-16 03:10:01 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
/* give BL notice if HB state chaged */
|
2009-05-02 23:25:55 +00:00
|
|
|
if (hold_button != hold_button_old) {
|
2009-04-16 03:10:01 +00:00
|
|
|
backlight_hold_changed(hold_button);
|
2009-04-18 06:38:55 +00:00
|
|
|
hold_button_old=hold_button;
|
2009-04-16 03:10:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (hold_button)
|
|
|
|
{
|
2009-04-18 06:38:55 +00:00
|
|
|
button_read = BUTTON_NONE;
|
2009-04-16 03:10:01 +00:00
|
|
|
}
|
2009-04-14 05:17:03 +00:00
|
|
|
|
2009-04-18 06:38:55 +00:00
|
|
|
return button_read;
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
2007-10-22 07:01:59 +00:00
|
|
|
|