From 77aee1a940c908668469c63362252824fd2a5aeb Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Sun, 26 May 2019 15:29:44 +0200
Subject: [PATCH] feat(ips): Speed up display by using a buffer

---
 Hello_World/main.c           |  1 +
 ips/main.c                   |  3 ++-
 lib/card10/card10.h          |  2 ++
 lib/gfx/GUI_DEV/DEV_Config.c | 15 +--------------
 lib/gfx/LCD/LCD_Driver.c     | 27 ++++++++++++++++++++++++++-
 lib/gfx/LCD/LCD_Driver.h     |  3 +++
 6 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/Hello_World/main.c b/Hello_World/main.c
index ee2c9916..d4c1cd4f 100644
--- a/Hello_World/main.c
+++ b/Hello_World/main.c
@@ -29,6 +29,7 @@ int main(void)
     card10_diag();
 
     Paint_DrawImage(Heart, 0, 0, 160, 80);
+    LCD_Update();
 
     int h = 0;
     while (1) {
diff --git a/ips/main.c b/ips/main.c
index 5125ce2c..e47610b7 100644
--- a/ips/main.c
+++ b/ips/main.c
@@ -34,8 +34,9 @@ int main(void)
     Paint_DrawCircle(85,25, 22, GREEN, DRAW_FILL_EMPTY, DOT_PIXEL_2X2);
 
     Paint_DrawImage(gImage_40X40,120, 0,40, 40);
-    DEV_Delay_ms(10000);
     Paint_DrawImage(gImage_160X80,0, 0, 160, 80);
+    LCD_Update();
+    DEV_Delay_ms(3000);
 
     while (1) {
         TMR_Delay(MXC_TMR0, MSEC(1000), 0);
diff --git a/lib/card10/card10.h b/lib/card10/card10.h
index de8e96e4..36686311 100644
--- a/lib/card10/card10.h
+++ b/lib/card10/card10.h
@@ -1,5 +1,7 @@
 #ifndef CARD10_H
 
+#include "gpio.h"
+
 #include <stdint.h>
 
 void card10_init(void);
diff --git a/lib/gfx/GUI_DEV/DEV_Config.c b/lib/gfx/GUI_DEV/DEV_Config.c
index e38cfc6d..881b9eeb 100644
--- a/lib/gfx/GUI_DEV/DEV_Config.c
+++ b/lib/gfx/GUI_DEV/DEV_Config.c
@@ -36,26 +36,13 @@
 
 //const gpio_cfg_t DEV_CS_PIN = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
 //const gpio_cfg_t DEV_BL_PIN = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
+static spi_req_t req = {.rx_data = NULL, .bits=8, .width = SPI17Y_WIDTH_1, .ssel = 0, .deass = 1, .ssel_pol = SPI17Y_POL_LOW, .tx_num = 0, .rx_num = 0};
 
 /********************************************************************************/
 void lcd_write(uint8_t *data, int size)
 {
-    spi_req_t req;
-    //uint8_t tx_data[] = {data};
-    //uint8_t rx_data[] = {0};
-    //req.tx_data = tx_data;
     req.tx_data = data;
-    //req.rx_data = rx_data;
-    req.rx_data = NULL;
     req.len = size;
-    req.bits = 8;
-    req.width = SPI17Y_WIDTH_1;
-    req.ssel = 0;
-    req.deass = 1;
-    req.ssel_pol = SPI17Y_POL_LOW;
-    req.tx_num = 0;
-    req.rx_num = 0;
-
     SPI_MasterTrans(SPI, &req);
 }
 
diff --git a/lib/gfx/LCD/LCD_Driver.c b/lib/gfx/LCD/LCD_Driver.c
index ecc4d6d8..20f12e58 100644
--- a/lib/gfx/LCD/LCD_Driver.c
+++ b/lib/gfx/LCD/LCD_Driver.c
@@ -28,6 +28,7 @@
 #
 ******************************************************************************/
 #include "LCD_Driver.h"
+static uint8_t screen[LCD_HEIGHT][LCD_WIDTH][2];
 
 /*******************************************************************************
 function:
@@ -216,7 +217,7 @@ void LCD_SetCursor(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD  Yend)
 
 	LCD_WriteReg(0x2C);
 }
-
+#if 0
 /******************************************************************************
 function:	Clear screen function, refresh the screen to a certain color
 parameter	:
@@ -232,6 +233,7 @@ void LCD_Clear(UWORD Color)
 		}
 	 }
 }
+#endif
 
 /******************************************************************************
 function:	Refresh a certain area to the same color
@@ -275,12 +277,29 @@ parameter	:
 	  Y			:		Set the Y coordinate
 	  Color :		Set the color
 ******************************************************************************/
+#if 0
 void LCD_SetUWORD(UWORD x, UWORD y, UWORD Color)
 {
 	LCD_SetCursor(x,y,x,y);
 	LCD_WriteData_Word(Color); 	    
 } 
+#endif
+
+void LCD_SetUWORD(UWORD x, UWORD y, UWORD Color)
+{
+    screen[y][x][0] = (Color >> 8);
+    screen[y][x][1] = (Color & 0xFF);
+}
 
+void LCD_Clear(UWORD Color)
+{
+	UWORD i,j;
+	for(i = 0; i < LCD_WIDTH; i++){
+		for(j = 0; j < LCD_HEIGHT; j++){
+			LCD_SetUWORD(i, j, Color);
+		}
+	 }
+}
 
 void LCD_Set(uint8_t *data, int len)
 {
@@ -288,3 +307,9 @@ void LCD_Set(uint8_t *data, int len)
 	DEV_Digital_Write(DEV_DC_PIN,1);
     lcd_write(data, len);
 }
+
+void LCD_Update(void)
+{
+    LCD_Set((uint8_t*)screen, sizeof(screen));
+}
+
diff --git a/lib/gfx/LCD/LCD_Driver.h b/lib/gfx/LCD/LCD_Driver.h
index 725acdbc..54980b0c 100644
--- a/lib/gfx/LCD/LCD_Driver.h
+++ b/lib/gfx/LCD/LCD_Driver.h
@@ -48,4 +48,7 @@ void LCD_SetBacklight(UWORD Value);
 void LCD_Clear(UWORD Color);
 void LCD_ClearWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD UWORD);
 
+void LCD_Set(uint8_t *data, int len);
+void LCD_Update(void);
+
 #endif
-- 
GitLab