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

📄 dc_chap9.c

📁 使用ISP1362芯片的USB_OTG参考设计源代码比较新的版本
💻 C
📖 第 1 页 / 共 2 页
字号:
				{
					start_transmit( (unsigned short *)&string_dscrptr_product, (unsigned short)sizeof ( STRING_DESCRIPTOR) );
					Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 2)\r\n" );
					break;
				}
			case 3:
				{
					start_transmit( (unsigned short *)&string_dscrptr_serialnumber, (unsigned short)sizeof ( STRING_DESCRIPTOR) );
					Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 3)\r\n" );
					break;
				}
#else
			case 1:
				{
					start_transmit( (unsigned short *)string_dscrptr_manufacturer_ptr, string_dscrptr_manufacturer_ptr->bLength );
					Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 1)\r\n" );
					break;
				}
			case 2:
				{
					start_transmit( (unsigned short *)string_dscrptr_product_ptr, string_dscrptr_product_ptr->bLength );
					Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 2)\r\n" );
					break;
				}
			case 3:
				{
					start_transmit( (unsigned short *)string_dscrptr_serialnumber_ptr, string_dscrptr_serialnumber_ptr->bLength );
					Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 3)\r\n" );
					break;
				}
#endif
			default:	
				{
					Stall_handshake();
				}
		}
	}
	else								// Unsupported Descriptor?
	{
		Stall_handshake();
		ctrl.read=0;
	}
}

void Set_Descriptor()
{
	Stall_handshake();
}

void Get_Configuration()
{
	start_transmit( &dc_config_value, 0x01 );
	Dc_printf( WHITE, CONTINUE, "Get Configuration\r\n" );
}

void Set_Configuration()
{
//	intr_1.configured=0;
	if ( wValue )
		intr_1.configured=1;
	dc_config_value=wValue;
	zero_packet();							// end of status stage

	Dc_printf( WHITE, CONTINUE, "Set Configuration (New Configuration %d)\r\n", dc_config_value );
}

void Get_Interface()
{
	start_transmit( &dc_alt_setting_value, 1 );
	Dc_printf( WHITE, CONTINUE, "Get Interface\r\n" );
}

void Set_Interface()
{
	dc_alt_setting_value=wValue;

	beep( 880.00, 1.00, DECAY, POLY );


	Comm_w16(W_Ctrl_Out_Config, FIFOEN | FFOSZ_64);
	Comm_w16(W_Ctrl_In_Config, FIFOEN | DIR_IN | FFOSZ_64);
	Comm_w16(W_Ep_Config+1, FIFODISABLE);
	Comm_w16(W_Ep_Config+2, FIFODISABLE);
	Comm_w16(W_Ep_Config+3, FIFOEN | FFOSZ_64);

#ifdef	USE_DOUBLE_BUFFER_FOR_DEV_EP4
	Comm_w16(W_Ep_Config+4, FIFOEN | DIR_IN | FFOSZ_64 | DBLBUF);
#else
	Comm_w16(W_Ep_Config+4, FIFOEN | DIR_IN | FFOSZ_64);
#endif

	Comm_w16(W_Ep_Config+5, FIFOEN | FFOISO | FFOSZ_I_512);
	Comm_w16(W_Ep_Config+6, FIFOEN | DIR_IN | FFOISO | FFOSZ_I_512);
	Comm_w16(W_Ep_Config+7, FIFODISABLE);
	Comm_w16(W_Ep_Config+8, FIFODISABLE);
	Comm_w16(W_Ep_Config+9, FIFODISABLE);
	Comm_w16(W_Ep_Config+10, FIFODISABLE);
	Comm_w16(W_Ep_Config+11, FIFODISABLE);
	Comm_w16(W_Ep_Config+12, FIFODISABLE);
	Comm_w16(W_Ep_Config+13, FIFODISABLE);
	Comm_w16(W_Ep_Config+14, FIFODISABLE);



	zero_packet();							// end of status stage

	Dc_printf( WHITE, CONTINUE, "Set Interface (Alt setting %d)\r\n", dc_alt_setting_value );
}

void Synch_Frame()
{
	zero_packet();							// end of status stage
}

void start_transmit( unsigned short *table, unsigned short len )
{
	pControlData = table;
	
	if ( wLength > len )		// if the host request data more than descriptor size
		wLength = len;		// the device should return appropriate length

	if  ( wLength > MAX_PACKET_SIZE0 )
	{
		Comm_w( W_Ctrl_In_Buf, MAX_PACKET_SIZE0, pControlData );
		wCount=MAX_PACKET_SIZE0;
	}
	else
	{
		Comm_w( W_Ctrl_In_Buf, wLength, pControlData );
		ctrl.read=0;					// end of data stage
		wCount=0;
	}
	Comm( Valid_Ctrl_In );
}

void Stall_handshake()
{
	disable_INT();
	disable_Dc();

	Comm( Stall_Ctrl_Out );
	Comm( Stall_Ctrl_In );

	enable_Dc();
	enable_INT();
	Dc_printf( WHITE, CONTINUE, "Endpoint0 Stalled\r\n" );
}

void zero_packet()
{
	Comm_w16( W_Ctrl_In_Buf, 0 );
	Comm( Valid_Ctrl_In );
}


DEVICE_DESCRIPTOR	 device_dscrptr
={
	sizeof ( DEVICE_DESCRIPTOR ),		// bLength: sizeo of this descriptor in bytes
	DEVICE,								// bDescriptorType: DEVICE=1
	0x0110,								// bcdUSB: USB1.1 (0110)
	0,									// bDeviceClass
	0,									// bDeviceSubClass
	0,									// bDeviceProtocol
	MAX_PACKET_SIZE0,					// bMaxPacketSize
//	0x0471,								// idVendor PHILIPS vendor ID:  0x0471
	PHILIPS_VID,						// idVendor PHILIPS vendor ID:  0x0471
//	0x0168,								// idProduct
	WASABI_PID,							// idProduct
	0x0100,								//bcdDevice
	1,									// iManufacturer
	2,									// iProduct
	3,									// iSerialNumber
	1									// bNumConfigurations
};

OTG_DESCRIPTOR			otg_dscrptr
={
	sizeof ( OTG_DESCRIPTOR ),
	OTG,
	0x03
};

CONFIG_DESCRIPTOR_TABLE	configuration_dscrptr_table
 = {
	 {
		sizeof ( CONFIGURATION_DESCRIPTOR ),
		CONFIGURATION,
		sizeof ( CONFIG_DESCRIPTOR_TABLE ),
		1,
		1,
		0,
		0xC0,
		0x32
	}, 
	 {
		sizeof ( INTERFACE_DESCRIPTOR ),
		INTERFACE,
		0,
		0,
		0,
		0,
		0,
		0,
		0
	},
	 {
		sizeof ( INTERFACE_DESCRIPTOR ),
		INTERFACE,
		0,
		1,
		4,
		0,
		0,
		0,
		0
	},
	{
		sizeof ( ENDPOINT_DESCRIPTOR ),
		ENDPOINT,
		0x03,
		0x02,
		0x0040,
		0
	},
	{
		sizeof ( ENDPOINT_DESCRIPTOR ),
		ENDPOINT,
		0x84,
		0x02,
		0x0040,
		0
	},
	{
		sizeof ( ENDPOINT_DESCRIPTOR ),
		ENDPOINT,
		0x05,
		0x01,
		0x0200,
		0x01
	},
	{
		sizeof ( ENDPOINT_DESCRIPTOR ),
		ENDPOINT,
		0x86,
		0x01,
		0x0200,
		0x01
	},
	{
		sizeof ( OTG_DESCRIPTOR ),
		OTG,
		0x03
	}
 };


STRING_LANGID			string_langid
={
	sizeof ( STRING_LANGID ),			// language ID
	STRING,
	{
		9, 4
	}	
};


#if 0
STRING_DESCRIPTOR		string_dscrptr_manufacturer
={
	sizeof ( STRING_DESCRIPTOR ),		// iManufacturer
	STRING,
	{
		'P',0,
		'h',0,
		'i',0,
		'l',0,
		'i',0,
		'p',0,
		's',0,
		' ',0,
		'S',0,
		'e',0,
		'm',0,
		'i',0,
		'c',0,
		'o',0,
		'n',0,
		'd',0,
		'u',0,
		'c',0,
		't',0,
		'o',0,
		'r',0,
		's',0,
		' ',0,
		'I',0,
		'S',0,
		'P',0,
		'1',0,
		'3',0,
		'6',0,
		'2',0
	}
};

STRING_DESCRIPTOR		string_dscrptr_product
={
	sizeof ( STRING_DESCRIPTOR ),		// iPdoruct
	STRING,
	{
		'W',0,
		'A',0,
		'S',0,
		'A',0,
		'B',0,
		'I',0,
		'-',0,
		'H',0,
		'o',0,
		't',0,
		'!',0,
		' ',0,
		' ',0,
		'O',0,
		'T',0,
		'G',0,
		'-',0,
		'D',0,
		'e',0,
		'm',0,
		'o',0
	}
};

STRING_DESCRIPTOR		string_dscrptr_serialnumber
={
	sizeof ( STRING_DESCRIPTOR ),		// iSerialNumber
	STRING,
	{
		'V',0,
		'e',0,
		'r',0,
		's',0,
		'i',0,
		'o',0,
		'n',0,
		' ',0,
		'X',0,
		'.',0,
		'X',0
	}
};

#else
#endif




#include	<string.h>
#include	<alloc.h>


STRING_DESCRIPTOR *str_to_str_descriptor( char *src )
{
	char			*trg_base;
	char 			*trg;
	unsigned char	length;
	unsigned char	i;
	

	length		= strlen( src );

	if ( NULL == (trg_base	= (char *)malloc( sizeof( char ) * ((length << 1) + 2) )) )
		mprintf( LIGHTRED, ABORT, "malloc failed @ str_to_str_descriptor" );
	
	trg		= trg_base;
	
	*trg++	= (length << 1) + 2;
	*trg++	= STRING;
	
	for ( i = 0; i < length; i++ )
	{
		*trg++	= *src++;
		*trg++	= 0;
	}
	
	return ( (STRING_DESCRIPTOR *)trg_base );
}




void string_descriptor_init( void )
{
//                                     0         1         2         3         4         5     
//									   0123456789012345678901234567890123456789012345678901234567<<
	char	manufacturer[]			= "Philips Semiconductors @Tokyo     Philips Japan, Ltd.";
	char	product[]				= "WASABI-Hot! \"On-The-Go\" demonstration program for ISP1362";
	char	serialnumber[ 64 ];
	
	sprintf( serialnumber, "version %s (build : %s - %s)", VERSION_NUMBER, __DATE__, __TIME__ );
	
	string_dscrptr_manufacturer_ptr		= str_to_str_descriptor( manufacturer );
	string_dscrptr_product_ptr			= str_to_str_descriptor( product );
	string_dscrptr_serialnumber_ptr		= str_to_str_descriptor( serialnumber );
}


void overwrite_OTG_descriptor( unsigned char value )
{
	*((((unsigned char *)(&configuration_dscrptr_table)) + ( sizeof ( CONFIG_DESCRIPTOR_TABLE ) )) - 1)		= value;
	*(((unsigned char *)(&otg_dscrptr) + 3) - 1)	= value;
}


















⌨️ 快捷键说明

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