当前位置: 首页>>代码示例>>C++>>正文


C++ USBD_CDC_SetTxBuffer函数代码示例

本文整理汇总了C++中USBD_CDC_SetTxBuffer函数的典型用法代码示例。如果您正苦于以下问题:C++ USBD_CDC_SetTxBuffer函数的具体用法?C++ USBD_CDC_SetTxBuffer怎么用?C++ USBD_CDC_SetTxBuffer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了USBD_CDC_SetTxBuffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HAL_TIM_PeriodElapsedCallback

/**
  * @brief  TIM period elapsed callback
  * @param  htim: TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(USBD_CDC_PACKET_SEND_OK == true)
	{
	  USBD_CDC_PACKET_BYTES_COUNT = 0;
	  for(; USBD_CDC_PACKET_BYTES_COUNT < APP_RX_DATA_SIZE; USBD_CDC_PACKET_BYTES_COUNT++)
		{
			fifo_pop_return_t data_return = fifo_pop(usb_cdc_dev_tx_fifo);
			if(data_return.status == false)
				break;
			UserTxBuffer[USBD_CDC_PACKET_BYTES_COUNT] = data_return.character;
		}
	}
  if(USBD_CDC_PACKET_BYTES_COUNT == 0)
	  return;
    USBD_CDC_SetTxBuffer(&usb_cdc_dev_param, UserTxBuffer, USBD_CDC_PACKET_BYTES_COUNT);
    
    if(USBD_CDC_TransmitPacket(&usb_cdc_dev_param) == USBD_OK)
    {
    	USBD_CDC_PACKET_SEND_OK = true;
    }
    else
    	USBD_CDC_PACKET_SEND_OK = false;
  //}
}
开发者ID:MorgothCreator,项目名称:mSdk,代码行数:30,代码来源:usbd_cdc_interface.c

示例2: serviceUSBWrite

void serviceUSBWrite()
{
    if (usbTransferHasCompleted)
    {
        //printf("USB Transfer Completed\r\n");
        // Set USB as no longer active
        usbIsActive = 0;

        usbTransmitBufferLengths[activeUsbBuffer] = 0;

        // Set the active USB buffer to the next buffer
        activeUsbBuffer++;
        if (activeUsbBuffer >= USB_SEND_BUFFER_NUM)
        {
            activeUsbBuffer = 0;
        }

        // Clear the overrun status
        usbBufferOverrun = 0;

        usbTransferHasCompleted = 0;
    }

    // If usb in inactive and
    // the active buffer has data and
    // we can start another transfer
    if (usbIsActive == 0 &&
        usbTransmitBufferLengths[activeUsbBuffer] > 0)
    {
        // Mark USB as active to not overwrite buffer
        usbIsActive = 1;

        // Increase the nextBuffer ptr
        if (nextUsbBuffer == activeUsbBuffer)
        {
            nextUsbBuffer++;
            if (nextUsbBuffer >= USB_SEND_BUFFER_NUM)
            {
                nextUsbBuffer = 0;
            }
        }

        //printf("Writing %lu bytes to USB stack\r\n", usbTransmitBufferLengths[activeUsbBuffer]);

        // Transmit the current active buffer across USB
        // Actual transmission will take place in a later USB IRQ
        USBD_CDC_SetTxBuffer(&USBD_Device,
                             usbTransmitBuffers[activeUsbBuffer],
                             usbTransmitBufferLengths[activeUsbBuffer]);

        USBD_CDC_TransmitPacket(&USBD_Device);
    }

    if (reinitUSB)
    {
        reinitUSB = 0;

        USBD_CDC_RegisterInterface(&USBD_Device, &cdcInterface);
    }
}
开发者ID:CalPolyRobotics,项目名称:IGVC-OlympusFirmware,代码行数:60,代码来源:usb_otg.c

示例3: VCP_Write

/**
  * @brief  VCP_Write
  * 		Transmit a len block of data to host through the IN Endpoint.
  *
  * @param  pbuf: Buffer of data to be transmit
  * @param  len: Number of to data be transmit (in bytes)
  * @retval The number of transmitted byte
  */
int VCP_Write(uint8_t *pbuf, uint16_t len)
{
	if (len > CDC_DATA_HS_OUT_PACKET_SIZE)
	    {
	        int offset;
	        for (offset = 0; offset < len; offset++)
	        {
	            int todo = MIN(CDC_DATA_HS_OUT_PACKET_SIZE,
	            		len - offset);
	            int done = VCP_Write(((char *)pbuf) + offset, todo);
	            if (done != todo)
	                return offset + done;
	        }

	        return len;
	    }

	    USBD_CDC_HandleTypeDef *pCDC =
	            (USBD_CDC_HandleTypeDef *)hUSBDDevice.pClassData;
	    while(pCDC->TxState) { } //Wait for previous transfer

	    USBD_CDC_SetTxBuffer(&hUSBDDevice, (uint8_t *)pbuf, len);
	    if (USBD_CDC_TransmitPacket(&hUSBDDevice) != USBD_OK)
	        return 0;

	    while(pCDC->TxState) { } //Wait until transfer is done
	    return len;
}
开发者ID:aoscarius,项目名称:USBVCPShell,代码行数:36,代码来源:usbd_cdc_vcp.c

示例4: HAL_TIM_PeriodElapsedCallback

/**
  * @brief  TIM period elapsed callback
  * @param  htim: TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  uint32_t buffptr;
  uint32_t buffsize;
  
  if(UserTxBufPtrOut != UserTxBufPtrIn)
  {
    if(UserTxBufPtrOut > UserTxBufPtrIn) /* Rollback */
    {
      buffsize = APP_RX_DATA_SIZE - UserTxBufPtrOut;
    }
    else 
    {
      buffsize = UserTxBufPtrIn - UserTxBufPtrOut;
    }
    
    buffptr = UserTxBufPtrOut;
    
    USBD_CDC_SetTxBuffer(&USBD_Device, (uint8_t*)&UserTxBuffer[buffptr], buffsize);
    
    if(USBD_CDC_TransmitPacket(&USBD_Device) == USBD_OK)
    {
      UserTxBufPtrOut += buffsize;
      if (UserTxBufPtrOut >= APP_RX_DATA_SIZE)
      {
        UserTxBufPtrOut -= APP_RX_DATA_SIZE;
      }
    }
  }
}
开发者ID:davidlaone,项目名称:hot-butter,代码行数:35,代码来源:usbd_cdc_interface.c

示例5: CDC_Itf_Init

/**
  * @brief  Initializes the CDC media low layer      
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
  /*##-6- Enable TIM peripherals Clock #######################################*/
  USBCDCTIMx_CLK_ENABLE();

  /*##-7- Configure the NVIC for TIMx ########################################*/
  /* Set Interrupt Group Priority */
  HAL_NVIC_SetPriority(USBCDCTIMx_IRQn, 6, 0);

  /* Enable the TIMx global Interrupt */
  HAL_NVIC_EnableIRQ(USBCDCTIMx_IRQn);
  /*##-3- Configure the TIM Base generation  #################################*/
  TIM_Config();
  
  /*##-4- Start the TIM Base generation in interrupt mode ####################*/
  /* Start Channel1 */
  if(HAL_TIM_Base_Start_IT(&USBCDCTimHandle) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  
  /*##-5- Set Application Buffers ############################################*/
  USBD_CDC_SetTxBuffer(&usb_cdc_dev_param, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(&usb_cdc_dev_param, UserRxBuffer);
  
  return (USBD_OK);
}
开发者ID:MorgothCreator,项目名称:mSdk,代码行数:33,代码来源:usbd_cdc_interface.c

示例6: VCP_SendDataSynch

void VCP_SendDataSynch(const uint8 *buffer, int size)
{
    if (gBF.connectToHost == 0)
    {
        return;
    }

    USBD_CDC_HandleTypeDef *pCDC = handleUSBD.pClassData;

    do 
    {
        if (sizeBuffer + size > SIZE_BUFFER_VCP)
        {
            int reqBytes = SIZE_BUFFER_VCP - sizeBuffer;
            LIMITATION(reqBytes, reqBytes, 0, size);
            while (pCDC->TxState == 1) {};
            memcpy(buffSend + sizeBuffer, buffer, reqBytes);
            USBD_CDC_SetTxBuffer(&handleUSBD, buffSend, SIZE_BUFFER_VCP);
            USBD_CDC_TransmitPacket(&handleUSBD);
            size -= reqBytes;
            buffer += reqBytes;
            sizeBuffer = 0;
        }
        else
        {
            memcpy(buffSend + sizeBuffer, buffer, size);
            sizeBuffer += size;
            size = 0;
        }
    } while (size);
}
开发者ID:Sasha7b9,项目名称:Osci,代码行数:31,代码来源:VCP.c

示例7: CDC_Itf_Init

/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
#if 0
  /*##-1- Configure the UART peripheral ######################################*/
  /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
  /* USART configured as follow:
      - Word Length = 8 Bits
      - Stop Bit    = One Stop bit
      - Parity      = No parity
      - BaudRate    = 115200 baud
      - Hardware flow control disabled (RTS and CTS signals) */
  UartHandle.Instance        = USARTx;
  UartHandle.Init.BaudRate   = 115200;
  UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
  UartHandle.Init.StopBits   = UART_STOPBITS_1;
  UartHandle.Init.Parity     = UART_PARITY_NONE;
  UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
  UartHandle.Init.Mode       = UART_MODE_TX_RX;
  
  if(HAL_UART_Init(&UartHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  /*##-2- Put UART peripheral in IT reception process ########################*/
  /* Any data received will be stored in "UserTxBuffer" buffer  */
  if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)UserTxBuffer, 1) != HAL_OK)
  {
    /* Transfer error in reception process */
    Error_Handler();
  }
  
  /*##-3- Configure the TIM Base generation  #################################*/
  now done in HAL_MspInit
  TIM_Config();
#endif
  
    /*##-4- Start the TIM Base generation in interrupt mode ####################*/
    /* Start Channel1 */
    __HAL_TIM_ENABLE_IT(&TIM3_Handle, TIM_IT_UPDATE);
  
    /*##-5- Set Application Buffers ############################################*/
    USBD_CDC_SetTxBuffer(&hUSBDDevice, UserTxBuffer, 0);
    USBD_CDC_SetRxBuffer(&hUSBDDevice, UserRxBuffer);

    UserRxBufCur = 0;
    UserRxBufLen = 0;
  
    /* NOTE: we cannot reset these here, because USBD_CDC_SetInterrupt
     * may be called before this init function to set these values.
     * This can happen if the USB enumeration occurs after the call to
     * USBD_CDC_SetInterrupt.
    user_interrupt_char = VCP_CHAR_NONE;
    user_interrupt_data = NULL;
    */

    return (USBD_OK);
}
开发者ID:patrickhpunkt,项目名称:micropython,代码行数:65,代码来源:usbd_cdc_interface.c

示例8: USBD_CDC_HAL_TIM_PeriodElapsedCallback

/**
  * @brief  TIM period elapsed callback
  * @param  htim: TIM handle
  * @retval None
  */
void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
    if (!dev_is_connected) {
        // CDC device is not connected to a host, so we are unable to send any data
        return;
    }

    if (UserTxBufPtrOut == UserTxBufPtrIn && !UserTxNeedEmptyPacket) {
        // No outstanding data to send
        return;
    }

    if (UserTxBufPtrOut != UserTxBufPtrOutShadow) {
        // We have sent data and are waiting for the low-level USB driver to
        // finish sending it over the USB in-endpoint.
        // We have a 15 * 10ms = 150ms timeout
        if (UserTxBufPtrWaitCount < 15) {
            PCD_HandleTypeDef *hpcd = hUSBDDevice.pData;
            USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
            if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) {
                // USB in-endpoint is still reading the data
                UserTxBufPtrWaitCount++;
                return;
            }
        }
        UserTxBufPtrOut = UserTxBufPtrOutShadow;
    }

    if (UserTxBufPtrOutShadow != UserTxBufPtrIn || UserTxNeedEmptyPacket) {
        uint32_t buffptr;
        uint32_t buffsize;

        if (UserTxBufPtrOutShadow > UserTxBufPtrIn) { // rollback
            buffsize = APP_TX_DATA_SIZE - UserTxBufPtrOutShadow;
        } else {
            buffsize = UserTxBufPtrIn - UserTxBufPtrOutShadow;
        }

        buffptr = UserTxBufPtrOutShadow;

        USBD_CDC_SetTxBuffer(&hUSBDDevice, (uint8_t*)&UserTxBuffer[buffptr], buffsize);

        if (USBD_CDC_TransmitPacket(&hUSBDDevice) == USBD_OK) {
            UserTxBufPtrOutShadow += buffsize;
            if (UserTxBufPtrOutShadow == APP_TX_DATA_SIZE) {
                UserTxBufPtrOutShadow = 0;
            }
            UserTxBufPtrWaitCount = 0;

            // According to the USB specification, a packet size of 64 bytes (CDC_DATA_FS_MAX_PACKET_SIZE)
            // gets held at the USB host until the next packet is sent.  This is because a
            // packet of maximum size is considered to be part of a longer chunk of data, and
            // the host waits for all data to arrive (ie, waits for a packet < max packet size).
            // To flush a packet of exactly max packet size, we need to send a zero-size packet.
            // See eg http://www.cypress.com/?id=4&rID=92719
            UserTxNeedEmptyPacket = (buffsize == CDC_DATA_FS_MAX_PACKET_SIZE && UserTxBufPtrOutShadow == UserTxBufPtrIn);
        }
    }
}
开发者ID:patrickhpunkt,项目名称:micropython,代码行数:63,代码来源:usbd_cdc_interface.c

示例9: CDC_Transmit_FS

/**
  * @brief  CDC_Transmit_FS
  *         Data send over USB IN endpoint are sent over CDC interface 
  *         through this function.           
  *         @note
  *         
  *                 
  * @param  Buf: Buffer of data to be send
  * @param  Len: Number of data to be send (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
  */
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
  uint8_t result = USBD_OK;

  if ( hUsbDevice_0 == NULL ) return USBD_FAIL;
  if ( hUsbDevice_0->dev_state != USBD_STATE_CONFIGURED ) return USBD_FAIL;
  USBD_CDC_HandleTypeDef *pCDC =
          (USBD_CDC_HandleTypeDef *)hUsbDevice_0->pClassData;

  /* Determine if transfer is already in progress.   */
  /* If transfer in progress is stuck in that state, */
  /* then reset the interface and try again.         */

  if ( pCDC->TxState != 0 ) {
      return USBD_BUSY;
  }

  usb_last_tx_not_busy_timestamp = HAL_GetTick();

   /* USER CODE BEGIN 8 */
	if (Len > APP_TX_DATA_SIZE)
	{
		int offset;
		for (offset = 0; offset < Len; offset++)
		{
			int todo = MIN(APP_TX_DATA_SIZE,
						   Len - offset);
			result = CDC_Transmit_FS(Buf + offset, todo);
			if ( ( result != USBD_OK ) && ( result != USBD_BUSY ) ) {
				/* Error:  Break out now */
				return result;
			}
		}

		return USBD_OK;
	}

	pCDC = (USBD_CDC_HandleTypeDef *)hUsbDevice_0->pClassData;

	uint32_t tx_completion_wait_timestamp = HAL_GetTick();
	while(pCDC->TxState)
	{
	    if ( HAL_GetTick() - tx_completion_wait_timestamp > (uint32_t)100 ) {
	        /* Timeout */
	        return USBD_BUSY;
	    }
	} //Wait for previous transfer to complete

	int i;
	for ( i = 0; i < Len; i++ ) {
		UserLowLevelTxBufferFS[i] =  Buf[i];
	}
	USBD_CDC_SetTxBuffer(hUsbDevice_0, &UserLowLevelTxBufferFS[0], Len);
	result = USBD_CDC_TransmitPacket(hUsbDevice_0);

	/* USER CODE END 8 */
	return result;
}
开发者ID:Kartazio,项目名称:navxmxp,代码行数:69,代码来源:usbd_cdc_if.c

示例10: CDC_Transmit_FS

/**
  * @brief  CDC_Transmit_FS
  *         Data send over USB IN endpoint are sent over CDC interface 
  *         through this function.           
  *         @note
  *         
  *                 
  * @param  Buf: Buffer of data to be send
  * @param  Len: Number of data to be send (in bytes)
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
  */
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
  uint8_t result = USBD_OK;
  /* USER CODE BEGIN 8 */ 
  USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBuffer, Len);   
  result = USBD_CDC_TransmitPacket(hUsbDevice_0);
  /* USER CODE END 8 */ 
  return result;
}
开发者ID:Myzhar,项目名称:RoboDiscovery-F4,代码行数:20,代码来源:usbd_cdc_if.c

示例11: CDC_Init_FS

/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{ 
  /* USER CODE BEGIN 3 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
  return (USBD_OK);
  /* USER CODE END 3 */ 
}
开发者ID:vortex314,项目名称:workspace_2016,代码行数:15,代码来源:usbd_cdc_if.c

示例12: CDC_Itf_Init

/**
  * @brief  CDC_Itf_Init
  *         Initializes the CDC media low layer
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Itf_Init(void)
{
  
  /*##-5- Set Application Buffers ############################################*/
  USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(&USBD_Device, UserRxBuffer);
  
  return (USBD_OK);
}
开发者ID:Ribster,项目名称:Labview,代码行数:15,代码来源:usbd_cdc_interface.c

示例13: CDC_Transmit_HS

/**
  * @brief  CDC_Transmit_HS
  *         Data send over USB IN endpoint are sent over CDC interface 
  *         through this function.           
  *         @note
  *         
  *                 
  * @param  Buf: Buffer of data to be send
  * @param  Len: Number of data to be send (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
  */
uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len)
{
  uint8_t result = USBD_OK;
  /* USER CODE BEGIN 12 */ 
  USBD_CDC_SetTxBuffer(hUsbDevice_1, Buf, Len);   
  result = USBD_CDC_TransmitPacket(hUsbDevice_1);
  /* USER CODE END 12 */ 
  return result;
}
开发者ID:maya2003,项目名称:bdm,代码行数:20,代码来源:usbd_cdc_if.c

示例14: CDC_Init_HS

/**
  * @brief  CDC_Init_HS
  *         Initializes the CDC media low layer over the USB HS IP
  * @param  None
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_HS(void)
{
  hUsbDevice_1 = &hUsbDeviceHS;
  /* USER CODE BEGIN 8 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(hUsbDevice_1, UserTxBufferHS, 0);
  USBD_CDC_SetRxBuffer(hUsbDevice_1, UserRxBufferHS);
  return (USBD_OK);
  /* USER CODE END 8 */ 
}
开发者ID:maya2003,项目名称:bdm,代码行数:16,代码来源:usbd_cdc_if.c

示例15: CDC_Init_FS

/**
  * @brief  CDC_Init_FS
  *         Initializes the CDC media low layer over the FS USB IP
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  hUsbDevice_0 = &hUsbDeviceFS;
  /* USER CODE BEGIN 4 */ 
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBuffer, 0);
  USBD_CDC_SetRxBuffer(hUsbDevice_0, UserRxBuffer);
  return (USBD_OK);
  /* USER CODE END 4 */ 
}
开发者ID:Myzhar,项目名称:RoboDiscovery-F4,代码行数:16,代码来源:usbd_cdc_if.c


注:本文中的USBD_CDC_SetTxBuffer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。