Module usb_device::class
source · [−]Expand description
For implementing standard as well as vendor-specific USB classes.
To implement a new class, implement the UsbClass
trait. The trait contains
numerous callbacks that you can use to respond to USB events. None of the methods are required,
and you only need to override the ones that your specific class needs to function. See the trait
documentation for more information on the callback methods.
Your class should not hold a direct reference to the UsbBus
object. Rather it
should take a temporary reference to the UsbBusAllocator
object
exposed by the bus in its constructor, and use that to allocate endpoints, as well as interface
and string handles. Using the Endpoint
handles which wrap a reference to
the UsbBus
instance ensures that classes cannot inadvertently access an endpoint owned by
another class.
In addition to implementing the trait, add struct methods for the end-user to send and receive
data via your class. For example, a serial port class might have class-specific methods read
and write
to read and write data.