src/platform/arm-teensy3/usb_serial.c
int usb_serial_read(void *buffer, uint32_t size)
{
	uint8_t *p = (uint8_t *)buffer;
	uint32_t qty, count=0;

	while (size) {
		if (!usb_configuration) break;
		if (!rx_packet) {
			rx:
			rx_packet = usb_rx(CDC_RX_ENDPOINT);
			if (!rx_packet) break;
			if (rx_packet->len == 0) {
				usb_free(rx_packet);
				goto rx;
			}
		}
		qty = rx_packet->len - rx_packet->index;
		if (qty > size) qty = size;
		memcpy(p, rx_packet->buf + rx_packet->index, qty);
		p += qty;
		count += qty;
		size -= qty;
		rx_packet->index += qty;
		if (rx_packet->index >= rx_packet->len) {
			usb_free(rx_packet);
			rx_packet = NULL;
		}
	}
	return count;
}
// read a block of bytes to a buffer
read a block of bytes to a buffer
read a block of bytes to a buffer
int usb_serial_read(void *buffer, uint32_t size)
{
	uint8_t *p = (uint8_t *)buffer;
	uint32_t qty, count=0;
	while (size) {
		if (!usb_configuration) break;
		if (!rx_packet) {
			rx:
			rx_packet = usb_rx(CDC_RX_ENDPOINT);
			if (!rx_packet) break;
			if (rx_packet->len == 0) {
				usb_free(rx_packet);
				goto rx;
			}
		}
		qty = rx_packet->len - rx_packet->index;
		if (qty > size) qty = size;
		memcpy(p, rx_packet->buf + rx_packet->index, qty);
		p += qty;
		count += qty;
		size -= qty;
		rx_packet->index += qty;
		if (rx_packet->index >= rx_packet->len) {
			usb_free(rx_packet);
			rx_packet = NULL;
		}
	}
	return count;
}
int usb_serial_read ( void * buffer , uint32_t size ) { uint8_t * p = ( uint8_t * ) buffer ; uint32_t qty , count = 0 ; while ( size ) { if ( ! usb_configuration ) break ; if ( ! rx_packet ) { rx : rx_packet = usb_rx ( CDC_RX_ENDPOINT ) ; if ( ! rx_packet ) break ; if ( rx_packet -> len == 0 ) { usb_free ( rx_packet ) ; goto rx ; } } qty = rx_packet -> len - rx_packet -> index ; if ( qty > size ) qty = size ; memcpy ( p , rx_packet -> buf + rx_packet -> index , qty ) ; p += qty ; count += qty ; size -= qty ; rx_packet -> index += qty ; if ( rx_packet -> index >= rx_packet -> len ) { usb_free ( rx_packet ) ; rx_packet = NULL ; } } return count ; }
read a block of bytes to a buffer
read a block of bytes to a buffer