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 
00054 //_____ M A C R O S ________________________________________________________
00055 
00056 //_____ D E F I N I T I O N ________________________________________________
00057 
00058 //_____ P R I V A T E   D E C L A R A T I O N ______________________________
00059 
00060 extern U8   code *pbuffer;
00061 extern U8   data_to_transfer;
00062 extern S_line_coding   line_coding;
00063 
00064 //_____ D E C L A R A T I O N ______________________________________________
00065 
00076 Bool usb_user_read_request(U8 type, U8 request)
00077 {
00078 U8  descriptor_type ;
00079 U8  string_type     ;
00080 
00081    string_type     = Usb_read_byte();
00082    descriptor_type = Usb_read_byte();
00083    switch(request)
00084    {
00085       case GET_LINE_CODING:
00086          cdc_get_line_coding();
00087                return TRUE;
00088                break;
00089 
00090       case SET_LINE_CODING:
00091          cdc_set_line_coding();
00092                return TRUE;
00093                break;
00094 
00095       case SET_CONTROL_LINE_STATE:
00096          cdc_set_control_line_state();
00097       return TRUE;
00098       break;
00099 
00100       default:
00101          return FALSE;
00102          break;
00103 
00104    }
00105    return FALSE;
00106 }
00107 
00108 
00118 Bool usb_user_get_descriptor(U8 type, U8 string)
00119 { /*
00120    switch(type)
00121    {
00122       case STRING_DESCRIPTOR:
00123          switch (string)
00124          {
00125             case LANG_ID:
00126                data_to_transfer = sizeof (usb_user_language_id);
00127                pbuffer = &(usb_user_language_id.bLength);
00128                return TRUE;
00129                break;
00130             case MAN_INDEX:
00131                data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00132                pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00133                return TRUE;
00134                break;
00135             case PROD_INDEX:
00136                data_to_transfer = sizeof (usb_user_product_string_descriptor);
00137                pbuffer = &(usb_user_product_string_descriptor.bLength);
00138                return TRUE;
00139                break;
00140             case SN_INDEX:
00141                data_to_transfer = sizeof (usb_user_serial_number);
00142                pbuffer = &(usb_user_serial_number.bLength);
00143                return TRUE;
00144                break;
00145             default:
00146                return FALSE;
00147          }
00148       default:
00149          return FALSE;
00150    }*/
00151 
00152    return FALSE;
00153 }
00154 
00163 void usb_user_endpoint_init(U8 conf_nb)
00164 {
00165   usb_configure_endpoint(INT_EP,      \
00166                          TYPE_INTERRUPT,     \
00167                          DIRECTION_IN,  \
00168                          SIZE_32,       \
00169                          ONE_BANK,     \
00170                          NYET_ENABLED);
00171 
00172   usb_configure_endpoint(TX_EP,      \
00173                          TYPE_BULK,  \
00174                          DIRECTION_OUT,  \
00175                          SIZE_32,     \
00176                          ONE_BANK,     \
00177                          NYET_ENABLED);
00178 
00179   usb_configure_endpoint(RX_EP,      \
00180                          TYPE_BULK,     \
00181                          DIRECTION_IN,  \
00182                          SIZE_32,       \
00183                          ONE_BANK,     \
00184                          NYET_ENABLED);
00185 
00186   Usb_reset_endpoint(INT_EP);
00187   Usb_reset_endpoint(TX_EP);
00188   Usb_reset_endpoint(RX_EP);
00189 
00190 
00191 }
00192 
00201 void cdc_get_line_coding(void)
00202 {
00203    Usb_ack_receive_setup();
00204    Usb_write_byte(LSB0(line_coding.dwDTERate));
00205    Usb_write_byte(LSB1(line_coding.dwDTERate));
00206    Usb_write_byte(LSB2(line_coding.dwDTERate));
00207    Usb_write_byte(LSB3(line_coding.dwDTERate));
00208    Usb_write_byte(line_coding.bCharFormat);
00209    Usb_write_byte(line_coding.bParityType);
00210    Usb_write_byte(line_coding.bDataBits);
00211 
00212    Usb_send_control_in();
00213    while(!(Is_usb_read_control_enabled()));
00214      //Usb_clear_tx_complete();
00215 
00216    while(!Is_usb_receive_out());
00217    Usb_ack_receive_out();
00218 }
00219 
00220 
00229 void cdc_set_line_coding (void)
00230 {
00231    Usb_ack_receive_setup();
00232    while (!(Is_usb_receive_out()));
00233    LSB0(line_coding.dwDTERate) = Usb_read_byte();
00234    LSB1(line_coding.dwDTERate) = Usb_read_byte();
00235    LSB2(line_coding.dwDTERate) = Usb_read_byte();
00236    LSB3(line_coding.dwDTERate) = Usb_read_byte();
00237    line_coding.bCharFormat = Usb_read_byte();
00238    line_coding.bParityType = Usb_read_byte();
00239    line_coding.bDataBits = Usb_read_byte();
00240    Usb_ack_receive_out();
00241 
00242    Usb_send_control_in();                // send a ZLP for STATUS phase
00243    while(!(Is_usb_read_control_enabled()));
00244 }
00245 
00246 
00257 void cdc_set_control_line_state (void)
00258 {
00259    Usb_ack_receive_setup();
00260    Usb_send_control_in();
00261    while(!(Is_usb_read_control_enabled()));
00262 
00263 }
00264 
00265 

Generated on Mon May 5 15:57:55 2008 for ATMEL by  doxygen 1.5.1-p1