touch devices: Disable touch on softlock.

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>
This commit is contained in:
Jean-Louis Biasini 2013-09-02 11:03:56 +02:00 committed by Amaury Pouly
parent ef2dd06d5e
commit df6eb82f51
15 changed files with 174 additions and 6 deletions

View File

@ -294,6 +294,10 @@ static int get_action_worker(int context, int timeout,
{
last_button = BUTTON_NONE;
keys_locked = false;
#if defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN)
/* enable back touch device */
button_enable_touch(true);
#endif
splash(HZ/2, str(LANG_KEYLOCK_OFF));
return ACTION_REDRAW;
}
@ -307,6 +311,13 @@ static int get_action_worker(int context, int timeout,
return ACTION_REDRAW;
}
}
#if defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN)
else
{
/* make sure touchpad get reactivated if we quit the screen */
button_enable_touch(true);
}
#endif
context &= ~ALLOW_SOFTLOCK;
#endif /* HAS_BUTTON_HOLD */
@ -373,7 +384,10 @@ static int get_action_worker(int context, int timeout,
unlock_combo = button;
keys_locked = true;
splash(HZ/2, str(LANG_KEYLOCK_ON));
#if defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN)
/* disable touch device on keylock */
button_enable_touch(false);
#endif
button_clear_queue();
return ACTION_REDRAW;
}

View File

@ -1734,3 +1734,7 @@ thread.c
#endif
#endif /* defined(SIMULATOR) */
#if defined(HAVE_TOUCHPAD)
drivers/touchpad.c
#endif

View File

@ -672,3 +672,15 @@ int button_apply_acceleration(const unsigned int data)
return delta;
}
#endif /* HAVE_WHEEL_ACCELERATION */
#if (defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN)) && !defined(HAS_BUTTON_HOLD)
void button_enable_touch(bool en)
{
#ifdef HAVE_TOUCHPAD
touchpad_enable(en);
#endif
#ifdef HAVE_TOUCHSCREEN
touchscreen_enable(en);
#endif
}
#endif

View File

@ -0,0 +1,43 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2013 by Jean-Louis Biasini
*
* 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 <stdbool.h>
#include "button.h"
#include "touchpad.h"
#include "button-target.h"
static bool touch_enabled = true;
void touchpad_enable(bool en)
{
if(en != touch_enabled)
{
touch_enabled = en;
touchpad_enable_device(en);
}
}
int touchpad_filter(int button)
{
if(!touch_enabled)
button &= ~BUTTON_TOUCHPAD;
return button;
}

View File

@ -31,6 +31,7 @@
#define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03)
#define BUTTON_MARGIN_Y (int)(LCD_HEIGHT * 0.03)
static bool touch_enabled = true;
static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT;
static const int touchscreen_buttons[3][3] =
{
@ -121,6 +122,8 @@ static void map_pixels(int *x, int *y)
/* TODO: add jitter (and others) filter */
int touchscreen_to_pixels(int x, int y, int *data)
{
if(!touch_enabled)
return 0;
x &= 0xFFFF;
y &= 0xFFFF;
@ -169,6 +172,19 @@ enum touchscreen_mode touchscreen_get_mode(void)
return current_mode;
}
void touchscreen_enable(bool en)
{
if(en != touch_enabled)
{
touch_enabled = en;
touchscreen_enable_device(en);
}
}
bool touchscreen_is_enabled(void)
{
return touch_enabled;
}
#if ((CONFIG_PLATFORM & PLATFORM_ANDROID) == 0)
/* android has an API for this */

View File

@ -119,4 +119,12 @@ int touchscreen_last_touch(void);
#include "touchscreen.h"
#endif
#ifdef HAVE_TOUCHPAD
#include "touchpad.h"
#endif
#if (defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN)) && !defined(HAS_BUTTON_HOLD)
void button_enable_touch(bool en);
#endif
#endif /* _BUTTON_H_ */

View File

@ -0,0 +1,28 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2013 by Jean-Louis Biasini
*
* 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.
*
****************************************************************************/
#ifndef _TOUCHDEV_H_
#define _TOUCHDEV_H_
void touchpad_enable(bool en);
int touchpad_filter(int button);
#endif /* _TOUCHDEV_H_ */

View File

@ -51,5 +51,8 @@ enum touchscreen_mode touchscreen_get_mode(void);
void touchscreen_disable_mapping(void);
void touchscreen_reset_mapping(void);
int touchscreen_get_scroll_threshold(void);
void touchscreen_enable(bool en);
void touchscreen_enable_device(bool en);
bool touchscreen_is_enabled(void);
#endif /* __TOUCHSCREEN_INCLUDE_H_ */

View File

@ -66,7 +66,7 @@ void button_init_device(void)
bottomright.px_x = LCD_WIDTH;
bottomright.px_y = LCD_HEIGHT;
imx233_touchscreen_init();
imx233_touchscreen_enable(true);
@ -104,6 +104,11 @@ static int touch_to_pixels(int *val_x, int *val_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;

View File

@ -28,6 +28,7 @@
#include "string.h"
#include "usb.h"
#include "power-imx233.h"
#include "touchpad.h"
#ifndef BOOTLOADER
@ -274,7 +275,7 @@ static void do_interrupt(void)
imx233_pinctrl_setup_irq(0, 27, true, true, false, &rmi_attn_cb, 0);
}
void touchdev_enable(bool en)
void touchpad_enable_device(bool en)
{
t_enable = en;
queue_post(&rmi_queue, RMI_SET_SLEEP_MODE, en ? RMI_SLEEP_MODE_LOW_POWER : RMI_SLEEP_MODE_SENSOR_SLEEP);
@ -433,5 +434,5 @@ int button_read_device(void)
default:
break;
}
return res | touchpad_read_device();
return res | touchpad_filter(touchpad_read_device());
}

View File

@ -24,7 +24,7 @@
#include <stdbool.h>
bool button_debug_screen(void);
void touchpad_set_sensitivity(int level);
void touchdev_enable(bool en);
void touchpad_enable_device(bool en);
/* Main unit's buttons */
#define BUTTON_POWER 0x00000001
@ -47,6 +47,10 @@ void touchdev_enable(bool en);
BUTTON_PLAYPAUSE|BUTTON_BACK| \
BUTTON_BOTTOMRIGHT|BUTTON_BOTTOMLEFT)
#define BUTTON_TOUCHPAD (BUTTON_LEFT|BUTTON_UP|BUTTON_RIGHT|BUTTON_DOWN| \
BUTTON_SELECT|BUTTON_PLAYPAUSE|BUTTON_BACK| \
BUTTON_BOTTOMRIGHT|BUTTON_BOTTOMLEFT)
/* Software power-off */
#define POWEROFF_BUTTON BUTTON_POWER
#define POWEROFF_COUNT 10

View File

@ -129,6 +129,11 @@ void button_init_device(void)
set_rockbox_ready();
}
void touchscreen_enable_device(bool en)
{
(void)en; /* FIXME: do something smart */
}
int button_read_device(int *data)
{
int btn = last_btns;

View File

@ -393,10 +393,14 @@ static void button_event(int key, bool pressed)
#endif
default:
#ifdef HAVE_TOUCHSCREEN
new_btn = key_to_touch(key, mouse_coords);
if(touchscreen_is_enabled())
new_btn = key_to_touch(key, mouse_coords);
if (!new_btn)
#endif
new_btn = key_to_button(key);
#ifdef HAVE_TOUCHPAD
new_btn = touchpad_filter(new_btn);
#endif
break;
}
/* Call to make up for scrollwheel target implementation. This is

View File

@ -300,3 +300,10 @@ void adc_close(void)
sleep(20);
__cpm_stop_sadc();
}
#ifndef HAS_BUTTON_HOLD
void touchscreen_enable_device(bool en)
{
(void)en; /* FIXME: do something smart */
}
#endif

View File

@ -381,3 +381,17 @@ void touchpad_set_sensitivity(int level)
(void)level;
}
#endif
#if defined(HAVE_TOUCHSCREEN) && !defined HAS_BUTTON_HOLD
void touchscreen_enable_device(bool en)
{
(void)en;
}
#endif
#if defined(HAVE_TOUCHPAD) && !defined HAS_BUTTON_HOLD
void touchpad_enable_device(bool en)
{
(void)en;
}
#endif