?? usb_drv.c
字號:
case LANG_ID:
{
data_to_transfer = sizeof (usb_language);
pbuffer = &(usb_language.bLength);
break;
}
case MAN_INDEX:
{
data_to_transfer = sizeof (usb_manufacturer);
pbuffer = &(usb_manufacturer.bLength);
break;
}
case PROD_INDEX:
{
data_to_transfer = sizeof (usb_product);
pbuffer = &(usb_product.bLength);
break;
}
case SN_INDEX:
{
data_to_transfer = sizeof (usb_serial_number);
pbuffer = &(usb_serial_number.bLength);
break;
}
default:
{
Usb_clear_RXSETUP();
while (!Usb_setup_received())
{
Usb_set_STALLRQ(); /* send stall */
while ((!(Usb_STALL_sent())) && (Usb_setup_received()));
Usb_clear_STALLED();
Usb_clear_STALLRQ();
}
Usb_clear_DIR(); /* set in on EP0 */
return;
}
}
break;
}
default:
{
Usb_clear_RXSETUP();
while (!Usb_setup_received())
{
Usb_set_STALLRQ(); /* send stall */
while ((!(Usb_STALL_sent())) && (Usb_setup_received()));
Usb_clear_STALLED();
Usb_clear_STALLRQ();
}
Usb_clear_DIR(); /* set in on EP0 */
return;
}
}
ACC = Usb_read_byte(); /* don't care of wIndex field */
ACC = Usb_read_byte();
((Byte*)&wLength)[1] = Usb_read_byte(); /* read wLength */
((Byte*)&wLength)[0] = Usb_read_byte();
if (wLength > data_to_transfer)
{
if ((data_to_transfer % EP_CONTROL_LENGTH) == 0)
{
zlp = TRUE; /* send a zero length packet */
}
else
{
zlp = FALSE; /* no need of zero length packet */
}
}
else
{
data_to_transfer = (Byte)wLength; /* send only requested number of data */
}
Usb_clear_RXSETUP() ; /* clear the receive setup flag */
while (data_to_transfer > EP_CONTROL_LENGTH)
{
pbuffer = send_ep0_packet(pbuffer, EP_CONTROL_LENGTH);
data_to_transfer -= EP_CONTROL_LENGTH;
while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
if ((Usb_rx_complete())) /* if no cancel from USB Host */
{
Usb_clear_RXOUT();
return;
}
if (Usb_tx_complete())
{
Usb_clear_TXCMPL();
}
}
/* send last data packet */
pbuffer = send_ep0_packet(pbuffer, data_to_transfer);
data_to_transfer = 0;
while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
if ((Usb_rx_complete())) /* if no cancel from USB Host */
{
Usb_clear_RXOUT();
return;
}
if (Usb_tx_complete())
{
Usb_clear_TXCMPL();
}
if (zlp == TRUE)
{
send_ep0_packet(pbuffer, 0);
while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
if ((Usb_rx_complete())) /* if no cancel from USB Host */
{
Usb_clear_RXOUT();
return;
}
if (Usb_tx_complete())
{
Usb_clear_TXCMPL();
}
}
while ((!(Usb_rx_complete())) && (!(Usb_setup_received())));
if (Usb_setup_received())
{
return;
}
if (Usb_rx_complete())
{
Usb_clear_DIR(); /* set in on EP0 */
Usb_clear_RXOUT();
}
}
/*F**************************************************************************
* NAME: usb_get_configuration
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function manages the GET_CONFIGURATION request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void usb_get_configuration (void)
{
Usb_clear_RXSETUP();
Usb_set_DIR();
if (USBCON & MSK_CONFG)
{
Usb_write_byte(1);
}
else
{
Usb_write_byte(0);
}
Usb_set_TXRDY();
while (!(Usb_tx_complete()));
Usb_clear_TXCMPL();
while (!(Usb_rx_complete()));
Usb_clear_RXOUT();
Usb_clear_DIR();
}
/*F**************************************************************************
* NAME: usb_get_status
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function manages the GET_STATUS request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void usb_get_status (void)
{
Byte wIndex;
ACC = Usb_read_byte(); /* dummy read */
ACC = Usb_read_byte(); /* dummy read */
wIndex = Usb_read_byte();
Usb_clear_RXSETUP();
Usb_set_DIR();
switch(bmRequestType)
{
case REQUEST_DEVICE_STATUS:
{
Usb_write_byte(SELF_POWERED);
break;
}
case REQUEST_INTERFACE_STATUS:
{
Usb_write_byte(0x00);
break;
}
case REQUEST_ENDPOINT_STATUS:
{
wIndex = wIndex & MSK_EP_DIR;
Usb_write_byte(endpoint_status[wIndex]);
break;
}
}
Usb_write_byte(0x00);
Usb_set_TXRDY();
while ((!(Usb_tx_complete())) || (Usb_setup_received()));
Usb_clear_TXCMPL();
while ((!(Usb_rx_complete())) || (Usb_setup_received()));
Usb_clear_RXOUT();
Usb_clear_DIR();
}
/*F**************************************************************************
* NAME: usb_set_feature
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function manages the SET_FEATURE request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void usb_set_feature (void)
{
if (bmRequestType == ZERO_TYPE)
{
Usb_clear_RXSETUP();
Usb_set_STALLRQ();
while (!(Usb_STALL_sent()));
Usb_clear_STALLRQ();
}
if (bmRequestType == INTERFACE_TYPE)
{
Usb_clear_RXSETUP();
Usb_set_STALLRQ();
while (!(Usb_STALL_sent()));
Usb_clear_STALLRQ();
}
if (bmRequestType == ENDPOINT_TYPE)
{
if (Usb_read_byte() == 0x00)
{
ACC = Usb_read_byte(); /* dummy read */
switch (Usb_read_byte()) /* check wIndex */
{
case ENDPOINT_1:
{
Usb_select_ep(EP_IN);
Usb_set_STALLRQ();
Usb_select_ep(EP_CONTROL);
endpoint_status[1] = 0x01;
Usb_clear_RXSETUP();
Usb_set_TXRDY();
while (!(Usb_tx_complete()));
Usb_clear_TXCMPL();
break;
}
case ENDPOINT_2:
{
Usb_select_ep(EP_OUT);
Usb_set_STALLRQ();
Usb_select_ep(EP_CONTROL);
endpoint_status[2] = 0x01;
Usb_clear_RXSETUP();
Usb_set_TXRDY();
while (!(Usb_tx_complete()));
Usb_clear_TXCMPL();
break;
}
default:
{
Usb_clear_RXSETUP();
Usb_set_STALLRQ();
while (!(Usb_STALL_sent()));
Usb_clear_STALLRQ();
break;
}
}
}
}
}
/*F**************************************************************************
* NAME: usb_clear_feature
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* This function manages the SET_FEATURE request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void usb_clear_feature (void)
{
if (bmRequestType == ZERO_TYPE)
{
Usb_clear_RXSETUP();
Usb_set_STALLRQ();
while (!(Usb_STALL_sent()));
Usb_clear_STALLRQ();
}
if (bmRequestType == INTERFACE_TYPE)
{
Usb_clear_RXSETUP();
Usb_set_STALLRQ();
while (!(Usb_STALL_sent()));
Usb_clear_STALLRQ();
}
if (bmRequestType == ENDPOINT_TYPE)
{
if (Usb_read_byte() == 0x00)
{
ACC = Usb_read_byte(); /* dummy read */
switch (Usb_read_byte()) /* check wIndex */
{
case ENDPOINT_1:
{
Usb_select_ep(EP_IN);
if(Usb_STALL_requested())
{
Usb_clear_STALLRQ();
}
if(Usb_STALL_sent())
{
Usb_clear_STALLED();
}
UEPRST = 0x02;
UEPRST = 0x00;
Usb_select_ep(EP_CONTROL);
endpoint_status[EP_IN] = 0x00;
Usb_clear_RXSETUP();
Usb_set_TXRDY();
while (!(Usb_tx_complete()));
Usb_clear_TXCMPL();
break;
}
case ENDPOINT_2:
{
Usb_select_ep(EP_OUT);
if(Usb_STALL_requested())
{
Usb_clear_STALLRQ();
}
if(Usb_STALL_sent())
{
Usb_clear_STALLED();
}
UEPRST = 0x04;
UEPRST = 0x00;
Usb_select_ep(EP_CONTROL);
endpoint_status[EP_OUT] = 0x00;
Usb_clear_RXSETUP();
Usb_set_TXRDY();
while (!(Usb_tx_complete()));
Usb_clear_TXCMPL();
break;
}
case ENDPOINT_0:
{
Usb_clear_RXSETUP();
Usb_set_TXRDY();
while (!(Usb_tx_complete()));
Usb_clear_TXCMPL();
break;
}
default:
{
Usb_clear_RXSETUP();
Usb_set_STALLRQ();
while (!(Usb_STALL_sent()));
Usb_clear_STALLRQ();
break;
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -