Closed algernon closed 6 years ago
It looks like the cost of this is non-trivial, even if BootKeyboard
itself is optimized out: 538 bytes of PROGMEM and 2 bytes of RAM with my own sketch, and size-map does not have BootKeyboard
in it anywhere.
Looking at what is adding such a significant amount...
Ow. Keyboard_::press
went from 78 bytes to 176. That if branch seems to be killing us.
I think I have a way to make the boot stuff optional, and have zero run-time cost when boot support is not compiled in (and less overhead when it is). I can even make the default being on.
If all goes well, to disable it, all one will have to do is #define KEYBOARDIOHID_BOOT_REPORT 0
in the user sketch, before including anything else.
If I do a bit of template magic, I was able to cut down the extra PROGMEM size to 124 bytes with fallback disabled. That is still a lot. And the code is incredibly ugly.
I have another idea, which involves introducing a KeyboardAPI
, and having Keyboard
be an implementation of that, with CombinedKeyboard
being a weak default, and NKROKeyboard
or BootKeyboard
being other options. The user can then just override the symbol in their sketch, and live happily ever after.
I have high hopes for this last idea...
I'm closing this in favour of using the kaleidoscope::hid
facade to implement a similar thing. The still useful parts of the PR will be re-submitted separately.
Based on earlier work by @obra, this first refactors
BootKeyboard
a little, preparing it to be used as a fallback, then adds a bit of logic toKeyboard
that dispatches everything toBootKeyboard
if we are in boot mode. By default, we rely on the host to send aSET_PROTOCOL
request to put us into boot mode, while defaulting to report mode. The default can be changed by settingBootKeyboard.default_protocol
toHID_BOOT_PROTOCOL
. If a manual override is required,BootKeyboard.setProtocol
can do that.Boot mode is optional, and disabled by default. Another PR against
Kaleidoscope
will add a small macro that makes it easier to enable it.While this works on FreeBSD (which does not support NKRO), I have not tested it anywhere else.
Fixes #10.