Clarify usb_powered() and fix some code.
Either by mistake or because its meaning changed, usb_powered() doesn't mean
what the name suggest, so clarify its meaning by renaming it to usb_powered_only.
So use of usb_powered() are replaced by usb_inserted() when it makes more sense.
Change-Id: I112887e2d8560e84587bee5f55c826dde8c806d8
Reviewed-on: http://gerrit.rockbox.org/1097
Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index e58393e..934085c 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -1149,12 +1149,10 @@
}
}
#endif
-#ifdef HAVE_USB_POWER
- case SKIN_TOKEN_USB_POWERED:
- if (usb_powered())
+ case SKIN_TOKEN_USB_INSERTED:
+ if (usb_inserted())
return "u";
return NULL;
-#endif
case SKIN_TOKEN_BATTERY_SLEEPTIME:
{
if (get_sleep_timer() == 0)
diff --git a/apps/main.c b/apps/main.c
index 6016451..211f7f1 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -586,7 +586,8 @@
mounted = true; /* mounting done @ end of USB mode */
}
#ifdef HAVE_USB_POWER
- if (usb_powered()) /* avoid deadlock */
+ /* if there is no host or user requested no USB, skip this */
+ if (usb_powered_only())
break;
#endif
}
diff --git a/apps/plugin.c b/apps/plugin.c
index 8a6c577..c6b9744 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -712,9 +712,7 @@
charging_state,
# endif
#endif
-#ifdef HAVE_USB_POWER
- usb_powered,
-#endif
+ usb_inserted,
/* misc */
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
diff --git a/apps/plugin.h b/apps/plugin.h
index e55dcf1..f781f60 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -160,12 +160,12 @@
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 232
+#define PLUGIN_API_VERSION 233
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 232
+#define PLUGIN_MIN_API_VERSION 233
/* plugin return codes */
/* internal returns start at 0x100 to make exit(1..255) work */
@@ -823,9 +823,8 @@
bool (*charging_state)(void);
# endif
#endif
-#ifdef HAVE_USB_POWER
- bool (*usb_powered)(void);
-#endif
+ /* usb */
+ bool (*usb_inserted)(void);
/* misc */
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c
index b0976d5..289b399 100644
--- a/apps/plugins/battery_bench.c
+++ b/apps/plugins/battery_bench.c
@@ -358,11 +358,12 @@
ret |= BIT_CHARGING;
#endif
#endif
+ /* USB insertion means nothing if USB cannot power the device */
#ifdef HAVE_USB_POWER
- if (rb->usb_powered())
+ if (rb->usb_inserted())
ret |= BIT_USB_POWER;
#endif
- return ret;
+ return ret;
}
#endif
diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index 62bcffe..74c4826 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -199,7 +199,8 @@
void usb_status_event(int current_status);
#endif
#ifdef HAVE_USB_POWER
-bool usb_powered(void);
+/* returns whether the USB is in powered-only state */
+bool usb_powered_only(void);
#ifdef HAVE_USB_CHARGING_ENABLE
enum {
USB_CHARGING_DISABLE, /* the USB code will never ask for more than 100mA */
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index a4b260b..61cf1b3 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -329,9 +329,9 @@
if (usb_inserted()
#ifdef HAVE_USB_POWER
#if (CURRENT_USB < CURRENT_NORMAL)
- || usb_powered()
+ || usb_powered_only()
#else
- && !usb_powered()
+ && !usb_powered_only()
#endif
#endif
) {
diff --git a/firmware/usb.c b/firmware/usb.c
index fc89df7..a736f31 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -769,7 +769,7 @@
}
#ifdef HAVE_USB_POWER
-bool usb_powered(void)
+bool usb_powered_only(void)
{
return usb_state == USB_POWERED;
}
diff --git a/lib/skin_parser/tag_table.c b/lib/skin_parser/tag_table.c
index 2cea048..d2aded1 100644
--- a/lib/skin_parser/tag_table.c
+++ b/lib/skin_parser/tag_table.c
@@ -43,7 +43,7 @@
{ SKIN_TOKEN_BATTERY_SLEEPTIME, "bs", "", SKIN_REFRESH_DYNAMIC },
{ SKIN_TOKEN_BATTERY_CHARGING, "bc", "", SKIN_REFRESH_DYNAMIC },
{ SKIN_TOKEN_BATTERY_CHARGER_CONNECTED, "bp", "", SKIN_REFRESH_DYNAMIC },
- { SKIN_TOKEN_USB_POWERED, "bu", "", SKIN_REFRESH_DYNAMIC },
+ { SKIN_TOKEN_USB_INSERTED, "bu", "", SKIN_REFRESH_DYNAMIC },
{ SKIN_TOKEN_RTC_PRESENT, "cc", "", FEATURE_TAG },
diff --git a/lib/skin_parser/tag_table.h b/lib/skin_parser/tag_table.h
index 94f82fd..dc0c11f 100644
--- a/lib/skin_parser/tag_table.h
+++ b/lib/skin_parser/tag_table.h
@@ -102,7 +102,7 @@
SKIN_TOKEN_BATTERY_CHARGER_CONNECTED,
SKIN_TOKEN_BATTERY_CHARGING,
SKIN_TOKEN_BATTERY_SLEEPTIME,
- SKIN_TOKEN_USB_POWERED,
+ SKIN_TOKEN_USB_INSERTED,
/* Sound */
SKIN_TOKEN_SOUND_PITCH,
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index 922b9e8..b540735 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -313,7 +313,7 @@
#endif
#ifdef HAVE_USB_POWER
-bool usb_powered(void)
+bool usb_powered_only(void)
{
return false;
}