📄 usb_enum.c
字号:
if( usb_user_get_descriptor(descriptor_type, string_type)==FALSE )
{
Usb_enable_stall_handshake();
Usb_ack_receive_setup();
return;
}
break;
}
ACC = Usb_read_byte(); //!< don't care of wIndex field
ACC = Usb_read_byte();
((U8*)&wLength)[1] = Usb_read_byte(); //!< read wLength
((U8*)&wLength)[0] = Usb_read_byte();
Usb_ack_receive_setup() ; //!< clear the receive setup flag
Usb_set_DIR(); /* set out on EP0 */
if (wLength > data_to_transfer)
{
if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
else { zlp = FALSE;} //!< no need of zero length packet
}
else
{
data_to_transfer = (U8)wLength; //!< send only requested number of data
}
while((data_to_transfer != 0) && (!Is_usb_receive_out()))
{
if (data_to_transfer > EP_CONTROL_LENGTH) { c = EP_CONTROL_LENGTH; }
else { c = data_to_transfer; }
data_to_transfer -= c;
while ( c!= 0 )
{
Usb_write_byte(*pbuffer);
c--;
pbuffer ++;
}
Usb_send_control_in();
while((!Is_usb_read_control_enabled()) && (!Is_usb_receive_out()));
Usb_ack_in_ready();
/* while(!Is_usb_read_control_enabled()); // snd3 like, not compatible with c5131
while(data_to_transfer != 0)
{
Usb_write_byte(*pbuffer);
pbuffer ++;
data_to_transfer --;
}
Usb_send_control_in();
*/
}
// Usb_send_control_in();
if(Is_usb_receive_out()) //!< abort from Host
{
Usb_ack_receive_out();
return;
}
if(zlp == TRUE)
{
Usb_send_control_in();
while((!Is_usb_read_control_enabled()) && (!Is_usb_receive_out()));
Usb_ack_in_ready();
}
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)
//!
//! @param none
//!
//! @return none
//!
void usb_get_configuration(void)
{
Usb_ack_receive_setup();
Usb_set_DIR(); /* set out on EP0 */
Usb_write_byte(usb_configuration_nb);
// Usb_ack_in_ready();
Usb_send_control_in();
while(!Is_usb_in_ready());// while(!Is_usb_read_control_enabled());
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)
//!
//! @param none
//!
//! @return none
//!
void usb_get_status(void)
{
U8 wIndex;
ACC = Usb_read_byte(); //!< dummy read
ACC = Usb_read_byte(); //!< dummy read
wIndex = Usb_read_byte();
switch(bmRequestType)
{
case REQUEST_DEVICE_STATUS: Usb_ack_receive_setup();
Usb_set_DIR();
Usb_write_byte(DEVICE_STATUS);
break;
case REQUEST_INTERFACE_STATUS: Usb_ack_receive_setup();
Usb_set_DIR();
Usb_write_byte(INTERFACE_STATUS);
break;
case REQUEST_ENDPOINT_STATUS: Usb_ack_receive_setup();
Usb_set_DIR();
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_in_ready());
Usb_ack_in_ready();
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)
//!
//! @param none
//!
//! @return none
//!
void usb_set_feature(void)
{
U8 wValue;
U8 wIndex;
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();
ACC = 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_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)
//!
//! @param none
//!
//! @return none
//!
void usb_clear_feature(void)
{
U8 wValue;
U8 wIndex;
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();
ACC = 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_enable_stall_handshake();
Usb_ack_receive_setup();
return;
}
}
else
{
Usb_enable_stall_handshake();
Usb_ack_receive_setup();
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -