📄 usb_standard_request.c
字号:
Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } break; } Usb_ack_receive_setup() ; //!< clear the receive setup flag if ((LSBwLength > data_to_transfer) || (MSBwLength)) { if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; } else { zlp = FALSE; } //!< no need of zero length packet LSBwLength = data_to_transfer; MSBwLength = 0x00; } else { data_to_transfer = LSBwLength; //!< send only requested number of data } while((data_to_transfer != 0) && (!Is_usb_receive_out())) { while(!Is_usb_read_control_enabled()); nb_byte=0; while(data_to_transfer != 0) //!< Send data until necessary { if(nb_byte++==EP_CONTROL_LENGTH) //!< Check endpoint 0 size { break; }//#ifndef AVRGCC// Usb_write_byte(*pbuffer++);//#else // AVRGCC does not support point to PGM space //#warning AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++));//#endif data_to_transfer --; } Usb_send_control_in(); } if(Is_usb_receive_out()) { Usb_ack_receive_out(); return; } //!< abort from Host if(zlp == TRUE) { while(!Is_usb_read_control_enabled()); Usb_send_control_in(); } while(!Is_usb_receive_out()); Usb_ack_receive_out();}//! usb_get_configuration.//!//! This function manages the GET CONFIGURATION request. The current//! configuration number is returned.//!//! @warning Code:xx bytes (function code length)//!void usb_get_configuration(void){ Usb_ack_receive_setup(); Usb_write_byte(usb_configuration_nb); Usb_ack_in_ready(); while( !Is_usb_receive_out() ); Usb_ack_receive_out();}//! usb_get_status.//!//! This function manages the GET STATUS request. The device, interface or//! endpoint status is returned.//!//! @warning Code:xx bytes (function code length)//!void usb_get_status(void){U8 wIndex;U8 dummy; dummy = Usb_read_byte(); //!< dummy read dummy = Usb_read_byte(); //!< dummy read wIndex = Usb_read_byte(); switch(bmRequestType) { case REQUEST_DEVICE_STATUS: Usb_ack_receive_setup(); Usb_write_byte(DEVICE_STATUS); break; case REQUEST_INTERFACE_STATUS: Usb_ack_receive_setup(); Usb_write_byte(INTERFACE_STATUS); break; case REQUEST_ENDPOINT_STATUS: Usb_ack_receive_setup(); wIndex = wIndex & MSK_EP_DIR; Usb_write_byte(endpoint_status[wIndex]); break; default: Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } Usb_write_byte(0x00); Usb_send_control_in(); while( !Is_usb_receive_out() ); Usb_ack_receive_out();}//! usb_set_feature.//!//! This function manages the SET FEATURE request. The USB test modes are//! supported by this function.//!//! @warning Code:xx bytes (function code length)//!void usb_set_feature(void){U8 wValue;U8 wIndex;U8 dummy; if (bmRequestType == INTERFACE_TYPE) { //!< 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(); return; } else if (bmRequestType == ENDPOINT_TYPE) { wValue = Usb_read_byte(); dummy = Usb_read_byte(); //!< dummy read if (wValue == FEATURE_ENDPOINT_HALT) { wIndex = (Usb_read_byte() & MSK_EP_DIR); if (wIndex == EP_CONTROL) { Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } Usb_select_endpoint(wIndex); if(Is_usb_endpoint_enabled()) { Usb_enable_stall_handshake(); Usb_select_endpoint(EP_CONTROL); endpoint_status[wIndex] = 0x01; Usb_ack_receive_setup(); Usb_send_control_in(); } else { Usb_select_endpoint(EP_CONTROL); Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } } else { Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } }}//! usb_clear_feature.//!//! This function manages the SET FEATURE request.//!//! @warning Code:xx bytes (function code length)//!void usb_clear_feature(void){U8 wValue;U8 wIndex;U8 dummy; if (bmRequestType == ZERO_TYPE) { //!< 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(); return; } else if (bmRequestType == INTERFACE_TYPE) { //!< 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(); return; } else if (bmRequestType == ENDPOINT_TYPE) { wValue = Usb_read_byte(); dummy = Usb_read_byte(); //!< dummy read if (wValue == FEATURE_ENDPOINT_HALT) { wIndex = (Usb_read_byte() & MSK_EP_DIR); Usb_select_endpoint(wIndex); if(Is_usb_endpoint_enabled()) { if(wIndex != EP_CONTROL) { Usb_disable_stall_handshake(); Usb_reset_endpoint(wIndex); Usb_reset_data_toggle(); } Usb_select_endpoint(EP_CONTROL); endpoint_status[wIndex] = 0x00; Usb_ack_receive_setup(); Usb_send_control_in(); } else { Usb_select_endpoint(EP_CONTROL); Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } } else { Usb_enable_stall_handshake(); Usb_ack_receive_setup(); return; } }}//! usb_get_interface.//!//! TThis function manages the GET_INTERFACE request.//!//! @warning Code:xx bytes (function code length)//!void usb_get_interface (void){ Usb_enable_stall_handshake(); Usb_ack_receive_setup();}//! usb_set_interface.//!//! TThis function manages the SET_INTERFACE request.//!//! @warning Code:xx bytes (function code length)//!void usb_set_interface (void){ Usb_ack_receive_setup(); Usb_send_control_in(); //!< send a ZLP for STATUS phase while(!Is_usb_in_ready());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -