• STM32 USB Host Library 学习笔记 (2) USBH_InterruptSendData() USBH_ClrFeature()


     1 /**
     2   * @brief  USBH_InterruptSendData
     3   *         Sends the data on Interrupt OUT Endpoint
     4   * @param  pdev: Selected device
     5   * @param  buff: Buffer pointer from where the data needs to be copied
     6   * @param  length: Length of the data to be sent
     7   * @param  hc_num: Host channel Number
     8   * @retval Status. 
     9   */
    10 USBH_Status USBH_InterruptSendData( USB_OTG_CORE_HANDLE *pdev, 
    11                                 uint8_t *buff, 
    12                                 uint8_t length,
    13                                 uint8_t hc_num)
    14 {
    15 
    16   pdev->host.hc[hc_num].ep_is_in = 0;  
    17   pdev->host.hc[hc_num].xfer_buff = buff;
    18   pdev->host.hc[hc_num].xfer_len = length;
    19   
    20   if(pdev->host.hc[hc_num].toggle_in == 0)
    21   {
    22     pdev->host.hc[hc_num].data_pid = HC_PID_DATA0;
    23   }
    24   else
    25   {
    26     pdev->host.hc[hc_num].data_pid = HC_PID_DATA1;
    27   }
    28 
    29   pdev->host.hc[hc_num].toggle_in ^= 1;  
    30   
    31   HCD_SubmitRequest (pdev , hc_num);  
    32   
    33   return USBH_OK;
    34 }

    toggle_in or toggle_out ?

     1 /**
     2   * @brief  USBH_BulkSendData
     3   *         Sends the Bulk Packet to the device
     4   * @param  pdev: Selected device
     5   * @param  buff: Buffer pointer from which the Data will be sent to Device
     6   * @param  length: Length of the data to be sent
     7   * @param  hc_num: Host channel Number
     8   * @retval Status
     9   */
    10 USBH_Status USBH_BulkSendData ( USB_OTG_CORE_HANDLE *pdev, 
    11                                 uint8_t *buff, 
    12                                 uint16_t length,
    13                                 uint8_t hc_num)
    14 { 
    15   pdev->host.hc[hc_num].ep_is_in = 0;
    16   pdev->host.hc[hc_num].xfer_buff = buff;
    17   pdev->host.hc[hc_num].xfer_len = length;  
    18 
    19  /* Set the Data Toggle bit as per the Flag */
    20   if ( pdev->host.hc[hc_num].toggle_out == 0)
    21   { /* Put the PID 0 */
    22       pdev->host.hc[hc_num].data_pid = HC_PID_DATA0;    
    23   }
    24  else
    25  { /* Put the PID 1 */
    26       pdev->host.hc[hc_num].data_pid = HC_PID_DATA1 ;
    27  }
    28 
    29   HCD_SubmitRequest (pdev , hc_num);   
    30   return USBH_OK;
    31 }
      else if (hcint.b.chhltd) // usb_hcd_int.c
      {
        MASK_HOST_INT_CHH (num);
        
        if(pdev->host.HC_Status[num] == HC_XFRC)
        {
          pdev->host.URB_State[num] = URB_DONE;  
          
          if (hcchar.b.eptype == EP_TYPE_BULK)
          {
            pdev->host.hc[num].toggle_out ^= 1; 
          }
        }
      }

     1 /**
     2 * @brief  USBH_ClrFeature
     3 *         This request is used to clear or disable a specific feature.
     4 
     5 * @param  pdev: Selected device
     6 * @param  ep_num: endpoint number 
     7 * @param  hc_num: Host channel number 
     8 * @retval Status
     9 */
    10 USBH_Status USBH_ClrFeature(USB_OTG_CORE_HANDLE *pdev,
    11                             USBH_HOST *phost,
    12                             uint8_t ep_num, 
    13                             uint8_t hc_num) 
    14 {
    15   
    16   phost->Control.setup.b.bmRequestType = USB_H2D | 
    17                                          USB_REQ_RECIPIENT_ENDPOINT |
    18                                          USB_REQ_TYPE_STANDARD;
    19   
    20   phost->Control.setup.b.bRequest = USB_REQ_CLEAR_FEATURE;
    21   phost->Control.setup.b.wValue.w = FEATURE_SELECTOR_ENDPOINT;
    22   phost->Control.setup.b.wIndex.w = ep_num;
    23   phost->Control.setup.b.wLength.w = 0;           
    24   
    25   if ((ep_num & USB_REQ_DIR_MASK ) == USB_D2H)
    26   { /* EP Type is IN */
    27     pdev->host.hc[hc_num].toggle_in = 0; 
    28   }
    29   else
    30   {/* EP Type is OUT */
    31     pdev->host.hc[hc_num].toggle_out = 0; 
    32   }
    33   
    34   return USBH_CtlReq(pdev, phost, 0 , 0 );   
    35 }
    
    

  • 相关阅读:
    CentOS6.3升级GCC到GCC4.8.2
    监督式学习 -- 分类决策树(一)
    DICOM医学图像处理:fo-dicom网络传输之 C-Echo and C-Store
    百度地图----->地图类型、定位模式、实时交通、我的位置、加入覆盖物、覆盖物详情及提示
    "浪潮杯"第六届ACM山东省省赛山科场总结
    标题栏风格设置
    ActionBarActivity设置全屏无标题
    王立平--自己定义TitleBar
    C++ const限定符
    黑马day14 过滤器概述&生命周期&运行过程
  • 原文地址:https://www.cnblogs.com/shangdawei/p/2667201.html
Copyright © 2020-2023  润新知