Example #1
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); 
}
Example #2
0
void USB_EndPoint3 (uint32_t event) {
  switch (event) {
    case USB_EVT_OUT:
      CDC_BulkOut ();                /* data received from Host */
      break;
    case USB_EVT_IN:
      CDC_BulkIn ();                 /* data expected from Host */
      break;
  }
}