From 1f5ebf7c8b1cf1724524b02900c230961f039370 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Mon, 6 Mar 2017 18:37:00 +0100 Subject: libpayload: Export usbhid_getmodifiers Add a new method to retrieve active usb keyboard modifiers. Change-Id: Ief6679ce782b58b9ced207f4f27504fb2a517b76 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/18602 Reviewed-by: Martin Roth Tested-by: build bot (Jenkins) --- payloads/libpayload/drivers/usb/usbhid.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'payloads/libpayload/drivers') diff --git a/payloads/libpayload/drivers/usb/usbhid.c b/payloads/libpayload/drivers/usb/usbhid.c index 68130f80b0..67aebb2ffd 100644 --- a/payloads/libpayload/drivers/usb/usbhid.c +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -87,6 +87,7 @@ usb_hid_destroy (usbdev_t *dev) static int keycount; #define KEYBOARD_BUFFER_SIZE 16 static short keybuffer[KEYBOARD_BUFFER_SIZE]; +static int modifiers; const char *countries[36][2] = { { "not supported", "us" }, @@ -244,9 +245,6 @@ static const struct layout_maps keyboard_layouts[] = { //#endif }; -#define MOD_SHIFT (1 << 0) -#define MOD_ALT (1 << 1) -#define MOD_CTRL (1 << 2) static void usb_hid_keyboard_queue(int ch) { /* ignore key presses if buffer full */ @@ -264,15 +262,17 @@ usb_hid_process_keyboard_event(usbhid_inst_t *const inst, { const usb_hid_keyboard_event_t *const previous = &inst->previous; - int i, keypress = 0, modifiers = 0; + int i, keypress = 0; - if (current->modifiers & 0x01) /* Left-Ctrl */ modifiers |= MOD_CTRL; - if (current->modifiers & 0x02) /* Left-Shift */ modifiers |= MOD_SHIFT; - if (current->modifiers & 0x04) /* Left-Alt */ modifiers |= MOD_ALT; + modifiers = 0; + + if (current->modifiers & 0x01) /* Left-Ctrl */ modifiers |= KB_MOD_CTRL; + if (current->modifiers & 0x02) /* Left-Shift */ modifiers |= KB_MOD_SHIFT; + if (current->modifiers & 0x04) /* Left-Alt */ modifiers |= KB_MOD_ALT; if (current->modifiers & 0x08) /* Left-GUI */ ; - if (current->modifiers & 0x10) /* Right-Ctrl */ modifiers |= MOD_CTRL; - if (current->modifiers & 0x20) /* Right-Shift */ modifiers |= MOD_SHIFT; - if (current->modifiers & 0x40) /* Right-AltGr */ modifiers |= MOD_ALT; + if (current->modifiers & 0x10) /* Right-Ctrl */ modifiers |= KB_MOD_CTRL; + if (current->modifiers & 0x20) /* Right-Shift */ modifiers |= KB_MOD_SHIFT; + if (current->modifiers & 0x40) /* Right-AltGr */ modifiers |= KB_MOD_ALT; if (current->modifiers & 0x80) /* Right-GUI */ ; if ((current->modifiers & 0x05) && ((current->keys[0] == 0x4c) || @@ -315,10 +315,10 @@ usb_hid_process_keyboard_event(usbhid_inst_t *const inst, continue; - /* Mask off MOD_CTRL */ + /* Mask off KB_MOD_CTRL */ keypress = map->map[modifiers & 0x03][current->keys[i]]; - if (modifiers & MOD_CTRL) { + if (modifiers & KB_MOD_CTRL) { switch (keypress) { case 'a' ... 'z': keypress &= 0x1f; @@ -509,3 +509,8 @@ int usbhid_getchar (void) return (int)ret; } + +int usbhid_getmodifiers(void) +{ + return modifiers; +} -- cgit v1.2.3