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)
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_kbd 
usb_hid_report_descriptor_kbd
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 271 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_kbd::report, TRUE, Usb_ack_receive_out, Usb_ack_receive_setup, usb_hid_report_descriptor_kbd, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.

Referenced by usb_user_read_request().

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

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 339 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().

00340 {
00341    Usb_ack_receive_setup();
00342    Usb_send_control_in();
00343 
00344    while(!Is_usb_receive_out());
00345    Usb_ack_receive_out();
00346    Usb_send_control_in();
00347 }

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 355 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().

00356 {
00357    U16 wInterface;
00358    
00359    // Get interface number to put in idle mode
00360    LSB(wInterface)=Usb_read_byte();
00361    MSB(wInterface)=Usb_read_byte();
00362    Usb_ack_receive_setup();
00363   
00364    g_u8_report_rate = u8_duration;
00365    
00366    Usb_send_control_in();
00367    while(!Is_usb_in_ready());
00368 }

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 375 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().

00376 {
00377    U16 wLength;
00378    U16 wInterface;
00379 
00380    // Get interface number to put in idle mode
00381    LSB(wInterface)= Usb_read_byte();
00382    MSB(wInterface)= Usb_read_byte();
00383    LSB(wLength)   = Usb_read_byte();
00384    MSB(wLength)   = Usb_read_byte();
00385    Usb_ack_receive_setup();
00386    
00387    if( wLength != 0 )
00388    {
00389       Usb_write_byte(g_u8_report_rate);
00390       Usb_send_control_in();
00391    }
00392    
00393    while(!Is_usb_receive_out());
00394    Usb_ack_receive_out();
00395 }

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 400 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_kbd, 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().

00401 {
00402    U16 wLength;
00403    U8  nb_byte;
00404    bit zlp=FALSE;
00405    U16 wInterface;
00406 
00407    LSB(wInterface)=Usb_read_byte();
00408    MSB(wInterface)=Usb_read_byte();
00409 
00410    data_to_transfer = sizeof(usb_conf_desc.hid_kbd);
00411    pbuffer = &(usb_conf_desc.hid_kbd.bLength);
00412 
00413    LSB(wLength) = Usb_read_byte();
00414    MSB(wLength) = Usb_read_byte();
00415    Usb_ack_receive_setup();
00416 
00417    if (wLength > data_to_transfer)
00418    {
00419       if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
00420       else { zlp = FALSE; }                     // no need of zero length packet
00421    }
00422    else
00423    {
00424       data_to_transfer = (U8)wLength;           // send only requested number of data
00425    }
00426 
00427    while((data_to_transfer != 0) && (!Is_usb_receive_out()))
00428    {
00429       while(!Is_usb_read_control_enabled());
00430 
00431       nb_byte=0;
00432       while(data_to_transfer != 0)              // Send data until necessary
00433       {
00434          if(nb_byte++==EP_CONTROL_LENGTH)       // Check endpoint 0 size
00435          {
00436             break;
00437          }
00438 #ifndef __GNUC__
00439          Usb_write_byte(*pbuffer++);
00440 #else    // AVRGCC does not support point to PGM space
00441 //warning with AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
00442          Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
00443 #endif
00444          data_to_transfer --;
00445       }
00446       Usb_send_control_in();
00447    }
00448 
00449    if(Is_usb_receive_out())
00450    { 
00451       // abort from Host
00452       Usb_ack_receive_out();
00453       return;
00454    }
00455    if(zlp == TRUE)
00456    { 
00457       while(!Is_usb_read_control_enabled());
00458       Usb_send_control_in();
00459    }
00460 
00461    while(!Is_usb_receive_out());
00462    Usb_ack_receive_out();
00463 }

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 89 of file usb_specific_request.c.

Referenced by usb_process_request().

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

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 177 of file usb_specific_request.c.

Referenced by usb_set_configuration().

00178 {
00179    usb_configure_endpoint( EP_KBD_IN,     \
00180                            TYPE_INTERRUPT,\
00181                            DIRECTION_IN,  \
00182                            SIZE_8,        \
00183                            ONE_BANK,      \
00184                            NYET_ENABLED);
00185 }

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 194 of file usb_specific_request.c.

Referenced by usb_get_interface().

00195 {
00196    return 0;  // Only one alternate setting possible for all interface
00197 }

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 205 of file usb_specific_request.c.

Referenced by usb_set_interface().

00206 {  
00207    // default setting selected = reset data toggle
00208    if( INTERFACE_NB_KBD == wInterface )
00209    {
00210       // Interface mouse
00211       Usb_select_endpoint(EP_KBD_IN);
00212       Usb_disable_stall_handshake();
00213       Usb_reset_endpoint(EP_KBD_IN);
00214       Usb_reset_data_toggle();
00215    }
00216 }

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 226 of file usb_specific_request.c.

Referenced by usb_get_descriptor().

00227 {
00228    switch(type)
00229    {
00230       case DESCRIPTOR_STRING:
00231       switch (string)
00232       {
00233          case LANG_ID:
00234          data_to_transfer = sizeof (usb_user_language_id);
00235          pbuffer = &(usb_user_language_id.bLength);
00236          return TRUE;
00237          break;
00238         
00239          case MAN_INDEX:
00240          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00241          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00242          return TRUE;
00243          break;
00244         
00245          case PROD_INDEX:
00246          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00247          pbuffer = &(usb_user_product_string_descriptor.bLength);
00248          return TRUE;
00249          break;
00250            
00251 #if (USB_DEVICE_SN_USE==ENABLE)              
00252          case SN_INDEX:
00253          data_to_transfer = sizeof (usb_user_serial_number);
00254          pbuffer = &(usb_user_serial_number.bLength);
00255 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00256          f_get_serial_string=TRUE;
00257          data_to_transfer += (SN_LENGTH*4);
00258 #endif
00259          return TRUE;
00260          break;
00261 #endif
00262       }
00263       break;
00264    }
00265    return FALSE;
00266 }

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_kbd usb_hid_report_descriptor_kbd

Definition at line 171 of file usb_descriptors.c.

U8 g_u8_report_rate = 0

Definition at line 70 of file usb_specific_request.c.

Referenced by usb_hid_get_idle(), and usb_hid_set_idle().


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