Instead of doing the plugging late, in .begin(), allow setting the protocol in the constructor, and mark the global object weak, so it can be overridden in a user sketch, with one that has the desired protocol set.
We originally moved the PluggableUSB().plug(this) call from the constructor to .begin() in 186c8b4538ee3fb8d014c7871ba12a1412b8c1dd, to make it possible to set the default protocol the boot keyboard boots up with. However, this never really worked reliably, and was a bit finicky.
By allowing to override the object, we can set the protocol more reliably.
As a side effect, by moving the plugging to the constructor, the library will also work better with the (currently work in progress) arduino core for GD32 - though that needs other changes on top of this.
Instead of doing the plugging late, in
.begin()
, allow setting the protocol in the constructor, and mark the global object weak, so it can be overridden in a user sketch, with one that has the desired protocol set.We originally moved the
PluggableUSB().plug(this)
call from the constructor to.begin()
in 186c8b4538ee3fb8d014c7871ba12a1412b8c1dd, to make it possible to set the default protocol the boot keyboard boots up with. However, this never really worked reliably, and was a bit finicky.By allowing to override the object, we can set the protocol more reliably.
As a side effect, by moving the plugging to the constructor, the library will also work better with the (currently work in progress) arduino core for GD32 - though that needs other changes on top of this.