USB device specific requests


Functions

void usb_user_endpoint_init (U8)
 This function configures the endpoints of the device application.
Bool usb_user_get_descriptor (U8, U8)
 This function returns the size and the pointer on a user information structure.
U8 usb_user_interface_get (U16 wInterface)
void usb_user_interface_reset (U16 wInterface, U8 alternate_setting)
Bool usb_user_read_request (U8, U8)
 This function is called by the standard USB read request function when the USB request is not supported.


Function Documentation

void usb_user_endpoint_init ( U8  conf_nb  ) 

This function configures the endpoints of the device application.

This function is called when the set configuration request has been received.

The core of this function should be correctly rewritten depending on the USB device application characteristics (the USB device application has specific endpoint configuration).

This function is called when the set configuration request has been received.

Definition at line 128 of file usb_specific_request.c.

References EP_ATTRIBUTES_IN, EP_ATTRIBUTES_OUT, EP_AUDIO_IN, EP_AUDIO_OUT, EP_KBD_IN, EP_SIZE_IN, EP_SIZE_KBD, and EP_SIZE_OUT.

00129 {
00130   
00131     (void)Usb_configure_endpoint( EP_KBD_IN,
00132                                  TYPE_INTERRUPT,
00133                                  DIRECTION_IN,
00134                                  EP_SIZE_KBD,
00135                                  SINGLE_BANK);
00136     
00137     (void)Usb_configure_endpoint( EP_AUDIO_OUT,
00138                                  EP_ATTRIBUTES_OUT,
00139                                  DIRECTION_OUT,
00140                                  EP_SIZE_OUT,
00141                                  DOUBLE_BANK);
00142 
00143     (void)Usb_configure_endpoint( EP_AUDIO_IN,
00144                                  EP_ATTRIBUTES_IN,
00145                                  DIRECTION_IN,
00146                                  EP_SIZE_IN,
00147                                  DOUBLE_BANK);
00148 }

Bool usb_user_get_descriptor ( U8  ,
U8   
)

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

Definition at line 473 of file usb_specific_request.c.

References data_to_transfer, LANG_ID, MAN_INDEX, pbuffer, PROD_INDEX, SN_INDEX, usb_user_language_id, usb_user_manufacturer_string_descriptor, usb_user_product_string_descriptor, and usb_user_serial_number.

00474 {
00475   pbuffer = NULL;
00476 
00477    switch(type)
00478    {
00479    case STRING_DESCRIPTOR:
00480       switch (string)
00481       {
00482          case LANG_ID:
00483          data_to_transfer = sizeof (usb_user_language_id);
00484          pbuffer = &usb_user_language_id;
00485          break;
00486 
00487          case MAN_INDEX:
00488          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00489          pbuffer = &usb_user_manufacturer_string_descriptor;
00490          break;
00491 
00492          case PROD_INDEX:
00493          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00494          pbuffer = &usb_user_product_string_descriptor;
00495          break;
00496 
00497          case SN_INDEX:
00498          data_to_transfer = sizeof (usb_user_serial_number);
00499          pbuffer = &usb_user_serial_number;
00500          break;
00501 
00502          default:
00503          break;
00504       }
00505       break;
00506 
00507   default:
00508     break;
00509    }
00510 
00511   return pbuffer != NULL;
00512 }

U8 usb_user_interface_get ( U16  wInterface  ) 

void usb_user_interface_reset ( U16  wInterface,
U8  alternate_setting 
)

Bool usb_user_read_request ( U8  bmRequestType,
U8  bmRequest 
)

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.

Definition at line 157 of file usb_specific_request.c.

References audio_micro_get_mute(), audio_micro_get_vol_cur(), audio_micro_get_vol_max(), audio_micro_get_vol_min(), audio_micro_get_vol_res(), audio_micro_set_mute(), audio_micro_set_volume(), audio_speaker_get_mute(), audio_speaker_get_vol_cur(), audio_speaker_get_vol_max(), audio_speaker_get_vol_min(), audio_speaker_get_vol_res(), audio_speaker_set_mute(), audio_speaker_set_sample_freq(), audio_speaker_set_volume(), check_audio_control_request(), st_audio_cmd::cs, hid_get_descriptor(), S_usb_user_configuration_descriptor::hid_kbd, st_audio_cmd::target, TARGET_MICRO, TARGET_SPEAKER, usb_conf_desc, usb_hid_get_idle(), usb_hid_report_descriptor_kbd, usb_hid_set_idle(), and usb_hid_set_report_ouput().

00158 {
00159    st_audio_cmd cmd;
00160 
00161    U16 wValue;
00162    LSB(wValue)=Usb_read_endpoint_data(EP_CONTROL, 8);
00163    MSB(wValue)=Usb_read_endpoint_data(EP_CONTROL, 8);
00164 
00165    // HID Keyboard stuff
00166    if( USB_SETUP_GET_STAND_INTERFACE == bmRequestType )
00167    {
00168       switch( bmRequest )
00169       {
00170          case SETUP_GET_DESCRIPTOR:
00171          switch( MSB(wValue) ) // Descriptor ID
00172          {
00173             case HID_DESCRIPTOR:
00174             hid_get_descriptor(
00175                sizeof(usb_conf_desc.hid_kbd)
00176             ,  (const U8*)&usb_conf_desc.hid_kbd);
00177             return TRUE;
00178             // no break here
00179    
00180             case HID_REPORT_DESCRIPTOR:
00181             hid_get_descriptor(
00182                sizeof(usb_hid_report_descriptor_kbd)
00183             ,  usb_hid_report_descriptor_kbd);
00184             return TRUE;
00185    
00186             case HID_PHYSICAL_DESCRIPTOR:
00187             // TODO
00188             break;
00189          }
00190          break;
00191       }
00192    }
00193 
00194    //** Specific request from Class Audio
00195    //* AudioControl Requests
00196    if( USB_SETUP_SET_CLASS_INTER == bmRequestType )
00197    {
00198       switch( bmRequest )
00199       {
00200          // HID Stuff
00201 
00202          case HID_SET_REPORT:
00203          // The MSB wValue field specifies the Report Type
00204          // The LSB wValue field specifies the Report ID
00205          switch (MSB(wValue))
00206          {
00207             case HID_REPORT_INPUT:
00208             // TODO
00209             break;
00210             
00211             case HID_REPORT_OUTPUT:
00212             usb_hid_set_report_ouput();
00213             return TRUE;
00214             // no break here
00215 
00216             case HID_REPORT_FEATURE:
00217             break;
00218          }
00219          break;
00220 
00221          case HID_SET_IDLE:
00222          usb_hid_set_idle(LSB(wValue), MSB(wValue));
00223          return TRUE;
00224    
00225          case HID_SET_PROTOCOL:
00226          // TODO if you use a sub class HID_SUB_CLASS_BOOT
00227          break;
00228 
00229 
00230 
00231          // Audio stuff
00232 
00233          case SETUP_AUDIO_SET_CUR:
00234          cmd = check_audio_control_request(wValue);
00235          switch( cmd.target )
00236          {
00237             case TARGET_SPEAKER:
00238             switch( cmd.cs )
00239             {
00240                case AUDIO_FU_CONTROL_CS_MUTE:
00241                audio_speaker_set_mute();
00242                return TRUE;
00243                //break;
00244                case AUDIO_FU_CONTROL_CS_VOLUME:
00245                audio_speaker_set_volume();
00246                return TRUE;
00247                //break;
00248             }
00249             break;
00250             case TARGET_MICRO:
00251             switch( cmd.cs )
00252             {
00253                case AUDIO_FU_CONTROL_CS_MUTE:
00254                audio_micro_set_mute();
00255                return TRUE;
00256                //break;
00257                case AUDIO_FU_CONTROL_CS_VOLUME:
00258                audio_micro_set_volume();
00259                return TRUE;
00260                //break;
00261             }
00262             break;
00263          }
00264          break;
00265 
00266          case SETUP_AUDIO_SET_MIN:
00267          case SETUP_AUDIO_SET_MAX:
00268          case SETUP_AUDIO_SET_RES:
00269          case SETUP_AUDIO_SET_MEM:
00270          // TODO
00271          break;
00272       }
00273    }
00274 
00275    if( USB_SETUP_GET_CLASS_INTER == bmRequestType )
00276    {
00277       // HID stuff
00278       switch( bmRequest )
00279       {
00280          case HID_GET_REPORT:
00281          // TODO
00282          break;
00283          case HID_GET_IDLE:
00284          usb_hid_get_idle(LSB(wValue));
00285          return TRUE;
00286          case HID_GET_PROTOCOL:
00287          // TODO if you use a sub class HID_SUB_CLASS_BOOT
00288          break;
00289       }
00290 
00291 
00292 
00293       // Audio stuff
00294 
00295       switch( bmRequest )
00296       {
00297          case SETUP_AUDIO_GET_CUR:
00298          cmd = check_audio_control_request(wValue);
00299          switch( cmd.target )
00300          {
00301             case TARGET_SPEAKER:
00302             switch( cmd.cs )
00303             {
00304                case AUDIO_FU_CONTROL_CS_MUTE:
00305                audio_speaker_get_mute();
00306                return TRUE;
00307                //break;
00308                case AUDIO_FU_CONTROL_CS_VOLUME:
00309                audio_speaker_get_vol_cur();
00310                return TRUE;
00311                //break;
00312             }
00313             break;
00314             case TARGET_MICRO:
00315             switch( cmd.cs )
00316             {
00317                case AUDIO_FU_CONTROL_CS_MUTE:
00318                audio_micro_get_mute();
00319                return TRUE;
00320                //break;
00321                case AUDIO_FU_CONTROL_CS_VOLUME:
00322                audio_micro_get_vol_cur();
00323                return TRUE;
00324                //break;
00325             }
00326             break;
00327          }
00328          break;
00329 
00330          case SETUP_AUDIO_GET_MIN:
00331          cmd = check_audio_control_request(wValue);
00332          switch( cmd.target )
00333          {
00334             case TARGET_SPEAKER:
00335             switch( cmd.cs )
00336             {
00337                case AUDIO_FU_CONTROL_CS_MUTE:
00338                audio_speaker_get_mute();
00339                return TRUE;
00340                //break;
00341                case AUDIO_FU_CONTROL_CS_VOLUME:
00342                audio_speaker_get_vol_min();
00343                return TRUE;
00344                //break;
00345             }
00346             break;
00347             case TARGET_MICRO:
00348             switch( cmd.cs )
00349             {
00350                case AUDIO_FU_CONTROL_CS_MUTE:
00351                audio_micro_get_mute();
00352                return TRUE;
00353                //break;
00354                case AUDIO_FU_CONTROL_CS_VOLUME:
00355                audio_micro_get_vol_min();
00356                return TRUE;
00357                //break;
00358             }
00359             break;
00360          }
00361          break;
00362 
00363          case SETUP_AUDIO_GET_MAX:
00364          cmd = check_audio_control_request(wValue);
00365          switch( cmd.target )
00366          {
00367             case TARGET_SPEAKER:
00368             switch( cmd.cs )
00369             {
00370                case AUDIO_FU_CONTROL_CS_MUTE:
00371                audio_speaker_get_mute();
00372                return TRUE;
00373                //break;
00374                case AUDIO_FU_CONTROL_CS_VOLUME:
00375                audio_speaker_get_vol_max();
00376                return TRUE;
00377                //break;
00378             }
00379             break;
00380             case TARGET_MICRO:
00381             switch( cmd.cs )
00382             {
00383                case AUDIO_FU_CONTROL_CS_MUTE:
00384                audio_micro_get_mute();
00385                return TRUE;
00386                //break;
00387                case AUDIO_FU_CONTROL_CS_VOLUME:
00388                audio_micro_get_vol_max();
00389                return TRUE;
00390                //break;
00391             }
00392             break;
00393          }
00394          break;
00395 
00396          case SETUP_AUDIO_GET_RES:
00397          cmd = check_audio_control_request(wValue);
00398          switch( cmd.target )
00399          {
00400             case TARGET_SPEAKER:
00401             switch( cmd.cs )
00402             {
00403                case AUDIO_FU_CONTROL_CS_MUTE:
00404                audio_speaker_get_mute();
00405                return TRUE;
00406                //break;
00407                case AUDIO_FU_CONTROL_CS_VOLUME:
00408                audio_speaker_get_vol_res();
00409                return TRUE;
00410                //break;
00411             }
00412             break;
00413             case TARGET_MICRO:
00414             switch( cmd.cs )
00415             {
00416                case AUDIO_FU_CONTROL_CS_MUTE:
00417                audio_micro_get_mute();
00418                return TRUE;
00419                //break;
00420                case AUDIO_FU_CONTROL_CS_VOLUME:
00421                audio_micro_get_vol_res();
00422                return TRUE;
00423                //break;
00424             }
00425             break;
00426          }
00427          break;
00428 
00429          case SETUP_AUDIO_GET_MEM:
00430          case SETUP_AUDIO_GET_STAT:
00431          // TODO
00432          break;
00433       }
00434    }
00435 
00436    //* AudioStreaming Requests
00437    if( USB_SETUP_SET_CLASS_ENDPOINT == bmRequestType )
00438    {
00439       switch( bmRequest )
00440       {
00441          case SETUP_AUDIO_SAMPLING_FREQ_CONTROL:
00442            audio_speaker_set_sample_freq();
00443            return TRUE;
00444            //break;
00445          case SETUP_AUDIO_SET_MEM:
00446          case SETUP_AUDIO_SET_MIN:
00447          case SETUP_AUDIO_SET_MAX:
00448          case SETUP_AUDIO_SET_RES:
00449          // TODO
00450          break;
00451       }
00452    }
00453    if( USB_SETUP_GET_CLASS_ENDPOINT == bmRequestType )
00454    {
00455       switch( bmRequest )
00456       {
00457          case SETUP_AUDIO_GET_CUR:
00458          case SETUP_AUDIO_GET_MIN:
00459          case SETUP_AUDIO_GET_MAX:
00460          case SETUP_AUDIO_GET_RES:
00461          case SETUP_AUDIO_GET_MEM:
00462          case SETUP_AUDIO_GET_STAT:
00463          // TODO
00464          break;
00465       }
00466    }
00467    return FALSE;  // No supported bmRequest
00468 }


Generated on Fri Feb 19 02:32:07 2010 for AVR32 - USB AUDIO Example by  doxygen 1.5.5