#include "usb_phy.h"
#endif
+#include "ringbuf.h"
+
/* Provided by users. */
extern void USB_DeviceClockInit(void);
extern void USB_DeviceIsrEnable(void);
/*******************************************************************************
* Variables
******************************************************************************/
+
+static uint8_t cdc_rx_buf_space[1024];
+
+static struct ringbuf cdc_rx_buf =
+ RINGBUF_INIT (cdc_rx_buf_space, sizeof (cdc_rx_buf_space));
+
/* Data structure of virtual com device */
usb_cdc_vcom_struct_t s_cdcVcom;
{
/* User: add your own code for send complete event */
s_sendComplete = 1;
+ USB_DeviceRecvRequest (handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
USB0->INTEN |= USB_INTEN_SOFTOKEN_MASK;
#endif
+
+ if (s_recvSize) {
+ for (uint32_t offset = 0; s_recvSize-- > 0; offset++) {
+ if (ringbuf_is_full (&cdc_rx_buf))
+ break;
+
+ ringbuf_write (&cdc_rx_buf, s_currRecvBuf[offset]);
+ }
+
+ s_recvSize = 0;
+ } else
+
if (!s_recvSize)
{
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
#endif
+
+ USB_DeviceRecvRequest (handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
}
}
else
{
s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
}
+
+ USB_DeviceRecvRequest (handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize);
}
}
break;
{
USB_DeviceKhciIsrFunction (s_cdcVcom.deviceHandle);
}
+
+bool usb_serial_read (char *c)
+{
+ if (ringbuf_is_empty (&cdc_rx_buf)) {
+ if (!s_recvSize || s_recvSize == (uint32_t) -1)
+ USB_DeviceRecvRequest (s_cdcVcom.deviceHandle,
+ USB_CDC_VCOM_BULK_OUT_ENDPOINT,
+ s_currRecvBuf,
+ s_usbBulkMaxPacketSize);
+
+ return false;
+ }
+
+ *c = ringbuf_read (&cdc_rx_buf);
+
+ return true;
+}