Skip to content

Commit dd2d457

Browse files
committed
Always run USB polling from an interrupt to avoid lag from rendering
Sending while text was scrolling was running very slowly
1 parent a7a2ffd commit dd2d457

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

firmware/main.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class CodepointSender
210210
{
211211
// Start sending keys if it's not running yet
212212
if (m_send_timer.alarm_id == 0) {
213-
add_repeating_timer_ms(5, key_send_callback, this, &m_send_timer);
213+
add_repeating_timer_ms(1, key_send_callback, this, &m_send_timer);
214214
update();
215215
}
216216
}
@@ -273,6 +273,10 @@ int main()
273273
usb_init();
274274
stdio_usb_init();
275275

276+
// Run USB polling from an interrupt as the main loop slows down when rendering
277+
static struct repeating_timer usb_timer;
278+
add_repeating_timer_ms(5, background_usb_poll, NULL, &usb_timer);
279+
276280
printf("\n\nDevice has reset\n");
277281

278282
// GPIOs 0-11 as inputs with pull-up
@@ -332,16 +336,8 @@ int main()
332336
// Scroll so 0,0 in memory is actually rendered in the top-left corner
333337
st7789_vertical_scroll(300);
334338

335-
// Start the application
336-
// Temporarily polls usb from an interrupt as app.load() blocks for a while
337-
{
338-
struct repeating_timer timer;
339-
add_repeating_timer_ms(5, background_usb_poll, NULL, &timer);
340-
341-
app.load("fonts");
342-
343-
cancel_repeating_timer(&timer);
344-
}
339+
// Start the application (blocking until loaded)
340+
app.load("fonts");
345341

346342
// Turn on data input LEDs (inverted as this drives a P-channel mosfet)
347343
{
@@ -366,8 +362,6 @@ int main()
366362
UserInput send_switch(PIN_SWITCH_SEND);
367363

368364
while (true) {
369-
usb_poll();
370-
371365
if (needs_render) {
372366
needs_render = false;
373367

firmware/usb.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ void usb_poll(void)
7373
{
7474
tud_task();
7575

76-
// Send reports at a fixed interval
77-
const uint32_t interval_ms = 5;
78-
static uint32_t start_ms = 0;
79-
80-
if (board_millis() - start_ms < interval_ms) {
81-
return; // not enough time
82-
}
83-
84-
start_ms += interval_ms;
85-
8676
if (!tud_hid_ready()) {
8777
return;
8878
}

0 commit comments

Comments
 (0)