📄 usb.h
字号:
#include "ABSACC.H"
#define ISO_BIT 0x10
#define MAX_EP 0x05 // maximum number of endpoints (Ep0 + max of 4 data endpoints)
#define INT_CLEAR 0xff
//*****************************************************************************************
// Constant Defines
//*****************************************************************************************
#define TIMEOUT_RETRY 0x06 // Maximum no. of timeout retries during USB xfer
// USB device descriptors
typedef struct
{
WORD wVID, wPID; // Vendor ID and Product ID
BYTE bClass; //
BYTE bNumOfEPs; // actual number endpoint from slave
BYTE iMfg; // Manufacturer ID
BYTE iPdt; // Product ID
BYTE bId1;
BYTE bId2;
BYTE bEPAddr[MAX_EP]; // bit 7 = 1 = use PID_IN,
BYTE bAttr[MAX_EP]; // ISO | Bulk | Interrupt | Control
WORD wPayLoad[MAX_EP]; // ISO range: 1-1023, Bulk: 1-64, etc
WORD bInterval[MAX_EP]; // polling interval (for LS)
BYTE bData1[MAX_EP]; // DataToggle value
} USBDEV, *pUSBDEV;
// USB specific request
typedef struct
{
BYTE bmRequest;
BYTE bRequest;
WORD wValue;
WORD wIndex;
WORD wLength;
} SetupPKG, *pSetupPKG;
typedef struct
{
unsigned char usbaddr;
// unsigned char endpoint;
unsigned char pid;
unsigned char wPayload;
unsigned int wLen;
unsigned char *buffer;
SetupPKG setup;
unsigned char epbulkin;
unsigned char epbulkout;
} XXGPKG, *pXXGPKG;
// Standard Device Descriptor
typedef struct //14 fields and 18 bytes;
{ BYTE bLength; //Descriptor size in bytes --descriptor
BYTE bDescriptorType; //The constant DEVICE(01h) --descriptor
WORD bcdUSB; //The USB specification number that the Device and the descriptor comply with;
BYTE bDeviceClass; //device class
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0; //maximum packet size for endpoint 0;
WORD idVendor;
WORD idProduct;
WORD bcdDevice; //the device's release number;
BYTE iManufacturer; //an index that points to a string describing the manufacture;
BYTE iProduct; //an index that points to a string describing the product;
BYTE iSerialNumber;
BYTE bNumConfigurations; //the number of configuration the device supports;
} sDevDesc, *pDevDesc;
// Standard Configuration Descriptor describes the device's feature and abilities;
typedef struct
{
BYTE bLength; // Size of descriptor in Byte
BYTE bType; // the constant Configuration(02h)
WORD wLength; // the number of data bytes that the device returns,
BYTE bNumIntf; // Number of interfaces the configuration supports;
BYTE bCV; // bConfigurationValue,identifies the configuration for Get_Configuration and Set_Configuration;
BYTE bIndex; // iConfiguration,index to a string that describes the configuration;
BYTE bAttr; // Self power/bus power and remote wakeup;
BYTE bMaxPower; // Power config
} sCfgDesc, *pCfgDesc;
// Standard Interface Descriptor 9 bytes
typedef struct
{ BYTE bLength;
BYTE bType; //the constant INTERFACE(04h);
BYTE iNum; //Number identifying this interface;
BYTE iAltString; //Value used to select an alternate setting;
BYTE bEndPoints; //Number of endpoints supported in addition to Endpoint0;
BYTE iClass; //class code
BYTE iSub; //subclass code
BYTE iProto; //protocol code
BYTE iIndex; //index of string descriptor for interface;
} sIntfDesc, *pIntfDesc;
// Standard EndPoint Descriptor 7 bytes
typedef struct
{ BYTE bLength;
BYTE bType; //the constant endpoint(05h);
BYTE bEPAdd; //includes the endpoint number(bits 0 through 3) and direction(bit 7);
BYTE bAttr; //bits 1 and 0 specify the type of transfer the endpoint supports.00=control,10=bulk...;
WORD wPayLoad; //maximum packet size supported; low-speed this must be 0x08
BYTE bInterval; //for full-speed bulk and control transfers,the value is ignored.
} sEPDesc, *pEPDesc;
/*-------------------------------------------------------------------------
* Standard Chapter 9 definition
*-------------------------------------------------------------------------
*/
#define GET_STATUS 0x00
#define CLEAR_FEATURE 0x01
#define SET_FEATURE 0x03
#define SET_ADDRESS 0x05
#define GET_DESCRIPTOR 0x06
#define SET_DESCRIPTOR 0x07
#define GET_CONFIG 0x08
#define SET_CONFIG 0x09
#define GET_INTERFACE 0x0a
#define SET_INTERFACE 0x0b
#define SYNCH_FRAME 0x0c
#define DEVICE 0x01
#define CONFIGURATION 0x02
#define STRING 0x03
#define INTERFACE 0x04
#define ENDPOINT 0x05
#define STDCLASS 0x00
/*-------------------------------------------------------------------------
* USB Host control command definitions
*-------------------------------------------------------------------------
*/
//cmd
#define WRITE0 0x42
#define WRITE1 0xc2
#define READ 0x04
#define SETUP 0x41
#define SEND_ACK 0x20
//pid
#define PID_SETUP 0xD0
#define PID_IN 0x90
#define PID_OUT 0x10
//flag
#define DEV_TGL 0x01
#define PKT_VLD 0x04
#define PKT_ERR 0x02
#define PKT_DATA 0x40
#define PKT_SENT 0x02
#define DEV_ACK 0x20
#define DEV_NAK 0x10
#define DEV_STALL 0x08
#define DEV_TO 0x80
// Alarms
#define MP3_REQ 0x02
void usbBufRead(unsigned char *s, unsigned char c);
void usbBufWrite(unsigned char *s, unsigned char c);
void usbReset(void);
unsigned char usbXfer(unsigned char endPoint);
unsigned char ep0Xfer(void);
unsigned char epBulkSend(unsigned char *pBuffer,unsigned int len);
unsigned char epBulkRcv(unsigned char *pBuffer,unsigned int len);
unsigned char setAddress(unsigned char addr);
unsigned char setConfiguration(void);
unsigned char setDesc(void);
unsigned char enumUsbDev(BYTE usbaddr);
void usbInit(void);
void checkKeyLED(void);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -