df6eb82f51
Target that have a touchpad/touchscreen should disable it while being locked (In order to avoid LCD to drain battery power due to "key locked" constant reporting messages. If they a have a keylock button this was already handled at driver level. If not (e.g. fuze+), they will have to implement a switch at driver level that action.c can operate on softlock. This patch does the following for any target having a touchpad or a touchscreen and no HAS_BUTTON_HOLD (ie any softlock target) 1) it implements the code to call button_enable_touch(bool en) in action.c. 2) button_enable_touch is implemented in button.c and call either touchpad_enable or touchscreen_enable 3) those two function are implemented respectively in touchscreen.c and a new touchpad.c file. They provide a generic way to silents touch's device and call a function at driver level where target specific code can be implemented if possible/needed (for power saving for instance). Those function name are touchpad_enable_device and touchscreen_enable_device 4) we implement an empty function at driver level of targets that need it to have them still being able to compiled. Change-Id: I9ead78a25bd33466a8533f5b9f259b395cb5ce49 Reviewed-on: http://gerrit.rockbox.org/569 Reviewed-by: Thomas Martitz <kugel@rockbox.org> Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
132 lines
3.5 KiB
C
132 lines
3.5 KiB
C
/***************************************************************************
|
|
* __________ __ ___.
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
* \/ \/ \/ \/ \/
|
|
* $Id$
|
|
*
|
|
* Copyright (C) 2011 by Amaury Pouly
|
|
*
|
|
* 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.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
****************************************************************************/
|
|
#include "button-target.h"
|
|
#include "system.h"
|
|
#include "system-target.h"
|
|
#include "pinctrl-imx233.h"
|
|
#include "power-imx233.h"
|
|
#include "string.h"
|
|
#include "usb.h"
|
|
#include "touchscreen.h"
|
|
#include "touchscreen-imx233.h"
|
|
|
|
struct touch_calibration_point
|
|
{
|
|
short px_x; /* known pixel value */
|
|
short px_y;
|
|
short val_x; /* touchscreen value at the known pixel */
|
|
short val_y;
|
|
};
|
|
|
|
static struct touch_calibration_point topleft, bottomright;
|
|
|
|
/* Amaury Pouly: values on my device
|
|
* Portait: (x and y are swapped)
|
|
* (0,0) = 200, 300
|
|
* (240,400) = 3900, 3800
|
|
* Landscape:
|
|
* (0,0) = 200, 3800
|
|
* (400,240) = 3900, 300
|
|
*/
|
|
void button_init_device(void)
|
|
{
|
|
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
|
|
topleft.val_x = 300;
|
|
topleft.val_y = 200;
|
|
|
|
bottomright.val_x = 3800;
|
|
bottomright.val_y = 3900;
|
|
#else
|
|
topleft.val_x = 300;
|
|
topleft.val_y = 3900;
|
|
|
|
bottomright.val_x = 3800;
|
|
bottomright.val_y = 200;
|
|
#endif
|
|
topleft.px_x = 0;
|
|
topleft.px_y = 0;
|
|
|
|
bottomright.px_x = LCD_WIDTH;
|
|
bottomright.px_y = LCD_HEIGHT;
|
|
|
|
imx233_touchscreen_init();
|
|
imx233_touchscreen_enable(true);
|
|
|
|
/* power button */
|
|
imx233_pinctrl_acquire(0, 11, "power");
|
|
imx233_pinctrl_set_function(0, 11, PINCTRL_FUNCTION_GPIO);
|
|
imx233_pinctrl_enable_gpio(0, 11, false);
|
|
/* select button */
|
|
imx233_pinctrl_acquire(0, 14, "select");
|
|
imx233_pinctrl_set_function(0, 14, PINCTRL_FUNCTION_GPIO);
|
|
imx233_pinctrl_enable_gpio(0, 14, false);
|
|
}
|
|
|
|
static int touch_to_pixels(int *val_x, int *val_y)
|
|
{
|
|
short x,y;
|
|
|
|
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
|
|
x = *val_y;
|
|
y = *val_x;
|
|
#else
|
|
x = *val_x;
|
|
y = *val_y;
|
|
#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;
|
|
|
|
x = MAX(0, MIN(x, LCD_WIDTH - 1));
|
|
y = MAX(0, MIN(y, LCD_HEIGHT - 1));
|
|
|
|
*val_x = x;
|
|
*val_y = y;
|
|
|
|
return (x<<16)|y;
|
|
}
|
|
|
|
void touchscreen_enable_device(bool en)
|
|
{
|
|
imx233_touchscreen_enable(en);
|
|
}
|
|
|
|
static int touchscreen_read_device(int *data)
|
|
{
|
|
int x, y;
|
|
if(!imx233_touchscreen_get_touch(&x, &y))
|
|
return 0;
|
|
if(data)
|
|
*data = touch_to_pixels(&x, &y);
|
|
return touchscreen_to_pixels(x, y, data);
|
|
}
|
|
|
|
int button_read_device(int *data)
|
|
{
|
|
int res = 0;
|
|
/* B0P11: #power
|
|
* B0P14: #select */
|
|
if(!imx233_pinctrl_get_gpio(0, 11))
|
|
res |= BUTTON_POWER;
|
|
if(!imx233_pinctrl_get_gpio(0, 14))
|
|
res |= BUTTON_MENU;
|
|
return res | touchscreen_read_device(data);
|
|
}
|