Defines | Functions | Variables

# USB device standard requests decoding

## Defines
#define | ATTACHED 0
#define | POWERED 1
#define | DEFAULT 2
#define | ADDRESSED 3
#define | CONFIGURED 4
#define | SUSPENDED 5
#define | USB_REMOTE_WAKEUP 1
#define | Is_device_enumerated() ((usb_configuration_nb!=0) ? TRUE : FALSE)
| Returns true when device connected and correctly enumerated with an host.
#define | Is_device_not_enumerated() ((usb_configuration_nb!=0) ? FALSE : TRUE)
## Functions
void | usb_process_request (void)
| This function reads the SETUP request sent to the default control endpoint and calls the appropriate function.
void | usb_generate_remote_wakeup (void)
| This function manages the remote wakeup generation to wake up the host controlle.
## Variables
U8 | usb_configuration_nb
| Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device when its value is different from zero, it means the device mode is enumerated Used with USB_DEVICE_FEATURE == ENABLED only /.
U8 | remote_wakeup_feature

## Define Documentation

#define ATTACHED 0

Definition at line 70 of file usb_standard_request.h.

#define POWERED 1

Definition at line 71 of file usb_standard_request.h.

#define DEFAULT 2

Definition at line 72 of file usb_standard_request.h.

#define ADDRESSED 3

Definition at line 73 of file usb_standard_request.h.

#define CONFIGURED 4

Definition at line 74 of file usb_standard_request.h.

#define SUSPENDED 5

Definition at line 75 of file usb_standard_request.h.

#define USB_REMOTE_WAKEUP 1

Definition at line 77 of file usb_standard_request.h.

Referenced by usb_set_feature().

#define Is_device_enumerated | ( | ) | ((usb_configuration_nb!=0) ? TRUE : FALSE)

Returns true when device connected and correctly enumerated with an host.

The device high level application should tests this before performing any applicative requests

Definition at line 83 of file usb_standard_request.h.

Referenced by mouse_task().

#define Is_device_not_enumerated | ( | ) | ((usb_configuration_nb!=0) ? FALSE : TRUE)

Definition at line 84 of file usb_standard_request.h.

## Function Documentation

void usb_process_request | ( | void | ) |

This function reads the SETUP request sent to the default control endpoint and calls the appropriate function.

When exiting of the usb_read_request function, the device is ready to manage the next request.

If the received request is not supported or a none USB standard request, the function will call for custom decoding function in usb_specific_request module.

Parameters:

  none |

Returns:
  none

Note:
  list of supported requests: SETUP_GET_DESCRIPTOR SETUP_GET_CONFIGURATION SETUP_SET_ADDRESS SETUP_SET_CONFIGURATION SETUP_CLEAR_FEATURE SETUP_SET_FEATURE SETUP_GET_STATUS

When exiting of the usb_read_request function, the device is ready to manage the next request.

Definition at line 109 of file usb_standard_request.c.

References endpoint_status, EP_CONTROL, MSK_EP_DIR, SETUP_CLEAR_FEATURE, SETUP_GET_CONFIGURATION, SETUP_GET_DESCRIPTOR, SETUP_GET_INTERFACE, SETUP_GET_STATUS, SETUP_SET_ADDRESS, SETUP_SET_CONFIGURATION, SETUP_SET_FEATURE, SETUP_SET_INTERFACE, Usb_ack_control_out, Usb_ack_receive_setup, usb_clear_feature(), Usb_enable_stall_handshake, usb_get_configuration(), usb_get_descriptor(), usb_get_interface(), usb_get_status(), Usb_read_byte, usb_set_address(), usb_set_configuration(), usb_set_feature(), usb_set_interface(), USB_SETUP_GET_STAND_DEVICE, USB_SETUP_GET_STAND_INTERFACE, USB_SETUP_SET_STAND_DEVICE, USB_SETUP_SET_STAND_INTERFACE, and usb_user_read_request().

Referenced by usb_device_task().

    {
       U8 bmRequestType;
       U8 bmRequest;

       Usb_ack_control_out();
       bmRequestType = Usb_read_byte();
       bmRequest     = Usb_read_byte();

       switch (bmRequest)
       {
          case SETUP_GET_DESCRIPTOR:
          if (USB_SETUP_GET_STAND_DEVICE == bmRequestType)
          {
             if( usb_get_descriptor() )
                return;
          }
          break;

          case SETUP_GET_CONFIGURATION:
          if (USB_SETUP_GET_STAND_DEVICE == bmRequestType)
          {
             usb_get_configuration();
             return;
          }
          break;

          case SETUP_SET_ADDRESS:
          if (USB_SETUP_SET_STAND_DEVICE == bmRequestType)
          {
             usb_set_address();
             return;
          }
          break;

          case SETUP_SET_CONFIGURATION:
          if (USB_SETUP_SET_STAND_DEVICE == bmRequestType)
          {
             if( usb_set_configuration() )
                return;
          }
          break;

          case SETUP_CLEAR_FEATURE:
          if (usb_clear_feature(bmRequestType))
             return;
          break;

          case SETUP_SET_FEATURE:
          if (usb_set_feature(bmRequestType))
             return;
          break;

          case SETUP_GET_STATUS:
          if (usb_get_status(bmRequestType))
             return;
          break;

          case SETUP_GET_INTERFACE:
          if (USB_SETUP_GET_STAND_INTERFACE == bmRequestType)
          {
             if( usb_get_interface() )
                return;
          }
          break;

          case SETUP_SET_INTERFACE:
          if (bmRequestType == USB_SETUP_SET_STAND_INTERFACE)
          {
             if( usb_set_interface() )
                return;
          }
          break;

          default:
          break;
       }

       // un-supported like standard request => call to user read request
       if( !usb_user_read_request(bmRequestType, bmRequest) )
       {
          // Request unknow in the specific request list from interface
          // keep that order (set StallRq/clear RxSetup) or a
          // OUT request following the SETUP may be acknowledged
          Usb_enable_stall_handshake();
          Usb_ack_receive_setup();
          endpoint_status[(EP_CONTROL & MSK_EP_DIR)] = 0x01;
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void usb_generate_remote_wakeup | ( | void | ) |

This function manages the remote wakeup generation to wake up the host controlle.

If the received request is not supported or a none USB standard request, the function will call for custom decoding function in usb_specific_request module.

Parameters:

  none |

Returns:
  none

Definition at line 615 of file usb_standard_request.c.

References DISABLED, ENABLED, FALSE, Is_pll_ready, remote_wakeup_feature, Usb_initiate_remote_wake_up, Usb_unfreeze_clock, and Wait_pll_ready.

Referenced by switch_event_int().

    {
       if(Is_pll_ready()==FALSE)
       {
          Pll_start_auto();
          Wait_pll_ready();
       }
       Usb_unfreeze_clock();
       if (remote_wakeup_feature == ENABLED)
       {
          Usb_initiate_remote_wake_up();
          remote_wakeup_feature = DISABLED;
       }
    }

Here is the caller graph for this function:

## Variable Documentation

U8 usb_configuration_nb

Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device when its value is different from zero, it means the device mode is enumerated Used with USB_DEVICE_FEATURE == ENABLED only /.

Definition at line 100 of file usb_standard_request.c.

U8 remote_wakeup_feature

Definition at line 101 of file usb_standard_request.c.