⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb.h

📁 sl811hs 的驱动
💻 H
字号:
/////////////////////////////////////Hardware define//////////////////////////////////////

//*****************************************************************************************
//USB Control Register Memory
//*****************************************************************************************
//USBControl0 Description
#define EP0AControl 0x00 	//Control Register0
#define EP0AAddress 0x01 	//Address Register0
#define EP0AXferLen 0x02 	//Transfer length Register0
#define EP0AStatus 	0x03 	//Status Register0
#define EP0ACounter 0x04 	//Counter Register0
//USBControl1 Description
#define EP0BControl	0x08 	//Control Register1
#define EP0BAddress 0x09 	//Address Register1
#define EP0BXferLen 0x0a 	//Transfer length Register1
#define EP0BStatus 	0x0b 	//Status Register1
#define EP0BCounter 0x0c 	//Counter Register1

#define EP1AControl    		0x10	// EP1 Endpoint Registers (set A)
#define EP1AAddress    		0x11
#define EP1AXferLen    		0x12
#define EP1AStatus     		0x13
#define EP1ACounter    		0x14

#define EP2AControl    		0x20	// EP1 Endpoint Registers (set A)
#define EP2AAddress    		0x21
#define EP2AXferLen    		0x22
#define EP2AStatus     		0x23
#define EP2ACounter    		0x24

#define EP0A_Slave_Buf		0x40					// Start address for EP0 buffer
#define EP1A_Slave_Buf		EP0A_Slave_Buf+EP0_LEN	// Start address for EP1A buffer
#define EP2A_Slave_Buf		0xc0

//*****************************************************************************************
//SL811HS Control Register Memory Map
//*****************************************************************************************
#define CtrlReg 	0x05 	//Control Register
#define IntEna 		0x06 	//Interrupt Enable
#define USBAddress	0x07
#define IntStatus	0x0d 	//Interrupt Status
#define DATASet 	0x0e 	//DATA Set
#define CSOFcnt 	0x0f 	//SOF Counter High and Control Register

//*****************************************************************************************
//DATA0/DATA1 Mapping
//*****************************************************************************************
#define cMemStart 	0x10 	//Host Memory Start
#define ubufA 		0x80 	//Buffer A address for DATA0
#define ubufB 		0xc0 	//Buffer B address for DATA1
#define uxferLen 	0x40 	//Xfer Length
#define sMemSize 	0xc0 	//Total SL811HS memory size
#define cMemEnd 	256  	//Upper limit of memory
//*****************************************************************************************
//Buffers use for configuration and Vendor Specific command
//*****************************************************************************************

#define EP0Buf 		0x40 	//Endpoint 0 Buffer where SL811HS memory starts
#define EP0Len 		0x40 	//Length of config buffer EP0Buf

//*****************************************************************************************
//SL811HS Code Bit Definitions
//*****************************************************************************************
#define DATA0_WR 	0x07 	//Arm+Enable+tranmist to Host+DATA0
#define DATA1_WR 	0x05 	//Arm+Enable+tranmist to Host on DATA1
#define ZDATA0_WR 	0x47 	//Arm+Transaction Ignored+tranmist to Host+DATA0
#define ZDATA1_WR 	0x45 	//Arm+Transaction Ignored+tranmist to Host+DATA1
#define DATA0_RD 	0x03 	//Arm+Enable+received from Host+DATA0
#define DATA1_RD 	0x43	//Arm+Enable+received from Host+DATA1
#define PID_SOF 	0xa5 	//SOF Token
#define PID_SETUP 	0x2d 	//SETUP Token
#define PID_IN 		0x69	//IN Token
#define PID_OUT 	0xe1 	//OUT Token
#define PID_PRE 	0x3c 	//PRE Token
#define PID_NAK 	0x5a 	//NAK Token
#define PID_STALL 	0x1e 	//STALL Token
#define PID_DATA0 	0xc3 	//DATA0 Token
#define PID_DATA1 	0X4b 	//DATA1 Token
#define MAX_RETRY 	0xffff 	//Number of Re-try

/////////////////////////////////////Software define//////////////////////////////////////

//*****************************************************************************************
// Constant Defines
//*****************************************************************************************
#define NULL		0
#define TRUE   		1
#define FALSE  		0

//----------------------------------
// SL811S Slave Device Specific
//----------------------------------
#define EP0_LEN 			64		// EP0 MaxPktSize 
#define EP1_LEN 			64		// EP1 MaxPktSize---edit on 04-07-22:47
#define EP2_LEN 			64		// EP2 MaxPktSize---edit on 04-07-22:47 
#define MAXIFCNUM			8		// Maximum of 8 interfaces
#define TIME_OUT			5		// Task time out


//----------------------------------
// EPx Control Register Bit Mask
//----------------------------------
#define DATA0_OUT    		0x03   	// (Data0 + OUT/SETUP + Enable + Arm)
#define DATA1_OUT    		0x43   	// (Data1 + OUT/SETUP + Enable + Arm)
#define DATA0_IN    		0x07   	// (Data0 + IN + Enable + Arm)
#define DATA1_IN    		0x47   	// (Data1 + IN + Enable + Arm)
#define DATAX	    		0x40   	// Data sequence bits
#define ENABLE_ISO    		0x10   	// Enable ISO on endpoint
#define SEND_STALL    		0x27   	// (STALL + IN + Enable + Arm)
#define DIRECTION 			0x04   	// OUT - '0', receive from host
									// IN  - '1', transmit to host	

#define DATA0_IN_ENABLE		0x07   	// (Data0 + IN + Enable)
#define DATA0_IN_DISABLE	0x04   	// (Data0 + IN + Disable)
#define DATA0_OUT_ENABLE    0x03
#define DATA0_OUT_DISABLE	0x00

//----------------------------------
// Interrupt Register Bit Masks
//----------------------------------
#define EP0_DONE			0x01
#define EP1_DONE			0x02
#define EP2_DONE			0x04
#define EP3_DONE			0x08
#define DMA_DONE			0x10
#define SOF_DONE			0x20
#define USB_RESET_DONE		0x40

//----------------------------------
// EPx Status Register Bit Masks
//----------------------------------
#define EP_ACK				0x01
#define EP_ERROR			0x02
#define EP_TIMEOUT			0x04
#define EP_SEQUENCE			0x08
#define EP_SETUP			0x10
#define EP_OVERFLOW			0x20
#define EP_NAK				0x40
#define EP_STALL			0x80



//----------------------------------
// Standard Chapter 9 definition
//----------------------------------
#define STD_REQUEST			0x00
#define CLASS_REQUEST		0x01
#define VENDOR_REQUEST		0x02
#define RECIPIENT_DEV		0x00
#define RECIPIENT_IFC		0x01
#define RECIPIENT_ENP		0x02

#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
#define HIDCLASS        	0x03
#define HUBCLASS	 		0x09  

//----------------------------------
// Class Descriptor for HID 
//----------------------------------
#define GET_REPORT      	0x01
#define GET_IDLE        	0x02
#define GET_PROTOCOL    	0x03

#define SET_REPORT      	0x09
#define SET_IDLE        	0x0A
#define SET_PROTOCOL    	0x0B

#define HID_DEV         	0x21
#define HID_REPORT      	0x22
#define HID_PHYSICAL    	0x23

#define INPUT        		0x01
#define OUPUT     	    	0x02
#define FEATURE    	   		0x03

#define NONE	        	0x00
#define KEYBOARD        	0x01
#define MOUSE	        	0x02




/////////////////////////////////////Description//////////////////////////////////////
//*****************************************************************************************
// Constant specific to USB Slave Descriptors
//*****************************************************************************************
#define DEV_LEN		18			// Device Descriptor Length
#define HID_LEN		9			// HID-Class Descriptor Length
#define CFG_LEN		41			// Configuration Descriptor Length
#define REP_LEN		57			// HID Report Descriptor Length


//---------------------------------------------------------------------------------------------------------------------
// DEVICE DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
B8 const Dev_Descp[] = {	DEV_LEN,			// bLength: Size of descriptor
							0x01,				// bDescriptorType: Device	
							0x10,0x01,			// bcdUSB: USB 1.1
							0x00,				// bDeviceClass: none
							0x00,				// bDeviceSubClass: none
							0x00,				// bDeviceProtocol: none
							EP0_LEN,			// bMaxPacketSize0: 8/64 bytes
							0xB4,0x04,			// idVendor: 0x04B4 - Cypress
							0x11,0x08,			// idProduct: 0x1111 - SL811S
							0x00,0x01,			// bcdDevice: version 1.0
							0x01,				// iManufacturer: Cypress
							0x02,				// iProduct: Cypress SL811S - HID Consumer Control
							0x00,				// iSerialNumber: none
							0x01};				// bNumConfigurations: 1


//---------------------------------------------------------------------------------------------------------------------
// CONFIGURATION DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
B8	const Cfg_Descp[] = {	0x09,				// bLength: Size of descriptor
							0x02,				// bDescriptorType: Configuration	
							CFG_LEN,0x00,		// wTotalLength: Cfg+Ifc+Class+Ep = 34 bytes
							0x01,				// bNumInterfaces: 1 interface
							0x01,				// bConfigurationValue: 1
							0x00,				// iConfiguration: none
							0x60,				// bmAttributes: bus-powered, remote-wakeup  edit on 7-21
							0x32,				// MaxPower: 100mA

//---------------------------------------------------------------------------------------------------------------------
// INTERFACE DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
							0x09,				// bLength: Size of descriptor
							0x04,				// bDescriptorType: Interface
							0x00,				// bInterfaceNumber: #0
							0x00,				// bAlternateSetting: #0
							0x02,				// bNumEndpoints: 2
							0x03,				// bInterfaceClass: HID-class
							0x00,				// bInterfaceSubClass: none
							0x00,				// bInterfaceProtocol: none
							0x00,				// iInterface: none

//---------------------------------------------------------------------------------------------------------------------
// HID-CLASS DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
							0x09,				// bLength: Size of descriptor
							0x21,				// bDescriptorType: HID Class
							0x00,0x01,			// bcdHID: HID Class version 1.1
							0x00,				// bCountryCode: none
							0x01,				// bNumDescriptors: 1 report descp
							0x22,				// bDescriptorType: report descriptor type
							REP_LEN,0x00,		// wDescriptorLength: 31 bytes

//---------------------------------------------------------------------------------------------------------------------
// ENDPOINT DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
							0x07,				// bLength: Size of descriptor
							0x05,				// bDescriptorType: Endpoint
							0x81,				// bEndpointAddress: IN, EP1
							0x02,				// bmAttributes: Bulk
							EP1_LEN,0x00,		// wMaxPacketSize: 
							0x0A,				// bInterval: 10ms
							
//---------------------------------------------------------------------------------------------------------------------
// ENDPOINT DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------							
							0x07,				// bLength: Size of descriptor
							0x05,				// bDescriptorType: Endpoint
							0x02,				// bEndpointAddress: OUT, EP2
							0x02,				// bmAttributes: Bulk
							EP2_LEN,0x00,		// wMaxPacketSize: 
							0x0A};				// bInterval: 10ms
							

//---------------------------------------------------------------------------------------------------------------------
// REPORT DESCRIPTOR
//--------------------------------------------------------------------------------------------------------------------------
// Bytes |  Bit 7  |  Bit 6  |  Bit 5  |  Bit 4  |  Bit 3  |  Bit 2  |  Bit 1  |  Bit 0  | 
//--------------------------------------------------------------------------------------------------------------------------
//   0   |  ScanNT |  ScanPT |  BassB   |  Stop   |  Play   |  VolDn  |  VolUp  |  Mute	 | << MultiMedia Audio Control
//--------------------------------------------------------------------------------------------------------------------------
//   1   |  Email  |  BookM  | Refresh |  Stop   | Forward |  Back   |   Home  |  Search | << Internet Application Control
//--------------------------------------------------------------------------------------------------------------------------
B8	const Rep_Descp[] = {	0x05, 0x0C,			// USAGE_PAGE (Consumer Devices)
							0x09, 0x01,			// USAGE (Consumer Control)
							0xA1, 0x01,			// COLLECTION (Application)
							0x15, 0x00,			//  LOGICAL_MINIMUM (0)
							0x25, 0x01,			//  LOGICAL_MAXIMUM (1)
							0x09, 0xE2,			//    USAGE (Mute)					// 	 MultiMedia Audio Control
							0x09, 0xE9,			//    USAGE (Volume Up)
							0x09, 0xEA,			//    USAGE (Volume Down)
							0x09, 0xCD,			//    USAGE (Play/Pause)
							0x09, 0xB7,			//    USAGE (Stop)
							0x09, 0xB6,			//    USAGE (Scan Previous Track)
							0x09, 0xB5,			//    USAGE (Scan Next Track)
							0x09, 0xE5, 		//    USAGE (Bass Boost)								
							0x0A, 0x21, 0x02,	//    USAGE (AC Search)				// 	 Internet Application Control
							0x0A, 0x23, 0x02,	//    USAGE (AC Home)
							0x0A, 0x24, 0x02,	//    USAGE (AC Back)
							0x0A, 0x25, 0x02,	//    USAGE (AC Forward)
							0x0A, 0x26, 0x02,	//    USAGE (AC Stop)
							0x0A, 0x27, 0x02,	//    USAGE (AC Refresh)
							0x0A, 0x2A, 0x02,	//    USAGE (AC Favorites/Bookmark)
							0x0A, 0x8A, 0x01,	//    USAGE (AL Email Reader)
							0x75, 0x01,      	//  REPORT_SIZE (1)
							0x95, 0x10, 		//  REPORT_COUNT (16)
							0x81, 0x06,			//  INPUT (Data,Var,Rel,Prf)
							0xC0};				// END_COLLECTION

//---------------------------------------------------------------------------------------------------------------------
// STRING DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
B8 const LangString[] = {4,3,9,4};
B8 const MfgString[]  = {16,3,'C',0,'y',0,'p',0,'r',0,'e',0,'s',0,'s',0};
B8 const ProdString[] = {76,3,'C',0,'y',0,'p',0,'r',0,'e',0,'s',0,'s',0,' ',0,'S',0,'L',0,'8',0,'1',0,'1',0,'S',0,' ',0,'-',0,' ',0,'H',0,'I',0,'D',0,' ',0,'C',0,'o',0,'n',0,'s',0,'u',0,'m',0,'e',0,'r',0,' ',0,'C',0,'o',0,'n',0,'t',0,'r',0,'o',0,'l',0};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -