diff options
Diffstat (limited to 'board/cr50/board.c')
-rw-r--r-- | board/cr50/board.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c index 92a6808c11..3b7e1613d9 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -5,10 +5,13 @@ #include "common.h" #include "console.h" +#include "ec_version.h" #include "gpio.h" #include "hooks.h" #include "registers.h" #include "task.h" +#include "usb.h" +#include "usb_hid.h" #include "util.h" /* @@ -21,6 +24,26 @@ #include "gpio_list.h" +static void send_hid_event(void) +{ + uint64_t rpt = 0; + uint8_t *key_ptr = (void *)&rpt + 2; + /* Convert SW_N/SW_S/SW_W/SW_E to A,B,C,D keys */ + if (gpio_get_level(GPIO_SW_N)) + *key_ptr++ = 0x04; /* A keycode */ + if (gpio_get_level(GPIO_SW_S)) + *key_ptr++ = 0x05; /* B keycode */ + if (gpio_get_level(GPIO_SW_W)) + *key_ptr++ = 0x06; /* C keycode */ + if (gpio_get_level(GPIO_SW_E)) + *key_ptr++ = 0x07; /* D keycode */ + /* send the keyboard state over USB HID */ + set_keyboard_report(rpt); + /* check release in the future */ + hook_call_deferred(send_hid_event, 40); +} +DECLARE_DEFERRED(send_hid_event); + /* Interrupt handler for button pushes */ void button_event(enum gpio_signal signal) { @@ -32,6 +55,7 @@ void button_event(enum gpio_signal signal) signal -= (GPIO_SW_N_ - GPIO_SW_N); v = gpio_get_level(signal); + send_hid_event(); ccprintf("Button %d = %d\n", signal, v); gpio_set_level(signal - GPIO_SW_N + GPIO_LED_4, v); } @@ -49,3 +73,12 @@ static void board_init(void) gpio_enable_interrupt(GPIO_SW_E_); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + +const void * const usb_strings[] = { + [USB_STR_DESC] = usb_string_desc, + [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."), + [USB_STR_PRODUCT] = USB_STRING_DESC("Cr50"), + [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32), + [USB_STR_CONSOLE_NAME] = USB_STRING_DESC("Shell"), +}; +BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT); |