| [27b85d9] | 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 libdrv
 | 
|---|
 | 30 |  * @{
 | 
|---|
 | 31 |  */
 | 
|---|
 | 32 | /** @file
 | 
|---|
 | 33 |  * USB HID interface definition.
 | 
|---|
 | 34 |  */
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | #ifndef LIBDRV_USBHID_IFACE_H_
 | 
|---|
 | 37 | #define LIBDRV_USBHID_IFACE_H_
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | #include "ddf/driver.h"
 | 
|---|
 | 40 | #include <usb/usb.h>
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | /** IPC methods for USB HID device interface. */
 | 
|---|
 | 43 | typedef enum {
 | 
|---|
 | 44 |         /** Get number of events reported in single burst.
 | 
|---|
 | 45 |          * Parameters: none
 | 
|---|
 | 46 |          * Answer:
 | 
|---|
| [d7c72db] | 47 |          * - Size of one report in bytes.
 | 
|---|
| [27b85d9] | 48 |          */
 | 
|---|
 | 49 |         IPC_M_USBHID_GET_EVENT_LENGTH,
 | 
|---|
 | 50 |         /** Get single event from the HID device.
 | 
|---|
 | 51 |          * The word single refers to set of individual events that were
 | 
|---|
 | 52 |          * available at particular point in time.
 | 
|---|
 | 53 |          * Parameters:
 | 
|---|
 | 54 |          * - flags
 | 
|---|
 | 55 |          * The call is followed by data read expecting two concatenated
 | 
|---|
 | 56 |          * arrays.
 | 
|---|
 | 57 |          * Answer:
 | 
|---|
 | 58 |          * - EOK - events returned
 | 
|---|
 | 59 |          * - EAGAIN - no event ready (only in non-blocking mode)
 | 
|---|
 | 60 |          *
 | 
|---|
 | 61 |          * It is okay if the client requests less data. Extra data must
 | 
|---|
 | 62 |          * be truncated by the driver.
 | 
|---|
| [d7c72db] | 63 |          *
 | 
|---|
 | 64 |          * @todo Change this comment.
 | 
|---|
 | 65 |          */
 | 
|---|
 | 66 |         IPC_M_USBHID_GET_EVENT,
 | 
|---|
 | 67 |         
 | 
|---|
 | 68 |         /** Get the size of the report descriptor from the HID device.
 | 
|---|
 | 69 |          *
 | 
|---|
 | 70 |          * Parameters:
 | 
|---|
 | 71 |          * - none
 | 
|---|
 | 72 |          * Answer:
 | 
|---|
| [9dddb3d] | 73 |          * - EOK - method is implemented (expected always)
 | 
|---|
 | 74 |          * Parameters of the answer:
 | 
|---|
 | 75 |          * - Size of the report in bytes.
 | 
|---|
| [d7c72db] | 76 |          */
 | 
|---|
 | 77 |         IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH,
 | 
|---|
 | 78 |         
 | 
|---|
 | 79 |         /** Get the report descriptor from the HID device.
 | 
|---|
 | 80 |          *
 | 
|---|
 | 81 |          * Parameters:
 | 
|---|
 | 82 |          * - none
 | 
|---|
| [9dddb3d] | 83 |          * The call is followed by data read expecting the descriptor itself.
 | 
|---|
| [d7c72db] | 84 |          * Answer:
 | 
|---|
 | 85 |          * - EOK - report descriptor returned.
 | 
|---|
| [27b85d9] | 86 |          */
 | 
|---|
| [d7c72db] | 87 |         IPC_M_USBHID_GET_REPORT_DESCRIPTOR
 | 
|---|
| [27b85d9] | 88 | } usbhid_iface_funcs_t;
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | /** USB HID interface flag - return immediately if no data are available. */
 | 
|---|
 | 91 | #define USBHID_IFACE_FLAG_NON_BLOCKING (1 << 0)
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | /** USB HID device communication interface. */
 | 
|---|
 | 94 | typedef struct {
 | 
|---|
| [3facf63a] | 95 |         /** Get size of the event in bytes.
 | 
|---|
| [27b85d9] | 96 |          *
 | 
|---|
 | 97 |          * @param[in] fun DDF function answering the request.
 | 
|---|
| [d7c72db] | 98 |          * @return Size of the event in bytes.
 | 
|---|
| [27b85d9] | 99 |          */
 | 
|---|
| [3facf63a] | 100 |         size_t (*get_event_length)(ddf_fun_t *fun);
 | 
|---|
| [27b85d9] | 101 | 
 | 
|---|
 | 102 |         /** Get single event from the HID device.
 | 
|---|
 | 103 |          *
 | 
|---|
 | 104 |          * @param[in] fun DDF function answering the request.
 | 
|---|
| [3facf63a] | 105 |          * @param[out] buffer Buffer with raw data from the device.
 | 
|---|
| [27b85d9] | 106 |          * @param[out] act_size Actual number of returned events.
 | 
|---|
 | 107 |          * @param[in] flags Flags (see USBHID_IFACE_FLAG_*).
 | 
|---|
 | 108 |          * @return Error code.
 | 
|---|
 | 109 |          */
 | 
|---|
| [d7c72db] | 110 |         int (*get_event)(ddf_fun_t *fun, uint8_t *buffer, size_t size,
 | 
|---|
| [266fcd8] | 111 |             size_t *act_size, int *event_nr, unsigned int flags);
 | 
|---|
| [d7c72db] | 112 |         
 | 
|---|
 | 113 |         /** Get size of the report descriptor in bytes.
 | 
|---|
 | 114 |          *
 | 
|---|
 | 115 |          * @param[in] fun DDF function answering the request.
 | 
|---|
 | 116 |          * @return Size of the report descriptor in bytes.
 | 
|---|
 | 117 |          */
 | 
|---|
 | 118 |         size_t (*get_report_descriptor_length)(ddf_fun_t *fun);
 | 
|---|
 | 119 |         
 | 
|---|
 | 120 |         /** Get the report descriptor from the HID device.
 | 
|---|
 | 121 |          *
 | 
|---|
 | 122 |          * @param[in] fun DDF function answering the request.
 | 
|---|
 | 123 |          * @param[out] desc Buffer with the report descriptor.
 | 
|---|
| [9dddb3d] | 124 |          * @param[in] size Size of the allocated @p desc buffer.
 | 
|---|
 | 125 |          * @param[out] act_size Actual size of the report descriptor returned.
 | 
|---|
| [d7c72db] | 126 |          * @return Error code.
 | 
|---|
 | 127 |          */
 | 
|---|
 | 128 |         int (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc, 
 | 
|---|
 | 129 |             size_t size, size_t *act_size);
 | 
|---|
| [27b85d9] | 130 | } usbhid_iface_t;
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 | #endif
 | 
|---|
 | 134 | /**
 | 
|---|
 | 135 |  * @}
 | 
|---|
 | 136 |  */
 | 
|---|