亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usb_standard_requests.c

?? USB CDC and HID composite unit.
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// USB_Standard_Requests.c
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Implementation details and suggestions
//-----------------------------------------------------------------------------
//
// [HALT and STALL handling on interrupt and bulk EPs]
//	HALT is set to one by
//	- Hardware (firmware) condition
//	- SetFeature( ENDPOINT_HALT )
//
//	HALT is reset to zero by
//	- SetConfiguration(), SetInterface()
//	- ClearFeature(ENDPOINT_HALT), if the hardware (firmware) condition meets
//
//	GetStatus( ENDPOINT ) returns the HALT state of the EP.
//	STALL is always returned by the EP while the EP is in HALT.
//	Isochronous EP doesn't support HALT/STALL
//
//	This implementaion fully supports this HALT scheme, exept for Hardware HALT
//
// [Data toggle handling on interrupt and bulk EPs]
//	- Set to DATA0 on Set_Configuration and Set_Interface
//	- Set to DATA0 on ClearFeature( ENDPOINT_HALT )
//
//	This implementaion fully supports this data toggle scheme
//
// [Bus-powered/Self-powered]
//	USB device can switch the actual power source on the fly.
//	bmAttributes of the config descriptor shows the default power source.
//		D6:	0 = pure bus-powered device
//			1 = pure self-powered or switchable device.
//	bMaxPower of the config descriptor indicates power requirement from the bus in mA / 2
//		pure bus-powered and switchable device has to set this value to other than 0
//		when this value is less than or equal to 50 (=100mA), enumeration will always success
//		but when more than 50, enumeration may fail
//	GetStatus( DEVICE ) returns the current power source
//		D0: 0 = bus-powered / 1 = self-powered.
//
//	This implementaion gives a pure bus-powered device
//
// [Suspend/Resume and Remote wakeup]
//	This sequence differs according to OS
//	Windows
//		Non remote wakeup device, System hibernates
//			Suspend bus (stop SOF)	- System standby (PC) - Suspend interrupt (device)
//			...
//			bus reset				- System wake up (PC) - (no Suspend interrupt)
//			start enumeration again
//
//		Remote wakeup device
//			SetFeature( DEVICE_REMOTE_WAKEUP )
//			Suspend bus (stop SOF)	- System standby (PC) - Suspend interrupt (device)
//			...
//			Resume bus (start SOF)	- System wake up (PC) - Resume interrupt (device)
//			ClearFeature( DEVICE_REMOTE_WAKEUP )
//
//	MacOSX
//		Non remote wakeup device
//			Suspend bus (stop SOF)	- System sleep   (Mac) - Suspend interrupt (device)
//			...
//			Resume bus (start SOF)	- System wake up (Mac) - Resume interrupt (device)
//			GetStatus( ENDPOINT ) (MSC) - depends on the class
//
//		Remote wakeup device
//			SetFeature( DEVICE_REMOTE_WAKEUP ) - at the end of enumeration
//			...
//			Suspend bus (stop SOF)	- System sleep   (Mac) - Suspend interrupt (device)
//			...
//			Resume bus (start SOF)	- System wake up (Mac) - Resume interrupt (device)
//
//	Linux
//		Linux seems not yet to establish suspend well
//
// This implementation gives non-remote-wakeup device
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include "USB_Type.h"
#include "USB_Configuration.h"
#include "USB_Register.h"
#include "USB_Descriptor.h"
#include "USB_ISR.h"
#include "USB_CDC_UART.h"
#include "USB_Main.h"
#include "USB_Standard_Requests.h"

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Static Variables in this file
//-----------------------------------------------------------------------------

// These are response packets used for communication with host
static BYTE code ONES_PACKET[2] = {0x01, 0x00};		
static BYTE code ZERO_PACKET[2] = {0x00, 0x00};		

//-----------------------------------------------------------------------------
// Local function prototypes
//-----------------------------------------------------------------------------

static void Get_Status(void);
static void Clear_Feature(void);
static void Set_Feature(void);
static void Set_Address(void);
static void Get_Descriptor(void);
static void Get_Configuration(void);
static void Set_Configuration(void);
static void Get_Interface(void);
static void Set_Interface(void);
static bit  Set_Halt( BYTE endpoint, BYTE status );

//-----------------------------------------------------------------------------
// configuration conditions
//-----------------------------------------------------------------------------

#if (defined USE_EP1_OUT) && !(defined ENABLE_EP1_OUT_ISO)
	#define USE_EP1_OUT_STATUS
#endif
#if (defined USE_EP2_OUT) && !(defined ENABLE_EP2_OUT_ISO)
	#define USE_EP2_OUT_STATUS
#endif
#if (defined USE_EP3_OUT) && !(defined ENABLE_EP3_OUT_ISO)
	#define USE_EP3_OUT_STATUS
#endif
#if (defined USE_EP1_IN) && !(defined ENABLE_EP1_IN_ISO)
	#define USE_EP1_IN_STATUS
#endif
#if (defined USE_EP2_IN) && !(defined ENABLE_EP2_IN_ISO)
	#define USE_EP2_IN_STATUS
#endif
#if (defined USE_EP3_IN) && !(defined ENABLE_EP3_IN_ISO)
	#define USE_EP3_IN_STATUS
#endif

//-----------------------------------------------------------------------------
// SDCC suport
//-----------------------------------------------------------------------------
#if defined SDCC
#pragma nooverlay
#endif // SDCC

//-----------------------------------------------------------------------------
// Standard device request dispatcher
//-----------------------------------------------------------------------------

void Standard_Device_Request( void )
{
	switch(Setup.bRequest)
	{
		case GET_STATUS:		Get_Status();			break;
		case CLEAR_FEATURE:		Clear_Feature();		break;
		case SET_FEATURE:		Set_Feature();			break;
		case SET_ADDRESS:		Set_Address();			break;
		case GET_DESCRIPTOR:	Get_Descriptor();		break;
		case GET_CONFIGURATION: Get_Configuration();	break;
		case SET_CONFIGURATION: Set_Configuration();	break;
		case GET_INTERFACE:		Get_Interface();		break;
//		case SET_INTERFACE:		Set_Interface();		break;

		case STD_REQ_RESERVE1:
		case STD_REQ_RESERVE2:
		case SET_DESCRIPTOR:
		case SET_INTERFACE:
		case SYNCH_FRAME:
		default:										break;
	}
}

//-----------------------------------------------------------------------------
// Support Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Get_Status
//-----------------------------------------------------------------------------
//
// Get_Status( DEVICE )		: returns the current state of
//								a) bus-powered/self-powered
//								b) remote wakeup enabled/disabled
// Get_Status( INTERFACE )	: returns always 0x00
// Get_Status( ENDPOINT )	: returns current state of EP HALT
//
//-----------------------------------------------------------------------------

static void Get_Status(void)
{
	bit aStatus;

	// Valid when wValue equals to zero, and wLength (data length) equals to 2 
	if ( (Setup.wValue.i == 0) && (Setup.wLength.i == 2) )
	{
		// Determine if recipient was device, interface, or EP
		switch( Setup.bmRequestType )					
		{
			case IN_DEVICE:							// If recipient was device
				if ( Setup.wIndex.i == 0 )			// Valid when wIndex equals to zero
				{
					// send 0x00, indicating bus power and no remote wake-up supported
					DataPtr = (BYTE*)&ZERO_PACKET;
					setup_handled = TRUE;
				}
				break;

			case IN_INTERFACE:						// See if recipient was interface						
				// Valid if device is configured and existing interface index
				if ( (USB_State == DEV_CONFIGURED) && (Setup.wIndex.i < DSC_NUM_INTERFACE) )												
				{
					// Status packet always returns 0x00
					DataPtr = (BYTE*)&ZERO_PACKET;		
					setup_handled = TRUE;
				}
				break;

			case IN_ENDPOINT:						// See if recipient was an endpoint							
				// Make sure device is configured and index msb = 0x00
				if ((USB_State == DEV_CONFIGURED) && (Setup.wIndex.c[MSB] == 0) )
				{
					aStatus = EP_IDLE;
					switch ( Setup.wIndex.c[LSB] )
					{
#ifdef USE_EP1_OUT_STATUS
						case EP1_OUT:	aStatus = Ep_StatusOUT1;	setup_handled = TRUE;	break;		
#endif
#ifdef USE_EP2_OUT_STATUS
						case EP2_OUT:	aStatus = Ep_StatusOUT2;	setup_handled = TRUE;	break;
#endif
#ifdef USE_EP3_OUT_STATUS
						case EP3_OUT:	aStatus = Ep_StatusOUT3;	setup_handled = TRUE;	break;
#endif
#ifdef USE_EP1_IN_STATUS
						case EP1_IN:	aStatus = Ep_StatusIN1;		setup_handled = TRUE;	break;		
#endif
#ifdef USE_EP2_IN_STATUS
						case EP2_IN:	aStatus = Ep_StatusIN2;		setup_handled = TRUE;	break;
#endif
#ifdef USE_EP3_IN_STATUS
						case EP3_IN:	aStatus = Ep_StatusIN3;		setup_handled = TRUE;	break;
#endif
						default:															break;
					}
					if (aStatus == EP_HALT)
					{
						// If endpoint is halted, return 0x01,0x00
						DataPtr = (BYTE*)&ONES_PACKET;
					} else {
						// Otherwise return 0x00,0x00 to indicate endpoint active
						DataPtr = (BYTE*)&ZERO_PACKET;
					}
				}
				break;

			default:
				break;
		}
	}

	if ( setup_handled )
	{
		// Set serviced Setup Packet, Endpoint 0 intransmit mode, 
		Ep_Status0 = EP_TX;						
		DataSize = 2;						
	}
}

//-----------------------------------------------------------------------------
// Set_Halt
//-----------------------------------------------------------------------------
//
// Helper routine to set/reset HALT on the EP
//	endpoint:	Endopoint address, (EP1_OUT, EP1_IN, etc) defined in USB_Descriptor.h
//	status:		EP_IDLE / EP_HALT
//
//	Set/Reset HALT flag to the specified EP
//	Enable/disable STALL on the EP
//	Clear the data toggle
//
//-----------------------------------------------------------------------------

static bit Set_Halt( BYTE endpoint, BYTE status )
{
	BYTE controlReg;

	switch ( endpoint ) {

#ifdef USE_EP1_OUT_STATUS
		case EP1_OUT:	Ep_StatusOUT1 = status;		break;
#endif
#ifdef USE_EP2_OUT_STATUS
		case EP2_OUT:	Ep_StatusOUT2 = status;		break;
#endif
#ifdef USE_EP3_OUT_STATUS
		case EP3_OUT:	Ep_StatusOUT3 = status;		break;
#endif
#ifdef USE_EP1_IN_STATUS
		case EP1_IN:	Ep_StatusIN1  = status;		break;
#endif
#ifdef USE_EP2_IN_STATUS
		case EP2_IN:	Ep_StatusIN2  = status;		break;
#endif
#ifdef USE_EP3_IN_STATUS
		case EP3_IN:	Ep_StatusIN3  = status;		break;
#endif
		default:		return FALSE;
	}

	POLL_WRITE_BYTE (INDEX, endpoint & 0x7F);		// Set endpoint index masking IN/OUT bit
	if ( endpoint & 0x80 ) {						// IN endpoints
		if ( status == EP_IDLE )
			controlReg = (rbInCLRDT | rbInFLUSH);	// clear data toggle, SDSTL, STSTL
		else
			controlReg = (rbInCLRDT | rbInSDSTL | rbInFLUSH);	// send STALL
		POLL_WRITE_BYTE( EINCSRL, controlReg );

#if (defined ENABLE_EP1_IN_DOUBLE_BUF) || (defined ENABLE_EP2_IN_DOUBLE_BUF) || (defined ENABLE_EP3_IN_DOUBLE_BUF)
		{											// clear double buffer
			BYTE eincsrl;
			do {									// wait until FLUSH complete
				POLL_READ_BYTE( EINCSRL, eincsrl );
			} while ( eincsrl & rbInFLUSH );
			if ( eincsrl & rbInFIFONE ) {			// clear double buffer
				POLL_WRITE_BYTE( EINCSRL, controlReg );
			}
		}
#endif

	} else {										// OUT endpoints
		if ( status == EP_IDLE )
			controlReg = (rbOutCLRDT | rbOutFLUSH);	// clear data toggle, SDSTL, STSTL
		else
			controlReg = (rbOutCLRDT | rbOutSDSTL | rbOutFLUSH);	// send STALL
		POLL_WRITE_BYTE( EOUTCSRL, controlReg );

#if (defined ENABLE_EP1_OUT_DOUBLE_BUF) || (defined ENABLE_EP2_OUT_DOUBLE_BUF) || (defined ENABLE_EP3_OUT_DOUBLE_BUF)
		{											// clear double buffer
			BYTE eoutcsrl;
			do {									// wait until FLUSH complete
				POLL_READ_BYTE( EOUTCSRL, eoutcsrl );
			} while ( eoutcsrl & rbOutFLUSH );
			POLL_WRITE_BYTE( EOUTCSRL, controlReg );// clear double buffer
		}
#endif

	}
													// initialize USB-related variables
													// because the FIFO is flushed
	if ( endpoint == EP1_IN )
		IN1_FIFO_empty   = TRUE;
	if ( endpoint == EP2_IN )
		IN2_FIFO_empty   = TRUE;
	if ( endpoint == EP3_IN )
		IN2_FIFO_empty   = TRUE;
	if ( endpoint == EP1_OUT )
		OUT1_FIFO_loaded = FALSE;
	if ( endpoint == EP2_OUT )
		OUT2_FIFO_loaded = FALSE;
	if ( endpoint == EP3_OUT )
		OUT3_FIFO_loaded = FALSE;

	return TRUE;
}

//-----------------------------------------------------------------------------
// Clear_Feature
//-----------------------------------------------------------------------------
//
// Clear_Feature( DEVICE_REMOTE_WAKEUP ): disable remote wakeup
// Clear_Feature( ENDPOINT_HALT )		: clear HALT satate of the EP
//
//-----------------------------------------------------------------------------

static void Clear_Feature()
{
	if (   (USB_State == DEV_CONFIGURED)			// Make sure device is configured
		&& (Setup.wLength.i == 0) )					// and data length set to zero.
	{
		switch( Setup.bmRequestType )					
		{
			case OUT_DEVICE:						// for device, if remote wakeup is valid
				if (   (Setup.wValue.i == DEVICE_REMOTE_WAKEUP)
					&& (Setup.wIndex.i == 0) )
				{
					// disable remote wakeup here
					setup_handled = TRUE;
				}
				break;

			case OUT_ENDPOINT:						// for endpoint, if endpoint halt is valid
				if (   (Setup.wValue.i      == ENDPOINT_HALT)
					&& (Setup.wIndex.c[MSB] == 0) )
				{
					if ( Set_Halt( Setup.wIndex.c[LSB], EP_IDLE ) )
						setup_handled = TRUE;
				}
				break;

			default:
				break;
		}
	}
}

//-----------------------------------------------------------------------------
// Set_Feature
//-----------------------------------------------------------------------------
//
// Set_Feature( DEVICE_REMOTE_WAKEUP )	: enable remote wakeup
// Set_Feature( ENDPOINT_HALT )			: set HALT satate to the EP
//
//-----------------------------------------------------------------------------

static void Set_Feature(void)
{
	if (   (USB_State       == DEV_CONFIGURED)		// Make sure device is configured
		&& (Setup.wLength.i == 0) )					// and data length set to zero.
	{
		switch( Setup.bmRequestType )					
		{
			case OUT_DEVICE:						// for device, if remote wakeup is valid
				if (   (Setup.wValue.i == DEVICE_REMOTE_WAKEUP)
					&& (Setup.wIndex.i == 0) )
				{
					// enable remote wakeup here
					setup_handled = TRUE;
				}
				break;

			case OUT_ENDPOINT:						// for endpoint, if endpoint halt is valid
				if (   (Setup.wValue.i      == ENDPOINT_HALT)
					&& (Setup.wIndex.c[MSB] == 0) )
				{
					if ( Set_Halt( Setup.wIndex.c[LSB], EP_HALT ) )
						setup_handled = TRUE;
				}
				break;

			default:
				break;
		}
	}
}

//-----------------------------------------------------------------------------
// Set_Address
//-----------------------------------------------------------------------------
//
// Set device address to the USB engine
//
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品三级av| 日韩精品1区2区3区| 国产午夜精品久久久久久久| 日韩一区二区三区视频在线 | 91国产成人在线| 成人免费视频视频在线观看免费 | 欧美成人伊人久久综合网| 欧美精品aⅴ在线视频| 欧美三区免费完整视频在线观看| 91丝袜呻吟高潮美腿白嫩在线观看| 成人亚洲精品久久久久软件| 国产a视频精品免费观看| 粉嫩嫩av羞羞动漫久久久| 粉嫩av一区二区三区在线播放| 粉嫩av一区二区三区在线播放| 成人精品国产一区二区4080| av在线不卡免费看| 一本久久a久久精品亚洲| 91在线视频网址| 日本道免费精品一区二区三区| 欧美在线视频日韩| 6080亚洲精品一区二区| 日韩精品在线网站| 国产视频一区在线播放| 亚洲色图一区二区三区| 亚洲最大成人综合| 日韩精品乱码免费| 国产制服丝袜一区| 成人精品视频.| 欧美在线观看18| 日韩手机在线导航| 国产日韩成人精品| 亚洲在线观看免费| 青青草精品视频| 国产不卡视频在线播放| 91蝌蚪porny成人天涯| 欧美日本在线看| 久久一区二区视频| 一区二区三区中文在线| 日韩精品1区2区3区| 国产成a人亚洲精品| 欧美三级一区二区| 久久久久久久综合| 亚洲精品伦理在线| 伦理电影国产精品| 91丨九色丨蝌蚪丨老版| 正在播放亚洲一区| 国产精品久久久久久久久免费桃花 | 亚洲成人7777| 国产精品456露脸| 欧美色综合影院| 久久网站最新地址| 亚洲亚洲人成综合网络| 国产精品一区二区免费不卡| 91搞黄在线观看| 国产三级欧美三级日产三级99| 艳妇臀荡乳欲伦亚洲一区| 国产一区啦啦啦在线观看| 91国偷自产一区二区开放时间 | 蜜桃av一区二区三区电影| 成人深夜福利app| 69堂成人精品免费视频| 国产精品伦一区二区三级视频| 偷拍日韩校园综合在线| av网站免费线看精品| 欧美不卡123| 亚洲一区视频在线| 国产经典欧美精品| 欧美一级理论性理论a| 亚洲欧美色一区| 国产乱子伦视频一区二区三区 | 国产成人精品免费视频网站| 欧美日韩国产综合视频在线观看| 国产丝袜在线精品| 久久精品国产亚洲5555| 欧美日韩视频在线一区二区| 欧美国产亚洲另类动漫| 久久精品国产一区二区三| 欧美日韩免费一区二区三区 | 综合激情成人伊人| 国产一区二区不卡| 日韩欧美在线1卡| 亚洲福利视频三区| 色屁屁一区二区| 国产精品国产三级国产专播品爱网 | 高清国产一区二区三区| 欧美电影免费观看高清完整版| 亚瑟在线精品视频| 91激情在线视频| 亚洲精品免费播放| 91麻豆成人久久精品二区三区| 欧美韩国一区二区| 国产高清视频一区| 久久免费美女视频| 狠狠色狠狠色综合系列| 日韩一区二区三区观看| 日韩在线一区二区三区| 欧美喷水一区二区| 亚洲国产日韩a在线播放性色| 色哟哟在线观看一区二区三区| 中文字幕一区日韩精品欧美| 丁香五精品蜜臀久久久久99网站| 久久精品视频在线免费观看 | 精品日本一线二线三线不卡| 日韩精品电影一区亚洲| 欧美日韩精品一区二区| 亚洲国产aⅴ天堂久久| 欧美日韩五月天| 日韩av中文字幕一区二区| 91精品国产综合久久久久久 | 成人app下载| 国产精品动漫网站| 色综合久久66| 亚洲综合色视频| 欧美日韩三级视频| 免费不卡在线视频| 精品乱码亚洲一区二区不卡| 狠狠色综合播放一区二区| 国产午夜一区二区三区| av激情亚洲男人天堂| 亚洲欧美成人一区二区三区| 在线观看免费一区| 日韩影视精彩在线| 精品99一区二区三区| 国产ts人妖一区二区| 国产精品国产三级国产普通话三级 | 欧美国产精品一区二区| 不卡高清视频专区| 亚洲日本在线观看| 色综合一个色综合亚洲| 亚洲3atv精品一区二区三区| 日韩午夜在线播放| 国产精品一区二区无线| 国产精品欧美极品| 色综合久久综合中文综合网| 夜夜嗨av一区二区三区网页 | 亚洲欧美在线另类| 欧美色电影在线| 国产乱国产乱300精品| 亚洲摸摸操操av| 91麻豆精品91久久久久同性| 国产精品一区专区| 一区二区在线看| 欧美一级艳片视频免费观看| 国产成+人+日韩+欧美+亚洲| 亚洲综合av网| 欧美精品一区男女天堂| 波多野结衣视频一区| 久久精品一区二区三区不卡| 国产美女精品在线| 亚洲欧美成aⅴ人在线观看| 91精品黄色片免费大全| 成人性生交大片免费看视频在线 | 日韩精品每日更新| 国产精品免费av| 欧美狂野另类xxxxoooo| 国产91精品一区二区麻豆网站| 亚洲一区二区精品3399| 久久精品一区二区三区不卡| 欧美性大战久久久久久久蜜臀| 国内精品免费**视频| 亚洲综合成人在线| 国产三级一区二区| 在线不卡一区二区| 99精品视频一区| 老司机精品视频线观看86| 亚洲日本在线天堂| 欧美精品一区二区三区在线播放| 欧美视频一区二区在线观看| 国产成人精品www牛牛影视| 石原莉奈在线亚洲三区| 成人欧美一区二区三区黑人麻豆| 日韩欧美色电影| 欧美日韩你懂的| 一本色道a无线码一区v| 国产成人在线网站| 日本午夜一本久久久综合| 亚洲精品乱码久久久久久久久 | 久久久久久久综合| 欧美一级午夜免费电影| 在线观看91视频| 波多野结衣中文字幕一区| 国产美女精品在线| 麻豆精品精品国产自在97香蕉 | 一本到不卡精品视频在线观看| 国产综合色精品一区二区三区| 午夜国产精品影院在线观看| 亚洲桃色在线一区| 中文字幕一区二区三区在线观看| 精品国产乱码久久久久久图片| 在线播放国产精品二区一二区四区| 99这里都是精品| 成人激情文学综合网| 国产传媒日韩欧美成人| 国产一区二区三区久久悠悠色av| 麻豆精品一区二区综合av| 亚洲成人777| 天天av天天翘天天综合网| 一区二区三区中文字幕| 亚洲精品成人天堂一二三|