📄 usbdriver.h
字号:
/*----------------------------------------------------------------------------------
*
* COPYRIGHT (c) 2001 by Singing Electrons, Inc. All rights reserved.
*
* Module Name : C:\se\adi\hidclass\Source\usbdriver.h
*
* Description : Contains function prototypes and definitions for use by the USBDriver clients
*
*
* Revision History : At bottom of the file.
*
*---------------------------------------------------------------------------------*/
#ifndef _USBDRIVER_H
#define _USBDRIVER_H
#define USB_CONTROL_REQUEST_TYPE_DIRECTION_MASK 0x80
#define USB_CONTROL_REQUEST_TYPE_DIRECTION_BITSHIFT 7
#define USB_CONTROL_REQUEST_TYPE_TYPE_MASK 0x60
#define USB_CONTROL_REQUEST_TYPE_TYPE_BITSHIFT 5
#define USB_CONTROL_REQUEST_TYPE_RECIPIENT_MASK 0x1f
#define USB_CONTROL_REQUEST_TYPE_RECIPIENT_BITSHIFT 0
#define USB_CONTROL_REQUEST_GET_DIRECTION(a) ((a & USB_CONTROL_REQUEST_TYPE_DIRECTION_MASK) >> USB_CONTROL_REQUEST_TYPE_DIRECTION_BITSHIFT)
#define USB_CONTROL_REQUEST_GET_TYPE(a) ((a & USB_CONTROL_REQUEST_TYPE_TYPE_MASK) >> USB_CONTROL_REQUEST_TYPE_TYPE_BITSHIFT)
#define USB_CONTROL_REQUEST_GET_RECIPIENT(a) (a & USB_CONTROL_REQUEST_TYPE_RECIPIENT_MASK)
#define USB_CONTROL_REQUEST_TYPE_OUT 0
#define USB_CONTROL_REQUEST_TYPE_IN 1
#define USB_CONTROL_REQUEST_TYPE_STANDARD 0x00
#define USB_CONTROL_REQUEST_TYPE_CLASS 0x01
#define USB_CONTROL_REQUEST_TYPE_VENDOR 0x02
#define USB_CONTROL_REQUEST_TYPE_DEVICE 0x00
#define USB_CONTROL_REQUEST_TYPE_INTERFACE 0x01
#define USB_CONTROL_REQUEST_TYPE_ENDPOINT 0x02
#define USB_CONTROL_REQUEST_TYPE_OTHER 0x03
#define USB_GET_DESCRIPTOR 6
#define USB_SET_DESCRIPTOR 7
enum {
USB_DEVICE_DESCRIPTOR = 1,
USB_CONFIGURATION_DESCRIPTOR,
USB_STRING_DESCRIPTOR,
USB_INTERFACE_DESCRIPTOR,
USB_ENDPOINT_DESCRIPTOR
};
#define CONTROL_PIPE_PACKET_SIZE 64
typedef struct tagUSB_SETUP_DATA{
UCHAR bmRequestType;
UCHAR bRequest;
USHORT wValue;
USHORT wIndex;
USHORT wLength;
}USB_SETUP_DATA, *PUSB_SETUP_DATA;
static inline void CopyDMABufferToSETUPStruct(PUSB_SETUP_DATA pSetupStruct, void *pDMABuffer)
{
pSetupStruct->bmRequestType = ((PUCHAR)pDMABuffer)[0];
pSetupStruct->bRequest = ((PUCHAR)pDMABuffer)[1];
pSetupStruct->wValue = ((PUSHORT)pDMABuffer)[1];
pSetupStruct->wIndex = ((PUSHORT)pDMABuffer)[2];
pSetupStruct->wLength = ((PUSHORT)pDMABuffer)[3];
}
//Callback function prototypes
typedef bool (* PSETUPPROC) (UCHAR endpointNumber, PUSB_SETUP_DATA pSetupData, void *buffer,
PUINT numBytesToTransfer);
typedef bool (* PGETDEVICEDESCRIPTORPROC) (void *buffer, PUINT numBytesToTransfer);
typedef bool (* PGETCONFIGDESCRIPTORPROC) (void *buffer, PUINT numBytesToTransfer);
typedef bool (* PGETSTRINGDESCRIPTORPROC) (UCHAR stringIndex, USHORT langID, void *buffer, PUINT numBytesToTransfer);
typedef void (* PINTCPROC)(UCHAR endpointNumber);
typedef bool (* POUTTCPROC)(UCHAR endpointNumber, void *buffer, UINT numBytesReceived, bool wasPCAsserted);
typedef void (* PMERRPROC)(UCHAR endpointNumber);
typedef bool (* POUTREQPROC)(void);
typedef void (* PSUSPENDPROC)(void);
typedef void (* PRESUMEPROC)(void);
typedef void (* PRESETPROC)(void);
typedef bool (* PCONFIGPROC)(UCHAR newConfiguration, UCHAR newInterface, UCHAR newAltSetting);
typedef void (* PSOFPROC)(void);
bool USBDriver_PreInit (void);
bool USBDriver_SetupEndpoint (UINT endpointNumber, UCHAR altSetting,
UCHAR interface, UCHAR configuration, UCHAR direction,
UCHAR ep_type, UINT maxPacketSize);
bool USBDriver_CompleteInit (PSETUPPROC pSetupProc, PGETDEVICEDESCRIPTORPROC pDevDescProc,
PGETCONFIGDESCRIPTORPROC pCfgDescProc, PGETSTRINGDESCRIPTORPROC pStringDescProc,
PINTCPROC pInTCProc, POUTTCPROC pOutTCProc, PMERRPROC pMerrProc, PSUSPENDPROC pSuspendProc, PRESUMEPROC pResumeProc,
PRESETPROC pResetProc, PCONFIGPROC pConfigProc, PSOFPROC pSOFProc, UINT controlEPMaxTransferSize);
void ActivateEndpoint (UCHAR endpointNumber, UCHAR endpointType, UCHAR maxPacketSize, UINT defaultMaxTransferSize);
void ArmEndpoint (UCHAR endpointNumber, UCHAR direction);
void StallEndpoint (UCHAR endpointToStall);
bool IsEndpointStalled (UCHAR endpointToCheck);
bool PepareINEPForXFer (UCHAR endpointNumber, void **ppDataBuffer);
bool PrepareOUTEPForXFer (UCHAR endpointNumber);
void UnprepareEP (UCHAR endpointNumber);
#endif //end of _USBDRIVER_H
/*----------------------------------------------------------------------------------
* $Log: usbdriver.h,v $
* Revision 1.2 2003/03/03 22:37:19 Devendra
* - Some code cleanup.
*
* Revision 1.1 2003/03/03 18:13:47 Devendra
* First Rev, the device enumerates as Mass Storage Class
*
* Revision 1.4 2003/01/16 19:11:00 Devendra
* - Added support to provide a callback for SOF interrupts.
*
* Revision 1.3 2003/01/15 01:37:20 Devendra
* - Changed the ISR declaration to used workaround specified by ADI dsptools website.
* - Changed the name of UnprepareOUTEP to UnprepareEP
*
* Revision 1.2 2003/01/10 01:53:26 Devendra
* - Added support for doing OUT transfers (including isoch. transfers).
*
* Revision 1.1 2003/01/09 01:16:36 Devendra
* First Rev of AudioClass - have the device enumerated as audio device, and the volume control and mute are functional!
*
* Revision 1.1 2002/10/31 00:30:59 Devendra
* Moved all files in one folder to avoid IDE related problems.
*
* Revision 1.2 2002/10/30 02:36:41 Devendra
* - Added more abstraction to HIDCLASS. So that it's possible to build
* different devices without making any changes to the HIDCLASS module.
* - Added proper support for handling USB SUSPEND, RESUME, and RESET events.
*
* Revision 1.1 2002/10/22 17:23:40 Devendra
* Rearranged file locations.
*
* Revision 1.4 2002/10/14 01:33:15 Devendra
* Got "custom" device functional with buttons and lights!
*
* Revision 1.3 2002/10/09 17:09:32 Devendra
* - Added support for handling IN endpoints.
* - Added HID descriptors (HID and HID Report)
* - Modified the Interface descriptors to comply to HID Class Spec.
* - Added functionality to use the push-buttons on the Eagle-35 as a mouse (for buttons as well as for movement).
* - The device is now a fully functioning USB Mouse!
*
* Revision 1.2 2002/10/08 19:57:02 Devendra
* - Added specific callbacks for getting Device, Config, and String descriptors.
* - BugFix: Max. Packet Size was not being set correctly in ArmEndpoint.
* - Added internal buffer based logging to allow real-time "printfs".
* - Added String descriptors.
*
* Revision 1.1 2002/09/20 06:51:30 Devendra
* First Rev.
*
*
*---------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -