-
Notifications
You must be signed in to change notification settings - Fork 155
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
make USB HID period configurable (and default is now 8ms) #998
make USB HID period configurable (and default is now 8ms) #998
Conversation
Fun. Still gotta fix test stubs then, and I have no clue what to do for 7e and f7. |
@goebish can you help out with the linker finding everything in modular build? I tried, but something seems messed up with my build environment :( |
I can take a look but I'll be back home in 10 days |
I think I found the issue. Can't simply make Solution: While at it, we should also remove |
seems to be linking properly; that's good |
so all this needs is testing that it works as expected then |
I'll try to do so this weekend. |
Couldn't resist. Works perfect down to 1 ms in non modular build (t8sg as my testing device for development here). I have no modular devo right now, I might try building a modular build for my t8sg for testing purposes. edit: while trying out the modular build I bricked the (unified) bootloader on my t8sg, so I'll have to dig out the ST-Link to continue testing. Might take couple of days. |
I noticed some interesting behavior in lower update rates. For example, with 50 ms, the average ist indeed 50 ms, but it actually alternates between 35 and 65 ms. But since nobody wants these slow update rates it's probably not worth investigating. From 1 to 10 ms i noticed very exact update rates. |
I'm not really sure about how USB endpoints work, but I think that's related to how the OS polls the device. For example, Windows seems to take the provided bInterval and round it down to a closest power of two (or always 32 if larger than 32). It should be possible to hide that by always requesting a lower polling rate or only letting the user choose power-of-two periods somehow, but I don't know if it's worth adapting to "features" of USB stacks that don't really harm operation. |
How are you measuring this?
True, and this is similar to an 8bitdo controller I tested as a example to compare the "laggy" usb, so we are good with 8ms :D |
I measured using Wireshark on MacOS, but honestly only exemplary on settings 1-10 and 50 ms. But I'm not deep into USB stuff, just wanted a proof of the changes working. Also tried these settings in Picasim simulator though wine on the same system, which shows the same behavior as the Wireshark results suggested. Since 50 ms isn't usable at all, it really is not worth investing there. Maybe we should limit the protocol option to 32. |
Yeah, I'd agree that limiting it at 32 or even 16 is probably more sane than 64. (at least for a new project) |
Hmm... I realised I didn't make mixers run more often than the default (5ms?) when the HID period is decreased. That might be a good idea. |
I took another T8SG lying around (actually a Radiomaster TX8, but they are all the same to me ;) and flashed it. edit: now got Wireshark working correctly. As you suspected, update rates are always the closest power of 2, so when in-between, it changes between the closest powers of 2 to match the specified usb period in average. I don't thinks this is really a good behavior, as the protocol option suggest more control than it actually has. If we limit it to 16 the maximum error is 7 ms. Or maybe 6 ms if we limit the protocol options to steps of 2 (2-16). What do you think? edit2: modular build still not working yet... |
Finally managed a working modular build for the T8SG. Works very well with the same behavior as non modular builds. Let's decide on the period setting and we're good for merging. |
Concerning the protocol option: |
I think it's best to keep everything in a sequential order here, such as I think the first option will become the true default when all is complete, right? (I don't see any way to set an alternate default without breaking the first listed option unless we write a callback in the protocol) |
The issue is that the last entry is the default... |
It doesn't seem to behave that way on other protocols in emulator. I suspect you accidentally loaded a model that already had config data or left in the code that sets it to 8 when it was previously unset. |
Reading up on USB... Actually the period depends on the operating speed of the USB device and host. On full and high speed we can have 1,2,4,8,16,32 but for low speed it is only 8, 16 or 32. So setting period in protocol interval doesn't necessarily reflect the true transfer interval of the hid. |
I believe all targets with HID support are running at full speed, and it would be extremely unlikely for someone to use a host device without full speed support. |
let's see if this actually improves anything... |
While this might make a little improvement, I'm a little concerned in yet another rom size increase in the modular platforms (especially devo7e). These are really tight on rom space, and the addition of HID_setinterval already adds a bit. It might even be useful to make thr default option of 8 ms hard-coded for the modular builds and add the protocol option, which needs HID_SetInterval, only in non modular builds |
Hmm.. I see... |
You last commit didn't add too much, it's just something we (unfortunately) always need to have in mind. |
Yeah, I get what you mean. It's easy to add things that use up space now, but if we always do that it becomes hard to get the space later for something that really needs it. |
We put a lot of effort into code cleanup, because ROM space for devo7e was absolutely used. Since then, things have gotten a little relaxed (and deviation development more or less subsided due to not many active developers). But as you notice in target_defs, a lot of features are already deactivated for the modular builds. |
…nything stubs might not be the right place to declare HID_prevXferComplete on platforms that don't use devo_hid.c, but I'm not sure where else makes sense
Looks like devo 8 is getting pretty close to fully used too, and t8sg not far behind... I suppose the only way to avoid the increase on non-modular is to simply not add code though right? |
Anyway, the increase seems pretty minimal for 7e now, so if that was the primary concern and the code is still working, I guess we're good. |
Hmm... I think I actually figured out a nice enough way to give us a callback without needing to run mixers in the actual USB endpoint callback -- the USB endpoint callback can start a clock to run the protocol callback in an interrupt later. |
I'll play around tomorrow and see if I can get it to compile. |
Hopefully I didn't just break everything lol |
Perhaps this PR could use a revised title due to the now larger scope of changes, and possibly incorporate an increase to 8 button inputs with it being more than a simple change now anyway. |
I'd prefer seperate Pull requests for timing and inputs. |
Does the callback method work with 1 instead of 0 in the CLOCK_StartTimer call on devo_hid.c line 146? |
Nope. |
Hmm... I'd like to see the callback method working, but I can't see what I'm doing wrong. |
Yes, I also expected it to work, but haven‘t spent time debugging. Since none of the the protocols currently runs mixers on demand and the benefit is small and should only noticeable with 500 Hz and above, I‘m fine with the previous solution. The more changes to the „main“ code, the higher the change for introducing issues. |
Running mixers on demand was already present since before 5c0a6bd. It was copied from sbus/sumd like a lot of other stuff. The callback from USB code was just to try guaranteeing perfect sync to USB host polling. I will go ahead and revert the two most recent commits for the sake of having a working system though. |
Yes I know, I didn't mean running mixers on demand but synchronizing callbacks. Mixer run time is about 1 ms worst case, I'm not too worried about this. #532 is some interesting read. |
I can't approve as I created this PR, but I'm good with this. |
No description provided.