From f71c65106f6b7131eb88c060b39677e9d2c75873 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 19 Jul 2020 21:20:30 +0200 Subject: [PATCH] fw: Only update display if a full frame was received Sometimes, the RPi fails to send out a message in time, leading to two, back-to-back SPI transactions. The beginning of the second is then lost in the long lcd_display() call. By applying this patch, we now miss the incomplete frame entirely, but at least we don't display garbage on the screen. Just looks like stutter. The real solution would be to fix in on the Linux / Python side, but this workaround is better than nothing for now. --- firmware/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 16e7830..e56d013 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -8,7 +8,7 @@ void spi_proc() { - static uint8_t spi_cs_last = 0; + static uint8_t new_data = 0; static uint8_t x = 0; static uint8_t y = DISPLAY_HEIGHT / 8 - 1; uint8_t spi_cs; @@ -21,21 +21,22 @@ void spi_proc() if (y == 0) { y = DISPLAY_HEIGHT / 8 - 1; x++; - if (x == DISPLAY_WIDTH) + if (x == DISPLAY_WIDTH) { x = 0; + new_data = 1; // Only update the display if a full frame was received + } } else { y--; } } } else { - if (spi_cs_last) { + if (new_data) { lcd_display(); + new_data = 0; } x = 0; y = DISPLAY_HEIGHT / 8 - 1; } - - spi_cs_last = spi_cs; } int main()