Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CDC.available
27-11-2013, 08:05 PM, (This post was last modified: 27-11-2013, 08:09 PM by dc_740.)
#1
CDC.available
I was looking for some function like Serial.available but for CDC in pinguino 8 bits

Would something like this work? (I'm at the university, I just copy/pasted some code from the source)
It would be added to usb_cdc.c (p8)

Quote:

u8 CDCAvailable(){
u8 i=0;
u8 length=64;

if (deviceState != CONFIGURED)
return 0;

// Only Process if we own the buffer aka not own by SIE
if (!CONTROL_LINE)
return 0;

// Only process if a serial device is connected
if (!EP_OUT_BD(CDC_DATA_EP_NUM).Stat.UOWN)
{
#ifdef DEBUG_PRINT_CDC
printf("Rx on EP %d, Size %d\r\n", CDC_DATA_EP_NUM, EP_OUT_BD(CDC_DATA_EP_NUM).Cnt);
#endif

// check how much bytes came
if (length > EP_OUT_BD(CDC_DATA_EP_NUM).Cnt)
return EP_OUT_BD(CDC_DATA_EP_NUM).Cnt;
}
return 0;
}

I didn't verify it. But it should work. What do you think?
Reply
28-11-2013, 07:37 AM,
#2
RE: CDC.available
Hi

I added a similar funcion for P32 processors with the name CDC.USBIsConnected.

Code:
BOOL CDCUSBNotConnected = false;

BOOL CDCUSBIsConnected(void)
{
  if ( (U1OTGSTATbits.VBUSVD != 0) && (U1OTGSTATbits.SESVD != 0) )
   {
    if (CDCUSBNotConnected == true)
     {
      CDC_init();
      CDCUSBNotConnected = false;
     }
    return(true);
   }
  else
   {
    CDCUSBNotConnected = true;
    return (false);
   }
}


The problem is which p8 and p32 have different registers.


Bye Bye, Moreno
Reply
29-11-2013, 06:30 PM,
#3
RE: CDC.available
in usb_bulk.c we use :

byte BULKavailable()
{
u8 received = (!EP_OUT_BD(BULK_DATA_EP_NUM).Stat.UOWN) &&(EP_OUT_BD(BULK_DATA_EP_NUM).Cnt > 0);
return(received );
}
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)