From df6eb82f5156256e1999374ce9b1a159610ff9a0 Mon Sep 17 00:00:00 2001 From: Jean-Louis Biasini Date: Mon, 2 Sep 2013 11:03:56 +0200 Subject: 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 Reviewed-by: Amaury Pouly --- firmware/SOURCES | 4 ++ firmware/drivers/button.c | 12 ++++++ firmware/drivers/touchpad.c | 43 ++++++++++++++++++++++ firmware/drivers/touchscreen.c | 16 ++++++++ firmware/export/button.h | 8 ++++ firmware/export/touchpad.h | 28 ++++++++++++++ firmware/export/touchscreen.h | 3 ++ .../arm/imx233/creative-zenxfi2/button-zenxfi2.c | 7 +++- .../arm/imx233/sansa-fuzeplus/button-fuzeplus.c | 5 ++- .../arm/imx233/sansa-fuzeplus/button-target.h | 6 ++- firmware/target/hosted/android/button-android.c | 5 +++ firmware/target/hosted/sdl/button-sdl.c | 6 ++- .../ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c | 7 ++++ 13 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 firmware/drivers/touchpad.c create mode 100644 firmware/export/touchpad.h (limited to 'firmware') diff --git a/firmware/SOURCES b/firmware/SOURCES index 5f1ae3d31c..0210abe2f7 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -1734,3 +1734,7 @@ thread.c #endif #endif /* defined(SIMULATOR) */ + +#if defined(HAVE_TOUCHPAD) +drivers/touchpad.c +#endif diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index c165e8f566..1cc95428ab 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -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 diff --git a/firmware/drivers/touchpad.c b/firmware/drivers/touchpad.c new file mode 100644 index 0000000000..1d78ee1c3e --- /dev/null +++ b/firmware/drivers/touchpad.c @@ -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 +#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; +} diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c index 823c2e7a92..8ce2400ca2 100644 --- a/firmware/drivers/touchscreen.c +++ b/firmware/drivers/touchscreen.c @@ -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 */ diff --git a/firmware/export/button.h b/firmware/export/button.h index 6276a033cc..7109c00f97 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h @@ -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_ */ diff --git a/firmware/export/touchpad.h b/firmware/export/touchpad.h new file mode 100644 index 0000000000..ad08469459 --- /dev/null +++ b/firmware/export/touchpad.h @@ -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_ */ diff --git a/firmware/export/touchscreen.h b/firmware/export/touchscreen.h index a27e60c653..7421fe0b33 100644 --- a/firmware/export/touchscreen.h +++ b/firmware/export/touchscreen.h @@ -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_ */ diff --git a/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c index 74b8d649b3..4f2a2775bf 100644 --- a/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c +++ b/firmware/target/arm/imx233/creative-zenxfi2/button-zenxfi2.c @@ -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; diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c index afabdd3bc3..05c4da8540 100644 --- a/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c +++ b/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c @@ -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()); } diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h b/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h index 1c94b76cdc..ce5ffe464a 100644 --- a/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h +++ b/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h @@ -24,7 +24,7 @@ #include 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 diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c index ee8b32d704..b4f3d1bd90 100644 --- a/firmware/target/hosted/android/button-android.c +++ b/firmware/target/hosted/android/button-android.c @@ -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; diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c index 4bd4b8de64..f69c0a509b 100644 --- a/firmware/target/hosted/sdl/button-sdl.c +++ b/firmware/target/hosted/sdl/button-sdl.c @@ -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 diff --git a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c index e6f0cd9cc3..d06cb28f40 100644 --- a/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c +++ b/firmware/target/mips/ingenic_jz47xx/onda_vx747/sadc-onda_vx747.c @@ -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 -- cgit v1.2.3