| [0e41957] | 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 usb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief USB HID device related types.
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef LIBUSB_HID_H_
|
|---|
| 36 | #define LIBUSB_HID_H_
|
|---|
| 37 |
|
|---|
| [2e15ac40] | 38 | #include <usb/usb.h>
|
|---|
| 39 | #include <driver.h>
|
|---|
| [243cb86] | 40 | #include <usb/classes/hidparser.h>
|
|---|
| [c694b7e] | 41 | #include <usb/descriptor.h>
|
|---|
| [2e15ac40] | 42 |
|
|---|
| [0e41957] | 43 | /** USB/HID device requests. */
|
|---|
| 44 | typedef enum {
|
|---|
| 45 | USB_HIDREQ_GET_REPORT = 1,
|
|---|
| 46 | USB_HIDREQ_GET_IDLE = 2,
|
|---|
| 47 | USB_HIDREQ_GET_PROTOCOL = 3,
|
|---|
| 48 | /* Values 4 to 8 are reserved. */
|
|---|
| 49 | USB_HIDREQ_SET_REPORT = 9,
|
|---|
| 50 | USB_HIDREQ_SET_IDLE = 10,
|
|---|
| 51 | USB_HIDREQ_SET_PROTOCOL = 11
|
|---|
| 52 | } usb_hid_request_t;
|
|---|
| 53 |
|
|---|
| [fd17ab5] | 54 | /** USB/HID interface protocols. */
|
|---|
| 55 | typedef enum {
|
|---|
| 56 | USB_HID_PROTOCOL_NONE = 0,
|
|---|
| 57 | USB_HID_PROTOCOL_KEYBOARD = 1,
|
|---|
| 58 | USB_HID_PROTOCOL_MOUSE = 2
|
|---|
| 59 | } usb_hid_protocol_t;
|
|---|
| [0e41957] | 60 |
|
|---|
| [a3b1107] | 61 | /** Part of standard USB HID descriptor specifying one class descriptor.
|
|---|
| 62 | *
|
|---|
| 63 | * (See HID Specification, p.22)
|
|---|
| 64 | */
|
|---|
| 65 | typedef struct {
|
|---|
| [c694b7e] | 66 | /** Type of class-specific descriptor (Report or Physical). */
|
|---|
| 67 | uint8_t type;
|
|---|
| 68 | /** Length of class-specific descriptor in bytes. */
|
|---|
| 69 | uint16_t length;
|
|---|
| 70 | } __attribute__ ((packed)) usb_standard_hid_class_descriptor_info_t;
|
|---|
| [a3b1107] | 71 |
|
|---|
| 72 | /** Standard USB HID descriptor.
|
|---|
| 73 | *
|
|---|
| 74 | * (See HID Specification, p.22)
|
|---|
| 75 | *
|
|---|
| [c694b7e] | 76 | * It is actually only the "header" of the descriptor, it does not contain
|
|---|
| 77 | * the last two mandatory fields (type and length of the first class-specific
|
|---|
| 78 | * descriptor).
|
|---|
| [a3b1107] | 79 | */
|
|---|
| 80 | typedef struct {
|
|---|
| [c694b7e] | 81 | /** Total size of this descriptor in bytes.
|
|---|
| 82 | *
|
|---|
| 83 | * This includes all class-specific descriptor info - type + length
|
|---|
| 84 | * for each descriptor.
|
|---|
| 85 | */
|
|---|
| [a3b1107] | 86 | uint8_t length;
|
|---|
| 87 | /** Descriptor type (USB_DESCTYPE_HID). */
|
|---|
| 88 | uint8_t descriptor_type;
|
|---|
| 89 | /** HID Class Specification release. */
|
|---|
| 90 | uint16_t spec_release;
|
|---|
| 91 | /** Country code of localized hardware. */
|
|---|
| 92 | uint8_t country_code;
|
|---|
| [c694b7e] | 93 | /** Total number of class-specific (i.e. Report and Physical)
|
|---|
| 94 | * descriptors.
|
|---|
| [6986418] | 95 | *
|
|---|
| 96 | * @note There is always only one Report descriptor.
|
|---|
| [c694b7e] | 97 | */
|
|---|
| 98 | uint8_t class_desc_count;
|
|---|
| [6986418] | 99 | /** First mandatory class descriptor (Report) info. */
|
|---|
| 100 | usb_standard_hid_descriptor_class_item_t report_desc_info;
|
|---|
| [a3b1107] | 101 | } __attribute__ ((packed)) usb_standard_hid_descriptor_t;
|
|---|
| 102 |
|
|---|
| [c694b7e] | 103 | /**
|
|---|
| 104 | *
|
|---|
| 105 | */
|
|---|
| 106 | typedef struct {
|
|---|
| 107 | usb_standard_interface_descriptor_t iface_desc;
|
|---|
| 108 | usb_standard_endpoint_descriptor_t *endpoints;
|
|---|
| 109 | usb_standard_hid_descriptor_t hid_desc;
|
|---|
| [6986418] | 110 | uint8_t *report_desc;
|
|---|
| 111 | //usb_standard_hid_class_descriptor_info_t *class_desc_info;
|
|---|
| 112 | //uint8_t **class_descs;
|
|---|
| [c694b7e] | 113 | } usb_hid_iface_t;
|
|---|
| 114 |
|
|---|
| 115 | /**
|
|---|
| 116 | *
|
|---|
| 117 | */
|
|---|
| 118 | typedef struct {
|
|---|
| 119 | usb_standard_configuration_descriptor_t config_descriptor;
|
|---|
| 120 | usb_hid_iface_t *interfaces;
|
|---|
| 121 | } usb_hid_configuration_t;
|
|---|
| [a3b1107] | 122 |
|
|---|
| [2e15ac40] | 123 | /**
|
|---|
| 124 | * @brief USB/HID keyboard device type.
|
|---|
| 125 | *
|
|---|
| 126 | * Quite dummy right now.
|
|---|
| 127 | */
|
|---|
| 128 | typedef struct {
|
|---|
| 129 | device_t *device;
|
|---|
| [c694b7e] | 130 | usb_hid_configuration_t *conf;
|
|---|
| [2e15ac40] | 131 | usb_address_t address;
|
|---|
| [1b29d6fa] | 132 | usb_endpoint_t poll_endpoint;
|
|---|
| [243cb86] | 133 | usb_hid_report_parser_t *parser;
|
|---|
| [2e15ac40] | 134 | } usb_hid_dev_kbd_t;
|
|---|
| 135 |
|
|---|
| [6986418] | 136 | // TODO: more configurations!
|
|---|
| 137 |
|
|---|
| [0e41957] | 138 | #endif
|
|---|
| 139 | /**
|
|---|
| 140 | * @}
|
|---|
| 141 | */
|
|---|