Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions components/legacy/usb/usbdevice/class/cdc_vcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
{
rt_base_t level;
struct vcom *data;
#ifdef RT_USING_SERIAL_V2
struct rt_serial_rx_fifo *rx_fifo;
#endif

RT_ASSERT(func != RT_NULL);

Expand All @@ -351,7 +354,15 @@ static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
/* receive data from USB VCOM */
level = rt_hw_interrupt_disable();

#ifdef RT_USING_SERIAL_V2
rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx;
if (rx_fifo != RT_NULL)
{
rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size);
}
#else
rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
#endif
rt_hw_interrupt_enable(level);

/* notify receive data */
Expand Down Expand Up @@ -514,10 +525,6 @@ static rt_err_t _function_enable(ufunction_t func)
data->ep_out->buffer = rt_malloc(CDC_RX_BUFSIZE);
RT_ASSERT(data->ep_out->buffer != RT_NULL);

#ifdef RT_USING_SERIAL_V2
data->serial.serial_rx = &data->rx_ringbuffer;
#endif

data->ep_out->request.buffer = data->ep_out->buffer;
data->ep_out->request.size = EP_MAXPACKET(data->ep_out);

Expand Down Expand Up @@ -719,18 +726,30 @@ static int _vcom_getc(struct rt_serial_device *serial)
rt_base_t level;
struct ufunction *func;
struct vcom *data;
#ifdef RT_USING_SERIAL_V2
struct rt_serial_rx_fifo *rx_fifo;
#endif

func = (struct ufunction*)serial->parent.user_data;
data = (struct vcom*)func->user_data;
RT_UNUSED(data);

result = -1;

level = rt_hw_interrupt_disable();

#ifdef RT_USING_SERIAL_V2
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
if(rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0)
{
result = ch;
}
#else
if(rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
{
result = ch;
}
#endif

rt_hw_interrupt_enable(level);

Expand Down
Loading