📄 usb_enum.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 : usbenum.c
//* Object : USB peripheral validation.
//*
//* 1.0 07/24/01 ODi : Creation
//*----------------------------------------------------------------------------
#include "usb_enum.h"
#include "main.h"
/* =================================================================== */
/* DFU mode Descriptor set */
/* =================================================================== */
/* ====================================================================== */
/* STANDARD REQUEST DESCRIPTION */
/* ====================================================================== */
char currentCfg;
/* ************************************ */
/* GetConfiguration */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* Return: */
/* Nothing */
/* Description: */
/* This request returns the current */
/* device configuration value */
/* ************************************ */
void GetConfiguration(void *pVoid) /* Default Pipe Handler */
{
AT91PS_Pipe pPipe = (AT91PS_Pipe) pVoid;
pPipe->Write(pPipe, (char *) ¤tCfg, 1,
(AT91PF_PipeWriteCallBack) 0, (void *) 0);
}
/* ************************************ */
/* GetDescriptor */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* Return: */
/* Nothing */
/* Description: */
/* This request returns the */
/* specified descriptor if the */
/* descriptor exists */
/* ************************************ */
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
void GetDescriptor(
char type, /* Descriptor type */
char index, /* Descriptor index */
short langID, /* Language ID */
short length, /* Desriptor length */
void *pVoid)
{
AT91PS_Pipe pPipe = (AT91PS_Pipe) pVoid;
if (type == USB_DEVICE) {
pPipe->Write(
pPipe,
(char const *) &(USB_DFU_DESC.dfuModeDevDesc),
MIN(sizeof(AT91S_UsbDevice), length),
(AT91PF_PipeWriteCallBack) 0, (void *) 0);
}
else if (type == USB_CONFIGURATION) {
if (index == 0) {
pPipe->Write(
pPipe,
(char const *) &(USB_DFU_DESC.dfuModeCfgDesc),
MIN( length, wTotalLength((char const *) &(USB_DFU_DESC.dfuModeCfgDesc))) ,
(AT91PF_PipeWriteCallBack) 0, (void *) 0);
}
else
pPipe->AbortWrite(pPipe);
}
else if (type == USB_STRING)
pPipe->AbortWrite(pPipe);
else
pPipe->AbortWrite(pPipe);
}
/* ************************************ */
/* GetStatus */
/* */
/* Arguments: */
/* pPipe: pointer to default pipe */
/* handler */
/* pSetup: pointer to setup datas */
/* Return: */
/* Nothing */
/* Description: */
/* This request returns status for */
/* the specified endpoint */
/* ************************************ */
void GetStatus (
char recipient, /* device, interface, endpoint */
short index, /* interface or endpoint index */
void *pVoid)
{
AT91PS_Pipe pPipe = (AT91PS_Pipe) pVoid;
short status = 0;
if (recipient == 0) {
status = 1;
pPipe->Write(pPipe, (char *) &status, 2, (AT91PF_PipeWriteCallBack) 0, (void *) 0);
}
else if (recipient == 1) {
if (index == 0) {
status = 0;
pPipe->Write(pPipe, (char *) &status, 2, (AT91PF_PipeWriteCallBack) 0, (void *) 0);
}
else
pPipe->AbortWrite(pPipe);
}
else
pPipe->AbortWrite(pPipe);
}
/* ************************************ */
/* SetConfiguration */
/* */
/* Arguments: */
/* Return: */
/* Nothing */
/* Description: */
/* This request sets the device */
/* configuration */
/* ************************************ */
void SetConfiguration(
short configurationValue, /* Configuration value */
void *pVoid)
{
//AT91PS_Pipe pPipe = (AT91PS_Pipe) pVoid;
if (configurationValue == 1) {
currentCfg = 1;
AT91F_UdpSetState(UDP_BASE, UDP_CONFG);
// Start the STATUS IN stage
AT91F_UdpEpEow(UDP_BASE, 0);
}
else {
AT91F_UdpEpStall(UDP_BASE, 0);
//pPipe->AbortWrite(pPipe);
}
}
/* ************************************ */
/* SetAddress */
/* */
/* Arguments: */
/* Return: */
/* Nothing */
/* Description: */
/* This request sets the device */
/* configuration */
/* ************************************ */
void SetAddress(
char addressValue,
void *pVoid)
{
// Start the STATUS IN stage
AT91F_UdpEpEow(UDP_BASE, 0);
// Wait for the end of the STATUS IN stage
while ( !(AT91F_UdpEpUisr(UDP_BASE, 0) & UDP_TXCOMPLETE) );
AT91F_UdpEpUicr(UDP_BASE, 0, UDP_TXCOMPLETE);
// Set the address
AT91F_UdpSetAddress(UDP_BASE, (unsigned int) addressValue);
// Enter in Address state
AT91F_UdpSetState(UDP_BASE, UDP_FADDEN);
}
/* ************************************ */
/* DfuDownload */
/* */
/* Arguments: */
/* Return: */
/* Nothing */
/* Description: */
/* This request sets the device */
/* configuration */
/* ************************************ */
void DfuDownload(
AT91PS_DfuDesc pDfu,
unsigned short length,
AT91PF_PipeReadCallBack callback)
{
AT91PS_Pipe pPipe = pDfu->pPipe;
static char *ramAddress = (char *) BASE_LOAD_ADDRESS;
pDfu->dfuStatus.bStatus = (char) AT91C_DFU_OK;
pPipe->Read(pPipe, ramAddress, length, callback, pDfu);
ramAddress += length;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -