浏览代码

add 'pause'

philippe44 5 年之前
父节点
当前提交
876ae491a1
共有 3 个文件被更改,包括 20 次插入4 次删除
  1. 17 2
      components/display/SSD1306.c
  2. 2 1
      components/display/display.c
  3. 1 1
      components/display/display.h

+ 17 - 2
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);
 		}
 	}	

+ 2 - 1
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';

+ 1 - 1
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);