-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #117: Rework host USB ready timeout #118
Conversation
@eightycc is it related also to boot keyboard? |
@dhalbert Over to you for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. A few ideas and q's:
-
Did you try spinning on
supervisor.runtime.usb_connected
to see if that worked out instead of trying the no-op sends? The advantage of that is that the connection testing could then be refactored into a single common routine, to reduce code size. It could be made part offind_device()
, so that not only does it have to find the device, but it also has to test connectivity. -
Instead of a fixed timeout, each
__init__()
could take an optional argument, timeout: int = 20)
. That would allow quicker failures for people who don't need to wait 20 seconds. (20 seconds is a long time). The timeout could get passed tofind_device()
if 1. is implemented. -
A better error message:
raise OSError("Failed to initialize HID device. Are you connected?")
. Of course, you're not connected, no one is going to see this :) .
@dhalbert Thanks for the thoughtful review.
|
If there's just one mention, it could be longer, because it will be in only .mpy (especially if frozen). I realized it will show up on boards with displays even if they don't have USB connectivity, so making it a bit more helpful will help at least some of the time. |
@dhalbert I've made the updates you requested. CI is failing due to my import of
|
@dhalbert Also, I should have given the |
Hmm, this is because We could add limited support of In the meantime, you could guard the @makermelissa Do you have any opinion about adding limited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good -- did you test in the two cases of cold and warm RPi host startup?
Why did you lengthen the timeout to 45 seconds? That is a really long time, more than the 15 seconds you were seeing during initial testing. If someone needs a timeout that long, they could explicitly supply it.
Yes, I did increase the timeout to 45 seconds. The reason is that the PI 4 was actually taking about 40 seconds, but I didn't see it because there's another timeout deeper in the USB code that was adding a second for every one of my seconds. Yikes! |
@dhalbert Yes, I did test hot and cold. Hot starts up immediately. I saw the guarding of other imports and had wondered about it. Now I know that Blinka is part of the ecosystem. If I delay say 1 or 2 seconds in the Blinka case, it should just fail like it used to in all cases with a Since the timeout interval won't affect normal usage, I'm not too worried about a long timeout in the failing case. But, it's your call. Timeouts and watchdogs are both bears to get right! |
I just want to confirm my understanding of the use case. Let's suppose you have an RPi with, say, a MacroPad plugged in, and also a conventional keyboard and a USB stick drive. When you power up the RPi, can it take up to 40 seconds for it to be responsive to the keyboard, and to mount the USB drive? Is this an RPi 4 or something that boots more slowly? |
Yes, the RPi 4 takes that long to get to USB enumeration. I'm testing with a stock 4G model loaded with an up to date but unmodified Raspbian 32-bit image. On POR, it's got gobs o' blobs that it has to load up before it even gets to the kernel. The use case is any USB device that is already plugged in at POR. In the case of the OP on the issue, it's a Pico bridging an old scan-style Amiga keyboard to USB. |
Another idea is if the timeout is |
@dhalbert Double-plus good on the timeout Shall I wait for adafruit/Adafruit_Blinka#711 or plow ahead with the guard? Or maybe you'd like me to write a pull for Blinka? |
I started looking at Blinka and usb_gadget but didn't get very far into it, and I have other things i need to work on at the moment. You could look at what it would take in Blinka, but we don't have to hold this up, since you have a workaround without it. We can always revise this library again. |
@dhalbert Over to you for what should be a final review! I'm digging into Blinka now and will update adafruit/Adafruit_Blinka#711 when I've got additional status. Interesting that reversing 117 gives 711, but I digress badly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your perseverance through the review process. I think this is a significant improvement to the current semantics.
In discord someone mentioned that supervisor.runtime.usb_connected
may not detect disconnection properly: it might still return True. However, that is not this library's problem, and we can investigate that separately.
I am going to make this a major revision change, because the semantics have changed, since the devices now by default wait indefinitely instead of only a second or two.
I tested this on a MacroPad, first when it was connected to a live host computer, and then secondly with a data/charge switch (https://www.adafruit.com/search?q=data+charge+usb+switch). In the latter case, I plugged it in and powered the board, and then waited about half a minute before flipping the switch to data. The code waited until there was data connectivity.
where to get mpy files ? |
Just grab the Edit: You can find the |
The new release, 6.0.0, will go in the daily bundle tonight. |
@dhalbert have some questions about CP, must open new issue for this or ask somewhere else? |
@uzi18 If you have general use questions, ask in discord, https://adafru.it/discord, channel #help-with-circuitpython. That is community-based support with some staff people hanging out. Or you can open a thread in our forums, which is "official" support: https://forums.adafruit.com/viewforum.php?f=60. For a dialog, discord works well. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_HID to 6.0.0 from 5.4.0: > Merge pull request adafruit/Adafruit_CircuitPython_HID#118 from eightycc/issue_117 Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Resolves #117.