USB: Remove unused HID data

This commit is contained in:
Florin9doi 2024-07-27 11:38:02 +03:00 committed by lightningterror
parent 3a55653c3e
commit 15dfc0496e
3 changed files with 12 additions and 55 deletions

View File

@ -302,42 +302,11 @@ static const uint8_t hid_usage_keys[0x100] = {
bool hid_has_events(HIDState* hs) bool hid_has_events(HIDState* hs)
{ {
return hs->n > 0 || hs->idle_pending; return hs->n > 0;
}
#if 0
// Unused
static void hid_idle_timer(void* opaque)
{
HIDState* hs = (HIDState*)opaque;
hs->idle_pending = true;
hs->event(hs);
}
#endif
static void hid_del_idle_timer(HIDState* hs)
{
/*if (hs->idle_timer) {
timer_del(hs->idle_timer);
timer_free(hs->idle_timer);
hs->idle_timer = NULL;
}*/
} }
void hid_set_next_idle(HIDState* hs) void hid_set_next_idle(HIDState* hs)
{ {
/*if (hs->idle) {
uint64_t expire_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
NANOSECONDS_PER_SECOND * hs->idle * 4 / 1000;
if (!hs->idle_timer) {
hs->idle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, hid_idle_timer, hs);
}
timer_mod_ns(hs->idle_timer, expire_time);
}
else {
hid_del_idle_timer(hs);
}*/
} }
static void hid_pointer_event(HIDState* hs, InputEvent* evt) static void hid_pointer_event(HIDState* hs, InputEvent* evt)
@ -532,10 +501,10 @@ static void hid_keyboard_process_keycode(HIDState* hs)
if (hs->kbd.modifiers & (1 << 9)) if (hs->kbd.modifiers & (1 << 9))
{ {
/* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0. /* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0.
* Here we're processing the second hid_code. By dropping bit 9 * Here we're processing the second hid_code. By dropping bit 9
* and setting bit 8, the scancode after 0x1d will access the * and setting bit 8, the scancode after 0x1d will access the
* second half of the table. * second half of the table.
*/ */
hs->kbd.modifiers ^= (1 << 8) | (1 << 9); hs->kbd.modifiers ^= (1 << 8) | (1 << 9);
return; return;
} }
@ -550,8 +519,8 @@ static void hid_keyboard_process_keycode(HIDState* hs)
case 0xe6: case 0xe6:
case 0xe7: case 0xe7:
/* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R. /* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R.
* Handle releases here, or fall through to process presses. * Handle releases here, or fall through to process presses.
*/ */
if (keycode & (1 << 7)) if (keycode & (1 << 7))
{ {
hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f)); hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f));
@ -561,11 +530,11 @@ static void hid_keyboard_process_keycode(HIDState* hs)
case 0xe8: case 0xe8:
case 0xe9: case 0xe9:
/* USB modifiers are just 1 byte long. Bits 8 and 9 of /* USB modifiers are just 1 byte long. Bits 8 and 9 of
* hs->kbd.modifiers implement a state machine that detects the * hs->kbd.modifiers implement a state machine that detects the
* 0xe0 and 0xe1/0x1d sequences. These bits do not follow the * 0xe0 and 0xe1/0x1d sequences. These bits do not follow the
* usual rules where bit 7 marks released keys; they are cleared * usual rules where bit 7 marks released keys; they are cleared
* elsewhere in the function as the state machine dictates. * elsewhere in the function as the state machine dictates.
*/ */
hs->kbd.modifiers |= 1 << (hid_code & 0x0f); hs->kbd.modifiers |= 1 << (hid_code & 0x0f);
return; return;
@ -641,7 +610,6 @@ void hid_pointer_activate(HIDState* hs)
{ {
if (!hs->ptr.mouse_grabbed) if (!hs->ptr.mouse_grabbed)
{ {
//qemu_input_handler_activate(hs->s);
hs->ptr.mouse_grabbed = 1; hs->ptr.mouse_grabbed = 1;
} }
} }
@ -652,8 +620,6 @@ int hid_pointer_poll(HIDState* hs, uint8_t* buf, int len)
int index; int index;
HIDPointerEvent* e; HIDPointerEvent* e;
hs->idle_pending = false;
hid_pointer_activate(hs); hid_pointer_activate(hs);
/* When the buffer is empty, return the last event. Relative /* When the buffer is empty, return the last event. Relative
@ -745,8 +711,6 @@ int hid_pointer_poll(HIDState* hs, uint8_t* buf, int len)
int hid_keyboard_poll(HIDState* hs, uint8_t* buf, int len) int hid_keyboard_poll(HIDState* hs, uint8_t* buf, int len)
{ {
hs->idle_pending = false;
if (len < 2) if (len < 2)
{ {
return 0; return 0;
@ -817,14 +781,10 @@ void hid_reset(HIDState* hs)
hs->n = 0; hs->n = 0;
hs->protocol = 1; hs->protocol = 1;
hs->idle = 0; hs->idle = 0;
hs->idle_pending = false;
hid_del_idle_timer(hs);
} }
void hid_free(HIDState* hs) void hid_free(HIDState* hs)
{ {
//qemu_input_handler_unregister(hs->s);
hid_del_idle_timer(hs);
} }
void hid_init(HIDState* hs, int kind, HIDEventFunc event) void hid_init(HIDState* hs, int kind, HIDEventFunc event)

View File

@ -312,7 +312,6 @@ struct HIDState
int kind; int kind;
int32_t protocol; int32_t protocol;
uint8_t idle; uint8_t idle;
bool idle_pending;
HIDEventFunc event; HIDEventFunc event;
}; };

View File

@ -851,7 +851,6 @@ namespace usb_hid
sw.Do(&s->hid.n); sw.Do(&s->hid.n);
sw.Do(&s->hid.protocol); sw.Do(&s->hid.protocol);
sw.Do(&s->hid.idle); sw.Do(&s->hid.idle);
sw.Do(&s->hid.idle_pending);
return !sw.HasError(); return !sw.HasError();
} }
@ -914,7 +913,6 @@ namespace usb_hid
sw.Do(&s->hid.n); sw.Do(&s->hid.n);
sw.Do(&s->hid.protocol); sw.Do(&s->hid.protocol);
sw.Do(&s->hid.idle); sw.Do(&s->hid.idle);
sw.Do(&s->hid.idle_pending);
return !sw.HasError(); return !sw.HasError();
} }