Skip to content

Commit cc8325b

Browse files
committed
Don't wake the host from suspend on mouse movement
Only wake the host when we have a report with keys or buttons pressed. This matches real device behavior.
1 parent adf5ab9 commit cc8325b

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

firmware/src/main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ void __no_inline_not_in_flash_func(sof_handler)(uint32_t frame_count) {
7272
}
7373

7474
bool do_send_report(uint8_t interface, const uint8_t* report_with_id, uint8_t len) {
75-
if (tud_suspended()) {
75+
if (tud_suspended() &&
76+
(our_descriptor->should_cause_wakeup != nullptr) &&
77+
our_descriptor->should_cause_wakeup(report_with_id[0], report_with_id + 1, len - 1)) {
7678
tud_remote_wakeup();
7779
} else {
7880
tud_hid_n_report(interface, report_with_id[0], report_with_id + 1, len - 1);

firmware/src/our_descriptor.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ uint16_t kb_mouse_handle_get_report(uint8_t report_id, uint8_t* buffer, uint16_t
541541
return 0;
542542
}
543543

544+
bool kb_mouse_should_cause_wakeup(uint8_t report_id, const uint8_t* buffer, uint16_t len) {
545+
if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_CONSUMER)) {
546+
for (uint16_t i = 0; i < len; i++) {
547+
if (buffer[i] != 0) {
548+
return true;
549+
}
550+
}
551+
return false;
552+
}
553+
554+
if (report_id == REPORT_ID_MOUSE) {
555+
if ((len > 0) && (buffer[0] != 0)) {
556+
return true;
557+
}
558+
return false;
559+
}
560+
561+
return false;
562+
}
563+
544564
static const uint8_t horipad_neutral[] = { 0x00, 0x00, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x00 };
545565

546566
void horipad_clear_report(uint8_t* report, uint8_t report_id, uint16_t len) {
@@ -618,6 +638,7 @@ const our_descriptor_def_t our_descriptors[] = {
618638
.handle_get_report = kb_mouse_handle_get_report,
619639
.handle_set_report = kb_mouse_handle_set_report,
620640
.set_report_synchronous = kb_mouse_set_report_synchronous,
641+
.should_cause_wakeup = kb_mouse_should_cause_wakeup,
621642
},
622643
{
623644
.idx = 1,
@@ -627,6 +648,7 @@ const our_descriptor_def_t our_descriptors[] = {
627648
.handle_get_report = kb_mouse_handle_get_report,
628649
.handle_set_report = kb_mouse_handle_set_report,
629650
.set_report_synchronous = kb_mouse_set_report_synchronous,
651+
.should_cause_wakeup = kb_mouse_should_cause_wakeup,
630652
},
631653
{
632654
.idx = 2,

firmware/src/our_descriptor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef void (*handle_set_report_complete_t)(uint16_t interface, uint8_t report_
2727
typedef void (*clear_report_t)(uint8_t* report, uint8_t report_id, uint16_t len);
2828
typedef int32_t (*default_value_t)(uint32_t usage);
2929
typedef void (*sanitize_report_t)(uint8_t report_id, uint8_t* buffer, uint16_t len);
30+
typedef bool (*should_cause_wakeup_t)(uint8_t report_id, const uint8_t* buffer, uint16_t len);
3031

3132
struct our_descriptor_def_t {
3233
uint8_t idx;
@@ -46,6 +47,7 @@ struct our_descriptor_def_t {
4647
clear_report_t clear_report = nullptr;
4748
default_value_t default_value = nullptr;
4849
sanitize_report_t sanitize_report = nullptr;
50+
should_cause_wakeup_t should_cause_wakeup = nullptr;
4951
};
5052

5153
extern const our_descriptor_def_t our_descriptors[];

0 commit comments

Comments
 (0)