| 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 |
|
|---|
| 38 | #include <usb/usb.h>
|
|---|
| 39 | #include <driver.h>
|
|---|
| 40 | #include <usb/classes/hidparser.h>
|
|---|
| 41 | #include <usb/descriptor.h>
|
|---|
| 42 |
|
|---|
| 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 |
|
|---|
| 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;
|
|---|
| 60 |
|
|---|
| 61 | /** Part of standard USB HID descriptor specifying one class descriptor.
|
|---|
| 62 | *
|
|---|
| 63 | * (See HID Specification, p.22)
|
|---|
| 64 | */
|
|---|
| 65 | typedef struct {
|
|---|
| 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;
|
|---|
| 71 |
|
|---|
| 72 | /** Standard USB HID descriptor.
|
|---|
| 73 | *
|
|---|
| 74 | * (See HID Specification, p.22)
|
|---|
| 75 | *
|
|---|
| 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).
|
|---|
| 79 | */
|
|---|
| 80 | typedef struct {
|
|---|
| 81 | /** Total size of this descriptor in bytes.
|
|---|
| 82 | *
|
|---|
| 83 | * This includes all class-specific descriptor info - type + length
|
|---|
| 84 | * for each descriptor.
|
|---|
| 85 | */
|
|---|
| 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;
|
|---|
| 93 | /** Total number of class-specific (i.e. Report and Physical)
|
|---|
| 94 | * descriptors.
|
|---|
| 95 | */
|
|---|
| 96 | uint8_t class_desc_count;
|
|---|
| 97 | // /** First mandatory class descriptor info. */
|
|---|
| 98 | // usb_standard_hid_descriptor_class_item_t class_descriptor;
|
|---|
| 99 | } __attribute__ ((packed)) usb_standard_hid_descriptor_t;
|
|---|
| 100 |
|
|---|
| 101 | /**
|
|---|
| 102 | *
|
|---|
| 103 | */
|
|---|
| 104 | typedef struct {
|
|---|
| 105 | usb_standard_interface_descriptor_t iface_desc;
|
|---|
| 106 | usb_standard_endpoint_descriptor_t *endpoints;
|
|---|
| 107 | usb_standard_hid_descriptor_t hid_desc;
|
|---|
| 108 | usb_standard_hid_class_descriptor_info_t *class_desc_info;
|
|---|
| 109 | uint8_t **class_descs;
|
|---|
| 110 | } usb_hid_iface_t;
|
|---|
| 111 |
|
|---|
| 112 | /**
|
|---|
| 113 | *
|
|---|
| 114 | */
|
|---|
| 115 | typedef struct {
|
|---|
| 116 | usb_standard_configuration_descriptor_t config_descriptor;
|
|---|
| 117 | usb_hid_iface_t *interfaces;
|
|---|
| 118 | } usb_hid_configuration_t;
|
|---|
| 119 |
|
|---|
| 120 | /**
|
|---|
| 121 | * @brief USB/HID keyboard device type.
|
|---|
| 122 | *
|
|---|
| 123 | * Quite dummy right now.
|
|---|
| 124 | */
|
|---|
| 125 | typedef struct {
|
|---|
| 126 | device_t *device;
|
|---|
| 127 | usb_hid_configuration_t *conf;
|
|---|
| 128 | usb_address_t address;
|
|---|
| 129 | usb_endpoint_t poll_endpoint;
|
|---|
| 130 | usb_hid_report_parser_t *parser;
|
|---|
| 131 | } usb_hid_dev_kbd_t;
|
|---|
| 132 |
|
|---|
| 133 | #endif
|
|---|
| 134 | /**
|
|---|
| 135 | * @}
|
|---|
| 136 | */
|
|---|