usb_specific_request.h File Reference

#include "config.h"

Include dependency graph for usb_specific_request.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  S_usb_hid_report_descriptor
 Usb HID Report Descriptor. More...

Functions

Bool usb_user_read_request (U8, U8)
Bool usb_user_get_descriptor (U8, U8)
void usb_user_endpoint_init (U8)
 This function configures the endpoints.
void hid_get_report (void)
 This function manages hit get repport request.
void hid_set_report (void)
 This function manages hit set report request.
void usb_hid_get_interface (void)
 This function manages hid get interface request.
void usb_hid_set_idle (void)
 This function manages hid set idle request.
void hid_get_hid_descriptor (void)
void usb_hid_user_set_hid_report (void)

Variables

code S_usb_device_descriptor usb_dev_desc
code S_usb_user_configuration_descriptor usb_conf_desc
code S_usb_manufacturer_string_descriptor usb_user_manufacturer_string_descriptor
code S_usb_product_string_descriptor usb_user_product_string_descriptor
code S_usb_serial_number usb_user_serial_number
code S_usb_language_id usb_user_language_id


Function Documentation

Bool usb_user_read_request ( U8  type,
U8  request 
)

usb_user_read_request(type, request);

This function is called by the standard usb read request function when the Usb request is not supported. This function returns TRUE when the request is processed. This function returns FALSE if the request is not supported. In this case, a STALL handshake will be automatically sent by the standard usb read request function.

Parameters:
none 
Returns:
none

Definition at line 59 of file usb_specific_request.c.

References FALSE, GET_DESCRIPTOR, GET_INTERFACE, HID, hid_get_hid_descriptor(), hid_get_report(), hid_set_report(), REPORT, SET_CONFIGURATION, SET_HID_REPORT, SET_REPORT, TRUE, usb_hid_get_interface(), usb_hid_user_set_hid_report(), and Usb_read_byte.

Referenced by usb_process_request().

00060 {
00061 U8  descriptor_type ;
00062 U8  string_type     ;
00063 
00064    string_type     = Usb_read_byte();
00065    descriptor_type = Usb_read_byte();
00066    switch(request)
00067    {
00068       case GET_DESCRIPTOR:
00069 
00070          switch (descriptor_type)
00071          {
00072             case REPORT:
00073                hid_get_report();
00074                return TRUE;
00075                break;
00076 
00077             case HID:
00078                hid_get_hid_descriptor();
00079                return TRUE;
00080                break;
00081             default:
00082                return FALSE;
00083                break;
00084          }
00085          break;
00086       case SET_CONFIGURATION:
00087          switch (descriptor_type)
00088          {
00089             case SET_REPORT:
00090                hid_set_report();
00091                return TRUE;
00092                break;
00093 
00094             case HID:
00095                hid_set_report();
00096                return TRUE;
00097                break;
00098 
00099             case SET_HID_REPORT:
00100                usb_hid_user_set_hid_report();
00101                return TRUE;
00102                break;
00103 
00104             default:
00105                return FALSE;
00106                break;
00107          }
00108          break;
00109    case GET_INTERFACE:
00110 //      usb_hid_set_idle();
00111       usb_hid_get_interface();
00112       return TRUE;
00113       break;
00114 
00115       default:
00116          return FALSE;
00117          break;
00118 
00119    }
00120    return FALSE;
00121 }

Here is the call graph for this function:

Bool usb_user_get_descriptor ( U8  type,
U8  string 
)

usb_user_get_descriptor.

Parameters:
none 
Returns:
none

Definition at line 158 of file usb_specific_request.c.

References S_usb_serial_number::bLength, S_usb_product_string_descriptor::bLength, S_usb_manufacturer_string_descriptor::bLength, S_usb_language_id::bLength, data_to_transfer, FALSE, LANG_ID, MAN_INDEX, pbuffer, PROD_INDEX, SN_INDEX, STRING_DESCRIPTOR, TRUE, usb_user_language_id, usb_user_manufacturer_string_descriptor, usb_user_product_string_descriptor, and usb_user_serial_number.

Referenced by usb_get_descriptor().

00159 {
00160    switch(type)
00161    {
00162       case STRING_DESCRIPTOR:
00163          switch (string)
00164          {
00165             case LANG_ID:
00166                data_to_transfer = sizeof (usb_user_language_id);
00167                pbuffer = &(usb_user_language_id.bLength);
00168                return TRUE;
00169                break;
00170             case MAN_INDEX:
00171                data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00172                pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00173                return TRUE;
00174                break;
00175             case PROD_INDEX:
00176                data_to_transfer = sizeof (usb_user_product_string_descriptor);
00177                pbuffer = &(usb_user_product_string_descriptor.bLength);
00178                return TRUE;
00179                break;
00180             case SN_INDEX:
00181                data_to_transfer = sizeof (usb_user_serial_number);
00182                pbuffer = &(usb_user_serial_number.bLength);
00183                return TRUE;
00184                break;
00185             default:
00186                return FALSE;
00187          }
00188       default:
00189          return FALSE;
00190    }
00191 
00192    return FALSE;
00193 }

void usb_user_endpoint_init ( U8  conf_nb  ) 

This function configures the endpoints.

usb_user_endpoint_init.

Parameters:
none 
Returns:
none

Definition at line 133 of file usb_specific_request.c.

References DIRECTION_IN, DIRECTION_OUT, EP_HID_IN, EP_HID_OUT, NYET_ENABLED, ONE_BANK, SIZE_8, TYPE_INTERRUPT, and usb_configure_endpoint.

Referenced by usb_set_configuration().

00134 {
00135   usb_configure_endpoint(EP_HID_IN,      \
00136                          TYPE_INTERRUPT,     \
00137                          DIRECTION_IN,  \
00138                          SIZE_8,       \
00139                          ONE_BANK,     \
00140                          NYET_ENABLED);
00141 
00142   usb_configure_endpoint(EP_HID_OUT,      \
00143                          TYPE_INTERRUPT,     \
00144                          DIRECTION_OUT,  \
00145                          SIZE_8,       \
00146                          ONE_BANK,     \
00147                          NYET_ENABLED);
00148 
00149 }

void hid_get_report ( void   ) 

This function manages hit get repport request.

hid_get_report.

Parameters:
none 
Returns:
none

< read wLength

< clear the receive setup flag

< send only requested number of data

< Send data until necessary

< Check endpoint 0 size

Definition at line 204 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, Usb_write_byte, wInterface, and zlp.

Referenced by usb_user_read_request().

00205 {
00206 
00207 U16 wLength;
00208 U8  nb_byte;
00209 bit zlp;
00210 
00211 
00212 
00213    LSB(wInterface)=Usb_read_byte();
00214    MSB(wInterface)=Usb_read_byte();
00215 
00216    data_to_transfer = sizeof(usb_hid_report_descriptor);
00217    pbuffer = &(usb_hid_report_descriptor.report[0]);
00218 
00219    LSB(wLength) = Usb_read_byte();      
00220    MSB(wLength) = Usb_read_byte();
00221    Usb_ack_receive_setup() ;                  
00222 
00223    if (wLength > data_to_transfer)
00224    {
00225       if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
00226       else { zlp = FALSE; }                   
00227    }
00228    else
00229    {
00230       data_to_transfer = (U8)wLength;         
00231    }
00232 
00233    while((data_to_transfer != 0) && (!Is_usb_receive_out()))
00234    {
00235       while(!Is_usb_read_control_enabled());
00236 
00237       nb_byte=0;
00238       while(data_to_transfer != 0)        
00239       {
00240          if(nb_byte++==EP_CONTROL_LENGTH) 
00241          {
00242             break;
00243          }
00244 #ifndef AVRGCC
00245          Usb_write_byte(*pbuffer++);
00246 #else    // AVRGCC does not support point to PGM space
00247 #warning with avrgcc assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
00248          Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
00249 #endif
00250          data_to_transfer --;
00251       }
00252       Usb_send_control_in();
00253    }
00254 
00255    Usb_send_control_in();
00256 
00257    if(Is_usb_receive_out()) { Usb_ack_receive_out(); return; } 
00258    if(zlp == TRUE)        { Usb_send_control_in(); }
00259 
00260    while(!Is_usb_receive_out());
00261    Usb_ack_receive_out();
00262 }

void hid_set_report ( void   ) 

This function manages hit set report request.

hid_set_report.

Parameters:
none 
Returns:
none

Definition at line 274 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().

00275 {
00276    Usb_ack_receive_setup();
00277    Usb_send_control_in();
00278 
00279    while(!Is_usb_receive_out());
00280    Usb_ack_receive_out();
00281    Usb_send_control_in();
00282 
00283 }

void usb_hid_get_interface ( void   ) 

This function manages hid get interface request.

usb_hid_get_interface.

Parameters:
none 
Returns:
none

Definition at line 317 of file usb_specific_request.c.

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

Referenced by usb_user_read_request().

00318 {
00319   U8 dummy;
00320   dummy = Usb_read_byte();
00321   dummy = Usb_read_byte();
00322   LSB(wInterface)=Usb_read_byte();
00323   MSB(wInterface)=Usb_read_byte();
00324 
00325   Usb_ack_receive_setup();
00326 
00327   Usb_send_control_in();                       /* send a ZLP for STATUS phase */
00328   while(!Is_usb_in_ready());
00329 }

void usb_hid_set_idle ( void   ) 

This function manages hid set idle request.

usb_hid_set_idle.

Parameters:
none 
Returns:
none

Definition at line 294 of file usb_specific_request.c.

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

00295 {
00296   U8 dummy;
00297   dummy = Usb_read_byte();
00298   dummy = Usb_read_byte();
00299   LSB(wInterface)=Usb_read_byte();
00300   MSB(wInterface)=Usb_read_byte();
00301 
00302   Usb_ack_receive_setup();
00303 
00304   Usb_send_control_in();                       /* send a ZLP for STATUS phase */
00305   while(!Is_usb_in_ready());
00306 }

void hid_get_hid_descriptor ( void   ) 

Referenced by usb_user_read_request().

void usb_hid_user_set_hid_report ( void   ) 

Definition at line 331 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().

00332 {
00333 
00334    Usb_ack_receive_setup();
00335    Usb_send_control_in();
00336 
00337    while(!Is_usb_receive_out());
00338 
00339    if(Usb_read_byte()==0x55)
00340       if(Usb_read_byte()==0xAA)
00341          if(Usb_read_byte()==0x55)
00342             if(Usb_read_byte()==0xAA)
00343             {
00344                jump_bootloader=1;
00345             }
00346    Usb_ack_receive_out();
00347    Usb_send_control_in();
00348    while(!Is_usb_in_ready());
00349 }


Variable Documentation

code S_usb_device_descriptor usb_dev_desc

Definition at line 38 of file usb_descriptors.c.

code S_usb_user_configuration_descriptor usb_conf_desc

Definition at line 57 of file usb_descriptors.c.

code S_usb_manufacturer_string_descriptor usb_user_manufacturer_string_descriptor

Definition at line 102 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().

code S_usb_product_string_descriptor usb_user_product_string_descriptor

Definition at line 111 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().

code S_usb_serial_number usb_user_serial_number

Definition at line 120 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().

code S_usb_language_id usb_user_language_id

Definition at line 129 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().


Generated on Fri Jan 26 17:33:06 2007 for Atmel by  doxygen 1.5.1-p1