Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

James Buren and committed by
Solomon Peachy
f647cde3 9cf45374

+82 -1
+3
firmware/export/powermgmt.h
··· 166 166 void set_battery_capacity(int capacity); /* set local battery capacity value */ 167 167 int get_battery_capacity(void); /* get local battery capacity value */ 168 168 void set_battery_type(int type); /* set local battery type */ 169 + #ifdef USB_ENABLE_HID 170 + void set_battery_reporting(bool enable); 171 + #endif 169 172 170 173 void set_sleeptimer_duration(int minutes); 171 174 int get_sleep_timer(void);
+21
firmware/powermgmt.c
··· 48 48 #if (CONFIG_PLATFORM & PLATFORM_HOSTED) 49 49 #include <time.h> 50 50 #endif 51 + #ifdef USB_ENABLE_HID 52 + #include "usbstack/usb_hid.h" 53 + #endif 51 54 52 55 #if (defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(COWON_D2)) \ 53 56 && !defined (SIMULATOR) ··· 637 640 power_history[0] = power_hist_item(); 638 641 } 639 642 643 + #ifdef USB_ENABLE_HID 644 + static bool battery_reporting = false; 645 + static int battery_report_percent = -1; 646 + 647 + void set_battery_reporting(bool enable) 648 + { 649 + battery_reporting = enable; 650 + battery_report_percent = -1; 651 + } 652 + #endif 653 + 640 654 /* 641 655 * Monitor the presence of a charger and perform critical frequent steps 642 656 * such as running the battery voltage filter. ··· 750 764 next_power_hist += HZ*60; 751 765 collect_power_history(); 752 766 } 767 + 768 + #ifdef USB_ENABLE_HID 769 + if (battery_reporting && battery_report_percent != battery_percent) { 770 + battery_report_percent = battery_percent; 771 + usb_hid_send(HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS, battery_report_percent); 772 + } 773 + #endif 753 774 } 754 775 } /* power_thread */ 755 776
+31 -1
firmware/usbstack/usb_hid.c
··· 23 23 #include "usb_core.h" 24 24 #include "usb_drv.h" 25 25 #include "kernel.h" 26 + #include "powermgmt.h" 26 27 #include "usb_hid.h" 27 28 #include "usb_class_driver.h" 28 29 /*#define LOGF_ENABLE*/ ··· 109 110 #ifdef HAVE_USB_HID_MOUSE 110 111 REPORT_ID_MOUSE, 111 112 #endif 113 + REPORT_ID_BACKGROUND, 112 114 REPORT_ID_COUNT, 113 115 } report_id_t; 114 116 ··· 450 452 } 451 453 #endif /* HAVE_USB_HID_MOUSE */ 452 454 455 + #define BUF_LEN_BACKGROUND 1 456 + static uint8_t buf_set_background(unsigned char *buf, int id) 457 + { 458 + memset(buf, 0, BUF_LEN_BACKGROUND); 459 + buf[0] = (uint8_t)id; 460 + 461 + return BUF_LEN_BACKGROUND; 462 + } 463 + 453 464 static size_t descriptor_report_get(unsigned char *dest) 454 465 { 455 466 unsigned char *report = dest; ··· 551 562 PACK_VAL(report, END_COLLECTION); 552 563 #endif /* HAVE_USB_HID_MOUSE */ 553 564 565 + /* Background controls */ 566 + usb_hid_report = &usb_hid_reports[REPORT_ID_BACKGROUND]; 567 + usb_hid_report->usage_page = HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS; 568 + usb_hid_report->buf_set = buf_set_background; 569 + usb_hid_report->is_key_released = 0; 570 + 571 + pack_parameter(&report, 0, 1, USAGE_PAGE, HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS); 572 + pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DEVICE_BACKGROUND_CONTROLS); 573 + pack_parameter(&report, 0, 1, COLLECTION, COLLECTION_APPLICATION); 574 + pack_parameter(&report, 0, 1, REPORT_ID, REPORT_ID_BACKGROUND); 575 + pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DEVICE_BATTERY_STRENGTH); 576 + pack_parameter(&report, 0, 1, LOGICAL_MINIMUM, 0); 577 + pack_parameter(&report, 0, 1, LOGICAL_MAXIMUM, 100); 578 + pack_parameter(&report, 0, 1, REPORT_SIZE, 8); 579 + pack_parameter(&report, 0, 1, REPORT_COUNT, 1); 580 + pack_parameter(&report, 0, 1, INPUT, MAIN_ITEM_VARIABLE); 581 + PACK_VAL(report, END_COLLECTION); 582 + 554 583 return (size_t)(report - dest); 555 584 } 556 585 ··· 591 620 void usb_hid_init_connection(void) 592 621 { 593 622 logf("hid: init connection"); 594 - 595 623 active = true; 596 624 currently_sending = false; 625 + set_battery_reporting(true); 597 626 } 598 627 599 628 /* called by usb_core_init() */ ··· 614 643 void usb_hid_disconnect(void) 615 644 { 616 645 logf("hid: disconnect"); 646 + set_battery_reporting(false); 617 647 active = false; 618 648 currently_sending = false; 619 649 }
+27
firmware/usbstack/usb_hid_usage_tables.h
··· 120 120 #define HID_GENERIC_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY 0xB6 121 121 #define HID_GENERIC_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE 0xB7 122 122 123 + /* Generic Device Controls Page (0x06) */ 124 + #define HID_GENERIC_DEVICE_UNDEFINED 0x00 125 + #define HID_GENERIC_DEVICE_BACKGROUND_CONTROLS 0x01 126 + #define HID_GENERIC_DEVICE_BATTERY_STRENGTH 0x20 127 + #define HID_GENERIC_DEVICE_WIRELESS_CHANNEL 0x21 128 + #define HID_GENERIC_DEVICE_WIRELESS_ID 0x22 129 + #define HID_GENERIC_DEVICE_DISCOVER_WIRELESS_CHANNEL 0x23 130 + #define HID_GENERIC_DEVICE_SECURITY_CODE_CHARACTER_ENTERED 0x24 131 + #define HID_GENERIC_DEVICE_SECURITY_CODE_CHARACTER_ERASED 0x25 132 + #define HID_GENERIC_DEVICE_SECURITY_CODE_CLEARED 0x26 133 + #define HID_GENERIC_DEVICE_SEQUENCE_ID 0x27 134 + #define HID_GENERIC_DEVICE_SEQUENCE_ID_RESET 0x28 135 + #define HID_GENERIC_DEVICE_RF_SIGNAL_STRENGTH 0x29 136 + #define HID_GENERIC_DEVICE_SOFTWARE_VERSION 0x2A 137 + #define HID_GENERIC_DEVICE_PROTOCOL_VERSION 0x2B 138 + #define HID_GENERIC_DEVICE_HARDWARE_VERSION 0x2C 139 + #define HID_GENERIC_DEVICE_MAJOR 0x2D 140 + #define HID_GENERIC_DEVICE_MINOR 0x2E 141 + #define HID_GENERIC_DEVICE_REVISION 0x2F 142 + #define HID_GENERIC_DEVICE_HANDEDNESS 0x30 143 + #define HID_GENERIC_DEVICE_EITHER_HAND 0x31 144 + #define HID_GENERIC_DEVICE_LEFT_HAND 0x32 145 + #define HID_GENERIC_DEVICE_RIGHT_HAND 0x33 146 + #define HID_GENERIC_DEVICE_BOTH_HANDS 0x34 147 + #define HID_GENERIC_DEVICE_GRIP_POSE_OFFSET 0x40 148 + #define HID_GENERIC_DEVICE_POINTER_POSE_OFFSET 0x41 149 + 123 150 /* Keyboard/Keypad Page (0x07) */ 124 151 #define HID_KEYBOARD_RESERVED 0x00 125 152 #define HID_KEYBOARD_ERROR_ROLLOVER 0x01