/*---------------------------------------------------------------------------- check if character(s) are available at CDC_OutBuf *---------------------------------------------------------------------------*/ int CDC_OutBufAvailChar (int *availChar) { *availChar = CDC_BUF_COUNT(CDC_OutBuf); return (0); }
/*---------------------------------------------------------------------------- write data to CDC_InBuf *---------------------------------------------------------------------------*/ int CDC_WrInBuf (const char *buffer, int *length) { int bytesToWrite, bytesWritten; // Write *length bytes bytesToWrite = *length; bytesWritten = bytesToWrite; // Just block if we can't write all at once // +1 to prevent an overflow of the ring buffer while( CDC_BUF_SIZE - CDC_BUF_COUNT(CDC_InBuf) < bytesToWrite+1 ); //uint8_t flush = CDC_DepInEmpty; USB_DEVINTEN = 0; while (bytesToWrite--) { CDC_BUF_WR(CDC_InBuf, *buffer++); // Copy Data to buffer } //if( flush == 1 ){ //if( CDC_DepInEmpty && CDC_BUF_COUNT(CDC_InBuf) ){ if( CDC_DepInEmpty ){ CDC_DepInEmpty = 0; CDC_BulkIn(); } USB_DEVINTEN = DEV_STAT_INT | (0xFF<<1) | (USB_SOF_EVENT ? FRAME_INT : 0); return (bytesWritten); }