The fixed buffer size can be problematic for some use cases, see:
- https://github.com/trussed-dev/ctaphid-dispatch/pull/15
To avoid adding support for different buffer sizes to the crate, we can
just make the dispatch implementation generic over the buffer size. For
simple cases, a type alias is provided using the old buffer size.
This patch flattens the public API of ctaphid-dispatch by making the
dispatch and types modules private and re-exporting the relevant types
from the root and removes unnecessary re-exports of the types defined by
ctaphid-app.
The buffer size is an implementation detail of the dispatch
implementation. Applications should not depend on it. This patch makes
the App trait generic over the response size and changes the request
argument to use a slice instead of a reference to a heapless::Vec.
If applications need a minimum response size, they can still use a
const assertion to enforce it.
Dispatch::poll has to copy the request so that the app can write the
response to the interchange. Previously, we called
Responder::take_request to obtain the message out of the interchange.
This implementation had a stack usage of 15280 bytes while the message
size is only 7609 bytes.
With this patch, we only request a reference from the responder and
manually copy the message to a buffer. This reduces the stack size to
7664 bytes.
I have no idea why the take_request implementation creates an additional
copy of the message. But as this function is the root for all CTAPHID
commands, this means we can save around 7 kB stack virtually everywhere.
Similar optimizations may be possible in other functions too.