diff --git a/components/display/SSD1306.c b/components/display/SSD1306.c index 044aca24..1e27fcb7 100644 --- a/components/display/SSD1306.c +++ b/components/display/SSD1306.c @@ -39,6 +39,7 @@ static void Update( struct GDS_Device* Device ) { // not sure the compiler does not have to redo all calculation in for loops, so local it is int width = Device->Width, rows = Device->Height / 8; uint8_t *optr = Device->Shadowbuffer, *iptr = Device->Framebuffer; + int CurrentRow = -1, FirstCol = -1, LastCol = -1; // by row, find first and last columns that have been updated for (int r = 0; r < rows; r++) { @@ -53,8 +54,22 @@ static void Update( struct GDS_Device* Device ) { // now update the display by "byte rows" if (first--) { - SetColumnAddress( Device, first, last ); - SetPageAddress( Device, r, r); + + // only set column when useful, saves a fair bit of CPU + if (first > FirstCol && first <= FirstCol + 4 && last < LastCol && last >= LastCol - 4) { + first = FirstCol; + last = LastCol; + } else { + SetColumnAddress( Device, first, last ); + FirstCol = first; + LastCol = last; + } + + // Set row only when needed, otherwise let auto-increment work + if (r != CurrentRow) SetPageAddress( Device, r, Device->Height / 8 - 1 ); + CurrentRow = r + 1; + + // actual write Device->WriteData( Device, Device->Shadowbuffer + r*width + first, last - first + 1); } } diff --git a/components/display/display.c b/components/display/display.c index a1cb0e4d..8741cd7b 100644 --- a/components/display/display.c +++ b/components/display/display.c @@ -289,13 +289,14 @@ void displayer_metadata(char *artist, char *album, char *title) { /**************************************************************************************** * */ -void displayer_scroll(char *string, int speed) { +void displayer_scroll(char *string, int speed, int pause) { // need a display! if (!display) return; xSemaphoreTake(displayer.mutex, portMAX_DELAY); if (speed) displayer.speed = speed; + if (pause) displayer.pause = pause; displayer.offset = 0; strncpy(displayer.string, string, SCROLLABLE_SIZE); displayer.string[SCROLLABLE_SIZE] = '\0'; diff --git a/components/display/display.h b/components/display/display.h index 98b2dc92..e1b809e5 100644 --- a/components/display/display.h +++ b/components/display/display.h @@ -42,7 +42,7 @@ enum displayer_time_e { DISPLAYER_ELAPSED, DISPLAYER_REMAINING }; enum display_bus_cmd_e { DISPLAY_BUS_TAKE, DISPLAY_BUS_GIVE }; bool (*display_bus)(void *from, enum display_bus_cmd_e cmd); -void displayer_scroll(char *string, int speed); +void displayer_scroll(char *string, int speed, int pause); void displayer_control(enum displayer_cmd_e cmd, ...); void displayer_metadata(char *artist, char *album, char *title); void displayer_timer(enum displayer_time_e mode, int elapsed, int duration);