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