custom V-USB library #526
Replies: 3 comments 1 reply
-
|
I like this idea. I'm learning about how V-USB works even if I don't understand every detail. If you don't mind, here are some stream-of-consciousness notes from what passes for my brain Interupts and millis()It seems that a common design pattern (from the code I've seen so far) in initialising is as follows cli(); I believe this is also needed after a crash or other failure to make sure that both ends are in sync. It sometimes is associated with a watchdog reset. I guess if interrupts are disabled, you can't use any sort of regular delay() or millis() function, so it uses the compiler intrinsic for the half second delay. e.g. see https://github.com/heartscrytech/DigisparkMIDI/blob/master/DigiMIDI.h Not sure if that affects your design choice about using SOF keepalive. SOF frequencyIs SOF keepalive rate accurate to 1kHz, and if an app uses USB/SOF to implement mills() you're making the accuracy dependent on the USB host. Not sure what the tolerances are. CalibrationI found this recently https://github.com/jokkebk/TrinketMIDI/blob/master/trinketusb.c and nd it has an optional OSCCAL calibration function, presumably for those devices without a crystal. I'm mentioning it on the off-chance that it is of use in this discussion. Even if the idea is sound, it uses runtime floating point operations so may not be desirable in this form. Hope this stimulates debate, but please feel free to shout me down when I'm off-base, which does happen. |
Beta Was this translation helpful? Give feedback.
-
|
@prandeamus Here's a couple of posts that may help you with understanding USB: Although my latest blog post is focused on the CH55x MCUs, much of it is relevant to USB in general: To specifically address your question about the SOF timing accuacy, AFAIR the spec only requires +-0.25% for low-speed USB, but all PCs and laptops use xtal oscillators for the USB controllers, which have typical accuracy of +/-50ppm If you want a REALLY solid understanding of USB, then read this site: You can read about the latest and greatest OSCCAL tuner for V-USB and variants here: |
Beta Was this translation helpful? Give feedback.
-
|
Presumably, the core did use SOF as a timing source for millis() this would need to be dynamic/hotpluggable as we can't assume that a device will always be plugged into a USB host? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I thought of a way of possibly getting V-USB to coexist with ATTinyCore. Create a V-USB wrapper library that implments it's own millis using the SOFHOOK() in V-USB. You may need to break up the code in wiring.c into separate files (make a millis.c with the millis() fn and the ISR) in order to make it easier to override in the V-USB library.
This would also cleanly solve the 16.5/16MHz millis problem when using the 16.5MHz V-USB, as the USB SOF keepalive pulses come in at a steady 1KHz.
Beta Was this translation helpful? Give feedback.
All reactions