@@ -188,7 +188,7 @@ Miscellaneous functions
188188 Takes a 4-tuple (or list) and sends it to the USB host (the PC) to
189189 signal a HID mouse-motion event.
190190
191- .. note :: This function is deprecated. Use pyb.USB_HID() .send(...) instead.
191+ .. note :: This function is deprecated. Use :meth:` pyb.USB_HID.send()` instead.
192192
193193 .. function :: info([dump_alloc_table])
194194
@@ -254,6 +254,33 @@ Miscellaneous functions
254254
255255 Returns a string of 12 bytes (96 bits), which is the unique ID of the MCU.
256256
257+ .. function :: usb_mode([modestr], vid=0xf055, pid=0x9801, hid=pyb.hid_mouse)
258+
259+ If called with no arguments, return the current USB mode as a string.
260+
261+ If called with ``modestr `` provided, attempts to set USB mode.
262+ This can only be done when called from ``boot.py `` before
263+ :meth: `pyb.main() ` has been called. The following values of
264+ ``modestr `` are understood:
265+
266+ - ``None ``: disables USB
267+ - ``'VCP' ``: enable with VCP (Virtual COM Port) interface
268+ - ``'VCP+MSC' ``: enable with VCP and MSC (mass storage device class)
269+ - ``'VCP+HID' ``: enable with VCP and HID (human interface device)
270+
271+ For backwards compatibility, ``'CDC' `` is understood to mean
272+ ``'VCP' `` (and similarly for ``'CDC+MSC' `` and ``'CDC+HID' ``).
273+
274+ The ``vid `` and ``pid `` parameters allow you to specify the VID
275+ (vendor id) and PID (product id).
276+
277+ If enabling HID mode, you may also specify the HID details by
278+ passing the ``hid `` keyword parameter. It takes a tuple of
279+ (subclass, protocol, max packet length, polling interval, report
280+ descriptor). By default it will set appropriate values for a USB
281+ mouse. There is also a ``pyb.hid_keyboard `` constant, which is an
282+ appropriate tuple for a USB keyboard.
283+
257284Classes
258285-------
259286
@@ -277,4 +304,5 @@ Classes
277304 pyb.Switch.rst
278305 pyb.Timer.rst
279306 pyb.UART.rst
307+ pyb.USB_HID.rst
280308 pyb.USB_VCP.rst
0 commit comments