| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libusb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief USB HID parser.
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef LIBUSB_HIDPARSER_H_
|
|---|
| 36 | #define LIBUSB_HIDPARSER_H_
|
|---|
| 37 |
|
|---|
| 38 | #include <stdint.h>
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * Description of report items
|
|---|
| 42 | */
|
|---|
| 43 | typedef struct {
|
|---|
| 44 |
|
|---|
| 45 | uint8_t usage_min;
|
|---|
| 46 | uint8_t usage_max;
|
|---|
| 47 | uint8_t logical_min;
|
|---|
| 48 | uint8_t logical_max;
|
|---|
| 49 | uint8_t size;
|
|---|
| 50 | uint8_t count;
|
|---|
| 51 | uint8_t offset;
|
|---|
| 52 |
|
|---|
| 53 | } usb_hid_report_item_t;
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | /** HID report parser structure. */
|
|---|
| 57 | typedef struct {
|
|---|
| 58 | } usb_hid_report_parser_t;
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | /** HID parser callbacks for IN items. */
|
|---|
| 62 | typedef struct {
|
|---|
| 63 | /** Callback for keyboard.
|
|---|
| 64 | *
|
|---|
| 65 | * @param key_codes Array of pressed key (including modifiers).
|
|---|
| 66 | * @param count Length of @p key_codes.
|
|---|
| 67 | * @param arg Custom argument.
|
|---|
| 68 | */
|
|---|
| 69 | void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t modifiers, void *arg);
|
|---|
| 70 | } usb_hid_report_in_callbacks_t;
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | typedef enum {
|
|---|
| 74 | USB_HID_MOD_LCTRL = 0x01,
|
|---|
| 75 | USB_HID_MOD_LSHIFT = 0x02,
|
|---|
| 76 | USB_HID_MOD_LALT = 0x04,
|
|---|
| 77 | USB_HID_MOD_LGUI = 0x08,
|
|---|
| 78 | USB_HID_MOD_RCTRL = 0x10,
|
|---|
| 79 | USB_HID_MOD_RSHIFT = 0x20,
|
|---|
| 80 | USB_HID_MOD_RALT = 0x40,
|
|---|
| 81 | USB_HID_MOD_RGUI = 0x80,
|
|---|
| 82 | USB_HID_MOD_COUNT = 8
|
|---|
| 83 | } usb_hid_modifiers_t;
|
|---|
| 84 |
|
|---|
| 85 | static const usb_hid_modifiers_t
|
|---|
| 86 | usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
|
|---|
| 87 | USB_HID_MOD_LCTRL,
|
|---|
| 88 | USB_HID_MOD_LSHIFT,
|
|---|
| 89 | USB_HID_MOD_LALT,
|
|---|
| 90 | USB_HID_MOD_LGUI,
|
|---|
| 91 | USB_HID_MOD_RCTRL,
|
|---|
| 92 | USB_HID_MOD_RSHIFT,
|
|---|
| 93 | USB_HID_MOD_RALT,
|
|---|
| 94 | USB_HID_MOD_RGUI
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01
|
|---|
| 98 | //#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x02
|
|---|
| 99 | //#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x04
|
|---|
| 100 | //#define USB_HID_BOOT_KEYBOARD_COMPOSE 0x08
|
|---|
| 101 | //#define USB_HID_BOOT_KEYBOARD_KANA 0x10
|
|---|
| 102 |
|
|---|
| 103 | /*
|
|---|
| 104 | * modifiers definitions
|
|---|
| 105 | */
|
|---|
| 106 |
|
|---|
| 107 | int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
|
|---|
| 108 | const usb_hid_report_in_callbacks_t *callbacks, void *arg);
|
|---|
| 109 |
|
|---|
| 110 | int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
|
|---|
| 111 |
|
|---|
| 112 | int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
|
|---|
| 113 | const uint8_t *data, size_t size);
|
|---|
| 114 |
|
|---|
| 115 | int usb_hid_parse_report(const usb_hid_report_parser_t *parser,
|
|---|
| 116 | const uint8_t *data, size_t size,
|
|---|
| 117 | const usb_hid_report_in_callbacks_t *callbacks, void *arg);
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | int usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
|
|---|
| 121 |
|
|---|
| 122 | #endif
|
|---|
| 123 | /**
|
|---|
| 124 | * @}
|
|---|
| 125 | */
|
|---|