usb_specific_request.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00016 
00017 /* Copyright (c) 2007, 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  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00034  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00042  */
00043 
00044 
00045 //_____ I N C L U D E S ____________________________________________________
00046 
00047 #include "config.h"
00048 #include "conf_usb.h"
00049 #include "lib_mcu/usb/usb_drv.h"
00050 #include "usb_descriptors.h"
00051 #include "modules/usb/device_chap9/usb_standard_request.h"
00052 #include "usb_specific_request.h"
00053 #if ((USB_DEVICE_SN_USE==ENABLE) && (USE_DEVICE_SN_UNIQUE==ENABLE))
00054 #include "lib_mcu/flash/flash_drv.h"
00055 #endif
00056 
00057 //_____ D E F I N I T I O N ________________________________________________
00058 
00059 #ifdef __GNUC__
00060 extern PGM_VOID_P pbuffer;
00061 #else
00062 extern U8   code *pbuffer;
00063 #endif
00064 extern U8   data_to_transfer;
00065 
00066 
00067 //_____ D E C L A R A T I O N ______________________________________________
00068 
00077 Bool usb_user_read_request(U8 type, U8 request)
00078 {
00079    U8  wValue_msb;
00080    U8  wValue_lsb;
00081 
00082    // Read wValue
00083    wValue_lsb = Usb_read_byte();
00084    wValue_msb = Usb_read_byte();
00085 
00086    //** Specific request from Class
00087    if( USB_SETUP_GET_STAND_INTERFACE == type )
00088    {
00089       switch( request )
00090       {
00091          case SETUP_GET_DESCRIPTOR:
00092          switch( wValue_msb ) // Descriptor ID
00093          {
00094             default:
00095             // TODO
00096             break;
00097          }
00098          break;
00099       }
00100    }
00101    if( USB_SETUP_SET_CLASS_INTER == type )
00102    {
00103       switch( request )
00104       {
00105          default:
00106          break;
00107       }
00108    }
00109    if( USB_SETUP_GET_CLASS_INTER == type )
00110    {
00111       switch( request )
00112       {
00113          default:
00114          break;
00115       }
00116    }
00117    return FALSE;  // No supported request
00118 }
00119 
00120 
00125 void usb_user_endpoint_init(U8 conf_nb)
00126 {
00127    usb_configure_endpoint(EP_TEMP_IN,    \
00128                           TYPE_BULK,     \
00129                           DIRECTION_IN,  \
00130                           SIZE_64,       \
00131                           ONE_BANK,      \
00132                           NYET_ENABLED);
00133    usb_configure_endpoint(EP_TEMP_OUT,   \
00134                           TYPE_BULK,     \
00135                           DIRECTION_OUT, \
00136                           SIZE_64,       \
00137                           ONE_BANK,      \
00138                           NYET_ENABLED);
00139    usb_configure_endpoint(EP_TEMP_INT_IN,\
00140                           TYPE_BULK,     \
00141                           TYPE_INTERRUPT,\
00142                           SIZE_64,       \
00143                           ONE_BANK,      \
00144                           NYET_ENABLED);
00145 }
00146 
00147 
00154 U8   usb_user_interface_get( U16 wInterface )
00155 {
00156    return 0;  // Only one alternate setting possible for all interface
00157 }
00158 
00159 
00165 void usb_user_interface_reset(U16 wInterface, U8 alternate_setting)
00166 {  
00167    // default setting selected = reset data toggle
00168    if( INTERFACE_NB_TEMP == wInterface )
00169    {
00170       // Interface reset
00171       Usb_select_endpoint(EP_TEMP_IN);
00172       Usb_disable_stall_handshake();
00173       Usb_reset_endpoint(EP_TEMP_IN);
00174       Usb_reset_data_toggle();
00175       Usb_select_endpoint(EP_TEMP_OUT);
00176       Usb_disable_stall_handshake();
00177       Usb_reset_endpoint(EP_TEMP_OUT);
00178       Usb_reset_data_toggle();
00179    }
00180    if( INTERFACE_NB_SECOND_TEMP == wInterface )
00181    {
00182       // Interface reset
00183       Usb_select_endpoint(EP_TEMP_INT_IN);
00184       Usb_disable_stall_handshake();
00185       Usb_reset_endpoint(EP_TEMP_INT_IN);
00186       Usb_reset_data_toggle();
00187    }
00188 }
00189 
00190    
00198 Bool usb_user_get_descriptor(U8 type, U8 string)
00199 {
00200    switch(type)
00201    {
00202       case DESCRIPTOR_STRING:
00203       switch (string)
00204       {
00205          case LANG_ID:
00206          data_to_transfer = sizeof (usb_user_language_id);
00207          pbuffer = &(usb_user_language_id.bLength);
00208          return TRUE;
00209          break;
00210         
00211          case MAN_INDEX:
00212          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00213          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00214          return TRUE;
00215          break;
00216         
00217          case PROD_INDEX:
00218          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00219          pbuffer = &(usb_user_product_string_descriptor.bLength);
00220          return TRUE;
00221          break;
00222            
00223 #if (USB_DEVICE_SN_USE==ENABLE)              
00224          case SN_INDEX:
00225          data_to_transfer = sizeof (usb_user_serial_number);
00226          pbuffer = &(usb_user_serial_number.bLength);
00227 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00228          f_get_serial_string=TRUE;
00229          data_to_transfer += (SN_LENGTH*4);
00230 #endif
00231          return TRUE;
00232          break;
00233 #endif
00234       }
00235       break;
00236    }
00237    return FALSE;
00238 }
00239 
00240 

Generated on Mon Nov 3 10:08:24 2008 for ATMEL by  doxygen 1.5.3