I have some fairly elaborate USB emulation running on a couple of Leonardos (Keyboard, Joystick, Mouse) and it occurred to me recently that I'm using the same USB port on the Leos for my Serial print and println commands directed at the serial monitor for debugging purposes.
Is this for any reason bad practise? can my Serial.print statements interfere in any way with the use of the port for USB HID emulation? Or is the Leonardo actually emulating multiple USB devices, one for Serial and one for each emulation library I initialise? i.e. one Keyboard, one Joystick, etc.
This may be a really dumb question. I don't think I've ever seen any evidence of interference. I'm just wondering whether it might, for example, be wiser to complete one Keyboard interaction with the host machine in its entirety before doing a Serial.println command, rather than interspersing them.
In theory, a "composite USB device" can support a bunch of different "endpoints" that won't interfere with each other (at least, not if you're doing relatively low-bandwidth stuff like HID and Serial.)
In reality, most hardware USB controllers support a limited number of these endpoints, and you need one for each direction of a bi-directional device like a serial port. The 32u4 has 6 endpoints, and like Robin2, I didn't know you could get as much working simultaneously as you already have working. (perhaps HID reports share the 7th "Control Transfer" endpoint?)
But if it's working, there's no reason to expect it to be "bad practice."
Hmm well, I have 2 Leonardos in that project. One is emulating Keyboard, the other emulating Joystick. I actually dropped the Mouse code as it was easier to use an OTS micro trackpad than to emulate a mouse myself
So each one presumably is using 3 end points: 2 for the Serial connection and 1 for its HID task?
If I replace two Leos with a single Due (which is my plan at present) then I guess that would be 4 end points, as it would need 2 for the Serial connection and one each for Keyboard and Joystick. So I should still be OK...?
It's been working great on the Leos. I coulda built the whole thing with just one Leo, I guess, but I ran out of GPIO and flash, and way back when as a rank n00b I thought one Leo could only emulate one HID, so I split the whole app up onto 2 Leos (which taught me how to do bidirectional communication with i2cAnything, and that was fun).
The Due feels like, wow, moving into a mansion after living in a maisonette. Driving a Ferrari after putt-putting around in a 2CV. I'm still terrified of the 3.3v aspect but am being very, very careful