1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <zircon/compiler.h>
8 #include <stdbool.h>
9 #include <stdint.h>
10 
11 __BEGIN_CDECLS
12 
13 typedef struct {
14     uint32_t keymask[8];
15 } hid_keys_t;
16 
17 typedef struct keychar {
18     uint8_t c;
19     uint8_t shift_c;
20 } keychar_t;
21 
22 #define KEYMAP_SIZE 0x64
23 extern const keychar_t qwerty_map[KEYMAP_SIZE];
24 extern const keychar_t dvorak_map[KEYMAP_SIZE];
25 
26 void hid_kbd_parse_report(uint8_t buf[8], hid_keys_t* keys);
27 void hid_kbd_pressed_keys(const hid_keys_t* prev, const hid_keys_t* cur, hid_keys_t* pressed);
28 void hid_kbd_released_keys(const hid_keys_t* prev, const hid_keys_t* cur, hid_keys_t* released);
29 uint8_t hid_kbd_next_key(hid_keys_t* keys);
30 uint8_t hid_map_key(uint32_t usage, bool shift, const keychar_t* keymap);
31 
32 // iterates over keys in in the hid_keys_t structure.
33 // keys should be hid_keys_t*, keycode should be uint8_t
34 #define hid_for_every_key(keys, keycode) \
35     for (keycode = hid_kbd_next_key(keys); keycode; keycode = hid_kbd_next_key(keys))
36 __END_CDECLS
37