usb_specific_request.c

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00016 
00017 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms, with or without
00020  * modification, are permitted provided that the following conditions are met:
00021  *
00022  * 1. Redistributions of source code must retain the above copyright notice,
00023  * this list of conditions and the following disclaimer.
00024  *
00025  * 2. Redistributions in binary form must reproduce the above copyright notice,
00026  * this list of conditions and the following disclaimer in the documentation
00027  * and/or other materials provided with the distribution.
00028  *
00029  * 3. The name of Atmel may not be used to endorse or promote products derived
00030  * from this software without specific prior written permission.
00031  *
00032  * 4. This software may only be redistributed and used in connection with an Atmel
00033  * AVR product.
00034  *
00035  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00037  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00038  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00039  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00040  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00041  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00042  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00043  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00044  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00045  */
00046 
00047 
00048 //_____ I N C L U D E S ____________________________________________________
00049 
00050 #include "config.h"
00051 #include "conf_usb.h"
00052 #include "lib_mcu/usb/usb_drv.h"
00053 #include "usb_descriptors.h"
00054 #include "modules/usb/device_chap9/usb_standard_request.h"
00055 #include "usb_specific_request.h"
00056 #if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
00057 #include "lib_mcu/flash/flash_drv.h"
00058 #endif
00059 
00060 //_____ D E F I N I T I O N ________________________________________________
00061 
00062 #ifdef __GNUC__
00063 extern PGM_VOID_P pbuffer;
00064 #else
00065 extern U8   code *pbuffer;
00066 #endif
00067 extern U8   data_to_transfer;
00068 
00069 
00070 //_____ D E C L A R A T I O N ______________________________________________
00071 
00080 Bool usb_user_read_request(U8 type, U8 request)
00081 {
00082    U8  wValue_msb;
00083    U8  wValue_lsb;
00084 
00085    // Read wValue
00086    wValue_lsb = Usb_read_byte();
00087    wValue_msb = Usb_read_byte();
00088 
00089    //** Specific request from Class
00090    if( USB_SETUP_GET_STAND_INTERFACE == type )
00091    {
00092       switch( request )
00093       {
00094          case SETUP_GET_DESCRIPTOR:
00095          switch( wValue_msb ) // Descriptor ID
00096          {
00097             default:
00098             // TODO
00099             break;
00100          }
00101          break;
00102       }
00103    }
00104    if( USB_SETUP_SET_CLASS_INTER == type )
00105    {
00106       switch( request )
00107       {
00108          default:
00109          break;
00110       }
00111    }
00112    if( USB_SETUP_GET_CLASS_INTER == type )
00113    {
00114       switch( request )
00115       {
00116          default:
00117          break;
00118       }
00119    }
00120    return FALSE;  // No supported request
00121 }
00122 
00123 
00128 void usb_user_endpoint_init(U8 conf_nb)
00129 {
00130    usb_configure_endpoint(EP_TEMP_IN,    \
00131                           TYPE_BULK,     \
00132                           DIRECTION_IN,  \
00133                           SIZE_64,       \
00134                           ONE_BANK,      \
00135                           NYET_ENABLED);
00136    usb_configure_endpoint(EP_TEMP_OUT,   \
00137                           TYPE_BULK,     \
00138                           DIRECTION_OUT, \
00139                           SIZE_64,       \
00140                           ONE_BANK,      \
00141                           NYET_ENABLED);
00142    usb_configure_endpoint(EP_TEMP_INT_IN,\
00143                           TYPE_BULK,     \
00144                           TYPE_INTERRUPT,\
00145                           SIZE_64,       \
00146                           ONE_BANK,      \
00147                           NYET_ENABLED);
00148 }
00149 
00150 
00157 U8   usb_user_interface_get( U16 wInterface )
00158 {
00159    return 0;  // Only one alternate setting possible for all interface
00160 }
00161 
00162 
00168 void usb_user_interface_reset(U16 wInterface, U8 alternate_setting)
00169 {  
00170    // default setting selected = reset data toggle
00171    if( INTERFACE_NB_TEMP == wInterface )
00172    {
00173       // Interface reset
00174       Usb_select_endpoint(EP_TEMP_IN);
00175       Usb_disable_stall_handshake();
00176       Usb_reset_endpoint(EP_TEMP_IN);
00177       Usb_reset_data_toggle();
00178       Usb_select_endpoint(EP_TEMP_OUT);
00179       Usb_disable_stall_handshake();
00180       Usb_reset_endpoint(EP_TEMP_OUT);
00181       Usb_reset_data_toggle();
00182    }
00183    if( INTERFACE_NB_SECOND_TEMP == wInterface )
00184    {
00185       // Interface reset
00186       Usb_select_endpoint(EP_TEMP_INT_IN);
00187       Usb_disable_stall_handshake();
00188       Usb_reset_endpoint(EP_TEMP_INT_IN);
00189       Usb_reset_data_toggle();
00190    }
00191 }
00192 
00193    
00201 Bool usb_user_get_descriptor(U8 type, U8 string)
00202 {
00203    switch(type)
00204    {
00205       case DESCRIPTOR_STRING:
00206       switch (string)
00207       {
00208          case LANG_ID:
00209          data_to_transfer = sizeof (usb_user_language_id);
00210          pbuffer = &(usb_user_language_id.bLength);
00211          return TRUE;
00212          break;
00213         
00214          case MAN_INDEX:
00215          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00216          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00217          return TRUE;
00218          break;
00219         
00220          case PROD_INDEX:
00221          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00222          pbuffer = &(usb_user_product_string_descriptor.bLength);
00223          return TRUE;
00224          break;
00225            
00226 #if (USB_DEVICE_SN_USE==ENABLE)              
00227          case SN_INDEX:
00228          data_to_transfer = sizeof (usb_user_serial_number);
00229          pbuffer = &(usb_user_serial_number.bLength);
00230 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00231          f_get_serial_string=TRUE;
00232          data_to_transfer += (SN_LENGTH*4);
00233 #endif
00234          return TRUE;
00235          break;
00236 #endif
00237       }
00238       break;
00239    }
00240    return FALSE;
00241 }
00242 
00243 

Generated on Fri Sep 11 14:23:53 2009 for ATMEL by  doxygen 1.5.3