diff options
author | James Buren <braewoods+rb@braewoods.net> | 2021-03-05 11:51:44 -0600 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2021-03-06 04:15:02 +0000 |
commit | f647cde3c72d05fd9ba1a179ae1638883997ed2f (patch) | |
tree | 73830ff1e9b918861541b0cb8ff84f7eb0c74c74 /firmware/powermgmt.c | |
parent | 9cf45374e07c6a56f598f47d1fd83eab0291047e (diff) |
usb_hid: add support for Battery Strength
This allows rockbox to report its battery status through the
HID Battery Strength method that is available through the
Device Controls usage page.
Change-Id: Ia7a7dd9b9d476dd9df5a5f5becabc5ae823e9a89
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r-- | firmware/powermgmt.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 6cac300cdf..969d6167da 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -48,6 +48,9 @@ #if (CONFIG_PLATFORM & PLATFORM_HOSTED) #include <time.h> #endif +#ifdef USB_ENABLE_HID +#include "usbstack/usb_hid.h" +#endif #if (defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(COWON_D2)) \ && !defined (SIMULATOR) @@ -637,6 +640,17 @@ static void collect_power_history(void) power_history[0] = power_hist_item(); } +#ifdef USB_ENABLE_HID +static bool battery_reporting = false; +static int battery_report_percent = -1; + +void set_battery_reporting(bool enable) +{ + battery_reporting = enable; + battery_report_percent = -1; +} +#endif + /* * Monitor the presence of a charger and perform critical frequent steps * such as running the battery voltage filter. @@ -750,6 +764,13 @@ static void power_thread(void) next_power_hist += HZ*60; collect_power_history(); } + +#ifdef USB_ENABLE_HID + if (battery_reporting && battery_report_percent != battery_percent) { + battery_report_percent = battery_percent; + usb_hid_send(HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS, battery_report_percent); + } +#endif } } /* power_thread */ |