usb_hid.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /******************************************************************************
  2. *
  3. * Freescale Semiconductor Inc.
  4. * (c) Copyright 2004-2009 Freescale Semiconductor, Inc.
  5. * ALL RIGHTS RESERVED.
  6. *
  7. ******************************************************************************
  8. *
  9. * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
  10. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  11. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  12. * IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  13. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  15. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  16. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  17. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  18. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  19. * THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. **************************************************************************//*!
  22. *
  23. * @file usb_hid.h
  24. *
  25. * @author
  26. *
  27. * @version
  28. *
  29. * @date May-28-2009
  30. *
  31. * @brief The file contains USB stack HID class layer API header function.
  32. *
  33. *****************************************************************************/
  34. #ifndef _USB_HID_H
  35. #define _USB_HID_H
  36. /******************************************************************************
  37. * Includes
  38. *****************************************************************************/
  39. #include "types.h"
  40. #include "usb_descriptor.h"
  41. #include "usb_class.h"
  42. #ifdef COMPOSITE_DEV
  43. #include "usb_composite.h"
  44. #endif
  45. #include "usb_devapi.h"
  46. /******************************************************************************
  47. * Constants - None
  48. *****************************************************************************/
  49. /******************************************************************************
  50. * Macro's
  51. *****************************************************************************/
  52. #define MAX_QUEUE_ELEMS (4)
  53. /* class specific requests */
  54. #define USB_HID_GET_REPORT_REQUEST (0x01)
  55. #define USB_HID_GET_IDLE_REQUEST (0x02)
  56. #define USB_HID_GET_PROTOCOL_REQUEST (0x03)
  57. #define USB_HID_SET_REPORT_REQUEST (0x09)
  58. #define USB_HID_SET_IDLE_REQUEST (0x0A)
  59. #define USB_HID_SET_PROTOCOL_REQUEST (0x0B)
  60. /* for class specific requests */
  61. #define HIGH_BYTE_SHIFT (8)
  62. #define MSB_MASK (0xFF00)
  63. #define USB_HID_REQUEST_DIR_MASK (0x08)
  64. #define USB_HID_REQUEST_TYPE_MASK (0x01)
  65. #define REPORT_SIZE (4)
  66. #define CLASS_REQ_DATA_SIZE (0x01)
  67. #define HID_ENDPOINT (1)
  68. /******************************************************************************
  69. * Types
  70. *****************************************************************************/
  71. /* structure to hold a request in the endpoint queue */
  72. typedef struct _usb_class_hid_queue
  73. {
  74. uint_8 controller_ID; /* Controller ID*/
  75. uint_8 channel; /* Endpoint number */
  76. uint_8_ptr app_buff; /* Buffer to send */
  77. USB_PACKET_SIZE size; /* Size of the transfer */
  78. }USB_CLASS_HID_QUEUE, *PTR_USB_CLASS_HID_QUEUE;
  79. /* USB class hid endpoint data */
  80. typedef struct _usb_class_hid_endpoint
  81. {
  82. uint_8 endpoint; /* Endpoint number */
  83. uint_8 type; /* Type of endpoint (interrupt,
  84. bulk or isochronous) */
  85. uint_8 bin_consumer; /* Num of queued elements */
  86. uint_8 bin_producer; /* Num of de-queued elements */
  87. uint_8 queue_num; /* HIGH SPEED: Num of queue */
  88. USB_CLASS_HID_QUEUE queue[MAX_QUEUE_ELEMS]; /* Queue data */
  89. }USB_CLASS_HID_ENDPOINT;
  90. /* contains the endpoint data for non control endpoints */
  91. typedef struct _usb_class_hid_endpoint_data
  92. {
  93. /* Num of non control endpoints */
  94. uint_8 count;
  95. /* contains the endpoint info */
  96. #ifndef COMPOSITE_DEV
  97. USB_CLASS_HID_ENDPOINT ep[USB_MAX_SUPPORTED_ENDPOINTS]; //HID_DESC_ENDPOINT_COUNT];
  98. #else
  99. USB_CLASS_HID_ENDPOINT ep[COMPOSITE_DESC_ENDPOINT_COUNT];
  100. #endif
  101. }USB_CLASS_HID_ENDPOINT_DATA, *PTR_USB_CLASS_HID_ENDPOINT_DATA;
  102. /******************************************************************************
  103. * Global Functions
  104. *****************************************************************************/
  105. extern uint_8 USB_Class_HID_Init (
  106. uint_8 controller_ID,
  107. USB_CLASS_CALLBACK hid_class_callback,
  108. USB_REQ_FUNC vendor_req_callback,
  109. USB_CLASS_SPECIFIC_HANDLER_FUNC param_callback
  110. );
  111. extern void USB_Class_Hid_Event (
  112. uint_8 controller_ID, /* [IN] Controller ID */
  113. uint_8 event, /* [IN] Event Type */
  114. void* val /* [IN] Pointer to configuration Value */
  115. );
  116. #ifdef COMPOSITE_DEV
  117. extern uint_8 USB_HID_Other_Requests(uint_8 controller_ID,
  118. USB_SETUP_STRUCT * setup_packet,
  119. uint_8_ptr *data,
  120. USB_PACKET_SIZE *size);
  121. #endif
  122. extern uint_8 USB_Class_HID_DeInit
  123. (
  124. uint_8 controller_ID
  125. );
  126. extern uint_8 USB_Class_HID_Send_Data (
  127. uint_8 controller_ID,
  128. uint_8 ep_num,
  129. uint_8_ptr buff_ptr,
  130. USB_PACKET_SIZE size
  131. );
  132. #define USB_Class_HID_Periodic_Task USB_Class_Periodic_Task
  133. void USB_Service_Hid (PTR_USB_DEV_EVENT_STRUCT event);
  134. #endif