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.

Data Structures

struct  st_audio_cmd

Defines

#define TARGET_UNDEFINE   0
#define TARGET_MICRO   2

Functions

st_audio_cmd check_audio_control_request (void)
 Checks if the audio control request is a Feature Unit Control request for the good feature unit and channel.
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.
void audio_micro_set_mute (void)
void audio_micro_get_mute (void)
void audio_micro_set_volume (void)
void audio_micro_get_vol_cur (void)
void audio_micro_get_vol_min (void)
void audio_micro_get_vol_max (void)
void audio_micro_get_vol_res (void)

Variables

U8 interface_status [2] = {0,0}
U8 code * pbuffer
U8 data_to_transfer
bit b_micro_mute
 Mute control of micro TRUE when ACTIVE, FALSE otherwise.
S16 s16_micro_volume
 Represents the current volume of audio stream micro No effet in this demo.


Detailed Description

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

Definition in file usb_specific_request.c.


Define Documentation

#define TARGET_UNDEFINE   0

Definition at line 60 of file usb_specific_request.c.

Referenced by check_audio_control_request().

#define TARGET_MICRO   2

Definition at line 61 of file usb_specific_request.c.

Referenced by check_audio_control_request(), and usb_user_read_request().


Function Documentation

st_audio_cmd check_audio_control_request ( void   ) 

Checks if the audio control request is a Feature Unit Control request for the good feature unit and channel.

Returns:
the target audio and the Control Selector from request

Definition at line 412 of file usb_specific_request.c.

References AC_INTERFACE_NB, AUDIO_FU_CONTROL_CS_UNDEFINED, st_audio_cmd::cs, FEATURE_UNIT_ID, LSB, MSB, st_audio_cmd::target, TARGET_MICRO, TARGET_UNDEFINE, Usb_ack_receive_setup, and Usb_read_byte.

Referenced by usb_user_read_request().

00413 {
00414    st_audio_cmd cmd;
00415    U16 wValue;
00416    U16 wIndex;
00417    U16 length;
00418 
00419    LSB(wValue)=Usb_read_byte();
00420    MSB(wValue)=Usb_read_byte();
00421    LSB(wIndex)=Usb_read_byte();
00422    MSB(wIndex)=Usb_read_byte();
00423    LSB(length)=Usb_read_byte();
00424    MSB(length)=Usb_read_byte();
00425    Usb_ack_receive_setup();
00426 
00427    cmd.target = TARGET_UNDEFINE;
00428    cmd.cs     = AUDIO_FU_CONTROL_CS_UNDEFINED;
00429    
00430    // Note: The wValue field interpretation is qualified by the value in the wIndex field.
00431    // Check target of the command
00432    if( LSB(wIndex) == AC_INTERFACE_NB)
00433    {
00434       // The request is for the Feature Unit Control then
00435       // MSB(wIndex) = Feature Unit ID, LSB(wValue) = Channel Number (CN), MSB(wValue) = Control Selector (CS)
00436       cmd.cs = MSB(wValue);
00437 
00438       if( (MSB(wIndex) == FEATURE_UNIT_ID)
00439       &&  (LSB(wValue) == 0) )
00440       {
00441          // for Master Channel of micro
00442          cmd.target = TARGET_MICRO;
00443       }
00444    }
00445    return cmd;
00446 }

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

Referenced by usb_process_request().

00099 {
00100    st_audio_cmd cmd;
00101 
00102    //** Specific request from Class Audio
00103    //* AudioControl Requests
00104    if( USB_SETUP_SET_CLASS_INTER == type )
00105    {
00106       switch( request )
00107       {
00108          case SETUP_AUDIO_SET_CUR:
00109          cmd = check_audio_control_request();
00110          switch( cmd.target )
00111          {
00112             case TARGET_MICRO:
00113             switch( cmd.cs )
00114             {
00115                case AUDIO_FU_CONTROL_CS_MUTE:
00116                audio_micro_set_mute();
00117                return TRUE;
00118                break;
00119                case AUDIO_FU_CONTROL_CS_VOLUME:
00120                audio_micro_set_volume();
00121                return TRUE;
00122                break;
00123             }
00124             break;
00125          }
00126          break;
00127 
00128          case SETUP_AUDIO_SET_MIN:
00129          case SETUP_AUDIO_SET_MAX:
00130          case SETUP_AUDIO_SET_RES:
00131          // TODO
00132          break;
00133       }
00134    }
00135 
00136    if( USB_SETUP_GET_CLASS_INTER == type )
00137    {
00138       switch( request )
00139       {
00140          case SETUP_AUDIO_GET_CUR:
00141          cmd = check_audio_control_request();
00142          switch( cmd.target )
00143          {
00144             case TARGET_MICRO:
00145             switch( cmd.cs )
00146             {
00147                case AUDIO_FU_CONTROL_CS_MUTE:
00148                audio_micro_get_mute();
00149                return TRUE;
00150                break;
00151                case AUDIO_FU_CONTROL_CS_VOLUME:
00152                audio_micro_get_vol_cur();
00153                return TRUE;
00154                break;
00155             }
00156             break;
00157          }
00158          break;
00159          
00160          case SETUP_AUDIO_GET_MIN:
00161          cmd = check_audio_control_request();
00162          switch( cmd.target )
00163          {
00164             case TARGET_MICRO:
00165             switch( cmd.cs )
00166             {
00167                case AUDIO_FU_CONTROL_CS_MUTE:
00168                audio_micro_get_mute();
00169                return TRUE;
00170                break;
00171                case AUDIO_FU_CONTROL_CS_VOLUME:
00172                audio_micro_get_vol_min();
00173                return TRUE;
00174                break;
00175             }
00176             break;
00177          }
00178          break;
00179          
00180          case SETUP_AUDIO_GET_MAX:
00181          cmd = check_audio_control_request();
00182          switch( cmd.target )
00183          {
00184             case TARGET_MICRO:
00185             switch( cmd.cs )
00186             {
00187                case AUDIO_FU_CONTROL_CS_MUTE:
00188                audio_micro_get_mute();
00189                return TRUE;
00190                break;
00191                case AUDIO_FU_CONTROL_CS_VOLUME:
00192                audio_micro_get_vol_max();
00193                return TRUE;
00194                break;
00195             }
00196             break;
00197          }
00198          break;
00199          
00200          case SETUP_AUDIO_GET_RES:
00201          cmd = check_audio_control_request();
00202          switch( cmd.target )
00203          {
00204             case TARGET_MICRO:
00205             switch( cmd.cs )
00206             {
00207                case AUDIO_FU_CONTROL_CS_MUTE:
00208                audio_micro_get_mute();
00209                return TRUE;
00210                break;
00211                case AUDIO_FU_CONTROL_CS_VOLUME:
00212                audio_micro_get_vol_res();
00213                return TRUE;
00214                break;
00215             }
00216             break;
00217          }
00218          break;
00219       }
00220    }
00221    
00222    //* AudioStreaming Requests
00223    if( USB_SETUP_SET_CLASS_ENDPOINT == type )
00224    {
00225       switch( request )
00226       {
00227          case SETUP_AUDIO_SET_MEM:
00228          case SETUP_AUDIO_SET_MIN:
00229          case SETUP_AUDIO_SET_MAX:
00230          case SETUP_AUDIO_SET_RES:
00231          // TODO
00232          break;
00233       }
00234    }
00235    if( USB_SETUP_GET_CLASS_ENDPOINT == type )
00236    {
00237       switch( request )
00238       {
00239          case SETUP_AUDIO_GET_CUR:
00240          case SETUP_AUDIO_GET_MIN:
00241          case SETUP_AUDIO_GET_MAX:
00242          case SETUP_AUDIO_GET_RES:
00243          // TODO
00244          break;
00245       }
00246    }
00247 
00248    //* Additional Requests
00249    // Set Memory Request
00250    if( USB_SETUP_SET_CLASS_INTER == type )
00251    {
00252       switch( request )
00253       {
00254          case SETUP_AUDIO_SET_MEM:
00255          // TODO
00256          break;
00257       }
00258    }
00259    if( USB_SETUP_SET_CLASS_ENDPOINT == type )
00260    {
00261       switch( request )
00262       {
00263          case SETUP_AUDIO_SET_MEM:
00264          // TODO
00265          break;
00266       }
00267    }
00268    // Get Memory Request
00269    if( USB_SETUP_GET_CLASS_INTER == type )
00270    {
00271       switch( request )
00272       {
00273          case SETUP_AUDIO_GET_MEM:
00274          // TODO
00275          break;
00276       }
00277    }
00278    if( USB_SETUP_GET_CLASS_ENDPOINT == type )
00279    {
00280       switch( request )
00281       {
00282          case SETUP_AUDIO_GET_MEM:
00283          // TODO
00284          break;
00285       }
00286    }
00287    // Get Status Request
00288    if( USB_SETUP_GET_CLASS_INTER == type )
00289    {
00290       switch( request )
00291       {
00292          case SETUP_AUDIO_GET_STAT:
00293          // TODO
00294          break;
00295       }
00296    }
00297    if( USB_SETUP_GET_CLASS_ENDPOINT == type )
00298    {
00299       switch( request )
00300       {
00301          case SETUP_AUDIO_GET_STAT:
00302          // TODO
00303          break;
00304       }
00305    }
00306    return FALSE;  // No supported request
00307 }

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

Referenced by usb_set_configuration().

00315 {
00316    usb_configure_endpoint(EP_AUDIO_IN,     \
00317                           TYPE_ISOCHRONOUS,\
00318                           DIRECTION_IN,    \
00319                           SIZE_16,         \
00320                           TWO_BANKS,       \
00321                           NYET_ENABLED);
00322 }

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

Referenced by usb_get_interface().

00332 {
00333    return interface_status[wInterface];
00334 }

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

Referenced by usb_set_interface().

00343 {  
00344    interface_status[wInterface] = alternate_setting;
00345    // default setting selected = reset data toggle
00346    if((NB_OF_STREAMING_INTERFACE == wInterface )
00347    && (1 == alternate_setting))
00348    {
00349       // Interface for Microphone, alternate setting with endpoint
00350       Usb_select_endpoint(EP_AUDIO_IN);
00351       Usb_disable_stall_handshake();
00352       Usb_reset_endpoint(EP_AUDIO_IN);
00353       Usb_reset_data_toggle();
00354    }
00355 }

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

Referenced by usb_get_descriptor().

00366 {
00367    switch(type)
00368    {
00369       case DESCRIPTOR_STRING:
00370       switch (string)
00371       {
00372          case LANG_ID:
00373          data_to_transfer = sizeof (usb_user_language_id);
00374          pbuffer = &(usb_user_language_id.bLength);
00375          return TRUE;
00376          break;
00377         
00378          case MAN_INDEX:
00379          data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
00380          pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
00381          return TRUE;
00382          break;
00383         
00384          case PROD_INDEX:
00385          data_to_transfer = sizeof (usb_user_product_string_descriptor);
00386          pbuffer = &(usb_user_product_string_descriptor.bLength);
00387          return TRUE;
00388          break;
00389            
00390 #if (USB_DEVICE_SN_USE==ENABLE)              
00391          case SN_INDEX:
00392          data_to_transfer = sizeof (usb_user_serial_number);
00393          pbuffer = &(usb_user_serial_number.bLength);
00394 #if (USE_DEVICE_SN_UNIQUE==ENABLE)
00395          f_get_serial_string=TRUE;
00396          data_to_transfer += (SN_LENGTH*4);
00397 #endif
00398          return TRUE;
00399          break;
00400 #endif
00401       }
00402       break;
00403    }
00404    return FALSE;
00405 }

Here is the caller graph for this function:

void audio_micro_set_mute ( void   ) 

Definition at line 450 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00451 {
00452    while(!Is_usb_receive_out());
00453    b_micro_mute=Usb_read_byte();
00454    Usb_ack_receive_out();
00455    Usb_send_control_in();        // send a ZLP
00456 }

Here is the caller graph for this function:

void audio_micro_get_mute ( void   ) 

Definition at line 457 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00458 {
00459    Usb_write_byte(b_micro_mute);
00460    Usb_send_control_in();
00461    while(!Is_usb_receive_out()); // send a ZLP
00462    Usb_ack_receive_out();
00463 }

Here is the caller graph for this function:

void audio_micro_set_volume ( void   ) 

Definition at line 464 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00465 {
00466    while(!Is_usb_receive_out());
00467    LSB(s16_micro_volume)=Usb_read_byte();
00468    MSB(s16_micro_volume)=Usb_read_byte();
00469    Usb_ack_receive_out();
00470    Usb_send_control_in();        // send a ZLP
00471 }

Here is the caller graph for this function:

void audio_micro_get_vol_cur ( void   ) 

Definition at line 472 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00473 {
00474    Usb_write_byte(LSB(s16_micro_volume));
00475    Usb_write_byte(MSB(s16_micro_volume));
00476    Usb_send_control_in();
00477    while(!Is_usb_receive_out()); // send a ZLP
00478    Usb_ack_receive_out();
00479 }

Here is the caller graph for this function:

void audio_micro_get_vol_min ( void   ) 

Definition at line 480 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00481 {
00482    Usb_write_byte(LOW(MICRO_VOL_MIN));
00483    Usb_write_byte(HIGH(MICRO_VOL_MIN));
00484    Usb_send_control_in();
00485    while(!Is_usb_receive_out()); // send a ZLP
00486    Usb_ack_receive_out();
00487 }

Here is the caller graph for this function:

void audio_micro_get_vol_max ( void   ) 

Definition at line 488 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00489 {
00490    Usb_write_byte(LOW(MICRO_VOL_MAX));
00491    Usb_write_byte(HIGH(MICRO_VOL_MAX));
00492    Usb_send_control_in();
00493    while(!Is_usb_receive_out()); // send a ZLP
00494    Usb_ack_receive_out();
00495 }

Here is the caller graph for this function:

void audio_micro_get_vol_res ( void   ) 

Definition at line 496 of file usb_specific_request.c.

Referenced by usb_user_read_request().

00497 {
00498    Usb_write_byte(LOW(MICRO_VOL_RES));
00499    Usb_write_byte(HIGH(MICRO_VOL_RES));
00500    Usb_send_control_in();
00501    while(!Is_usb_receive_out()); // send a ZLP
00502    Usb_ack_receive_out();
00503 }

Here is the caller graph for this function:


Variable Documentation

U8 interface_status[2] = {0,0}

Definition at line 72 of file usb_specific_request.c.

Referenced by usb_user_interface_get(), and usb_user_interface_reset().

U8 code* pbuffer

Definition at line 91 of file usb_standard_request.c.

Referenced by usb_get_descriptor(), and usb_user_get_descriptor().

U8 data_to_transfer

Definition at line 96 of file usb_standard_request.c.

Referenced by usb_get_descriptor(), and usb_user_get_descriptor().

bit b_micro_mute

Mute control of micro TRUE when ACTIVE, FALSE otherwise.

Definition at line 65 of file audio_task.c.

S16 s16_micro_volume

Represents the current volume of audio stream micro No effet in this demo.

Definition at line 70 of file audio_task.c.


Generated on Fri Oct 31 15:31:43 2008 for ATMEL by  doxygen 1.5.3