📄 usbprinterdriverdescriptors.c
字号:
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "USBPrinterDriverDescriptors.h"
#include <board.h>
#include <usb/common/core/USBGenericDescriptor.h>
#include <usb/common/core/USBConfigurationDescriptor.h>
#include <usb/common/core/USBEndpointDescriptor.h>
#include <usb/common/core/USBStringDescriptor.h>
#include <usb/common/core/USBGenericRequest.h>
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "CDC Serial Device IDs"
/// This page lists the IDs used in the CDC Serial Device Descriptor.
///
/// !IDs
/// - USBPrinterDriverDescriptors_PRODUCTID
/// - USBPrinterDriverDescriptors_VENDORID
/// - USBPrinterDriverDescriptors_RELEASE
/// Device product ID.
#define USBPrinterDriverDescriptors_PRODUCTID 0x6119
/// Device vendor ID (Atmel).
#define USBPrinterDriverDescriptors_VENDORID 0x03EB
/// Device release number.
#define USBPrinterDriverDescriptors_RELEASE 0x0100
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
/// Returns the minimum between two values.
#define MIN(a, b) ((a < b) ? a : b)
//------------------------------------------------------------------------------
// Internal structures
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Configuration descriptor list for a device implementing a CDC serial driver.
//------------------------------------------------------------------------------
typedef struct {
/// Standard configuration descriptor.
USBConfigurationDescriptor configuration;
/// Data interface descriptor.
USBInterfaceDescriptor data;
/// Data OUT endpoint descriptor.
USBEndpointDescriptor dataOut;
/// Data IN endpoint descriptor.
USBEndpointDescriptor dataIn;
} __attribute__ ((packed)) USBPrinterDriverConfigurationDescriptors;
//------------------------------------------------------------------------------
// Exported variables
//------------------------------------------------------------------------------
/// Standard USB device descriptor for the CDC serial driver
const USBDeviceDescriptor deviceDescriptor = {
sizeof(USBDeviceDescriptor),
USBGenericDescriptor_DEVICE,
USBDeviceDescriptor_USB2_00,
USBPrintDeviceDescriptor_CLASS,
USBPrintDeviceDescriptor_SUBCLASS,
USBPrintDeviceDescriptor_PROTOCOL,
BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
USBPrinterDriverDescriptors_VENDORID,
USBPrinterDriverDescriptors_PRODUCTID,
USBPrinterDriverDescriptors_RELEASE,
0, // No string descriptor for manufacturer
1, // Index of product string descriptor is #1
0, // No string descriptor for serial number
1 // Device has 1 possible configuration
};
/// Standard USB configuration descriptor for the CDC serial driver
const USBPrinterDriverConfigurationDescriptors configurationDescriptors = {
// Standard configuration descriptor
{
sizeof(USBConfigurationDescriptor),
USBGenericDescriptor_CONFIGURATION,
sizeof(USBPrinterDriverConfigurationDescriptors),
1, // There are one interfaces in this configuration
1, // This is configuration #1
0, // No string descriptor for this configuration
BOARD_USB_BMATTRIBUTES,
USBConfigurationDescriptor_POWER(100)
},
// Data class interface standard descriptor
{
sizeof(USBInterfaceDescriptor),
USBGenericDescriptor_INTERFACE,
0, // This is interface #0
0, // This is alternate setting #0 for this interface
2, // This interface uses 2 endpoints
USBPrintDataInterfaceDescriptor_CLASS,
USBPrintDataInterfaceDescriptor_SUBCLASS,
USBPrintDataInterfaceDescriptor_PROTOCOL,
0 // No string descriptor for this interface
},
// Bulk-OUT endpoint standard descriptor
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointADDR_OUT,
USBEndpointDescriptor_BULK,
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(USBPrinterDriverDescriptors_DATAOUT),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 // Must be 0 for full-speed bulk endpoints
},
// Bulk-IN endpoint descriptor
{
sizeof(USBEndpointDescriptor),
USBGenericDescriptor_ENDPOINT,
USBEndpointADDR_IN,
USBEndpointDescriptor_BULK,
MIN(BOARD_USB_ENDPOINTS_MAXPACKETSIZE(USBPrinterDriverDescriptors_DATAIN),
USBEndpointDescriptor_MAXBULKSIZE_FS),
0 // Must be 0 for full-speed bulk endpoints
},
};
/// Language ID string descriptor
const unsigned char languageIdStringDescriptor[] = {
USBStringDescriptor_LENGTH(1),
USBGenericDescriptor_STRING,
USBStringDescriptor_ENGLISH_US
};
/// Product string descriptor
const unsigned char productStringDescriptor[] = {
USBStringDescriptor_LENGTH(12),
USBGenericDescriptor_STRING,
USBStringDescriptor_UNICODE('S'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('A'),
USBStringDescriptor_UNICODE('R'),
USBStringDescriptor_UNICODE('_'),
USBStringDescriptor_UNICODE('P'),
USBStringDescriptor_UNICODE('R'),
USBStringDescriptor_UNICODE('I'),
USBStringDescriptor_UNICODE('N'),
USBStringDescriptor_UNICODE('T'),
USBStringDescriptor_UNICODE('E'),
USBStringDescriptor_UNICODE('R'),
};
/// List of string descriptors used by the device
const unsigned char *stringDescriptors[] = {
languageIdStringDescriptor,
productStringDescriptor,
};
/// List of standard descriptors for the serial driver.
USBDDriverDescriptors usbPrinterDriverDescriptors = {
&deviceDescriptor,
(USBConfigurationDescriptor *) &(configurationDescriptors),
#ifdef BOARD_USB_UDPHS
&qualifierDescriptor,
(USBConfigurationDescriptor *) &(otherSpeedDescriptorsFS),
&deviceDescriptor,
(USBConfigurationDescriptor *) &(configurationDescriptorsHS),
&qualifierDescriptor,
(USBConfigurationDescriptor *) &(otherSpeedDescriptorsHS),
#else
0, // No full-speed device qualifier descriptor
0, // No full-speed other speed configuration
0, // No high-speed device descriptor
0, // No high-speed configuration descriptor
0, // No high-speed device qualifier descriptor
0, // No high-speed other speed configuration descriptor
#endif
stringDescriptors,
2 // 2 string descriptors in list
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -