📄 cdc_enumerate.c
字号:
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : cdc_enumerate.c
//* Object : Handle CDC enumeration
//*
//* 1.0 Apr 20 200 : ODi Creation
//* 1.1 14/Sep/2004 JPP : Minor change
//* 1.1 15/12/2004 JPP : suppress warning
//* 1.2 30-Jun-2006 JPP : Set in AT91C_UDP_EPTYPE_INT_IN
//* 1.3 2007-02-28 Hogo: Change for APS
//*----------------------------------------------------------------------------
#include "Project.h"
#include "cdc_enumerate.h"
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define AT91C_EP_IN_SIZE 0x40
#define APS_CODE
#ifdef APS_CODE
/* macros to deal with endianness problems ***********************************/
//#define LITTLE_ENDIAN(w) CONST_LSB(w),CONST_MSB(w)
char PrtPortStatus = 0x18;
#endif
#ifndef APS_CODE
const char devDescriptor[] = {
/* Device descriptor */
0x12, // bLength
0x01, // bDescriptorType
0x10, // bcdUSBL
0x01, //
0x02, // bDeviceClass: CDC class code
0x00, // bDeviceSubclass: CDC class sub code
0x00, // bDeviceProtocol: CDC Device protocol
0x08, // bMaxPacketSize0
0xEB, // idVendorL
0x03, //
0x24, // idProductL
0x61, //
0x10, // bcdDeviceL
0x01, //
0x00, // iManufacturer // 0x01
0x00, // iProduct
0x00, // SerialNumber
0x01 // bNumConfigs
};
#else
/* descriptor types **********************************************************/
#define USB_DESC_DEVICE 1
#define USB_DESC_CONFIG 2
#define USB_DESC_STRING 3
#define USB_DESC_INTERFACE 4
#define USB_DESC_ENDPOINT 5
/* device descriptor *********************************************************/
#define USB_DESC_DEVICE_SIZE 18 /* bytes */
const char devDescriptor[] = {
/* Device descriptor */
USB_DESC_DEVICE_SIZE, // bLength
USB_DESC_DEVICE, // bDescriptorType
0x10, // bcdUSBL
0x01, //
0x00, // bDeviceClass:
0x00, // bDeviceSubclass: CDC class sub code
0x00, // bDeviceProtocol: CDC Device protocol
0x08, // bMaxPacketSize0
0x71, // idVendorL Read CP 324HRS : 0x0471
0x04, //
// 0xD4, // idVendorL APS source : 0x1AD4
// 0x1A, //
0x02, // idProductL
0x00, //
0x00, // bcdDeviceL
0x01, //
0x01, // iManufacturer // 0x01
0x02, // iProduct
0x00, // SerialNumber
0x01 // bNumConfigs
};
#endif
#ifndef APS_CODE
const char cfgDescriptor[] = {
/* ============== CONFIGURATION 1 =========== */
/* Configuration 1 descriptor */
0x09, // CbLength
0x02, // CbDescriptorType
0x43, // CwTotalLength 2 EP + Control
0x00,
0x02, // CbNumInterfaces
0x01, // CbConfigurationValue
0x00, // CiConfiguration
0xC0, // CbmAttributes 0xA0
0x00, // CMaxPower
/* Communication Class Interface Descriptor Requirement */
0x09, // bLength
0x04, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
0x01, // bNumEndpoints
0x02, // bInterfaceClass
0x02, // bInterfaceSubclass
0x00, // bInterfaceProtocol
0x00, // iInterface
/* Header Functional Descriptor */
0x05, // bFunction Length
0x24, // bDescriptor type: CS_INTERFACE
0x00, // bDescriptor subtype: Header Func Desc
0x10, // bcdCDC:1.1
0x01,
/* ACM Functional Descriptor */
0x04, // bFunctionLength
0x24, // bDescriptor Type: CS_INTERFACE
0x02, // bDescriptor Subtype: ACM Func Desc
0x00, // bmCapabilities
/* Union Functional Descriptor */
0x05, // bFunctionLength
0x24, // bDescriptorType: CS_INTERFACE
0x06, // bDescriptor Subtype: Union Func Desc
0x00, // bMasterInterface: Communication Class Interface
0x01, // bSlaveInterface0: Data Class Interface
/* Call Management Functional Descriptor */
0x05, // bFunctionLength
0x24, // bDescriptor Type: CS_INTERFACE
0x01, // bDescriptor Subtype: Call Management Func Desc
0x00, // bmCapabilities: D1 + D0
0x01, // bDataInterface: Data Class Interface 1
/* Endpoint 1 descriptor */
0x07, // bLength
0x05, // bDescriptorType
0x83, // bEndpointAddress, Endpoint 03 - IN
0x03, // bmAttributes INT
0x08, // wMaxPacketSize
0x00,
0xFF, // bInterval
/* Data Class Interface Descriptor Requirement */
0x09, // bLength
0x04, // bDescriptorType
0x01, // bInterfaceNumber
0x00, // bAlternateSetting
0x02, // bNumEndpoints
0x0A, // bInterfaceClass
0x00, // bInterfaceSubclass
0x00, // bInterfaceProtocol
0x00, // iInterface
/* First alternate setting */
/* Endpoint 1 descriptor */
0x07, // bLength
0x05, // bDescriptorType
0x01, // bEndpointAddress, Endpoint 01 - OUT
0x02, // bmAttributes BULK
AT91C_EP_OUT_SIZE, // wMaxPacketSize
0x00,
0x00, // bInterval
/* Endpoint 2 descriptor */
0x07, // bLength
0x05, // bDescriptorType
0x82, // bEndpointAddress, Endpoint 02 - IN
0x02, // bmAttributes BULK
AT91C_EP_IN_SIZE, // wMaxPacketSize
0x00,
0x00 // bInterval
};
#else
/* refer to USB specification revision 2.0 page 264-273 */
#define NUM_INTERFACES 0x01
#define NUM_ENDPOINTS 2
//#define USB_MAIN_OUT 0b00000010 /* endpoint address (OUT,2) */
//#define USB_MAIN_IN 0b10000010 /* endpoint address (IN,2) */
#define USB_MAIN_OUT 0x02 /* endpoint address (OUT,2) */
#define USB_MAIN_IN 0x82 /* endpoint address (IN,2) */
#define USB_DESC_CONFIG_SIZE 9 /* bytes*/
#define USB_DESC_INTERFACE_SIZE 9 /* bytes*/
#define USB_DESC_ENDPOINT_SIZE 9 /* bytes*/
/* the configuration descriptor of our printer has one interface,
* which itself has two endpoints (main IN and OUT)
* the following array lays down the whole configuration descriptor
* which will be sent as a whole upon a GET_DESCRIPTOR device
* request */
/*
#define USB_TOTAL_LENGTH \
USB_DESC_CONFIG_SIZE + \
USB_DESC_INTERFACE_SIZE*NUM_INTERFACES + \
USB_DESC_ENDPOINT_SIZE*NUM_ENDPOINTS
USB_TOTAL_LENGTH = 9 + 9 * 1 + 7 * 2 = 32
*/
const char cfgDescriptor[] = {
/* ============== CONFIGURATION 1 =========== */
/* Configuration 1 descriptor */
USB_DESC_CONFIG_SIZE, // CbLength
USB_DESC_CONFIG, // CbDescriptorType
0x1B, // /* total length of config desc */
0x00,
NUM_INTERFACES, // CbNumInterfaces
0x01, // CbConfigurationValue
0x00, // CiConfiguration
0xC0, // CbmAttributes 0xA0 /* self-powered device */
0x00, // CMaxPower
/* Communication Class Interface Descriptor Requirement */
USB_DESC_INTERFACE_SIZE, // bLength
USB_DESC_INTERFACE, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
NUM_ENDPOINTS, // bNumEndpoints
0x07, // bInterfaceClass ; class code (printer)
0x01, // bInterfaceSubclass
0x02, // bInterfaceProtocol
0x00, // iInterface
/* Header Functional Descriptor */
// 0x05, // bFunction Length
// 0x24, // bDescriptor type: CS_INTERFACE
// 0x00, // bDescriptor subtype: Header Func Desc
// 0x10, // bcdCDC:1.1
// 0x01,
/* ACM Functional Descriptor */
// 0x04, // bFunctionLength
// 0x24, // bDescriptor Type: CS_INTERFACE
// 0x02, // bDescriptor Subtype: ACM Func Desc
// 0x00, // bmCapabilities
/* Union Functional Descriptor */
// 0x05, // bFunctionLength
// 0x24, // bDescriptorType: CS_INTERFACE
// 0x06, // bDescriptor Subtype: Union Func Desc
// 0x00, // bMasterInterface: Communication Class Interface
// 0x01, // bSlaveInterface0: Data Class Interface
/* Call Management Functional Descriptor */
// 0x05, // bFunctionLength
// 0x24, // bDescriptor Type: CS_INTERFACE
// 0x01, // bDescriptor Subtype: Call Management Func Desc
// 0x00, // bmCapabilities: D1 + D0
// 0x01, // bDataInterface: Data Class Interface 1
/* Endpoint 1 descriptor */
// 0x07, // bLength
// 0x05, // bDescriptorType
// 0x83, // bEndpointAddress, Endpoint 03 - IN
// 0x03, // bmAttributes INT
// 0x08, // wMaxPacketSize
// 0x00,
// 0xFF, // bInterval
/* Data Class Interface Descriptor Requirement */
// 0x09, // bLength
// 0x04, // bDescriptorType
// 0x01, // bInterfaceNumber
// 0x00, // bAlternateSetting
// 0x02, // bNumEndpoints
// 0x0A, // bInterfaceClass
// 0x00, // bInterfaceSubclass
// 0x00, // bInterfaceProtocol
// 0x00, // iInterface
/* First alternate setting */
/* Endpoint 1 descriptor */
/* main IN endpoint descriptor */
USB_DESC_ENDPOINT_SIZE, // bLength
USB_DESC_ENDPOINT, // bDescriptorType
USB_MAIN_IN, // bEndpointAddress, Endpoint 02 - IN
0x02, // bmAttributes BULK
AT91C_EP_OUT_SIZE, // wMaxPacketSize
0x00,
0x00, // bInterval
0x00,
0x00,
/* Endpoint 2 descriptor */
USB_DESC_ENDPOINT_SIZE, // bLength
USB_DESC_ENDPOINT, // bDescriptorType
USB_MAIN_OUT, // bEndpointAddress, Endpoint 02 - IN
0x02, // bmAttributes BULK
AT91C_EP_IN_SIZE, // wMaxPacketSize
0x00,
0x00, // bInterval
0x00,
0x00,
};
#endif
#ifdef APS_CODE
/* string descriptors ********************************************************/
/* refer to USB specification revision 2.0 page 273 for more information */
/* all strings are unicode
* byte 0 descriptor size in bytes (n)
* byte 1 descriptor type
* n-2 bytes unicode string
*/
#define USB_NBR_STRING 3
/* 0- supported LANGID as defined by Microsoft Windows */
const char usb_string0[] = {
4,
USB_DESC_STRING,
9,4
};
/* 1- manufacturer string */
const char usb_string1[] = {
8,
USB_DESC_STRING,
'A',0,
'P',0,
'S',0,
};
/* 2- product string */
const char usb_string2[] = {
24,
USB_DESC_STRING,
'H',0,
'R',0,
'S',0,
' ',0,
'P',0,
'R',0,
'I',0,
'N',0,
'T',0,
'E',0,
'R',0
};
/* this table allows easy access to any string descriptor given
* its string descriptor number */
typedef const char *usb_string_t;
const usb_string_t usb_string_descriptor[USB_NBR_STRING] = {
usb_string0,
usb_string1,
usb_string2
};
/* class device ID descriptor *************************************************/
/* this string describes the printer in IEEE 1284 device ID format
* see USB device class definition for printing device rev 1.1 page 6 */
const char usb_device_id_descriptor[] =
"\0LMFG:APS ;CMD: APS_SET ;\
MDL:CP324HRS 640 ;\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -