亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usbddriver.c

?? configure HID devices like USB mouse with A91SAM7SE CPU. Inlcude initilization for necessary periphe
?? 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 "USBDDriver.h"
#include "USBDDriverCallbacks.h"
#include "USBD.h"
#include <board.h>
#include <utility/trace.h>
#include <usb/common/core/USBGenericDescriptor.h>
#include <usb/common/core/USBDeviceDescriptor.h>
#include <usb/common/core/USBConfigurationDescriptor.h>
#include <usb/common/core/USBDeviceQualifierDescriptor.h>
#include <usb/common/core/USBEndpointDescriptor.h>
#include <usb/common/core/USBFeatureRequest.h>
#include <usb/common/core/USBSetAddressRequest.h>
#include <usb/common/core/USBGetDescriptorRequest.h>
#include <usb/common/core/USBSetConfigurationRequest.h>
#include <usb/common/core/USBInterfaceRequest.h>

#include <string.h>

//------------------------------------------------------------------------------
//      Local functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
/// Configures the device by setting it into the Configured state and
/// initializing all endpoints.
/// \param pDriver  Pointer to a USBDDriver instance.
/// \param cfgnum  Configuration number to set.
//------------------------------------------------------------------------------
static void SetConfiguration(USBDDriver *pDriver, unsigned char cfgnum)
{
    USBEndpointDescriptor *pEndpoints[BOARD_USB_NUMENDPOINTS+1];
    const USBConfigurationDescriptor *pConfiguration;

    // Use different descriptor depending on device speed
    if (USBD_IsHighSpeed()) {

        pConfiguration = pDriver->pDescriptors->pHsConfiguration;
    }
    else {

        pConfiguration = pDriver->pDescriptors->pFsConfiguration;
    }

    // Set & save the desired configuration
    USBD_SetConfiguration(cfgnum);
    pDriver->cfgnum = cfgnum;

    // If the configuration is not 0, configure endpoints
    if (cfgnum != 0) {
    
        // Parse configuration to get endpoint descriptors
        USBConfigurationDescriptor_Parse(pConfiguration, 0, pEndpoints, 0);
    
        // Configure endpoints
        int i = 0;
        while (pEndpoints[i] != 0) {
    
            USBD_ConfigureEndpoint(pEndpoints[i]);
            i++;
        }
    }
    // Should be done before send the ZLP
    USBDDriverCallbacks_ConfigurationChanged(cfgnum);

    // Acknowledge the request
    USBD_Write(0, // Endpoint #0
               0, // No data buffer
               0, // No data buffer
               (TransferCallback) 0,
               (void *)  0);
}

//------------------------------------------------------------------------------
/// Sends the current configuration number to the host.
/// \param pDriver  Pointer to a USBDDriver instance.
//------------------------------------------------------------------------------
static void GetConfiguration(const USBDDriver *pDriver)
{
    USBD_Write(0, &(pDriver->cfgnum), 1, 0, 0);
}

//------------------------------------------------------------------------------
/// Sends the current status of the device to the host.
/// \param pDriver  Pointer to a USBDDriver instance.
//------------------------------------------------------------------------------
static void GetDeviceStatus(const USBDDriver *pDriver)
{
    unsigned short data = 0;
    const USBConfigurationDescriptor *pConfiguration;

    // Use different configuration depending on device speed
    if (USBD_IsHighSpeed()) {

        pConfiguration = pDriver->pDescriptors->pHsConfiguration;
    }
    else {

        pConfiguration = pDriver->pDescriptors->pFsConfiguration;
    }

    // Check current configuration for power mode (if device is configured)
    if (pDriver->cfgnum != 0) {

        if (USBConfigurationDescriptor_IsSelfPowered(pConfiguration)) {

            data |= 1;
        }
    }

    // Check if remote wake-up is enabled
    if (pDriver->isRemoteWakeUpEnabled) {

        data |= 2;
    }

    // Send the device status
    USBD_Write(0, &data, 2, 0, 0);
}

//------------------------------------------------------------------------------
/// Sends the current status of an endpoints to the USB host.
/// \param bEndpoint  Endpoint number.
//------------------------------------------------------------------------------
static void GetEndpointStatus(unsigned char bEndpoint)
{
    unsigned short data = 0;

    // Check if the endpoint exists
    if (bEndpoint > BOARD_USB_NUMENDPOINTS) {

        USBD_Stall(0);
    }
    else {

        // Check if the endpoint if currently halted
        if (USBD_IsHalted(bEndpoint)) {

            data = 1;
        }
        
        // Send the endpoint status
        USBD_Write(0, &data, 2, 0, 0);
    }
}

//------------------------------------------------------------------------------
/// Sends the requested USB descriptor to the host if available, or STALLs  the
/// request.
/// \param pDriver  Pointer to a USBDDriver instance.
/// \param type  Type of the requested descriptor
/// \param index  Index of the requested descriptor.
/// \param length  Maximum number of bytes to return.
//------------------------------------------------------------------------------
static void GetDescriptor(
    const USBDDriver *pDriver,
    unsigned char type,
    unsigned char index,
    unsigned int length)
{
    const USBDeviceDescriptor *pDevice;
    const USBConfigurationDescriptor *pConfiguration;
    const USBDeviceQualifierDescriptor *pQualifier;
    const USBConfigurationDescriptor *pOtherSpeed;
    const USBGenericDescriptor **pStrings =
        (const USBGenericDescriptor **) pDriver->pDescriptors->pStrings;
    unsigned char numStrings = pDriver->pDescriptors->numStrings;
    const USBGenericDescriptor *pString;

    // Use different set of descriptors depending on device speed
    if (USBD_IsHighSpeed()) {

        TRACE_DEBUG("HS ");
        pDevice = pDriver->pDescriptors->pHsDevice;
        pConfiguration = pDriver->pDescriptors->pHsConfiguration;
        pQualifier = pDriver->pDescriptors->pHsQualifier;
        pOtherSpeed = pDriver->pDescriptors->pHsOtherSpeed;
    }
    else {

        TRACE_DEBUG("FS ");
        pDevice = pDriver->pDescriptors->pFsDevice;
        pConfiguration = pDriver->pDescriptors->pFsConfiguration;
        pQualifier = pDriver->pDescriptors->pFsQualifier;
        pOtherSpeed = pDriver->pDescriptors->pFsOtherSpeed;
    }

    // Check the descriptor type
    switch (type) {
        
        case USBGenericDescriptor_DEVICE:
            TRACE_INFO_WP("Dev ");

            // Adjust length and send descriptor
            if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice)) {

                length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pDevice);
            }
            USBD_Write(0, pDevice, length, 0, 0);
            break;

        case USBGenericDescriptor_CONFIGURATION:
            TRACE_INFO_WP("Cfg ");

            // Adjust length and send descriptor
            if (length > USBConfigurationDescriptor_GetTotalLength(pConfiguration)) {

                length = USBConfigurationDescriptor_GetTotalLength(pConfiguration);
            }
            USBD_Write(0, pConfiguration, length, 0, 0);
            break;

        case USBGenericDescriptor_DEVICEQUALIFIER:
            TRACE_INFO_WP("Qua ");

            // Check if descriptor exists
            if (!pQualifier) {

                USBD_Stall(0);
            }
            else {

                // Adjust length and send descriptor
                if (length > USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier)) {

                    length = USBGenericDescriptor_GetLength((USBGenericDescriptor *) pQualifier);
                }
                USBD_Write(0, pQualifier, length, 0, 0);
            }
            break;

        case USBGenericDescriptor_OTHERSPEEDCONFIGURATION:
            TRACE_INFO_WP("OSC ");

            // Check if descriptor exists
            if (!pOtherSpeed) {

                USBD_Stall(0);
            }
            else {

                // Adjust length and send descriptor
                if (length > USBConfigurationDescriptor_GetTotalLength(pOtherSpeed)) {

                    length = USBConfigurationDescriptor_GetTotalLength(pOtherSpeed);
                }
                USBD_Write(0, pOtherSpeed, length, 0, 0);
            }
            break;

        case USBGenericDescriptor_STRING:
            TRACE_INFO_WP("Str%d ", index);

            // Check if descriptor exists
            if (index > numStrings) {

                USBD_Stall(0);
            }
            else {

                pString = pStrings[index];

                // Adjust length and send descriptor
                if (length > USBGenericDescriptor_GetLength(pString)) {

                    length = USBGenericDescriptor_GetLength(pString);
                }
                USBD_Write(0, pString, length, 0, 0);
            }
            break;

        default:
            TRACE_WARNING(
                      "USBDDriver_GetDescriptor: Unknown descriptor type (%d)\n\r",
                      type);
            USBD_Stall(0);
    }
}

//------------------------------------------------------------------------------
/// Sets the active setting of the given interface if the configuration supports
/// it; otherwise, the control pipe is STALLed. If the setting of an interface
/// changes.
/// \parma pDriver  Pointer to a USBDDriver instance.
/// \parma infnum  Interface number.
/// \parma setting  New active setting for the interface.
//------------------------------------------------------------------------------
static void SetInterface(
    USBDDriver *pDriver,
    unsigned char infnum,
    unsigned char setting)
{
    // Make sure alternate settings are supported
    if (!pDriver->pInterfaces) {

        USBD_Stall(0);
    }
    else {

        // Change the current setting of the interface and trigger the callback 
        // if necessary
        if (pDriver->pInterfaces[infnum] != setting) {

            pDriver->pInterfaces[infnum] = setting;
            USBDDriverCallbacks_InterfaceSettingChanged(infnum, setting);
        }

        // Acknowledge the request
        USBD_Write(0, 0, 0, 0, 0);
    }
}

//------------------------------------------------------------------------------
/// Sends the currently active setting of the given interface to the USB
/// host. If alternate settings are not supported, this function STALLs the
/// control pipe.
/// \param pDriver  Pointer to a USBDDriver instance.
/// \param infnum  Interface number.
//------------------------------------------------------------------------------
static void GetInterface(
    const USBDDriver *pDriver,
    unsigned char infnum)
{
    // Make sure alternate settings are supported, or STALL the control pipe
    if (!pDriver->pInterfaces) {

        USBD_Stall(0);
    }
    else {

        // Sends the current interface setting to the host
        USBD_Write(0, &(pDriver->pInterfaces[infnum]), 1, 0, 0);
    }
}

#ifdef BOARD_USB_UDPHS
//------------------------------------------------------------------------------
// Performs the selected test on the USB device (high-speed only).
// \param test  Test selector value.
//------------------------------------------------------------------------------
static void USBDDriver_Test(unsigned char test)
{
    TRACE_DEBUG("UDPHS_Test\n\r");

    // the lower byte of wIndex must be zero
    // the most significant byte of wIndex is used to specify the specific test mode
    switch (test) {
        case USBFeatureRequest_TESTPACKET:
            //Test mode Test_Packet: 
            //Upon command, a port must repetitively transmit the following test packet until
            //the exit action is taken. This enables the testing of rise and fall times, eye 
            //patterns, jitter, and any other dynamic waveform specifications.
            //The test packet is made up by concatenating the following strings. 
            //(Note: For J/K NRZI data, and for NRZ data, the bit on the left is the first one 
            //transmitted. 揝

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人精品午夜视频免费| fc2成人免费人成在线观看播放 | 美国十次了思思久久精品导航| 国产一区二区在线视频| 色婷婷综合激情| 精品国产91乱码一区二区三区 | 在线区一区二视频| 精品国产一区二区三区忘忧草| 亚洲嫩草精品久久| 精品一区二区三区免费播放 | 日韩激情视频在线观看| 国产精选一区二区三区| 欧美人妇做爰xxxⅹ性高电影| 一区精品在线播放| 国产精品888| 91精品国产麻豆国产自产在线| 亚洲男人电影天堂| 丰满少妇久久久久久久| 91精品国产欧美一区二区18 | 色av成人天堂桃色av| 久久久久青草大香线综合精品| 日韩不卡一区二区| 欧美三区在线观看| 亚洲精品免费在线观看| 99久久夜色精品国产网站| 久久久久国产成人精品亚洲午夜 | 午夜激情一区二区| 在线免费av一区| 一区二区三区四区不卡在线| av福利精品导航| 国产精品毛片久久久久久久| 国产精品一二三区| 久久久不卡影院| 成人黄动漫网站免费app| 国产欧美精品一区| 成人免费高清在线| 亚洲国产精品成人综合| 成人天堂资源www在线| 国产欧美一区二区三区网站| 成人性色生活片| 成人欧美一区二区三区| www.日韩精品| 一区二区三区久久久| 精品视频全国免费看| 亚洲国产精品麻豆| 7777女厕盗摄久久久| 看电视剧不卡顿的网站| 精品电影一区二区| 国产福利一区在线观看| 国产精品乱人伦一区二区| av一区二区不卡| 亚洲精品美腿丝袜| 欧美日韩电影一区| 精品一区精品二区高清| 国产三级久久久| 色哟哟亚洲精品| 天天色综合天天| 久久精品一区二区三区不卡| 福利一区福利二区| 一区二区欧美在线观看| 9191国产精品| 国产在线视频一区二区三区| 国产精品国产三级国产aⅴ中文| 91啪在线观看| 日韩成人伦理电影在线观看| 国产精品视频九色porn| 91国产丝袜在线播放| 美女性感视频久久| 国产精品日日摸夜夜摸av| 欧美偷拍一区二区| 国产一区二区三区av电影 | 色视频欧美一区二区三区| 日本欧美一区二区| 国产精品不卡在线| 日韩精品中文字幕在线一区| 99久久久国产精品| 美女视频一区二区| 国产精品传媒视频| 日韩你懂的在线播放| 97精品国产露脸对白| 日本女优在线视频一区二区| 日韩理论片中文av| 精品噜噜噜噜久久久久久久久试看| 99在线精品观看| 国产一区二区在线影院| 日韩1区2区3区| 亚洲天堂中文字幕| 久久久久久一二三区| 91精品国产91久久久久久一区二区 | 麻豆91小视频| 亚洲一区二区三区视频在线播放| 久久九九全国免费| 日韩一区二区精品在线观看| 色菇凉天天综合网| 99麻豆久久久国产精品免费 | 色哟哟一区二区| 成人美女在线观看| 国产呦萝稀缺另类资源| 奇米精品一区二区三区在线观看| 亚洲最新在线观看| 国产精品伦理一区二区| 国产日韩欧美精品综合| 欧美r级电影在线观看| 制服丝袜亚洲色图| 欧美午夜精品一区| 色婷婷激情综合| 色婷婷一区二区三区四区| av成人动漫在线观看| av综合在线播放| 99久久精品久久久久久清纯| 成人性色生活片免费看爆迷你毛片| 国产精品综合一区二区| 国产一区二区福利| 国产一区二区三区免费播放| 美日韩一区二区| 国产乱码精品一区二区三| 精品一区二区在线视频| 精品写真视频在线观看| 久久精品国产网站| 久久精品国产网站| 国产麻豆成人传媒免费观看| 国产99久久久久久免费看农村| 国产不卡高清在线观看视频| 国产69精品久久久久777| 丁香五精品蜜臀久久久久99网站| 国产mv日韩mv欧美| 91麻豆高清视频| 欧美日韩一区在线| 欧美一激情一区二区三区| 欧美电影免费提供在线观看| 国产丝袜在线精品| 综合av第一页| 丝袜美腿亚洲色图| 裸体健美xxxx欧美裸体表演| 狠狠狠色丁香婷婷综合久久五月| 国产乱国产乱300精品| 91一区二区三区在线观看| 在线国产电影不卡| 日韩欧美电影一二三| 国产欧美精品国产国产专区| 亚洲欧美偷拍另类a∨色屁股| 亚洲另类色综合网站| 视频在线观看一区| 国产麻豆精品theporn| 91丨国产丨九色丨pron| 欧美久久一二三四区| 久久精品视频网| 亚洲第一二三四区| 国产一区二区三区日韩| 在线免费观看日韩欧美| 日韩美女在线视频| 亚洲色图欧美在线| 久久精品国产亚洲一区二区三区| 成人性生交大合| 欧美一级久久久久久久大片| 国产精品久久久久久久久免费相片| 亚洲国产裸拍裸体视频在线观看乱了 | 99国产精品久久| 欧美精品久久久久久久多人混战| 久久亚洲精品小早川怜子| 亚洲精品日韩综合观看成人91| 精品一区二区三区在线播放视频 | 日韩一区二区三区av| 日本一区二区动态图| 日韩精品色哟哟| 91麻豆成人久久精品二区三区| 欧美精品一区二| 亚洲国产日韩a在线播放性色| 国产成人一级电影| 欧美精品自拍偷拍动漫精品| 国产精品久久久久天堂| 麻豆91精品91久久久的内涵| 欧美日韩一区二区三区视频 | 成人午夜免费视频| 日韩一区二区三区电影在线观看 | 在线不卡中文字幕播放| 国产精品视频在线看| 狠狠色2019综合网| 91精品国产乱| 亚洲一区精品在线| 成人激情图片网| 久久午夜国产精品| 麻豆精品视频在线观看视频| 欧美日韩国产高清一区二区三区 | 欧美日韩国产片| 亚洲免费av观看| 不卡的av在线播放| 国产精品久久看| 成人网在线免费视频| 国产蜜臀av在线一区二区三区| 精品一区二区三区影院在线午夜 | 麻豆91在线看| 日韩一区二区三区av| 香蕉乱码成人久久天堂爱免费| 91国偷自产一区二区使用方法| 亚洲男女一区二区三区| 成人美女在线观看| 国产精品美女久久久久久久久久久| 国产成人av电影在线播放| 久久久久久电影|