diff options
author | Franklin Wei <franklin@rockbox.org> | 2020-06-26 20:53:15 -0400 |
---|---|---|
committer | Franklin Wei <franklin@rockbox.org> | 2020-06-27 13:27:40 -0400 |
commit | a65a341a0036737f161bfdd30adeab25faed3134 (patch) | |
tree | ba255c7d2ce392ca451c83f78a69caa50ba8e8a7 | |
parent | f49442d7b739e13985e0d0054aa27865c0acff0c (diff) | |
download | rockbox-a65a341a0036737f161bfdd30adeab25faed3134.tar.gz rockbox-a65a341a0036737f161bfdd30adeab25faed3134.zip |
button: allow disabling software poweroff
On some devices, the button driver allows a "software poweroff" by long-
pressing a certain key. This behavior is inconvnient when that button needs
to be held down for other purposes, such as moving the cursor in rockpaint
or sgt-untangle.
This patch allows selectively disabling the software poweroff (enabled by
default) from both core and plugin code.
Change-Id: I7580752888ae5c7c7c5eb1be5966e3d67f17d4b4
-rw-r--r-- | apps/plugin.c | 4 | ||||
-rw-r--r-- | apps/plugin.h | 8 | ||||
-rw-r--r-- | apps/plugins/lib/helper.c | 15 | ||||
-rw-r--r-- | apps/plugins/lib/helper.h | 10 | ||||
-rw-r--r-- | firmware/drivers/button.c | 16 | ||||
-rw-r--r-- | firmware/export/button.h | 5 |
6 files changed, 55 insertions, 3 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 1506554790..7d40a8db4f 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -387,6 +387,10 @@ static const struct plugin_api rockbox_api = { | |||
387 | #ifdef HAS_BUTTON_HOLD | 387 | #ifdef HAS_BUTTON_HOLD |
388 | button_hold, | 388 | button_hold, |
389 | #endif | 389 | #endif |
390 | #ifdef HAVE_SW_POWEROFF | ||
391 | button_set_sw_poweroff_state, | ||
392 | button_get_sw_poweroff_state, | ||
393 | #endif | ||
390 | #ifdef HAVE_TOUCHSCREEN | 394 | #ifdef HAVE_TOUCHSCREEN |
391 | touchscreen_set_mode, | 395 | touchscreen_set_mode, |
392 | touchscreen_get_mode, | 396 | touchscreen_get_mode, |
diff --git a/apps/plugin.h b/apps/plugin.h index c737d7adeb..430c15a2a6 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -161,12 +161,12 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
161 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ | 161 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ |
162 | 162 | ||
163 | /* increase this every time the api struct changes */ | 163 | /* increase this every time the api struct changes */ |
164 | #define PLUGIN_API_VERSION 237 | 164 | #define PLUGIN_API_VERSION 238 |
165 | 165 | ||
166 | /* update this to latest version if a change to the api struct breaks | 166 | /* update this to latest version if a change to the api struct breaks |
167 | backwards compatibility (and please take the opportunity to sort in any | 167 | backwards compatibility (and please take the opportunity to sort in any |
168 | new function which are "waiting" at the end of the function table) */ | 168 | new function which are "waiting" at the end of the function table) */ |
169 | #define PLUGIN_MIN_API_VERSION 237 | 169 | #define PLUGIN_MIN_API_VERSION 238 |
170 | 170 | ||
171 | /* plugin return codes */ | 171 | /* plugin return codes */ |
172 | /* internal returns start at 0x100 to make exit(1..255) work */ | 172 | /* internal returns start at 0x100 to make exit(1..255) work */ |
@@ -435,6 +435,10 @@ struct plugin_api { | |||
435 | #ifdef HAS_BUTTON_HOLD | 435 | #ifdef HAS_BUTTON_HOLD |
436 | bool (*button_hold)(void); | 436 | bool (*button_hold)(void); |
437 | #endif | 437 | #endif |
438 | #ifdef HAVE_SW_POWEROFF | ||
439 | void (*button_set_sw_poweroff_state)(bool enable); | ||
440 | bool (*button_get_sw_poweroff_state)(void); | ||
441 | #endif | ||
438 | #ifdef HAVE_TOUCHSCREEN | 442 | #ifdef HAVE_TOUCHSCREEN |
439 | void (*touchscreen_set_mode)(enum touchscreen_mode); | 443 | void (*touchscreen_set_mode)(enum touchscreen_mode); |
440 | enum touchscreen_mode (*touchscreen_get_mode)(void); | 444 | enum touchscreen_mode (*touchscreen_get_mode)(void); |
diff --git a/apps/plugins/lib/helper.c b/apps/plugins/lib/helper.c index 5aa143a728..506903e808 100644 --- a/apps/plugins/lib/helper.c +++ b/apps/plugins/lib/helper.c | |||
@@ -66,6 +66,21 @@ void backlight_use_settings(void) | |||
66 | #endif /* CONFIG_CHARGING */ | 66 | #endif /* CONFIG_CHARGING */ |
67 | } | 67 | } |
68 | 68 | ||
69 | #ifdef HAVE_SW_POWEROFF | ||
70 | static bool original_sw_poweroff_state = true; | ||
71 | |||
72 | void sw_poweroff_disable(void) | ||
73 | { | ||
74 | original_sw_poweroff_state = rb->button_get_sw_poweroff_state(); | ||
75 | rb->button_set_sw_poweroff_state(false); | ||
76 | } | ||
77 | |||
78 | void sw_poweroff_restore(void) | ||
79 | { | ||
80 | rb->button_set_sw_poweroff_state(original_sw_poweroff_state); | ||
81 | } | ||
82 | #endif | ||
83 | |||
69 | #ifdef HAVE_REMOTE_LCD | 84 | #ifdef HAVE_REMOTE_LCD |
70 | /* Force the backlight on */ | 85 | /* Force the backlight on */ |
71 | void remote_backlight_force_on(void) | 86 | void remote_backlight_force_on(void) |
diff --git a/apps/plugins/lib/helper.h b/apps/plugins/lib/helper.h index 8086cb52d4..f2e9187a96 100644 --- a/apps/plugins/lib/helper.h +++ b/apps/plugins/lib/helper.h | |||
@@ -29,6 +29,16 @@ | |||
29 | void backlight_force_on(void); | 29 | void backlight_force_on(void); |
30 | void backlight_ignore_timeout(void); | 30 | void backlight_ignore_timeout(void); |
31 | void backlight_use_settings(void); | 31 | void backlight_use_settings(void); |
32 | |||
33 | #ifdef HAVE_SW_POWEROFF | ||
34 | /** | ||
35 | * Disable and restore software poweroff (i.e. holding PLAY on iPods). | ||
36 | * Only call _restore() if _disable() was called earlier! | ||
37 | */ | ||
38 | void sw_poweroff_disable(void); | ||
39 | void sw_poweroff_restore(void); | ||
40 | #endif | ||
41 | |||
32 | #ifdef HAVE_REMOTE_LCD | 42 | #ifdef HAVE_REMOTE_LCD |
33 | void remote_backlight_force_on(void); | 43 | void remote_backlight_force_on(void); |
34 | void remote_backlight_ignore_timeout(void); | 44 | void remote_backlight_ignore_timeout(void); |
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 9677580838..626afc415f 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -65,6 +65,9 @@ static bool phones_present = false; | |||
65 | #ifdef HAVE_LINEOUT_DETECTION | 65 | #ifdef HAVE_LINEOUT_DETECTION |
66 | static bool lineout_present = false; | 66 | static bool lineout_present = false; |
67 | #endif | 67 | #endif |
68 | #ifdef HAVE_SW_POWEROFF | ||
69 | static bool enable_sw_poweroff = true; | ||
70 | #endif | ||
68 | 71 | ||
69 | /* how long until repeat kicks in, in centiseconds */ | 72 | /* how long until repeat kicks in, in centiseconds */ |
70 | #define REPEAT_START (30*HZ/100) | 73 | #define REPEAT_START (30*HZ/100) |
@@ -280,7 +283,8 @@ static void button_tick(void) | |||
280 | which doesn't shut down easily with the OFF | 283 | which doesn't shut down easily with the OFF |
281 | key */ | 284 | key */ |
282 | #ifdef HAVE_SW_POWEROFF | 285 | #ifdef HAVE_SW_POWEROFF |
283 | if ((btn & POWEROFF_BUTTON | 286 | if (enable_sw_poweroff && |
287 | (btn & POWEROFF_BUTTON | ||
284 | #ifdef RC_POWEROFF_BUTTON | 288 | #ifdef RC_POWEROFF_BUTTON |
285 | || btn == RC_POWEROFF_BUTTON | 289 | || btn == RC_POWEROFF_BUTTON |
286 | #endif | 290 | #endif |
@@ -773,3 +777,13 @@ void button_enable_touch(bool en) | |||
773 | #endif | 777 | #endif |
774 | } | 778 | } |
775 | #endif | 779 | #endif |
780 | |||
781 | #ifdef HAVE_SW_POWEROFF | ||
782 | void button_set_sw_poweroff_state(bool en) { | ||
783 | enable_sw_poweroff = en; | ||
784 | } | ||
785 | |||
786 | bool button_get_sw_poweroff_state() { | ||
787 | return enable_sw_poweroff; | ||
788 | } | ||
789 | #endif | ||
diff --git a/firmware/export/button.h b/firmware/export/button.h index d9732ebe8b..36b615f216 100644 --- a/firmware/export/button.h +++ b/firmware/export/button.h | |||
@@ -130,4 +130,9 @@ int touchscreen_last_touch(void); | |||
130 | void button_enable_touch(bool en); | 130 | void button_enable_touch(bool en); |
131 | #endif | 131 | #endif |
132 | 132 | ||
133 | #ifdef HAVE_SW_POWEROFF | ||
134 | void button_set_sw_poweroff_state(bool en); | ||
135 | bool button_get_sw_poweroff_state(void); | ||
136 | #endif | ||
137 | |||
133 | #endif /* _BUTTON_H_ */ | 138 | #endif /* _BUTTON_H_ */ |