//! 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. //! bool usb_user_read_request(uint8_t bmRequestType, uint8_t bmRequest) { st_audio_cmd cmd; uint16_t wValue; LSB(wValue)=Usb_read_endpoint_data(EP_CONTROL, 8); MSB(wValue)=Usb_read_endpoint_data(EP_CONTROL, 8); // HID Keyboard stuff if( USB_SETUP_GET_STAND_INTERFACE == bmRequestType ) { switch( bmRequest ) { case SETUP_GET_DESCRIPTOR: switch( MSB(wValue) ) // Descriptor ID { case HID_DESCRIPTOR: hid_get_descriptor( sizeof(usb_conf_desc.hid_kbd) , (const uint8_t*)&usb_conf_desc.hid_kbd); return true; // no break here case HID_REPORT_DESCRIPTOR: hid_get_descriptor( sizeof(usb_hid_report_descriptor_kbd) , usb_hid_report_descriptor_kbd); return true; case HID_PHYSICAL_DESCRIPTOR: // TODO break; } break; } } //** Specific request from Class Audio //* AudioControl Requests if( USB_SETUP_SET_CLASS_INTER == bmRequestType ) { switch( bmRequest ) { // HID Stuff case HID_SET_REPORT: // The MSB wValue field specifies the Report Type // The LSB wValue field specifies the Report ID switch (MSB(wValue)) { case HID_REPORT_INPUT: // TODO break; case HID_REPORT_OUTPUT: usb_hid_set_report_ouput(); return true; // no break here case HID_REPORT_FEATURE: break; } break; case HID_SET_IDLE: usb_hid_set_idle(LSB(wValue), MSB(wValue)); return true; case HID_SET_PROTOCOL: // TODO if you use a sub class HID_SUB_CLASS_BOOT break; // Audio stuff case SETUP_AUDIO_SET_CUR: cmd = check_audio_control_request(wValue); switch( cmd.target ) { case TARGET_SPEAKER: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_speaker_set_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_speaker_set_volume(); return true; //break; } break; case TARGET_MICRO: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_micro_set_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_micro_set_volume(); return true; //break; } break; } break; case SETUP_AUDIO_SET_MIN: case SETUP_AUDIO_SET_MAX: case SETUP_AUDIO_SET_RES: case SETUP_AUDIO_SET_MEM: // TODO break; } } if( USB_SETUP_GET_CLASS_INTER == bmRequestType ) { // HID stuff switch( bmRequest ) { case HID_GET_REPORT: // TODO break; case HID_GET_IDLE: usb_hid_get_idle(LSB(wValue)); return true; case HID_GET_PROTOCOL: // TODO if you use a sub class HID_SUB_CLASS_BOOT break; } // Audio stuff switch( bmRequest ) { case SETUP_AUDIO_GET_CUR: cmd = check_audio_control_request(wValue); switch( cmd.target ) { case TARGET_SPEAKER: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_speaker_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_speaker_get_vol_cur(); return true; //break; } break; case TARGET_MICRO: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_micro_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_micro_get_vol_cur(); return true; //break; } break; } break; case SETUP_AUDIO_GET_MIN: cmd = check_audio_control_request(wValue); switch( cmd.target ) { case TARGET_SPEAKER: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_speaker_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_speaker_get_vol_min(); return true; //break; } break; case TARGET_MICRO: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_micro_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_micro_get_vol_min(); return true; //break; } break; } break; case SETUP_AUDIO_GET_MAX: cmd = check_audio_control_request(wValue); switch( cmd.target ) { case TARGET_SPEAKER: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_speaker_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_speaker_get_vol_max(); return true; //break; } break; case TARGET_MICRO: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_micro_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_micro_get_vol_max(); return true; //break; } break; } break; case SETUP_AUDIO_GET_RES: cmd = check_audio_control_request(wValue); switch( cmd.target ) { case TARGET_SPEAKER: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_speaker_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_speaker_get_vol_res(); return true; //break; } break; case TARGET_MICRO: switch( cmd.cs ) { case AUDIO_FU_CONTROL_CS_MUTE: audio_micro_get_mute(); return true; //break; case AUDIO_FU_CONTROL_CS_VOLUME: audio_micro_get_vol_res(); return true; //break; } break; } break; case SETUP_AUDIO_GET_MEM: case SETUP_AUDIO_GET_STAT: // TODO break; } } //* AudioStreaming Requests if( USB_SETUP_SET_CLASS_ENDPOINT == bmRequestType ) { switch( bmRequest ) { case SETUP_AUDIO_SAMPLING_FREQ_CONTROL: audio_speaker_set_sample_freq(); return true; //break; case SETUP_AUDIO_SET_MEM: case SETUP_AUDIO_SET_MIN: case SETUP_AUDIO_SET_MAX: case SETUP_AUDIO_SET_RES: // TODO break; } } if( USB_SETUP_GET_CLASS_ENDPOINT == bmRequestType ) { switch( bmRequest ) { case SETUP_AUDIO_GET_CUR: case SETUP_AUDIO_GET_MIN: case SETUP_AUDIO_GET_MAX: case SETUP_AUDIO_GET_RES: case SETUP_AUDIO_GET_MEM: case SETUP_AUDIO_GET_STAT: // TODO break; } } return false; // No supported 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. //! bool usb_user_read_request(U8 type, U8 request) { U8 wValue_msb; U8 wValue_lsb; // Read wValue wValue_lsb = Usb_read_endpoint_data(EP_CONTROL, 8); wValue_msb = Usb_read_endpoint_data(EP_CONTROL, 8); /* U8 descriptor_type; Usb_read_endpoint_data(EP_CONTROL, 8); // string_type descriptor_type = Usb_read_endpoint_data(EP_CONTROL, 8); */ //** Specific request from Class HID if( 0x81 == type ) // USB_SETUP_GET_STAND_INTERFACE { switch( request ) { case GET_DESCRIPTOR: switch( wValue_msb ) // Descriptor ID { #if (USB_HIGH_SPEED_SUPPORT==false) case HID_DESCRIPTOR: hid_get_descriptor( sizeof(usb_conf_desc_fs.hid) , (const U8*)&usb_conf_desc_fs.hid); return true; #else case HID_DESCRIPTOR: if( Is_usb_full_speed_mode() ) { hid_get_descriptor( sizeof(usb_conf_desc_fs.hid) , (const U8*)&usb_conf_desc_fs.hid); }else{ hid_get_descriptor( sizeof(usb_conf_desc_hs.hid_mouse) , (const U8*)&usb_conf_desc_hs.hid); } return true; #endif case HID_REPORT_DESCRIPTOR: hid_get_descriptor( sizeof(usb_hid_report_descriptor) , usb_hid_report_descriptor); return true; case HID_PHYSICAL_DESCRIPTOR: // TODO break; } break; } } if( 0x21 == type ) // USB_SETUP_SET_CLASS_INTER { switch( request ) { case HID_SET_REPORT: // The MSB wValue field specifies the Report Type // The LSB wValue field specifies the Report ID switch (wValue_msb) { case HID_REPORT_INPUT: // TODO break; case HID_REPORT_OUTPUT: Usb_ack_setup_received_free(); while (!Is_usb_control_out_received()); Usb_ack_control_out_received_free(); Usb_ack_control_in_ready_send(); while (!Is_usb_control_in_ready()); return true; case HID_REPORT_FEATURE: usb_hid_set_report_feature(); return true; break; } break; case HID_SET_IDLE: usb_hid_set_idle(wValue_lsb, wValue_msb); return true; case HID_SET_PROTOCOL: // TODO break; } } if( 0xA1 == type ) // USB_SETUP_GET_CLASS_INTER { switch( request ) { case HID_GET_REPORT: // TODO break; case HID_GET_IDLE: usb_hid_get_idle(wValue_lsb); return true; case HID_GET_PROTOCOL: // TODO break; } } return false; // No supported request }
//! @breif This function checks the specific request and if known then processes it //! //! @param type corresponding at bmRequestType (see USB specification) //! @param request corresponding at bRequest (see USB specification) //! //! @return TRUE, when the request is processed //! @return FALSE, if the request is'nt know (STALL handshake is managed by the main standard request function). //! Bool usb_user_read_request(U8 type, U8 request) { U8 wValue_msb; U8 wValue_lsb; // Read wValue wValue_lsb = Usb_read_byte(); wValue_msb = Usb_read_byte(); //** Specific request from Class HID if( USB_SETUP_GET_STAND_INTERFACE == type ) { switch( request ) { case SETUP_GET_DESCRIPTOR: switch( wValue_msb ) // Descriptor ID { case DESCRIPTOR_HID: hid_get_hid_descriptor(); return TRUE; break; case DESCRIPTOR_REPORT: hid_get_report_descriptor(); return TRUE; case DESCRIPTOR_PHYSICAL: // TODO break; } break; } } if( USB_SETUP_SET_CLASS_INTER == type ) { switch( request ) { case SETUP_HID_SET_REPORT: // The MSB wValue field specifies the Report Type // The LSB wValue field specifies the Report ID switch (wValue_msb) { case REPORT_TYPE_INPUT: // TODO break; case REPORT_TYPE_OUTPUT: usb_hid_set_report_ouput(); return TRUE; break; case REPORT_TYPE_FEATURE: break; } break; case SETUP_HID_SET_IDLE: usb_hid_set_idle(wValue_lsb,wValue_msb); return TRUE; case SETUP_HID_SET_PROTOCOL: // TODO break; } } if( USB_SETUP_GET_CLASS_INTER == type ) { switch( request ) { case SETUP_HID_GET_REPORT: // TODO break; case SETUP_HID_GET_IDLE: usb_hid_get_idle(wValue_lsb); return TRUE; case SETUP_HID_GET_PROTOCOL: // TODO break; } } return FALSE; // No supported request }