usb_specific_request.c File Reference

#include "config.h"
#include "conf_usb.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "modules/usb/device_chap9/usb_standard_request.h"
#include "usb_specific_request.h"
#include "lib_mcu/flash/flash_drv.h"

Include dependency graph for usb_specific_request.c:

Go to the source code of this file.

Functions

void hid_get_report_descriptor (void)
void usb_hid_set_report_ouput (void)
void usb_hid_set_idle (U8 u8_report_id, U8 u8_duration)
void usb_hid_get_idle (U8 u8_report_id)
void hid_get_hid_descriptor (void)
void usb_hid_set_report_feature (void)
Bool usb_user_read_request (U8 type, U8 request)
 This function checks the specific request and if known then processes it
void usb_user_endpoint_init (U8 conf_nb)
U8 usb_user_interface_get (U16 wInterface)
void usb_user_interface_reset (U16 wInterface, U8 alternate_setting)
Bool usb_user_get_descriptor (U8 type, U8 string)
 This function fills the global descriptor.

Variables

U8 code * pbuffer
U8 data_to_transfer
code
S_usb_hid_report_descriptor 
usb_hid_report_descriptor
U8 jump_bootloader = 0
U8 g_u8_report_rate = 0


Detailed Description

user call-back functions This file contains the user call-back functions corresponding to the application: - Compiler: IAR EWAVR and GNU GCC for AVR

Definition in file usb_specific_request.c.


Function Documentation

void hid_get_report_descriptor ( void   ) 

This function manages hit get repport request.

Definition at line 286 of file usb_specific_request.c.

References data_to_transfer, EP_CONTROL_LENGTH, FALSE, Is_usb_read_control_enabled, Is_usb_receive_out, LSB, MSB, pbuffer, S_usb_hid_report_descriptor::report, TRUE, Usb_ack_receive_out, Usb_ack_receive_setup, usb_hid_report_descriptor, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.

Referenced by usb_user_read_request().

00287 {
00288    U16 wLength;
00289    U8  nb_byte;
00290    bit zlp = FALSE;
00291    U16 wInterface;
00292 
00293    LSB(wInterface)=Usb_read_byte();
00294    MSB(wInterface)=Usb_read_byte();
00295 
00296    data_to_transfer = sizeof(usb_hid_report_descriptor);
00297    pbuffer = &(usb_hid_report_descriptor.report[0]);
00298 
00299    LSB(wLength) = Usb_read_byte();
00300    MSB(wLength) = Usb_read_byte();
00301    Usb_ack_receive_setup();
00302 
00303    if (wLength > data_to_transfer)
00304    {
00305       if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
00306       else { zlp = FALSE; }
00307    }
00308    else
00309    {
00310       data_to_transfer = (U8)wLength;           // send only requested number of data
00311    }
00312 
00313    while((data_to_transfer != 0) && (!Is_usb_receive_out()))
00314    {
00315       while(!Is_usb_read_control_enabled());
00316 
00317       nb_byte=0;
00318       while(data_to_transfer != 0)              // Send data until necessary
00319       {
00320          if(nb_byte++==EP_CONTROL_LENGTH)       // Check endpoint 0 size
00321          {
00322             break;
00323          }
00324 #ifndef __GNUC__
00325          Usb_write_byte(*pbuffer++);
00326 #else    // AVRGCC does not support point to PGM space
00327 //warning with AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
00328          Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
00329 #endif
00330          data_to_transfer --;
00331       }
00332       Usb_send_control_in();
00333    }
00334 
00335    if(Is_usb_receive_out())
00336    { 
00337       // abort from Host
00338       Usb_ack_receive_out();
00339       return;
00340    }
00341    if(zlp == TRUE)
00342    { 
00343       while(!Is_usb_read_control_enabled());
00344       Usb_send_control_in();
00345    }
00346 
00347    while(!Is_usb_receive_out());
00348    Usb_ack_receive_out();
00349 }

Here is the caller graph for this function:

void usb_hid_set_report_ouput ( void   ) 

This function manages hit set report request.

Definition at line 354 of file usb_specific_request.c.

References Is_usb_receive_out, Usb_ack_receive_out, Usb_ack_receive_setup, and Usb_send_control_in.

Referenced by usb_user_read_request().

00355 {
00356    Usb_ack_receive_setup();
00357    Usb_send_control_in();
00358 
00359    while(!Is_usb_receive_out());
00360    Usb_ack_receive_out();
00361    Usb_send_control_in();
00362 }

Here is the caller graph for this function:

void usb_hid_set_idle ( U8  u8_report_id,
U8  u8_duration 
)

This function manages hid set idle request.

Parameters:
Duration When the upper byte of wValue is 0 (zero), the duration is indefinite else from 0.004 to 1.020 seconds
Report ID 0 the idle rate applies to all input reports, else only applies to the Report ID

Definition at line 370 of file usb_specific_request.c.

References g_u8_report_rate, Is_usb_in_ready, LSB, MSB, Usb_ack_receive_setup, Usb_read_byte, and Usb_send_control_in.

Referenced by usb_user_read_request().

00371 {
00372    U16 wInterface;
00373    
00374    // Get interface number to put in idle mode
00375    LSB(wInterface)=Usb_read_byte();
00376    MSB(wInterface)=Usb_read_byte();
00377    Usb_ack_receive_setup();
00378   
00379    g_u8_report_rate = u8_duration;
00380    
00381    Usb_send_control_in();
00382    while(!Is_usb_in_ready());
00383 }

Here is the caller graph for this function:

void usb_hid_get_idle ( U8  u8_report_id  ) 

This function manages hid get idle request.

Parameters:
Report ID 0 the idle rate applies to all input reports, else only applies to the Report ID

Definition at line 390 of file usb_specific_request.c.

References g_u8_report_rate, Is_usb_receive_out, LSB, MSB, Usb_ack_receive_out, Usb_ack_receive_setup, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.

Referenced by usb_user_read_request().

00391 {
00392    U16 wLength;
00393    U16 wInterface;
00394 
00395    // Get interface number to put in idle mode
00396    LSB(wInterface)= Usb_read_byte();
00397    MSB(wInterface)= Usb_read_byte();
00398    LSB(wLength)   = Usb_read_byte();
00399    MSB(wLength)   = Usb_read_byte();
00400    Usb_ack_receive_setup();
00401    
00402    if( wLength != 0 )
00403    {
00404       Usb_write_byte(g_u8_report_rate);
00405       Usb_send_control_in();
00406    }
00407    
00408    while(!Is_usb_receive_out());
00409    Usb_ack_receive_out();
00410 }

Here is the caller graph for this function:

void hid_get_hid_descriptor ( void   ) 

This function manages hid get hid descriptor request.

Definition at line 434 of file usb_specific_request.c.

References S_usb_hid_descriptor::bLength, data_to_transfer, EP_CONTROL_LENGTH, FALSE, S_usb_user_configuration_descriptor::hid, Is_usb_read_control_enabled, Is_usb_receive_out, LSB, MSB, pbuffer, TRUE, Usb_ack_receive_out, Usb_ack_receive_setup, usb_conf_desc, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.

Referenced by usb_user_read_request().

00435 {
00436    U16 wLength;
00437    U8  nb_byte;
00438    bit zlp=FALSE;
00439    U16 wInterface;
00440 
00441    LSB(wInterface)=Usb_read_byte();
00442    MSB(wInterface)=Usb_read_byte();
00443 
00444    data_to_transfer = sizeof(usb_conf_desc.hid);
00445    pbuffer = &(usb_conf_desc.hid.bLength);
00446 
00447    LSB(wLength) = Usb_read_byte();
00448    MSB(wLength) = Usb_read_byte();
00449    Usb_ack_receive_setup();
00450 
00451    if (wLength > data_to_transfer)
00452    {
00453       if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
00454       else { zlp = FALSE; }                     // no need of zero length packet
00455    }
00456    else
00457    {
00458       data_to_transfer = (U8)wLength;           // send only requested number of data
00459    }
00460 
00461    while((data_to_transfer != 0) && (!Is_usb_receive_out()))
00462    {
00463       while(!Is_usb_read_control_enabled());
00464 
00465       nb_byte=0;
00466       while(data_to_transfer != 0)              // Send data until necessary
00467       {
00468          if(nb_byte++==EP_CONTROL_LENGTH)       // Check endpoint 0 size
00469          {
00470             break;
00471          }
00472 #ifndef __GNUC__
00473          Usb_write_byte(*pbuffer++);
00474 #else    // AVRGCC does not support point to PGM space
00475 //warning with AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
00476          Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
00477 #endif
00478          data_to_transfer --;
00479       }
00480       Usb_send_control_in();
00481    }
00482 
00483    if(Is_usb_receive_out())
00484    { 
00485       // abort from Host
00486       Usb_ack_receive_out();
00487       return;
00488    }
00489    if(zlp == TRUE)
00490    { 
00491       while(!Is_usb_read_control_enabled());
00492       Usb_send_control_in();
00493    }
00494 
00495    while(!Is_usb_receive_out());
00496    Usb_ack_receive_out();
00497 }

Here is the caller graph for this function:

void usb_hid_set_report_feature ( void   ) 

Definition at line 412 of file usb_specific_request.c.

References Is_usb_in_ready, Is_usb_receive_out, jump_bootloader, Usb_ack_receive_out, Usb_ack_receive_setup, Usb_read_byte, and Usb_send_control_in.

Referenced by usb_user_read_request().

00413 {
00414 
00415    Usb_ack_receive_setup();
00416    Usb_send_control_in();
00417 
00418    while(!Is_usb_receive_out());
00419 
00420    if(Usb_read_byte()==0x55)
00421       if(Usb_read_byte()==0xAA)
00422          if(Usb_read_byte()==0x55)
00423             if(Usb_read_byte()==0xAA)
00424             {
00425                jump_bootloader=1;
00426             }
00427    Usb_ack_receive_out();
00428    Usb_send_control_in();
00429    while(!Is_usb_in_ready());
00430 }

Here is the caller graph for this function:

Bool usb_user_read_request ( U8  type,
U8  request 
)

This function checks the specific request and if known then processes it

Parameters:
type corresponding at bmRequestType (see USB specification)
request corresponding at bRequest (see USB specification)
Returns:
TRUE, when the request is processed

FALSE, if the request is'nt know (STALL handshake is managed by the main standard request function).

Definition at line 91 of file usb_specific_request.c.

Referenced by usb_process_request().

00092 {
00093    U8    wValue_msb;
00094    U8    wValue_lsb;
00095 
00096    // Read wValue
00097    wValue_lsb = Usb_read_byte();
00098    wValue_msb = Usb_read_byte();
00099 
00100    //** Specific request from Class HID
00101    if( USB_SETUP_GET_STAND_INTERFACE == type )
00102    {
00103       switch( request )
00104       {
00105          case SETUP_GET_DESCRIPTOR:
00106          switch( wValue_msb ) // Descriptor ID
00107          {
00108             case DESCRIPTOR_HID:
00109             hid_get_hid_descriptor();
00110             return TRUE;
00111             break;
00112    
00113             case DESCRIPTOR_REPORT:
00114             hid_get_report_descriptor();
00115             return TRUE;
00116    
00117             case DESCRIPTOR_PHYSICAL:
00118             // TODO
00119             break;
00120          }
00121          break;
00122       }
00123    }
00124    if( USB_SETUP_SET_CLASS_INTER == type )
00125    {
00126       switch( request )
00127       {
00128          case SETUP_HID_SET_REPORT:
00129          // The MSB wValue field specifies the Report Type
00130          // The LSB wValue field specifies the Report ID
00131          switch (wValue_msb)
00132          {
00133             case REPORT_TYPE_INPUT:
00134             // TODO
00135             break;
00136             
00137             case REPORT_TYPE_OUTPUT:
00138             usb_hid_set_report_ouput();
00139             return TRUE;
00140             break;
00141 
00142             case REPORT_TYPE_FEATURE:
00143             usb_hid_set_report_feature();
00144             return TRUE;
00145             break;
00146          }
00147          break;
00148 
00149          case SETUP_HID_SET_IDLE:
00150          usb_hid_set_idle(wValue_lsb,wValue_msb);
00151          return TRUE;
00152    
00153          case SETUP_HID_SET_PROTOCOL:
00154          // TODO
00155          break;
00156       }
00157    }
00158    if( USB_SETUP_GET_CLASS_INTER == type )
00159    {
00160       switch( request )
00161       {
00162          case SETUP_HID_GET_REPORT:
00163          // TODO
00164          break;
00165          case SETUP_HID_GET_IDLE:
00166          usb_hid_get_idle(wValue_lsb);
00167          return TRUE;
00168          case SETUP_HID_GET_PROTOCOL:
00169          // TODO
00170          break;
00171       }
00172    }
00173    return FALSE;  // No supported request
00174 }

Here is the caller graph for this function:

void usb_user_endpoint_init ( U8  conf_nb  ) 

This function configures the endpoints

Parameters:
conf_nb configuration number choosed by USB host

Definition at line 181 of file usb_specific_request.c.

Referenced by usb_set_configuration().

00182 {
00183    usb_configure_endpoint( EP_HID_IN,   \
00184                            TYPE_INTERRUPT,\
00185                            DIRECTION_IN,  \
00186                            SIZE_8,        \
00187                            ONE_BANK,      \
00188                            NYET_ENABLED);
00189 
00190    usb_configure_endpoint( EP_HID_OUT,    \
00191                            TYPE_INTERRUPT,\
00192                            DIRECTION_OUT, \
00193                            SIZE_8,        \
00194                            ONE_BANK,      \
00195                            NYET_ENABLED);
00196 }

Here is the caller graph for this function:

U8 usb_user_interface_get ( U16  wInterface  ) 

This function returns the interface alternate setting

Parameters:
wInterface Interface selected
Returns:
alternate setting configurated

Definition at line 205 of file usb_specific_request.c.

Referenced by usb_get_interface().

00206 {
00207    return 0;  // Only one alternate setting possible for all interface
00208 }

Here is the caller graph for this function:

void usb_user_interface_reset ( U16  wInterface,
U8  alternate_setting 
)

This function selects (and resets) the interface alternate setting

Parameters:
wInterface Interface selected
alternate_setting alternate setting selected

Definition at line 216 of file usb_specific_request.c.

Referenced by usb_set_interface().

00217 {  
00218    // default setting selected = reset data toggle
00219    if( INTERFACE_NB == wInterface )
00220    {
00221       // Interface HID
00222       Usb_select_endpoint(EP_HID_IN);
00223       Usb_disable_stall_handshake();
00224       Usb_reset_endpoint(EP_HID_IN);
00225       Usb_reset_data_toggle();
00226       Usb_select_endpoint(EP_HID_OUT);
00227       Usb_disable_stall_handshake();
00228       Usb_reset_endpoint(EP_HID_OUT);
00229       Usb_reset_data_toggle();
00230    }
00231 }

Here is the caller graph for this function:

Bool usb_user_get_descriptor ( U8  type,
U8  string 
)

This function fills the global descriptor.

Parameters:
type corresponding at MSB of wValue (see USB specification)
string corresponding at LSB of wValue (see USB specification)
Returns:
FALSE, if the global descriptor no filled

Definition at line 241 of file usb_specific_request.c.

Referenced by usb_get_descriptor().

00242 {
00243    switch(type)
00244    {
00245       case DESCRIPTOR_STRING:
00246       switch (string)
00247       {
00248          case LANG_ID:
00249          data_to_transfer = sizeof (usb_user_language_id);
00250          pbuffer = &(usb_user_language_id.bLength);
00251          return TRUE;
00252          break;
00253         
00254          case MAN_INDEX:
00255          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00256          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00257          return TRUE;
00258          break;
00259         
00260          case PROD_INDEX:
00261          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00262          pbuffer = &(usb_user_product_string_descriptor.bLength);
00263          return TRUE;
00264          break;
00265            
00266 #if (USB_DEVICE_SN_USE==ENABLE)              
00267          case SN_INDEX:
00268          data_to_transfer = sizeof (usb_user_serial_number);
00269          pbuffer = &(usb_user_serial_number.bLength);
00270 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00271          f_get_serial_string=TRUE;
00272          data_to_transfer += (SN_LENGTH*4);
00273 #endif
00274          return TRUE;
00275          break;
00276 #endif
00277       }
00278       break;
00279    }
00280    return FALSE;
00281 }

Here is the caller graph for this function:


Variable Documentation

U8 code* pbuffer

Definition at line 94 of file usb_standard_request.c.

Referenced by hid_get_hid_descriptor(), hid_get_report_descriptor(), usb_get_descriptor(), and usb_user_get_descriptor().

U8 data_to_transfer

Definition at line 99 of file usb_standard_request.c.

Referenced by hid_get_hid_descriptor(), hid_get_report_descriptor(), usb_get_descriptor(), and usb_user_get_descriptor().

code S_usb_hid_report_descriptor usb_hid_report_descriptor

Definition at line 182 of file usb_descriptors.c.

U8 jump_bootloader = 0

Definition at line 69 of file usb_specific_request.c.

U8 g_u8_report_rate = 0

Definition at line 71 of file usb_specific_request.c.

Referenced by usb_hid_get_idle(), and usb_hid_set_idle().


Generated on Mon Sep 14 13:54:02 2009 for ATMEL by  doxygen 1.5.3