本文整理汇总了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;
//}
}
示例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);
}
}
示例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;
}
示例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;
}
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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 */
}
示例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);
}
示例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;
}
示例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 */
}
示例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 */
}