.../purism/common/stdio.c: Optimize I2C sends to eliminate dropped keys
Optimize I2C writes to the debugger by buffering up to 16 bytes at a time. Flush when the buffer is full or when reaching a newline, so lines are still sent in a timely manner. Sending >1 byte requires firmware/librem-ec-i2c-debugger#2 firmware for the I2C debugger.
Keyboard dropped key presses in I2C debugging builds were caused by the amount of time spent writing the "cur raw:" and "BAT" lines every second. There's ~20 ms of battery I2C activity followed by 100 ms of I2C debug, resulting in a 120 ms window where keypresses could be dropped.
Buffering the I2C output reduces the debug output time to 45 ms, total drop window of ~65 ms. This is fast enough that I don't notice dropped keys any more.
We could gain 20 ms more by using printf_fast() instead of printf(). This ignores %o/%i/%p, which we don't use anywhere. However it also ignores field widths (%02X, etc.) which we do use a lot; this might be an SDCC bug since the manual says it is supported. It seems to be fast enough for now without doing this.
Signed-off-by: Jonathon Hall jonathon.hall@puri.sm