stm32/usb: Add USB_VCP.irq method, to set a callback on USB data RX.

Usage:

    usb = pyb.USB_VCP()
    usb.irq(lambda u:print(u, u.read()), usb.IRQ_RX)

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2021-05-19 23:43:21 +10:00
parent 8c02b94946
commit 71e3538a32
5 changed files with 91 additions and 1 deletions

View File

@@ -109,6 +109,16 @@ Methods
Return value: number of bytes sent.
.. method:: USB_VCP.irq(handler=None, trigger=0, hard=False)
Register *handler* to be called whenever an event specified by *trigger*
occurs. The *handler* function must take exactly one argument, which will
be the USB VCP object. Pass in ``None`` to disable the callback.
Valid values for *trigger* are:
- ``USB_VCP.IRQ_RX``: new data is available for reading from the USB VCP object.
Constants
---------
@@ -117,3 +127,7 @@ Constants
USB_VCP.CTS
to select the flow control type.
.. data:: USB_VCP.IRQ_RX
IRQ trigger values for :meth:`USB_VCP.irq`.