void HandleSerial(void)
{
	// Only try to read in bytes from the CDC interface if the transmit buffer is not full 
	if (!(RingBuffer_IsFull(&FromHost_Buffer)))
	{
		int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		// Read bytes from the USB OUT endpoint into the USART transmit buffer 
		if (!(ReceivedByte < 0)){
		  	RingBuffer_Insert(&FromHost_Buffer, ReceivedByte);
			CDC_Device_SendByte(&VirtualSerial_CDC_Interface, ReceivedByte);
		}
	}

	while (RingBuffer_GetCount(&FromHost_Buffer) > 0)
	{
		int16_t c = RingBuffer_Remove(&FromHost_Buffer);

		if(c == '\n' || c == '\r'){
			if(cmd_cnt > 0 && (cmd[cmd_cnt-1] == '\n' || cmd[cmd_cnt-1] == '\r'))
				cmd_cnt--;
			cmd[cmd_cnt] = 0;			
			execute_command();
			cmd_cnt = 0;			
		}
		else{
			cmd[cmd_cnt++] = c;			
		}
	}
}
int16_t VncServerGetData(uint8_t * buffer, uint16_t maxsize)
{
    uint16_t size = 0;

    if(usbConnectionReset)
    {
        usbConnectionReset = false;
        return -1;
    }

    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    USB_USBTask();

    while(debugcounter > 64)
    {
        DDRF |= (1 << 0);
        PORTF |= (1 << 0);
        debugcounter -= 64;
        PORTF &= ~(1 << 0);
    }

    while ( size < maxsize )
    {
        int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
        if(ReceivedByte < 0)
            break;

        buffer[size++] = (uint8_t)ReceivedByte;
        debugcounter++;
    }

    return size;
}
Example #3
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
  SetupHardware();
  uint16_t bytesAvailable, currentByte;

  CDC_Device_CreateStream(&tpad_CDC_Interface, &USBSerialStream);
  sei();

  for (;;)
  {

    //
    // Read pressures from 16 buttons
    //
    ButtonStates();

    //
    // Handle incoming bytes
    //
    bytesAvailable = CDC_Device_BytesReceived(&tpad_CDC_Interface);
    while (bytesAvailable--) {
      currentByte = CDC_Device_ReceiveByte(&tpad_CDC_Interface);
      // TODO: implement led updates from host
    }

    CDC_Device_USBTask(&tpad_CDC_Interface);
    USB_USBTask();
  }
}
Example #4
0
File: note.c Project: Hylian/sdvx
int main(void)
{
  SetupHardware();

  /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
  CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

  GlobalInterruptEnable();

  while(1)
  {
    DebounceUpdate();
    EncoderUpdate();
    LedUpdate();

    SendSerial();

    /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
    CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    HID_Device_USBTask(&Mouse_HID_Interface);
    HID_Device_USBTask(&Keyboard_HID_Interface);

    USB_USBTask();
  }
}
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	RingBuffer_InitBuffer(&USBtoUSART_Buffer, USBtoUSART_Buffer_Data, sizeof(USBtoUSART_Buffer_Data));
	RingBuffer_InitBuffer(&USARTtoUSB_Buffer, USARTtoUSB_Buffer_Data, sizeof(USARTtoUSB_Buffer_Data));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
		if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
		}

		/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
		uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
		if (BufferCount)
		{
			Endpoint_SelectEndpoint(VirtualSerial_CDC_Interface.Config.DataINEndpoint.Address);

			/* Check if a packet is already enqueued to the host - if so, we shouldn't try to send more data
			 * until it completes as there is a chance nothing is listening and a lengthy timeout could occur */
			if (Endpoint_IsINReady())
			{
				/* Never send more than one bank size less one byte to the host at a time, so that we don't block
				 * while a Zero Length Packet (ZLP) to terminate the transfer is sent if the host isn't listening */
				uint8_t BytesToSend = MIN(BufferCount, (CDC_TXRX_EPSIZE - 1));

				/* Read bytes from the USART receive buffer into the USB IN endpoint */
				while (BytesToSend--)
				{
					/* Try to send the next byte of data to the host, abort if there is an error without dequeuing */
					if (CDC_Device_SendByte(&VirtualSerial_CDC_Interface,
											RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError)
					{
						break;
					}

					/* Dequeue the already sent byte from the buffer now we have confirmed that no transmission error occurred */
					RingBuffer_Remove(&USARTtoUSB_Buffer);
				}
			}
		}

		/* Load the next byte from the USART transmit buffer into the USART */
		if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer)))
		  Serial_SendByte(RingBuffer_Remove(&USBtoUSART_Buffer));

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Example #6
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	_setBrightness(50);

	for (;;)
	{
		/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
		CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();

		DS1302_clock_burst_read((uint8_t *) &rtc);

		_setDigit( rtc.Seconds % 10 );
		_setBrightness( 50 );

		_delay_ms(4);
    }
}
Example #7
0
void usb_serial_flush_input(void)
{
  int16_t i;
  int16_t bufsize = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);
  for(i=0; i<bufsize; i++)
    CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
}
Example #8
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	RingBuffer_InitBuffer(&USBtoUSART_Buffer, USBtoUSART_Buffer_Data, sizeof(USBtoUSART_Buffer_Data));
    RingBuffer_InitBuffer(&ToUSB_Buffer, ToUSB_Buffer_Data, sizeof(ToUSB_Buffer_Data));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
		if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
		}
		
		/* Load the next byte from the USART transmit buffer into the USART */
		if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer)))
		  Serial_SendByte(RingBuffer_Remove(&USBtoUSART_Buffer));

		cdc_send_USB_data(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Example #9
0
static int CDC_Device_getchar(FILE* Stream)
{
	if (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))
	  return _FDEV_EOF;

	return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
}
Example #10
0
uint8_t getch() {
	int ReceivedByte = -1;
	// wait until CDC sends a byte
	while (ReceivedByte < 0)
		ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
	return ReceivedByte;
}
Example #11
0
int
main(void) {
  uint8_t i = 1;
  uint8_t count = 3;

  setup();

  blink(3);
  _delay_ms(100);

  while (1) {
    // Print greeting at most count times.
    if (i <= count) {
      if (USB_DeviceState == DEVICE_STATE_Configured && ok_to_send) {
        blink(i);
        CDC_Device_SendString(&VirtualSerial_CDC_Interface, "Hello World! ");
        CDC_Device_SendByte(&VirtualSerial_CDC_Interface, '0' + i);
        CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\r\n");
        CDC_Device_Flush(&VirtualSerial_CDC_Interface);

        i++;
      }
    }

    if (USB_DeviceState == DEVICE_STATE_Configured) {
      /* Must throw away unused bytes from the host, or it will lock up
         while waiting for the device */
      CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
    }
    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    USB_USBTask();
  }
}
Example #12
0
int main(void) {
  SetupHardware();

  // If digital pin 6 (PD7) is low, fill channel data with a distinctive
  // pattern.
  DDRD &= 0b01111111;
  bool fill_with_pattern = bit_is_clear(PIND, 7);
  if (fill_with_pattern) {
    memset(_chandata, 0b01010101, 2048);
  }

  LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
  GlobalInterruptEnable();

  while (true) {
    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    USB_USBTask();

    if (connected) {
      uint8_t* position = _chandata;
      int16_t universe = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
      if (universe == -1) {
        // just a normal timeout, continue
        continue;
      }
      position += universe;

      while (position < _chandata + 2048) {
        int16_t channel_level =
            CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
        if (channel_level != -1) {
          *position = (uint8_t)channel_level;
          position += 4;
        } else {
          if (!connected) {
            // connection lost, forget our position and wait for a connection
            break;
          }
          // just a normal timeout, continue
          continue;
        }
      }
    }
  }
}
Example #13
0
void VCOM_echo(void)
{
	if(CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface))
	{
		in_buff[0] = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char *)in_buff, 1);
		Endpoint_ClearIN();
	}
}
Example #14
0
uint8_t gethexdigit(void)
{
	// read directly from serial port
	const uint8_t c = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
	if('0' <= c && c <= '9') return c-'0';
	if ('A' <= c && c && c <= 'F') return 10+c-'A';
	if ('a' <= c && c && c <= 'f') return 10+c-'a';
	return -1;
}
Example #15
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	GlobalInterruptEnable();

	uint8_t sending = 0;

	for (;;) {

		while (1) {
                	int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
			if (ReceivedByte < 0) 
				break;

			if (!configured) continue;

			if (!sending) {
				PORTC.OUTSET = PIN1_bm;
				sending = 1;
			}

			PORTD.OUTTGL = PIN5_bm;
                	while(!USART_IsTXDataRegisterEmpty(&USART));
                	USART_PutChar(&USART, ReceivedByte & 0xff);
		}

		if (sending) {
			USART_ClearTXComplete(&USART);
               		while(!USART_IsTXComplete(&USART));
			PORTC.OUTCLR = PIN1_bm;
			sending = 0;	
		}

                Endpoint_SelectEndpoint(VirtualSerial_CDC_Interface.Config.DataINEndpoint.Address);

                /* Check if a packet is already enqueued to the host - if so, we shouldn't try to send more data
                 * until it completes as there is a chance nothing is listening and a lengthy timeout could occur */

		if (configured && Endpoint_IsINReady()) {
			uint8_t maxbytes = CDC_TXRX_EPSIZE;
                	while (USART_RXBufferData_Available(&USART_data) && maxbytes-->0) {
                        	uint8_t b = USART_RXBuffer_GetByte(&USART_data);
				CDC_Device_SendByte(&VirtualSerial_CDC_Interface, b);
				PORTD.OUTTGL = PIN5_bm;
                	}
                }

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();

		if (loop++) continue;
		if (!configured) continue;

		PORTD.OUTTGL = PIN5_bm;
	}
}
Example #16
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	RingBuffer_InitBuffer(&USBtoUSART_Buffer);
	RingBuffer_InitBuffer(&USARTtoUSB_Buffer);

	sei();

	for (;;)
	{
		/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
		if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
		}

		/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
		RingBuff_Count_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
		if ((TIFR0 & (1 << TOV0)) || (BufferCount > BUFFER_NEARLY_FULL))
		{
			TIFR0 |= (1 << TOV0);

			if (USARTtoUSB_Buffer.Count) {
				LEDs_TurnOnLEDs(LEDMASK_TX);
				PulseMSRemaining.TxLEDPulse = TX_RX_LED_PULSE_MS;
			}

			/* Read bytes from the USART receive buffer into the USB IN endpoint */
			while (BufferCount--)
			  CDC_Device_SendByte(&VirtualSerial_CDC_Interface, RingBuffer_Remove(&USARTtoUSB_Buffer));

			/* Turn off TX LED(s) once the TX pulse period has elapsed */
			if (PulseMSRemaining.TxLEDPulse && !(--PulseMSRemaining.TxLEDPulse))
			  LEDs_TurnOffLEDs(LEDMASK_TX);

			/* Turn off RX LED(s) once the RX pulse period has elapsed */
			if (PulseMSRemaining.RxLEDPulse && !(--PulseMSRemaining.RxLEDPulse))
			  LEDs_TurnOffLEDs(LEDMASK_RX);
		}

		/* Load the next byte from the USART transmit buffer into the USART */
		if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer))) {
		  Serial_TxByte(RingBuffer_Remove(&USBtoUSART_Buffer));

		  	LEDs_TurnOnLEDs(LEDMASK_RX);
			PulseMSRemaining.RxLEDPulse = TX_RX_LED_PULSE_MS;
		}

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Example #17
0
//------------------------------------------------------------------------------
void appUsbDataReceived(Application *app)
{
    int16_t received_byte = 0;
    while((received_byte = CDC_Device_ReceiveByte(app->cdc_info)) >= 0)
    {
        RingBuffer_Insert(&app->buffer_, received_byte);
    }
    serialProcess(app);
}
Example #18
0
int main(void)
{
	SetupHardware();

	RingBuffer_InitBuffer(&USBtoUSART_Buffer, USBtoUSART_Buffer_Data, sizeof(USBtoUSART_Buffer_Data));
	RingBuffer_InitBuffer(&USARTtoUSB_Buffer, USARTtoUSB_Buffer_Data, sizeof(USARTtoUSB_Buffer_Data));

	LEDs_SetAllLEDs(0);

	sei();

	for (;;)
	{
		if ((PINF & 0x01) == 0x01)
			LEDs_SetAllLEDs(2);
		else
			LEDs_SetAllLEDs(0);
		/* Only try to read in bytes from the CDC interface if the (outbound) transmit buffer is not full */
		if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
		}

		/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
		uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
		if ((TIFR0 & (1 << TOV0)) || (BufferCount > (uint8_t)(sizeof(USARTtoUSB_Buffer_Data) * .75)))
		{
			/* Clear flush timer expiry flag */
			TIFR0 |= (1 << TOV0);

			/* Read bytes from the USART receive buffer into the USB IN endpoint */
			while (BufferCount--)
			{
				/* Try to send the next byte of data to the host, abort if there is an error without dequeuing */
				if (CDC_Device_SendByte(&VirtualSerial_CDC_Interface,
				                        RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError)
				{
					break;
				}

				/* Dequeue the already sent byte from the buffer now we have confirmed that no transmission error occurred */
				RingBuffer_Remove(&USARTtoUSB_Buffer);
			}
		}

		/* Load the next byte from the USART transmit buffer into the USART */
		if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer)))
		  Serial_SendByte(RingBuffer_Remove(&USBtoUSART_Buffer));

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Example #19
0
static int CDC_Device_getchar(FILE* Stream)
{
	int16_t ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));

	if (ReceivedByte < 0)
	  return _FDEV_EOF;

	return ReceivedByte;
}
Example #20
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	RingBuffer_InitBuffer(&FromHost_Buffer, FromHost_Buffer_Data, sizeof(FromHost_Buffer_Data));

	GlobalInterruptEnable();

	for (;;)
	{
		/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
		if (!(RingBuffer_IsFull(&FromHost_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&FromHost_Buffer, ReceivedByte);
		}

		while (RingBuffer_GetCount(&FromHost_Buffer) > 0)
		{
			static uint8_t EscapePending = 0;
			int16_t HD44780Byte = RingBuffer_Remove(&FromHost_Buffer);

			if (HD44780Byte == COMMAND_ESCAPE)
			{
				if (EscapePending)
				{
					HD44780_WriteData(HD44780Byte);
					EscapePending = 0;
				}
				else
				{
					/* Next received character is the command byte */
					EscapePending = 1;
				}
			}
			else
			{
				if (EscapePending)
				{
					HD44780_WriteCommand(HD44780Byte);
					EscapePending = 0;
				}
				else
				{
					HD44780_WriteData(HD44780Byte);
				}
			}
		}

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Example #21
0
void CDC_In_Task()
{
 /* Read bytes from the USB OUT endpoint and transmit to jennic if programming mode */
 if ( ringbuf_elements(&USBtoUSART_Buffer) < ringbuf_size(&USBtoUSART_Buffer)-2 ) {
   // TODO check int16_t type
   int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC1_Interface);
   if ( !(ReceivedByte < 0) )
     ringbuf_put(&USBtoUSART_Buffer, ReceivedByte);
 }
}
Example #22
0
/******************************************************************************
* Nombre de la funcion	: int16_t serial_read(void)
*    int16_t            : Si se leyo un byte exitosamente, retorna el byte, si
*                         no, retorna -1
* Creada por		: Alejandro Weinstein
* Fecha Creacion	: 2013-04-08
*
* Descripcion : Lee un byte desde el puerto serial virtual
******************************************************************************/
int16_t serial_read(void)
{
  int16_t ReceivedByte;
  ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
	  
  /* Read bytes from the USB OUT endpoint */
  if (!(ReceivedByte < 0)) {
    return ReceivedByte;
  } else {
    return -1;
  }

}
Example #23
0
static int CDC_Device_getchar_Blocking(FILE* Stream)
{
	while (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))
	{
		if (USB_DeviceState == DEVICE_STATE_Unattached)
		  return _FDEV_EOF;
	
		CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
		USB_USBTask();
	}

	return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
}
Example #24
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	sei();

    DDRB  |= (1 << 4);
    PORTB |= (1 << 4);


	for (;;)
	{
        int16_t c = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
        if (c > 0){
            switch (c) {
                case '1':
                    // this will eventually be to strobe the modem on pin of a telit module
                    // set port to output mode and low state
                    // stall for 1000 ms
                    // set port back to high impedance
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "received 1\r\n");
                    DDRD  |=  (1 << 0);
                    PORTD &= ~(1 << 0);

                    _delay_ms(1000);
                    DDRD  &= ~(1 << 0);
                    PORTD |=  (1 << 0);
                    break;
                case 'r':
                    // this will be to strobe the reset pin of a telit module
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "received r\r\n");
                    PORTB &= ~(1 << 4);
                    _delay_ms(200);
                    PORTB |= (1 << 4);
                    break;
                case '?':
                    // this wil be to inquire abouth the powermon pin of a telit module
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "received ?\r\n");
                    PORTB |= ~(1 << 4);
                    break;
                default:
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "unrecognized input\r\n");
            }
        }
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Example #25
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();
	
	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);

	for (;;)
	{
		CheckJoystickMovement();

		/* Discard all received data on the first CDC interface */
		while (CDC_Device_BytesReceived(&VirtualSerial1_CDC_Interface))
		  CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);

		/* Echo all received data on the second CDC interface */
		while (CDC_Device_BytesReceived(&VirtualSerial2_CDC_Interface))
		  CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface));
		  
		CDC_Device_USBTask(&VirtualSerial1_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial2_CDC_Interface);
		USB_USBTask();
	}
}
Example #26
0
void CDC_Arduino_In_Task()
{
uint16_t bytes = CDC_Device_BytesReceived(&VirtualSerial_CDC0_Interface);
	while(bytes--){
	/* Read bytes from the USB OUT endpoint and store it for the Arduino Serial Class */
 		if ( ringbuf_elements(&serialRx_Buffer) < ringbuf_size(&serialRx_Buffer)-2 ) {
   			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC0_Interface);
   			if ( !(ReceivedByte < 0) )
     				ringbuf_put(&serialRx_Buffer, ReceivedByte);
 		}
 		else{
 			return;
 		}
 	} // end while
}
Example #27
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		CheckJoystickMovement();

		/* Discard all received data on the first CDC interface */
		CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);

		/* Echo all received data on the second CDC interface */
		int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface);
		if (!(ReceivedByte < 0))
		  CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, (uint8_t)ReceivedByte);

		CDC_Device_USBTask(&VirtualSerial1_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial2_CDC_Interface);
		USB_USBTask();
	}
}
static int CDC_Device_getchar_Blocking(FILE* Stream)
{
	int16_t ReceivedByte;

	while ((ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))) < 0)
	{
		if (USB_DeviceState[corenum] == DEVICE_STATE_Unattached)
		  return _FDEV_EOF;

		CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
		USB_USBTask();
	}

	return ReceivedByte;
}
Example #29
0
void VCOM_bridge(void)
{
	uint32_t recv_count;
	recv_count = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);
	while(recv_count--)
	{
		out_buff[0] = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		uart_send_byte(out_buff[0]);
	}
	recv_count = uart_get_data(in_buff);
	if(recv_count)
	{
		CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char *)in_buff, recv_count);
		Endpoint_ClearIN();
	}
}
Example #30
0
uint8_t TerminalReceiveChar(unsigned int timeout)
{
    // Try to read a character from the USB library

    unsigned int start = GetMilliSeconds();

    while (GetMilliSeconds() - start < timeout)
    {
        int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

        if (!(ReceivedByte < 0))
        {
            // got a character
            return((unsigned char)ReceivedByte);
        }
    }
    return 0;
}