diff --git a/apps/action.c b/apps/action.c index 2492a7d08e..25f559f7bd 100644 --- a/apps/action.c +++ b/apps/action.c @@ -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; } 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 diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index 6ad0b986f3..54ab6be76f 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c @@ -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