Move HID ids to common HID code

The HID ids (accessory ids or UHID ids) were defined by the keyboard and
mouse implementations.

Instead, define them in the common HID part, and make that id part of
the sc_hid_event.

This prepares the introduction of gamepad support, which will handle
several gamepads (and ids) in the common HID gamepad code.

PR #5270 <https://github.com/Genymobile/scrcpy/pull/5270>
This commit is contained in:
Romain Vimont 2024-09-06 23:08:08 +02:00
parent dad04bf138
commit 2dd02ebb80
11 changed files with 30 additions and 42 deletions

View file

@ -8,6 +8,7 @@
#define SC_HID_MAX_SIZE 8
struct sc_hid_event {
uint16_t hid_id;
uint8_t data[SC_HID_MAX_SIZE];
uint8_t size;
};

View file

@ -200,6 +200,7 @@ const size_t SC_HID_KEYBOARD_REPORT_DESC_LEN =
static void
sc_hid_keyboard_event_init(struct sc_hid_event *hid_event) {
hid_event->hid_id = SC_HID_ID_KEYBOARD;
hid_event->size = SC_HID_KEYBOARD_EVENT_SIZE;
uint8_t *data = hid_event->data;

View file

@ -14,6 +14,8 @@
// 0x65 is Application, typically AT-101 Keyboard ends here.
#define SC_HID_KEYBOARD_KEYS 0x66
#define SC_HID_ID_KEYBOARD 1
extern const uint8_t SC_HID_KEYBOARD_REPORT_DESC[];
extern const size_t SC_HID_KEYBOARD_REPORT_DESC_LEN;

View file

@ -126,6 +126,7 @@ const size_t SC_HID_MOUSE_REPORT_DESC_LEN =
static void
sc_hid_mouse_event_init(struct sc_hid_event *hid_event) {
hid_event->hid_id = SC_HID_ID_MOUSE;
hid_event->size = SC_HID_MOUSE_EVENT_SIZE;
// Leave hid_event->data uninitialized, it will be fully initialized by
// callers

View file

@ -8,6 +8,8 @@
#include "hid/hid_event.h"
#include "input_events.h"
#define SC_HID_ID_MOUSE 2
extern const uint8_t SC_HID_MOUSE_REPORT_DESC[];
extern const size_t SC_HID_MOUSE_REPORT_DESC_LEN;