Skip to content

Commit ec20f9f

Browse files
committed
fix[usb]: support VCOM polling receive with Serial V2
Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
1 parent 8aaa706 commit ec20f9f

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

‎components/legacy/usb/usbdevice/class/cdc_vcom.c‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size)
337337
static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
338338
{
339339
rt_base_t level;
340+
rt_bool_t notify_rx = RT_FALSE;
340341
struct vcom *data;
341342
#ifdef RT_USING_SERIAL_V2
342343
struct rt_serial_rx_fifo *rx_fifo;
@@ -355,18 +356,30 @@ static rt_err_t _ep_out_handler(ufunction_t func, rt_size_t size)
355356
level = rt_hw_interrupt_disable();
356357

357358
#ifdef RT_USING_SERIAL_V2
358-
rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx;
359-
if (rx_fifo != RT_NULL)
359+
if (data->serial.config.rx_bufsz == 0)
360360
{
361-
rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size);
361+
rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
362+
}
363+
else
364+
{
365+
rx_fifo = (struct rt_serial_rx_fifo *)data->serial.serial_rx;
366+
if (rx_fifo != RT_NULL)
367+
{
368+
rt_ringbuffer_put(&rx_fifo->rb, data->ep_out->buffer, size);
369+
notify_rx = RT_TRUE;
370+
}
362371
}
363372
#else
364373
rt_ringbuffer_put(&data->rx_ringbuffer, data->ep_out->buffer, size);
374+
notify_rx = RT_TRUE;
365375
#endif
366376
rt_hw_interrupt_enable(level);
367377

368378
/* notify receive data */
369-
rt_hw_serial_isr(&data->serial,RT_SERIAL_EVENT_RX_IND);
379+
if (notify_rx)
380+
{
381+
rt_hw_serial_isr(&data->serial, RT_SERIAL_EVENT_RX_IND);
382+
}
370383
}
371384

372385
data->ep_out->request.buffer = data->ep_out->buffer;
@@ -732,20 +745,29 @@ static int _vcom_getc(struct rt_serial_device *serial)
732745

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

737749
result = -1;
738750

739751
level = rt_hw_interrupt_disable();
740752

741753
#ifdef RT_USING_SERIAL_V2
742-
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
743-
if(rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0)
754+
if (serial->config.rx_bufsz == 0)
744755
{
745-
result = ch;
756+
if (rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
757+
{
758+
result = ch;
759+
}
760+
}
761+
else
762+
{
763+
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
764+
if (rx_fifo != RT_NULL && rt_ringbuffer_getchar(&rx_fifo->rb, &ch) != 0)
765+
{
766+
result = ch;
767+
}
746768
}
747769
#else
748-
if(rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
770+
if (rt_ringbuffer_getchar(&data->rx_ringbuffer, &ch) != 0)
749771
{
750772
result = ch;
751773
}

0 commit comments

Comments
 (0)