keyboardio / KeyboardioHID

A HID library for Arduino
MIT License
34 stars 17 forks source link

Mouse: Append the descriptor late, in Mouse.begin #21

Closed algernon closed 6 years ago

algernon commented 6 years ago

Because Mouse is always instantiated, the constructor always runs, and thus, the node is always registered whenever the Mouse object is referenced, even if done so in code that gets optimized out. To combat this, and allow the compiler to optimize out Mouse fully, do the append in Mouse.begin. This way, if the Mouse global is referenced by code that gets optimized out, the constructor will be optimized out, allowing the full object to get dropped. As we call Mouse.begin during setup, there is no risk doing a late append, either.

This addresses the most important part of keyboardio/Kaleidoscope#257.