CH552/examples/USB/Device/VendorDefinedDev.C

336 lines
14 KiB
C++
Raw Normal View History

2018-10-17 10:44:45 +02:00
/********************************** (C) COPYRIGHT *******************************
* File Name : VendorDefinedDev.C
* Author : WCH
* Version : V1.0
* Date : 2017/01/20
* Description : CH554ģ<EFBFBD><EFBFBD>USB Module(CH554),<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CH37XDRV<EFBFBD><EFBFBD><EFBFBD>߰<EFBFBD>װISPTool<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD>ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><EFBFBD>Ͷ˵<EFBFBD>1
<EFBFBD>ж<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>372DEBUG.EXE<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><EFBFBD>߽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
*******************************************************************************/
#include "./Public/CH554.H"
#include "./Public/Debug.H"
#include <stdio.h>
#include <string.h>
#define THIS_ENDP0_SIZE DEFAULT_ENDP0_SIZE
// <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UINT8C MyDevDescr[] = { 0x12, 0x01, 0x10, 0x01,
0xFF, 0x80, 0x55, THIS_ENDP0_SIZE,
0x48, 0x43, 0x37, 0x55, // <20><><EFBFBD><EFBFBD>ID<49>Ͳ<EFBFBD>ƷID
0x00, 0x01, 0x01, 0x02,
0x00, 0x01 };
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UINT8C MyCfgDescr[] = { 0x09, 0x02, 0x27, 0x00, 0x01, 0x01, 0x00, 0x80, 0x32,
0x09, 0x04, 0x00, 0x00, 0x03, 0xFF, 0x80, 0x55, 0x00,
0x07, 0x05, 0x82, 0x02, 0x40, 0x00, 0x00,
0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00,
0x07, 0x05, 0x81, 0x03, 0x40, 0x00, 0x00 };
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UINT8C MyLangDescr[] = { 0x04, 0x03, 0x09, 0x04 };
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
UINT8C MyManuInfo[] = { 0x0E, 0x03, 'w', 0, 'c', 0, 'h', 0, '.', 0, 'c', 0, 'n', 0 };
// <20><>Ʒ<EFBFBD><C6B7>Ϣ
UINT8C MyProdInfo[] = { 0x0C, 0x03, 'C', 0, 'H', 0, '5', 0, '5', 0, '4', 0 };
UINT8 UsbConfig = 0; // USB<53><42><EFBFBD>ñ<EFBFBD>־
UINT8X Ep0Buffer[THIS_ENDP0_SIZE+2 >= MAX_PACKET_SIZE ? MAX_PACKET_SIZE : THIS_ENDP0_SIZE+2]; // OUT&IN
UINT8X Ep1Buffer[MAX_PACKET_SIZE]; // IN
UINT8X Ep2Buffer[2*MAX_PACKET_SIZE]; // OUT+IN
#define UsbSetupBuf ((PUSB_SETUP_REQ)Ep0Buffer)
#pragma NOAREGS
void USB_DeviceInterrupt( void ) interrupt INT_NO_USB using 1 /* USB<53>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ʹ<>üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>1 */
{
UINT8 i, len;
static UINT8 SetupReqCode, SetupLen;
static PUINT8 pDescr;
if ( UIF_TRANSFER ) { // USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if ( U_IS_NAK ) { // not enable for this example
// switch ( USB_INT_ST & ( MASK_UIS_TOKEN | MASK_UIS_ENDP ) ) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺͶ˵<CDB6><CBB5><EFBFBD>
// case UIS_TOKEN_OUT | 2: // endpoint 2# <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>´<EFBFBD>
// break;
// case UIS_TOKEN_IN | 2: // endpoint 2# <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>ϴ<EFBFBD>
// break;
// case UIS_TOKEN_IN | 1: // endpoint 1# <20>ж϶˵<CFB6><CBB5>ϴ<EFBFBD>
// break;
// default:
// break;
// }
}
else {
switch ( USB_INT_ST & ( MASK_UIS_TOKEN | MASK_UIS_ENDP ) ) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƺͶ˵<CDB6><CBB5><EFBFBD>
case UIS_TOKEN_OUT | 2: // endpoint 2# <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>´<EFBFBD>
if ( U_TOG_OK ) { // <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// UEP2_CTRL ^= bUEP_R_TOG; // <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ת
len = USB_RX_LEN;
for ( i = 0; i < len; i ++ ) {
Ep2Buffer[MAX_PACKET_SIZE+i] = Ep2Buffer[i] ^ 0xFF; // OUT<55><54><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>IN<49>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
}
UEP2_T_LEN = len;
UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK;// <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
}
break;
case UIS_TOKEN_IN | 2: // endpoint 2# <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>ϴ<EFBFBD>
// UEP2_CTRL ^= bUEP_T_TOG; // <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ת
UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_NAK; // <20><>ͣ<EFBFBD>ϴ<EFBFBD>
break;
case UIS_TOKEN_IN | 1: // endpoint 1# <20>ж϶˵<CFB6><CBB5>ϴ<EFBFBD>
// UEP1_CTRL ^= bUEP_T_TOG; // <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ת
UEP1_CTRL = UEP1_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_NAK; // <20><>ͣ<EFBFBD>ϴ<EFBFBD>
break;
case UIS_TOKEN_SETUP | 0: // endpoint 0# SETUP
len = USB_RX_LEN;
if ( len == sizeof( USB_SETUP_REQ ) ) { // SETUP<55><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SetupLen = UsbSetupBuf->wLengthL;
if ( UsbSetupBuf->wLengthH || SetupLen > 0x7F ) SetupLen = 0x7F;// <20><><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
len = 0; // Ĭ<><C4AC>Ϊ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>
SetupReqCode = UsbSetupBuf->bRequest;
if ( ( UsbSetupBuf->bRequestType & USB_REQ_TYP_MASK ) != USB_REQ_TYP_STANDARD ) { /* <20>DZ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD> */
len = 0xFF;
}
else { // <20><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
switch( SetupReqCode ) { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case USB_GET_DESCRIPTOR:
switch( UsbSetupBuf->wValueH ) {
case 1: // <20><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pDescr = (PUINT8)( &MyDevDescr[0] );
len = sizeof( MyDevDescr );
break;
case 2: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pDescr = (PUINT8)( &MyCfgDescr[0] );
len = sizeof( MyCfgDescr );
break;
case 3: // <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch( UsbSetupBuf->wValueL ) {
case 1:
pDescr = (PUINT8)( &MyManuInfo[0] );
len = sizeof( MyManuInfo );
break;
case 2:
pDescr = (PUINT8)( &MyProdInfo[0] );
len = sizeof( MyProdInfo );
break;
case 0:
pDescr = (PUINT8)( &MyLangDescr[0] );
len = sizeof( MyLangDescr );
break;
default:
len = 0xFF; // <20><>֧<EFBFBD>ֵ<EFBFBD><D6B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
break;
default:
len = 0xFF; // <20><>֧<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
}
if ( SetupLen > len ) SetupLen = len; // <20><><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>
len = SetupLen >= THIS_ENDP0_SIZE ? THIS_ENDP0_SIZE : SetupLen; // <20><><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><E4B3A4>
memcpy( Ep0Buffer, pDescr, len ); /* <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
SetupLen -= len;
pDescr += len;
break;
case USB_SET_ADDRESS:
SetupLen = UsbSetupBuf->wValueL; // <20>ݴ<EFBFBD>USB<53><EFBFBD><E8B1B8>ַ
break;
case USB_GET_CONFIGURATION:
Ep0Buffer[0] = UsbConfig;
if ( SetupLen >= 1 ) len = 1;
break;
case USB_SET_CONFIGURATION:
UsbConfig = UsbSetupBuf->wValueL;
break;
case USB_CLEAR_FEATURE:
if ( ( UsbSetupBuf->bRequestType & USB_REQ_RECIP_MASK ) == USB_REQ_RECIP_ENDP ) { // <20>˵<EFBFBD>
switch( UsbSetupBuf->wIndexL ) {
case 0x82:
UEP2_CTRL = UEP2_CTRL & ~ ( bUEP_T_TOG | MASK_UEP_T_RES ) | UEP_T_RES_NAK;
break;
case 0x02:
UEP2_CTRL = UEP2_CTRL & ~ ( bUEP_R_TOG | MASK_UEP_R_RES ) | UEP_R_RES_ACK;
break;
case 0x81:
UEP1_CTRL = UEP1_CTRL & ~ ( bUEP_T_TOG | MASK_UEP_T_RES ) | UEP_T_RES_NAK;
break;
case 0x01:
UEP1_CTRL = UEP1_CTRL & ~ ( bUEP_R_TOG | MASK_UEP_R_RES ) | UEP_R_RES_ACK;
break;
default:
len = 0xFF; // <20><>֧<EFBFBD>ֵĶ˵<C4B6>
break;
}
}
else len = 0xFF; // <20><><EFBFBD>Ƕ˵㲻֧<E3B2BB><D6A7>
break;
case USB_GET_INTERFACE:
Ep0Buffer[0] = 0x00;
if ( SetupLen >= 1 ) len = 1;
break;
case USB_GET_STATUS:
Ep0Buffer[0] = 0x00;
Ep0Buffer[1] = 0x00;
if ( SetupLen >= 2 ) len = 2;
else len = SetupLen;
break;
default:
len = 0xFF; // <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
#ifdef DE_PRINTF
printf("ErrEp0ReqCode=%02X\n",(UINT16)SetupReqCode);
#endif
break;
}
}
}
else {
len = 0xFF; // SETUP<55><50><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>
#ifdef DE_PRINTF
printf("ErrEp0ReqSize\n");
#endif
}
if ( len == 0xFF ) { // <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
SetupReqCode = 0xFF;
UEP0_CTRL = bUEP_R_TOG | bUEP_T_TOG | UEP_R_RES_STALL | UEP_T_RES_STALL; // STALL
}
else if ( len <= THIS_ENDP0_SIZE ) { // <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>״̬<D7B4>׶η<D7B6><CEB7><EFBFBD>0<EFBFBD><30><EFBFBD>Ȱ<EFBFBD>
UEP0_T_LEN = len;
UEP0_CTRL = bUEP_R_TOG | bUEP_T_TOG | UEP_R_RES_ACK | UEP_T_RES_ACK; // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>DATA1
}
else { // <20>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
UEP0_T_LEN = 0; // <20><>Ȼ<EFBFBD><C8BB>δ<EFBFBD><CEB4>״̬<D7B4>׶Σ<D7B6><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰԤ<C7B0><D4A4><EFBFBD>ϴ<EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>״̬<D7B4>׶<EFBFBD>
UEP0_CTRL = bUEP_R_TOG | bUEP_T_TOG | UEP_R_RES_ACK | UEP_T_RES_ACK; // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>DATA1
}
break;
case UIS_TOKEN_IN | 0: // endpoint 0# IN
switch( SetupReqCode ) {
case USB_GET_DESCRIPTOR:
len = SetupLen >= THIS_ENDP0_SIZE ? THIS_ENDP0_SIZE : SetupLen; // <20><><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><E4B3A4>
memcpy( Ep0Buffer, pDescr, len ); /* <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
SetupLen -= len;
pDescr += len;
UEP0_T_LEN = len;
UEP0_CTRL ^= bUEP_T_TOG; // <20><>ת
break;
case USB_SET_ADDRESS:
USB_DEV_AD = USB_DEV_AD & bUDA_GP_BIT | SetupLen;
UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
break;
default:
UEP0_T_LEN = 0; // ״̬<D7B4>׶<EFBFBD><D7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϻ<D0B6><CFBB><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD>ϴ<EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD>
UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
break;
}
break;
case UIS_TOKEN_OUT | 0: // endpoint 0# OUT
switch( SetupReqCode ) {
// case download:
// if ( U_TOG_OK ) { // <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// UEP0_CTRL ^= bUEP_R_TOG; // <20><>ת
// //<2F><>ȡ<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD>;
// //UEP0_CTRL = UEP0_CTRL & bUEP_R_TOG | bUEP_T_TOG | UEP_R_RES_ACK | UEP_T_RES_ACK; // Ԥ<><D4A4><EFBFBD>ϴ<EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>DATA1<41>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>״̬<D7B4>׶<EFBFBD>
// }
// break;
case USB_GET_DESCRIPTOR:
default:
if ( U_TOG_OK ) { // <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// if ( USB_RX_LEN ) control_status_error;
// else control_ok; // <20>յ<EFBFBD>0<EFBFBD><30><EFBFBD>Ȱ<EFBFBD><C8B0><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>/<2F>ϴ<EFBFBD>OK
}
// else control_status_error;
UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK; // ׼<><D7BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD>
break;
}
break;
default:
break;
}
}
UIF_TRANSFER = 0; // <20><><EFBFBD>жϱ<D0B6>־
}
else if ( UIF_BUS_RST ) { // USB<53><42><EFBFBD>߸<EFBFBD>λ
UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
UEP1_CTRL = bUEP_AUTO_TOG | UEP_R_RES_ACK;
UEP2_CTRL = bUEP_AUTO_TOG | UEP_R_RES_ACK | UEP_T_RES_NAK;
USB_DEV_AD = 0x00;
UIF_SUSPEND = 0;
UIF_TRANSFER = 0;
UIF_BUS_RST = 0; // <20><><EFBFBD>жϱ<D0B6>־
}
else if ( UIF_SUSPEND ) { // USB<53><42><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UIF_SUSPEND = 0;
if ( USB_MIS_ST & bUMS_SUSPEND ) { // <20><><EFBFBD><EFBFBD>
#ifdef DE_PRINTF
printf( "zz" ); // ˯<><CBAF>״̬
#endif
while ( XBUS_AUX & bUART0_TX ); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SAFE_MOD = 0x55;
SAFE_MOD = 0xAA;
WAKE_CTRL = bWAK_BY_USB | bWAK_RXD0_LO; // USB<53><42><EFBFBD><EFBFBD>RXD0<44><30><EFBFBD>ź<EFBFBD>ʱ<EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD>
PCON |= PD; // ˯<><CBAF>
SAFE_MOD = 0x55;
SAFE_MOD = 0xAA;
WAKE_CTRL = 0x00;
}
else { // <20><><EFBFBD><EFBFBD>
}
}
else { // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USB_INT_FG = 0xFF; // <20><><EFBFBD>жϱ<D0B6>־
}
}
/*******************************************************************************
* Function Name : InitUSB_Device()
* Description : USB<EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD>жϿ<EFBFBD><EFBFBD><EFBFBD>
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void InitUSB_Device( void ) // <20><>ʼ<EFBFBD><CABC>USB<53>
{
IE_USB = 0;
USB_CTRL = 0x00; // <20><><EFBFBD>趨ģʽ
UEP4_1_MOD = bUEP1_TX_EN; // <20>˵<EFBFBD>1<EFBFBD>ϴ<EFBFBD>IN
UEP2_3_MOD = bUEP2_RX_EN | bUEP2_TX_EN; // <20>˵<EFBFBD>2<EFBFBD>´<EFBFBD>OUT<55><54><EFBFBD>ϴ<EFBFBD>IN
UEP0_DMA = Ep0Buffer;
UEP1_DMA = Ep1Buffer;
UEP2_DMA = Ep2Buffer;
UEP0_CTRL = UEP_R_RES_ACK | UEP_T_RES_NAK;
UEP1_CTRL = bUEP_AUTO_TOG | UEP_R_RES_ACK;
UEP2_CTRL = bUEP_AUTO_TOG | UEP_R_RES_ACK | UEP_T_RES_NAK;
USB_DEV_AD = 0x00;
UDEV_CTRL = bUD_PD_DIS; // <20><>ֹDP/DM<44><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USB_CTRL = bUC_DEV_PU_EN | bUC_INT_BUSY | bUC_DMA_EN; // <20><><EFBFBD><EFBFBD>USB<53><EFBFBD><E8B1B8>DMA<4D><41><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ڼ<EFBFBD><DABC>жϱ<D0B6>־δ<D6BE><CEB4><EFBFBD><EFBFBD>ǰ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>NAK
UDEV_CTRL |= bUD_PORT_EN; // <20><><EFBFBD><EFBFBD>USB<53>˿<EFBFBD>
USB_INT_FG = 0xFF; // <20><><EFBFBD>жϱ<D0B6>־
USB_INT_EN = bUIE_SUSPEND | bUIE_TRANSFER | bUIE_BUS_RST;
IE_USB = 1;
}
main( ) {
UINT8 i;
CfgFsys();
mDelaymS(5); //<2F>޸<EFBFBD><DEB8><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʱ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>Ƶ<EFBFBD>ȶ<EFBFBD>
mInitSTDIO( ); /* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><30><CEAA><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD> */
#ifdef DE_PRINTF
printf( "Start @ChipID=%02X\n", (UINT16)CHIP_ID );
#endif
InitUSB_Device( );
EA = 1;
while ( 1 ) {
i = getkey( );
printf( "%c", (UINT8)i );
if ( i >= '0' && i <= 'z' ) {
memcpy( Ep1Buffer, (PUINT8C)(i-'0'), MAX_PACKET_SIZE ); /* <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD> */
UEP1_T_LEN = i-'0' > 8 ? 8 : i-'0';
UEP1_CTRL = UEP1_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK;
}
}
}