//===================================================================//
// Project Name : ZBoard
// Module Name : Master Firmware Program
// Product Type : License
// OS/Dev Tool : AT89C52, uVision 2
// Original Author : Ray Yang
// Organization : YBWork.com
// Original Date : July, 25, 2001
// Addr : Room 402, No. 131, Meilong No. 9
// TEL : 86-21-54630718
// EMail : rayyang2000@yahoo.com
// Website : http://www.ybwork.com
// Copyright : Copyright (L) YBWork.com, 2001
// Comments :
//
// << History >>
// July, 25, 2001 The first release
//===================================================================//
#include "HAL.H"
#include "USBD12.H"
#include "ZBoard.H"
#include "USB110.H"
#include "USB.H"
#include "CHAP9.H"
#define NUM_ENDPOINTS 4
#define CONFIG_DESCRIPTOR_LENGTH sizeof(USB_CONFIGURATION_DESCRIPTOR) \
+ sizeof(USB_INTERFACE_DESCRIPTOR) \
+ (NUM_ENDPOINTS * sizeof(USB_ENDPOINT_DESCRIPTOR))
extern CONTROL_XFER ControlData;
extern ZBOARDFLAGS bZBoardFlags;
code USB_DEVICE_DESCRIPTOR DeviceDescr =
{
sizeof(USB_DEVICE_DESCRIPTOR), // bLength
USB_DEVICE_DESCRIPTOR_TYPE, // bDescriptorType
SWAP(0x0110), // bcdUSB
0xff, // bDeviceClass
0xff, // bDeviceSubClass
0xff, // bDeviceProtocol
EP0_PACKET_SIZE, // bMaxPacketSize
SWAP(0x0471), // idVendor
SWAP(0x1801), // idProduct
SWAP(0x0010), // bcdDevice
1, // iManufacturer
2, // iProduct
3, // iSerialNumber
1 // bNumConfigurations
};
code USB_CONFIGURATION_DESCRIPTOR ConfigDescr =
{
sizeof(USB_CONFIGURATION_DESCRIPTOR), // bLength
USB_CONFIGURATION_DESCRIPTOR_TYPE, // bDescriptorType
SWAP(CONFIG_DESCRIPTOR_LENGTH), // wTotalLength
1, // bNumInterfaces
1, // bConfigurationValue
4, // iConfiguration
0x80, // bmAttributes
100 // MaxPower
};
code USB_INTERFACE_DESCRIPTOR InterfaceDescr =
{
sizeof(USB_INTERFACE_DESCRIPTOR), // bLength
USB_INTERFACE_DESCRIPTOR_TYPE, // bDescriptorLength
0, // bInterfaceNumber
0, // bAlternateSetting
NUM_ENDPOINTS, // bNumEndpoints
0xff, // bInterfaceClass
0xff, // bInterfaceSubClass
0xff, // bInterfaceProtocol
5 // iInterface
};
code USB_ENDPOINT_DESCRIPTOR EP1_TXDescr =
{
sizeof(USB_ENDPOINT_DESCRIPTOR), // bLength
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType
0x81, // bEndpointAddress
USB_ENDPOINT_TYPE_BULK, // bmAttributes
SWAP(EP1_PACKET_SIZE), // wMaxPacketSize
0 // bInterval
};
code USB_ENDPOINT_DESCRIPTOR EP1_RXDescr =
{
sizeof(USB_ENDPOINT_DESCRIPTOR), // bLength
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType
0x1, // bEndpointAddress
USB_ENDPOINT_TYPE_BULK, // bmAttributes
SWAP(EP1_PACKET_SIZE), // wMaxPacketSize
0 // bInterval
};
code USB_ENDPOINT_DESCRIPTOR EP2_TXDescr =
{
sizeof(USB_ENDPOINT_DESCRIPTOR), // bLength
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType
0x82, // bEndpointAddress
USB_ENDPOINT_TYPE_BULK, // bmAttributes
SWAP(EP2_TX_FIFO_SIZE), // wMaxPacketSize
0 // bInterval
};
code USB_ENDPOINT_DESCRIPTOR EP2_RXDescr =
{
sizeof(USB_ENDPOINT_DESCRIPTOR), // bLength
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType
0x2, // bEndpointAddress
USB_ENDPOINT_TYPE_BULK, // bmAttributes
SWAP(EP2_RX_FIFO_SIZE), // wMaxPacketSize
0 // bInterval
};
code unsigned char StringLANGID[] =
{
4, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
0x09, 0x04//SWAP(0x0409) // wLANGID
};
code unsigned char szManufacturer[] =
{
66, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// String...
'Y', 0, 'B', 0, 'W', 0, 'o', 0, 'r', 0, 'k', 0, '.', 0, 'c', 0, 'o', 0, 'm', 0,
' ', 0, 'r', 0, 'a', 0, 'y', 0, 'y', 0, 'a', 0, 'n', 0, 'g', 0, '2', 0, '0', 0,
'0', 0, '0', 0, '@', 0, 'y', 0, 'a', 0, 'h', 0, 'o', 0, 'o', 0, '.', 0, 'c', 0,
'o', 0, 'm', 0
};
code unsigned char szProduct[] =
{
46, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// String...
'Z', 0, 'B', 0, 'o', 0, 'a', 0, 'r', 0, 'd', 0, ' ', 0, '(', 0, 'L', 0, ')', 0,
' ', 0, 'R', 0, '&', 0, 'D', 0, ' ', 0, 'P', 0, 'a', 0, 'c', 0, 'k', 0, 'a', 0,
'g', 0, 'e', 0
};
code unsigned char szSerialNumber[] =
{
22, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// String...
'0', 0, '0', 0, '0', 0, '0', 0, '-', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0
};
code unsigned char szConfiguration[] =
{
98, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// String...
'T', 0, 'h', 0, 'i', 0, 's', 0, ' ', 0, 'c', 0, 'o', 0, 'n', 0, 'f', 0, 'i', 0,
'g', 0, 'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0, 'o', 0, 'n', 0, ' ', 0, 'i', 0,
's', 0, ' ', 0, 'u', 0, 's', 0, 'e', 0, 'd', 0, ' ', 0, 'f', 0, 'o', 0, 'r', 0,
' ', 0, 'Z', 0, 'B', 0, 'o', 0, 'a', 0, 'r', 0, 'd', 0, ' ', 0, 'p', 0, 'r', 0,
'o', 0, 'g', 0, 'r', 0, 'a', 0, 'm', 0, 'm', 0, 'e', 0, 'r', 0
};
code unsigned char szInterface[] =
{
70, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// String...
'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, ' ', 0,
't', 0, 'o', 0, ' ', 0, 't', 0, 'h', 0, 'e', 0, ' ', 0, 'Z', 0, 'B', 0, 'o', 0,
'a', 0, 'r', 0, 'd', 0, ' ', 0, 'p', 0, 'r', 0, 'o', 0, 'g', 0, 'r', 0, 'a', 0,
'm', 0, 'm', 0, 'e', 0, 'r', 0
};
code unsigned char szUserInfo[] =
{
114, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// String...
'T', 0, 'h', 0, 'e', 0, ' ', 0, 'o', 0, 'r', 0, 'i', 0, 'g', 0, 'i', 0, 'n', 0,
'a', 0, 'l', 0, ' ', 0, 'u', 0, 's', 0, 'e', 0, 'r', 0, ' ', 0, 'o', 0, 'f', 0,
' ', 0, 't', 0, 'h', 0, 'i', 0, 's', 0, ' ', 0, 'b', 0, 'o', 0, 'a', 0, 'r', 0,
'd', 0, ' ', 0, 'i', 0, 's', 0, ' ', 0, 'r', 0, 'a', 0, 'y', 0, 'y', 0, 'a', 0,
'n', 0, 'g', 0, '2', 0, '0', 0, '0', 0, '0', 0, '@', 0, 'y', 0, 'a', 0, 'h', 0,
'o', 0, 'o', 0, '.', 0, 'c', 0, 'o', 0, 'm', 0
};
/*
//*************************************************************************
// USB Protocol Layer
//*************************************************************************
*/
void reserved(void)
{
USB_Stall_EP0();
}
/*
//*************************************************************************
// USB standard device requests
//*************************************************************************
*/
void USBClassRequest_GetStatus(void)
{
unsigned char endp, txdat[2];
unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
unsigned char c;
if (bRecipient == USB_RECIPIENT_DEVICE) {
if(bZBoardFlags.bits.bRemote_Wakeup == 1)
txdat[0] = 3;
else
txdat[0] = 1;
txdat[1]=0;
USB_Single_Transmit(txdat, 2);
} else if (bRecipient == USB_RECIPIENT_INTERFACE) {
txdat[0]=0;
txdat[1]=0;
USB_Single_Transmit(txdat, 2);
} else if (bRecipient == USB_RECIPIENT_ENDPOINT) {
endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
c = USBD12_SelectEndpoint(endp*2 + 1); /* Control-in */
else
c = USBD12_SelectEndpoint(endp*2); /* Control-out */
if(c & USBD12_STALL) /*USBD12_STALL=0x02*/
txdat[0] = 1;
else
txdat[0] = 0;
txdat[1] = 0;
USB_Single_Transmit(txdat, 2);
} else
USB_Stall_EP0();
}
void USBClassRequest_ClearFeature(void)
{
unsigned char endp;
unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
if (bRecipient == USB_RECIPIENT_DEVICE
&& ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP)
{
DISABLE_INTERRUPTS;
bZBoardFlags.bits.bRemote_Wakeup = 0;
ENABLE_INTERRUPTS;
USB_Single_Transmit(0, 0);
}
else if (bReci