- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# 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_mouse
| Usb HID Report Descriptor Mouse. More...
struct | S_usb_hid_report_descriptor_kbd
| Usb HID Report Descriptor Keyboard. More...
## Defines
#define | MASS_STORAGE_RESET 0xFF
#define | GET_MAX_LUN 0xFE
## Functions
Bool | usb_user_read_request (U8, U8)
| usb_user_read_request(type, request);
Bool | usb_user_get_descriptor (U8, U8)
| usb_user_get_descriptor.This function returns the size and the pointer on a user information structure
void | usb_user_endpoint_init (U8)
| usb_user_endpoint_init.This function configures the endpoints.
void | hid_get_report (void)
| hid_get_report.This function manages hit get repport request.
void | hid_set_report (void)
| hid_set_report.This function manages hit set report request.
void | usb_hid_get_interface (void)
| usb_hid_get_interface.This function manages hid get interface request.
void | usb_hid_set_idle (void)
| usb_hid_set_idle.This function manages hid set idle request.
void | hid_get_hid_descriptor (void)
| hid_get_hid_descriptor.This function manages hid get hid descriptor request.
## Variables
code S_usb_device_descriptor | usb_dev_desc
code S_usb_user_configuration_descriptor | usb_conf_desc
code S_usb_user_configuration_descriptor | usb_other_conf_desc
code S_usb_device_qualifier_descriptor | usb_qual_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

## Define Documentation

#define MASS_STORAGE_RESET 0xFF

Definition at line 44 of file usb_specific_request.h.

Referenced by usb_user_read_request().

#define GET_MAX_LUN 0xFE

Definition at line 45 of file usb_specific_request.h.

Referenced by usb_user_read_request().

## 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, GET_MAX_LUN, get_nb_lun(), HID, hid_get_hid_descriptor(), hid_get_report(), hid_set_report(), MASS_STORAGE_RESET, ms_multiple_drive, REPORT, SET_CONFIGURATION, SET_REPORT, TRUE, Usb_ack_receive_setup, usb_hid_get_interface(), Usb_read_byte, Usb_send_control_in, and Usb_write_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
    00087        case SET_CONFIGURATION:
    00088          switch (descriptor_type)
    00089          {
    00090             case SET_REPORT:
    00091                hid_set_report();
    00092                return TRUE;
    00093                break;
    00094
    00095             default:
    00096                return FALSE;
    00097                break;
    00098          }
    00099          break;
    00100    case GET_INTERFACE:
    00101 //      usb_hid_set_idle();
    00102       usb_hid_get_interface();
    00103       return TRUE;
    00104       break;
    00105
    00106     case MASS_STORAGE_RESET:
    00107          Usb_ack_receive_setup();
    00108          Usb_send_control_in();
    00109          return TRUE;
    00110          break;
    00111
    00112     case GET_MAX_LUN:
    00113          Usb_ack_receive_setup();
    00114          Usb_write_byte( (get_nb_lun()-1) );
    00115          Usb_send_control_in();
    00116          ms_multiple_drive = 1;
    00117          return TRUE;
    00118          break;
    00119
    00120       default:
    00121          return FALSE;
    00122          break;
    00123
    00124    }
    00125    return FALSE;
    00126 }

Here is the call graph for this function:

Bool usb_user_get_descriptor | ( | U8 | type,
|  | U8 | string |
| ) |  |  |

usb_user_get_descriptor.This function returns the size and the pointer on a user information structure

Parameters:

  | none |

Returns:
  none

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

    00173 {
    00174    switch(type)
    00175    {
    00176       case STRING_DESCRIPTOR:
    00177          switch (string)
    00178          {
    00179             case LANG_ID:
    00180                data_to_transfer = sizeof (usb_user_language_id);
    00181                pbuffer = &(usb_user_language_id.bLength);
    00182                return TRUE;
    00183                break;
    00184             case MAN_INDEX:
    00185                data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
    00186                pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
    00187                return TRUE;
    00188                break;
    00189             case PROD_INDEX:
    00190                data_to_transfer = sizeof (usb_user_product_string_descriptor);
    00191                pbuffer = &(usb_user_product_string_descriptor.bLength);
    00192                return TRUE;
    00193                break;
    00194             case SN_INDEX:
    00195                data_to_transfer = sizeof (usb_user_serial_number);
    00196                pbuffer = &(usb_user_serial_number.bLength);
    00197                return TRUE;
    00198                break;
    00199             default:
    00200                return FALSE;
    00201          }
    00202       default:
    00203          return FALSE;
    00204    }
    00205
    00206    return FALSE;
    00207 }

void usb_user_endpoint_init | ( | U8 | conf_nb | ) |

usb_user_endpoint_init.This function configures the endpoints.

Parameters:

  | none |

Returns:
  none

Definition at line 138 of file usb_specific_request.c.

References DIRECTION_IN, DIRECTION_OUT, EP_MOUSE_IN, EP_MS_IN, EP_MS_OUT, NYET_ENABLED, ONE_BANK, SIZE_64, SIZE_8, TYPE_BULK, TYPE_INTERRUPT, and usb_configure_endpoint.

Referenced by usb_set_configuration().

    00139 {
    00140  usb_configure_endpoint(EP_MOUSE_IN,      \
    00141                          TYPE_INTERRUPT,     \
    00142                          DIRECTION_IN,  \
    00143                          SIZE_8,       \
    00144                          ONE_BANK,     \
    00145                          NYET_ENABLED);
    00146
    00147  usb_configure_endpoint(EP_MS_IN,      \
    00148                          TYPE_BULK,     \
    00149                          DIRECTION_IN,  \
    00150                          SIZE_64,       \
    00151                          ONE_BANK,     \
    00152                          NYET_ENABLED);
    00153
    00154  usb_configure_endpoint(EP_MS_OUT,     \
    00155                          TYPE_BULK,     \
    00156                          DIRECTION_OUT, \
    00157                          SIZE_64,       \
    00158                          ONE_BANK,     \
    00159                          NYET_ENABLED);
    00160 }

void hid_get_report | ( | void |  | ) |

hid_get_report.This function manages hit get repport request.

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 218 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_mouse::report, TRUE, Usb_ack_receive_out, Usb_ack_receive_setup, usb_hid_report_descriptor_mouse, Usb_read_byte, Usb_send_control_in, Usb_write_byte, wInterface, and zlp.

Referenced by usb_user_read_request().

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

void hid_set_report | ( | void |  | ) |

hid_set_report.This function manages hit set report request.

Parameters:

  | none |

Returns:
  none

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

    00289 {
    00290    Usb_ack_receive_setup();
    00291    Usb_send_control_in();
    00292
    00293    while(!Is_usb_receive_out());
    00294    Usb_ack_receive_out();
    00295    Usb_send_control_in();
    00296
    00297 }

void usb_hid_get_interface | ( | void |  | ) |

usb_hid_get_interface.This function manages hid get interface request.

Parameters:

  | none |

Returns:
  none

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

    00332 {
    00333   U8 dummy;
    00334   dummy = Usb_read_byte();
    00335   dummy = Usb_read_byte();
    00336   LSB(wInterface)=Usb_read_byte();
    00337   MSB(wInterface)=Usb_read_byte();
    00338
    00339   Usb_ack_receive_setup();
    00340
    00341   Usb_send_control_in();                       /* send a ZLP for STATUS phase */
    00342   while(!Is_usb_in_ready());
    00343 }

void usb_hid_set_idle | ( | void |  | ) |

usb_hid_set_idle.This function manages hid set idle request.

Parameters:

  | none |

Returns:
  none

Definition at line 308 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.

    00309 {
    00310   U8 dummy;
    00311   dummy = Usb_read_byte();
    00312   dummy = Usb_read_byte();
    00313   LSB(wInterface)=Usb_read_byte();
    00314   MSB(wInterface)=Usb_read_byte();
    00315
    00316   Usb_ack_receive_setup();
    00317
    00318   Usb_send_control_in();                       /* send a ZLP for STATUS phase */
    00319   while(!Is_usb_in_ready());
    00320 }

void hid_get_hid_descriptor | ( | void |  | ) |

hid_get_hid_descriptor.This function manages hid get hid descriptor request.

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 353 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_mouse, 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, Usb_write_byte, wInterface, and zlp.

Referenced by usb_user_read_request().

    00354 {
    00355
    00356 U16 wLength;
    00357 U8  nb_byte;
    00358 bit zlp=0;
    00359
    00360
    00361
    00362    LSB(wInterface)=Usb_read_byte();
    00363    MSB(wInterface)=Usb_read_byte();
    00364
    00365    data_to_transfer = sizeof(usb_conf_desc.hid_mouse);
    00366    pbuffer = &(usb_conf_desc.hid_mouse.bLength);
    00367
    00368    LSB(wLength) = Usb_read_byte();
    00369    MSB(wLength) = Usb_read_byte();
    00370    Usb_ack_receive_setup() ;
    00371
    00372    if (wLength > data_to_transfer)
    00373    {
    00374       if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
    00375       else { zlp = FALSE; }
    00376    }
    00377    else
    00378    {
    00379       data_to_transfer = (U8)wLength;
    00380    }
    00381
    00382    while((data_to_transfer != 0) && (!Is_usb_receive_out()))
    00383    {
    00384       while(!Is_usb_read_control_enabled());
    00385
    00386       nb_byte=0;
    00387       while(data_to_transfer != 0)
    00388       {
    00389          if(nb_byte++==EP_CONTROL_LENGTH)
    00390          {
    00391             break;
    00392          }
    00393 #ifndef AVRGCC
    00394          Usb_write_byte(*pbuffer++);
    00395 #else    // AVRGCC does not support point to PGM space
    00396 #warning with avrgcc assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
    00397          Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));
    00398 #endif
    00399          data_to_transfer --;
    00400       }
    00401       Usb_send_control_in();
    00402    }
    00403
    00404    Usb_send_control_in();
    00405
    00406    if(Is_usb_receive_out()) { Usb_ack_receive_out(); return; }
    00407    if(zlp == TRUE)        { Usb_send_control_in(); }
    00408
    00409    while(!Is_usb_receive_out());
    00410    Usb_ack_receive_out();
    00411 }

## 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.

Referenced by hid_get_hid_descriptor().

code S_usb_user_configuration_descriptor usb_other_conf_desc

code S_usb_device_qualifier_descriptor usb_qual_desc

code S_usb_manufacturer_string_descriptor usb_user_manufacturer_string_descriptor

Definition at line 133 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 142 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().

code S_usb_serial_number usb_user_serial_number

Definition at line 151 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().

code S_usb_language_id usb_user_language_id

Definition at line 160 of file usb_descriptors.c.

Referenced by usb_user_get_descriptor().