⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_cdc_enum.c

📁 AT89C5131的接口驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
  Usb_clear_rx();
  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_rx_setup();
    Usb_set_stall_request();
    while (!(Usb_stall_sent()));
    Usb_clear_stall_request();
  }
  if (bmRequestType == INTERFACE_TYPE)
  {
    Usb_clear_rx_setup();
    Usb_set_stall_request();
    while (!(Usb_stall_sent()));
    Usb_clear_stall_request();
  }
  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_stall_request();
          Usb_select_ep(EP_CONTROL);
          endpoint_status[EP_IN] = 0x01;
          Usb_clear_rx_setup();
          Usb_set_tx_ready();
          while (!(Usb_tx_complete()));
          Usb_clear_tx_complete();
          break;
        }
        default:
        {
          Usb_clear_rx_setup();
          Usb_set_stall_request();
          while (!(Usb_stall_sent()));
          Usb_clear_stall_request();
          Usb_clear_stalled();
          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_rx_setup();
    Usb_set_stall_request();
    while (!(Usb_stall_sent()));
    Usb_clear_stall_request();
  }
  if (bmRequestType == INTERFACE_TYPE)
  {
    Usb_clear_rx_setup();
    Usb_set_stall_request();
    while (!(Usb_stall_sent()));
    Usb_clear_stall_request();
  }
  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_clear_stall_request();
          usb_reset_endpoint(EP_IN);
          Usb_select_ep(EP_CONTROL);
          endpoint_status[EP_IN] = 0x00;
          Usb_clear_rx_setup();
          Usb_set_tx_ready();
          while (!(Usb_tx_complete()));
          Usb_clear_tx_complete();
          break;
        }
        case ENDPOINT_0:
        {
          Usb_clear_rx_setup();
          Usb_set_tx_ready();
          while (!(Usb_tx_complete()));
          Usb_clear_tx_complete();
          break;
        }
        default:
        {
          Usb_clear_rx_setup();
          Usb_set_stall_request();
          while (!(Usb_stall_sent()));
          Usb_clear_stall_request();
          break;
        }
      }
    }
  }
}




/*F**************************************************************************
* NAME: cdc_set_line_coding
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manages the SET_LINE_CODING CDC request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: command 0x20
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void cdc_set_line_coding (void)
{
  Usb_clear_rx_setup();
  while (!(Usb_rx_complete()));
  line_coding[0] = Usb_read_byte();
  line_coding[1] = Usb_read_byte();
  line_coding[2] = Usb_read_byte();
  line_coding[3] = Usb_read_byte();
  line_coding[4] = Usb_read_byte();
  line_coding[5] = Usb_read_byte();
  line_coding[6] = Usb_read_byte();
  Usb_clear_rx();

  Usb_set_tx_ready();                          /* send a ZLP for STATUS phase */
  while(!(Usb_tx_complete()));
  Usb_clear_tx_complete();
}


/*F**************************************************************************
* NAME: cdc_get_line_coding
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manages the SET_LINE_CODING CDC request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: command 0x21
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void cdc_get_line_coding (void)
{
  Usb_clear_rx_setup();
  Usb_set_DIR();

  Usb_write_byte(line_coding[0]);
  Usb_write_byte(line_coding[1]);
  Usb_write_byte(line_coding[2]);
  Usb_write_byte(line_coding[3]);
  Usb_write_byte(line_coding[4]);
  Usb_write_byte(line_coding[5]);
  Usb_write_byte(line_coding[6]);

  Usb_set_tx_ready();                          
  while(!(Usb_tx_complete()));
  Usb_clear_tx_complete();

  while (!(Usb_rx_complete()));           /* wait a ZLP for STATUS phase */
  Usb_clear_rx();
}


/*F**************************************************************************
* NAME: cdc_set_control_line_state
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manages the SET_CONTROL_LINE_LINE_STATE CDC request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: command 0x21
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void cdc_set_control_line_state (void)
{
  Usb_clear_rx_setup();

  Usb_set_tx_ready();                          
  while(!(Usb_tx_complete()));           /* send a ZLP for STATUS phase */
  Usb_clear_tx_complete();

}


/*F**************************************************************************
* NAME: cdc_send_break
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manages the SEND_BREAK CDC request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: command 0x23
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void cdc_send_break (void)
{
}

/*F**************************************************************************
* NAME: cdc_send_encapsulated_command
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manages the SEND_ENCAPSULATED_COMMAND CDC request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: command 0x00
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void cdc_send_encapsulated_command (void)
{
}

/*F**************************************************************************
* NAME: cdc_get_encapsulated_command
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manages the GET_ENCAPSULATED_COMMAND CDC request.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: command 0x00
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void cdc_get_encapsulated_command (void)
{
}


/*_____ E N D  O F  F I L E  _________________________________________________*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -