00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2014, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 00028 */ 00029 00030 /**\file 00031 * 00032 * Definitions used for general HID support. 00033 * 00034 * The HID Function supports following: 00035 * - 1 interface with 1 pipe in and 1 pipe out; 00036 * - An input report list; 00037 * - An output report list; 00038 * - handles requests: 00039 * - handles: GET_IDLE/SET_IDLE, 00040 * GET_REPORT/SET_REPORT, 00041 * SET_PROTOCOL/GET_PROTOCOL; 00042 * - stall : SET_DESCRIPTOR. 00043 */ 00044 00045 #ifndef _HIDDFUNCTION_H_ 00046 #define _HIDDFUNCTION_H_ 00047 /** \addtogroup usbd_hid 00048 * @{ 00049 */ 00050 00051 /*---------------------------------------------------------------------------- 00052 * Includes 00053 *----------------------------------------------------------------------------*/ 00054 00055 #include <stdint.h> 00056 00057 #include <HIDRequests.h> 00058 #include <HIDDescriptors.h> 00059 00060 #include "USBD.h" 00061 #include <USBDDriver.h> 00062 00063 /*---------------------------------------------------------------------------- 00064 * Definitions 00065 *----------------------------------------------------------------------------*/ 00066 00067 /** \addtogroup usbd_hid_events HIDD Event codes 00068 * @{ 00069 */ 00070 /** Report sent */ 00071 #define HIDD_EC_REPORTSENT 1 00072 /** Report changed */ 00073 #define HIDD_EC_REPORTCHANGED 2 00074 /** Report sent because of GET_REPORT Request */ 00075 #define HIDD_EC_GETREPORT 3 00076 /** Report changed because of SET_REPORT Request */ 00077 #define HIDD_EC_SETREPORT 4 00078 /** @}*/ 00079 00080 /*---------------------------------------------------------------------------- 00081 * Types 00082 *----------------------------------------------------------------------------*/ 00083 00084 /** 00085 * Callback function for HID report events. 00086 */ 00087 typedef void(*HIDDReportEventCallback)(uint32_t ec, void *pArg); 00088 00089 /** 00090 * Struct for a header of basic HID report descriptor. 00091 */ 00092 typedef struct _HIDDReportHeader { 00093 /** Callback when report done */ 00094 HIDDReportEventCallback fCallback; 00095 /** Callback arguments */ 00096 void* pArg; 00097 00098 /** Report size (ID + DATA) */ 00099 uint16_t wMaxSize; 00100 /** Transferred size */ 00101 uint16_t wTransferred; 00102 /** Report idle rate */ 00103 uint8_t bIdleRate; 00104 /** Delay count for Idle */ 00105 uint8_t bDelay; 00106 /** Report ID */ 00107 uint8_t bID; 00108 } HIDDReportHeader; 00109 00110 /** 00111 * Struct for an basic HID report descriptor. 00112 */ 00113 typedef struct _HIDDReport { 00114 /** Callback when report done */ 00115 HIDDReportEventCallback fCallback; 00116 /** Callback arguments */ 00117 void* pArg; 00118 00119 /** Report size (ID + DATA) */ 00120 uint16_t wMaxSize; 00121 /** Transferred size */ 00122 uint16_t wTransferred; 00123 /** Report idle rate */ 00124 uint8_t bIdleRate; 00125 /** Delay count for Idle */ 00126 uint8_t bDelay; 00127 /** Report ID */ 00128 uint8_t bID; 00129 /** Report data block start ... */ 00130 uint8_t bData[1]; 00131 } HIDDReport; 00132 00133 /** 00134 * Struct for an HID general function. 00135 * Supports Input/Output reports. No feature report support. 00136 */ 00137 typedef struct _HIDDFunction { 00138 /** USB Driver for the %device */ 00139 USBDDriver *pUsbd; 00140 /** HID descriptor */ 00141 HIDDescriptor *pHidDescriptor; 00142 /** HID Specific report descriptor */ 00143 uint8_t *pReportDescriptor; 00144 /** USB interface for HID function */ 00145 uint8_t bInterface; 00146 /** USB interrupt IN EP */ 00147 uint8_t bPipeIN; 00148 /** USB interrupt OUT EP */ 00149 uint8_t bPipeOUT; 00150 00151 /** HID Protocol */ 00152 uint8_t bProtocol; 00153 00154 /** HID Input reports list */ 00155 HIDDReport **pInputList; 00156 /** HID Output reports list */ 00157 HIDDReport **pOutputList; 00158 /** HID Input report list size */ 00159 uint8_t bInputListSize; 00160 /** Current input report */ 00161 uint8_t bCurrInput; 00162 /** HID Output reports list */ 00163 uint8_t bOutputListSize; 00164 /** Current output report */ 00165 uint8_t bCurrOutput; 00166 } HIDDFunction; 00167 00168 /*---------------------------------------------------------------------------- 00169 * Functions 00170 *----------------------------------------------------------------------------*/ 00171 00172 extern void HIDDFunction_Initialize( 00173 HIDDFunction * pHidd, 00174 USBDDriver * pUsbd, uint8_t bInterfaceNb, 00175 const uint8_t * pReportDescriptor, 00176 HIDDReport * pInputList [ ], uint8_t bInputListSize, 00177 HIDDReport * pOutputList [ ], uint8_t bOutputListSize); 00178 00179 extern USBGenericDescriptor* HIDDFunction_ParseInterface( 00180 HIDDFunction * pHidd, 00181 USBGenericDescriptor * pDescriptors, 00182 uint32_t dwLength); 00183 00184 extern uint32_t HIDDFunction_RequestHandler( 00185 HIDDFunction * pHidd, 00186 const USBGenericRequest * request); 00187 00188 extern uint32_t HIDDFunction_StartSendingInputs(HIDDFunction * pHidd); 00189 00190 extern uint32_t HIDDFunction_StartPollingOutputs(HIDDFunction * pHidd); 00191 00192 extern uint32_t HIDDFunction_Read( 00193 const HIDDFunction * pHidd, 00194 void * pData, uint32_t dwLength, 00195 TransferCallback fCallback, void * pArg); 00196 00197 extern uint32_t HIDDFunction_Write( 00198 const HIDDFunction * pHidd, 00199 void * pData, uint32_t dwLength, 00200 TransferCallback fCallback, void * pArg); 00201 00202 extern void HIDDFunction_InitializeReport( 00203 HIDDReport * pReport, 00204 uint16_t wSize, 00205 uint8_t bID, 00206 HIDDReportEventCallback fCallback, void* pArg); 00207 00208 /**@}*/ 00209 #endif /* #define _HIDDFUNCTION_H_ */ 00210