@@ -252,8 +252,8 @@ def active(self, *optional_value):
252252return self ._usbd .active (* optional_value )
253253
254254def _open_itf_cb (self ,desc ):
255- #Singleton callback from TinyUSBcustom class driver , when USB host does
256- #Set Configuration. Called once per interface or IAD.
255+ #Callback from TinyUSBlower layer , when USB host does Set
256+ # Configuration. Called once per interface or IAD.
257257
258258# Note that even if the configuration descriptor contains an IAD, 'desc'
259259# starts from the first interface descriptor in the IAD and not the IAD
@@ -291,7 +291,7 @@ def _open_itf_cb(self, desc):
291291itf .on_open ()
292292
293293def _reset_cb (self ):
294- #Callback when the USB device is reset by the host
294+ #TinyUSB lower layer callback when the USB device is reset by the host
295295
296296# Allow interfaces to respond to the reset
297297for itf in self ._itfs .values ():
@@ -302,7 +302,7 @@ def _reset_cb(self):
302302self ._ep_cbs = {}
303303
304304def _submit_xfer (self ,ep_addr ,data ,done_cb = None ):
305- #Singleton function to submit a USB transfer (of any type except control).
305+ #Submit a USB transfer (of any type except control) to TinyUSB lower layer .
306306#
307307# Generally, drivers should call Interface.submit_xfer() instead. See
308308# that function for documentation about the possible parameter values.
@@ -319,27 +319,31 @@ def _submit_xfer(self, ep_addr, data, done_cb=None):
319319return self ._usbd .submit_xfer (ep_addr ,data )
320320
321321def _xfer_pending (self ,ep_addr ):
322- #Singleton function to return True if transfer is pending on this endpoint.
322+ #Returns True if a transfer is pending on this endpoint.
323323#
324324# Generally, drivers should call Interface.xfer_pending() instead. See that
325325# function for more documentation.
326326return self ._ep_cbs [ep_addr ]or (self ._cb_ep == ep_addr and self ._cb_thread != get_ident ())
327327
328328def _xfer_cb (self ,ep_addr ,result ,xferred_bytes ):
329- #Singleton callback from TinyUSBcustom class driver when a transfer completes.
329+ #Callback from TinyUSBlower layer when a transfer completes.
330330cb = self ._ep_cbs .get (ep_addr ,None )
331331self ._cb_thread = get_ident ()
332332self ._cb_ep = ep_addr # Track while callback is running
333333self ._ep_cbs [ep_addr ]= None
334+
335+ # In most cases, 'cb' is a callback function for the transfer. Can also be:
336+ # - True (for a transfer with no callback)
337+ # - None (TinyUSB callback arrived for invalid endpoint, or no transfer.
338+ # Generally unlikely, but may happen in transient states.)
334339try :
335- # For a pending xfer, 'cb' should either a callback function or True (if no callback)
336340if callable (cb ):
337341cb (ep_addr ,result ,xferred_bytes )
338342finally :
339343self ._cb_ep = None
340344
341345def _control_xfer_cb (self ,stage ,request ):
342- #Singleton callback from TinyUSBcustom class driver when a control
346+ #Callback from TinyUSBlower layer when a control
343347# transfer is in progress.
344348#
345349# stage determines appropriate responses (possible values