| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Lubos Slovak
|
|---|
| 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 drvusbhid
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * USB HID driver API.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef USB_HID_USBHID_H_
|
|---|
| 37 | #define USB_HID_USBHID_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <stdint.h>
|
|---|
| 40 |
|
|---|
| 41 | #include <usb/hid/hidparser.h>
|
|---|
| 42 | #include <ddf/driver.h>
|
|---|
| 43 | #include <usb/dev/pipes.h>
|
|---|
| 44 | #include <usb/dev/driver.h>
|
|---|
| 45 | #include <usb/hid/hid.h>
|
|---|
| 46 | #include <bool.h>
|
|---|
| 47 |
|
|---|
| 48 | struct usb_hid_dev;
|
|---|
| 49 |
|
|---|
| 50 | typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *, void **data);
|
|---|
| 51 | typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *, void *data);
|
|---|
| 52 | typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, void *data, uint8_t *,
|
|---|
| 53 | size_t);
|
|---|
| 54 | typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, void *data,
|
|---|
| 55 | bool reason);
|
|---|
| 56 |
|
|---|
| 57 | // TODO: add function and class name??
|
|---|
| 58 | typedef struct usb_hid_subdriver {
|
|---|
| 59 | /** Function to be called when initializing HID device. */
|
|---|
| 60 | usb_hid_driver_init_t init;
|
|---|
| 61 | /** Function to be called when destroying the HID device structure. */
|
|---|
| 62 | usb_hid_driver_deinit_t deinit;
|
|---|
| 63 | /** Function to be called when data arrives from the device. */
|
|---|
| 64 | usb_hid_driver_poll poll;
|
|---|
| 65 | /** Function to be called when polling ends. */
|
|---|
| 66 | usb_hid_driver_poll_ended poll_end;
|
|---|
| 67 | /** Arbitrary data needed by the subdriver. */
|
|---|
| 68 | void *data;
|
|---|
| 69 | } usb_hid_subdriver_t;
|
|---|
| 70 |
|
|---|
| 71 | /*----------------------------------------------------------------------------*/
|
|---|
| 72 | /**
|
|---|
| 73 | * Structure for holding general HID device data.
|
|---|
| 74 | */
|
|---|
| 75 | typedef struct usb_hid_dev {
|
|---|
| 76 | /** Structure holding generic USB device information. */
|
|---|
| 77 | usb_device_t *usb_dev;
|
|---|
| 78 |
|
|---|
| 79 | /** Index of the polling pipe in usb_hid_endpoints array. */
|
|---|
| 80 | int poll_pipe_index;
|
|---|
| 81 |
|
|---|
| 82 | /** Subdrivers. */
|
|---|
| 83 | usb_hid_subdriver_t *subdrivers;
|
|---|
| 84 |
|
|---|
| 85 | /** Number of subdrivers. */
|
|---|
| 86 | int subdriver_count;
|
|---|
| 87 |
|
|---|
| 88 | /** Report descriptor. */
|
|---|
| 89 | uint8_t *report_desc;
|
|---|
| 90 |
|
|---|
| 91 | /** Report descriptor size. */
|
|---|
| 92 | size_t report_desc_size;
|
|---|
| 93 |
|
|---|
| 94 | /** HID Report parser. */
|
|---|
| 95 | usb_hid_report_t *report;
|
|---|
| 96 |
|
|---|
| 97 | uint8_t *input_report;
|
|---|
| 98 |
|
|---|
| 99 | size_t input_report_size;
|
|---|
| 100 | size_t max_input_report_size;
|
|---|
| 101 |
|
|---|
| 102 | int report_nr;
|
|---|
| 103 | } usb_hid_dev_t;
|
|---|
| 104 |
|
|---|
| 105 | /*----------------------------------------------------------------------------*/
|
|---|
| 106 |
|
|---|
| 107 | enum {
|
|---|
| 108 | USB_HID_KBD_POLL_EP_NO = 0,
|
|---|
| 109 | USB_HID_MOUSE_POLL_EP_NO = 1,
|
|---|
| 110 | USB_HID_GENERIC_POLL_EP_NO = 2,
|
|---|
| 111 | USB_HID_POLL_EP_COUNT = 3
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1];
|
|---|
| 115 |
|
|---|
| 116 | /*----------------------------------------------------------------------------*/
|
|---|
| 117 |
|
|---|
| 118 | usb_hid_dev_t *usb_hid_new(void);
|
|---|
| 119 |
|
|---|
| 120 | int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
|
|---|
| 121 |
|
|---|
| 122 | bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
|
|---|
| 123 | size_t buffer_size, void *arg);
|
|---|
| 124 |
|
|---|
| 125 | void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
|
|---|
| 126 | void *arg);
|
|---|
| 127 |
|
|---|
| 128 | //const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev);
|
|---|
| 129 |
|
|---|
| 130 | //const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
|
|---|
| 131 |
|
|---|
| 132 | void usb_hid_new_report(usb_hid_dev_t *hid_dev);
|
|---|
| 133 |
|
|---|
| 134 | int usb_hid_report_number(usb_hid_dev_t *hid_dev);
|
|---|
| 135 |
|
|---|
| 136 | //void usb_hid_report_received(void);
|
|---|
| 137 |
|
|---|
| 138 | //bool usb_hid_report_ready(void);
|
|---|
| 139 |
|
|---|
| 140 | void usb_hid_free(usb_hid_dev_t **hid_dev);
|
|---|
| 141 |
|
|---|
| 142 | #endif /* USB_HID_USBHID_H_ */
|
|---|
| 143 |
|
|---|
| 144 | /**
|
|---|
| 145 | * @}
|
|---|
| 146 | */
|
|---|