📄 standard.c
字号:
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support - ROUSSET -
* ----------------------------------------------------------------------------
* Copyright (c) 2006, 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 disclaiimer below.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer below in the documentation and/or
* other materials provided with the distribution.
*
* 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.
* ----------------------------------------------------------------------------
*/
/*
$Id: standard.c 122 2006-10-17 12:56:03Z jjoannic $
*/
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "common.h"
#include "device.h"
#include "board.h"
#include "trace.h"
#include "usb.h"
#include "standard.h"
//------------------------------------------------------------------------------
// Internal functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// \brief Callback for the STD_SetConfiguration function.
//
// Configures the device and the endpoints
// \param pClass Pointer to a class driver instance
//------------------------------------------------------------------------------
static void STD_ConfigureEndpoints(const S_std_class *pClass)
{
unsigned char i;
// Enter the Configured state
USB_SetConfiguration(pClass->pUsb);
// Configure endpoints
for (i = 0; i < (pClass->pUsb->dNumEndpoints-1); i++) {
USB_ConfigureEndpoint(pClass->pUsb,
pClass->pDescriptors->pEndpoints[i]);
}
}
//------------------------------------------------------------------------------
// \brief Sends a zero-length packet and starts the configuration procedure.
// \param pClass Pointer to a class driver instance
// \param bConfiguration Newly selected configuration
//------------------------------------------------------------------------------
static void STD_SetConfiguration(S_std_class *pClass,
unsigned char bConfiguration)
{
USB_SendZLP0(pClass->pUsb,
(Callback_f) STD_ConfigureEndpoints,
pClass);
}
//------------------------------------------------------------------------------
// \brief Sends the currently selected configuration to the host.
// \param pClass Pointer to a class driver instance
//------------------------------------------------------------------------------
static void STD_GetConfiguration(S_std_class *pClass)
{
if (ISSET(USB_GetState(pClass->pUsb), USB_STATE_CONFIGURED)) {
pClass->wData = 1;
}
else {
pClass->wData = 0;
}
USB_Write(pClass->pUsb, 0, &(pClass->wData), 1, 0, 0);
}
//------------------------------------------------------------------------------
// \brief Sends the current device status to the host.
// \param pClass Pointer to a class driver interface
//------------------------------------------------------------------------------
static void STD_GetDeviceStatus(S_std_class *pClass)
{
// Bus or self-powered ?
if (ISSET(pClass->pDescriptors->pConfiguration->bmAttibutes,
USB_CONFIG_SELF_NOWAKEUP)) {
// Self powered device
pClass->wDeviceStatus |= SELF_POWERED;
}
else {
// Bus powered device
pClass->wDeviceStatus &= ~SELF_POWERED;
}
// Return the device status
USB_Write(pClass->pUsb, 0, &(pClass->wDeviceStatus), 2, 0, 0);
}
//------------------------------------------------------------------------------
// \brief Sends the current status of specified endpoint to the host.
// \param pClass Pointer to a class driver instance
// \param bEndpoint Endpoint number
//------------------------------------------------------------------------------
static void STD_GetEndpointStatus(S_std_class *pClass,
unsigned char bEndpoint)
{
//! Retrieve the endpoint current status
pClass->wData = (unsigned short) USB_Halt(pClass->pUsb,
bEndpoint,
USB_GET_STATUS);
//! Return the endpoint status
USB_Write(pClass->pUsb, 0, &(pClass->wData), 2, 0, 0);
}
//------------------------------------------------------------------------------
// \brief Sends the device descriptor to the host.
//
// The number of bytes actually sent depends on both the length
// requested by the host and the actual length of the descriptor.
// \param pClass Pointer to a class driver instance
// \param wLength Number of bytes requested by the host
//------------------------------------------------------------------------------
static void STD_GetDeviceDescriptor(const S_std_class *pClass,
unsigned short wLength)
{
USB_Write(pClass->pUsb,
0,
(void *) pClass->pDescriptors->pDevice,
min(sizeof(S_usb_device_descriptor), wLength),
0,
0);
}
//------------------------------------------------------------------------------
// \brief Sends the configuration descriptor to the host.
//
// The number of bytes actually sent depends on both the length
// requested by the host and the actual length of the descriptor.
// \param pClass Pointer to a class driver instance
// \param wLength Number of bytes requested by the host
//------------------------------------------------------------------------------
static void STD_GetConfigurationDescriptor(const S_std_class *pClass,
unsigned short wLength)
{
USB_Write(pClass->pUsb,
0,
(void *) pClass->pDescriptors->pConfiguration,
min(pClass->pDescriptors->pConfiguration->wTotalLength,
wLength),
0,
0);
}
#if defined(HIGHSPEED)
//------------------------------------------------------------------------------
// \brief Sends the qualifier descriptor to the host.
//
// The number of bytes actually sent depends on both the length
// requested by the host and the actual length of the descriptor.
// \param pClass Pointer to a class driver instance
// \param wLength Number of bytes requested by the host
//------------------------------------------------------------------------------
static void STD_GetQualifierDescriptor(const S_std_class *pClass,
unsigned short wLength)
{
USB_Write(pClass->pUsb,
0,
(void *) pClass->pDescriptors->pQualifier,
min(pClass->pDescriptors->pQualifier->bLength, wLength),
0,
0);
}
//------------------------------------------------------------------------------
// \brief Sends the other speed configuration descriptor to the host.
//
// The number of bytes actually sent depends on both the length
// requested by the host and the actual length of the descriptor.
// \param pClass Pointer to a class driver instance
// \param wLength Number of bytes requested by the host
//------------------------------------------------------------------------------
static void STD_GetOSCDescriptor(const S_std_class *pClass,
unsigned short wLength)
{
USB_Write(pClass->pUsb,
0,
(void *) pClass->pDescriptors->pOtherSpeedConfiguration,
min(pClass->pDescriptors->pOtherSpeedConfiguration->wTotalLength,
wLength),
0,
0);
}
#endif
//------------------------------------------------------------------------------
// \brief Sends the specified string descriptor to the host
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -