From 494d30a96b57ee027e5849823a9cd1939070babd Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Wed, 7 Aug 2019 03:38:35 +0200
Subject: [PATCH] fix(display): Re-init SPI before every transaction

---
 lib/card10/card10.c          | 13 +------------
 lib/gfx/GUI_DEV/DEV_Config.c | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/lib/card10/card10.c b/lib/card10/card10.c
index b423704f..a08071aa 100644
--- a/lib/card10/card10.c
+++ b/lib/card10/card10.c
@@ -24,11 +24,7 @@
 #include <stdint.h>
 #include <string.h>
 
-/* XXX: The display supports max 15 Mhz, but we have stability issues at that rate.
- * Current suspicion is that the SDK is buggy.
- *
- * At 12 MHz things seem stable*/
-#define SPI_SPEED (12 * 1000 * 1000) // Bit Rate. Display has 15 MHz limit
+#define SPI_SPEED (15 * 1000 * 1000) // Bit Rate
 
 const gpio_cfg_t bhi_interrupt_pin = {
 	PORT_0, PIN_13, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
@@ -82,19 +78,12 @@ void card10_init(void)
 	spi17y_master_cfg.ss0 = Enable;
 	spi17y_master_cfg.ss1 = Disable;
 	spi17y_master_cfg.ss2 = Disable;
-
 	if (SPI_Init(SPI0, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
 		printf("Error configuring SPI\n");
 		while (1)
 			;
 	}
 
-	if (SPI_Init(SPI2, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
-		printf("Error configuring SPI\n");
-		while (1)
-			;
-	}
-
 	display_init();
 
 	leds_init();
diff --git a/lib/gfx/GUI_DEV/DEV_Config.c b/lib/gfx/GUI_DEV/DEV_Config.c
index 881b9eeb..099ce0a4 100644
--- a/lib/gfx/GUI_DEV/DEV_Config.c
+++ b/lib/gfx/GUI_DEV/DEV_Config.c
@@ -1,12 +1,12 @@
 /*****************************************************************************
-* | File      	:   DEV_Config.c
+* | File        :   DEV_Config.c
 * | Author      :   Waveshare team
 * | Function    :   Hardware underlying interface
 * | Info        :
 *                Used to shield the underlying layers of each master 
 *                and enhance portability
 *----------------
-* |	This version:   V1.0
+* | This version:   V1.0
 * | Date        :   2018-11-22
 * | Info        :
 
@@ -37,10 +37,22 @@
 //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};
+#define SPI_SPEED (15 * 1000 * 1000) // Bit Rate. Display has 15 MHz limit
 
 /********************************************************************************/
 void lcd_write(uint8_t *data, int size)
 {
+    sys_cfg_spi_t spi17y_master_cfg;
+
+    spi17y_master_cfg.map = MAP_A;
+    spi17y_master_cfg.ss0 = Enable;
+    spi17y_master_cfg.ss1 = Disable;
+    spi17y_master_cfg.ss2 = Disable;
+    if (SPI_Init(SPI2, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
+        printf("Error configuring SPI\n");
+        while (1)
+            ;
+    }
     req.tx_data = data;
     req.len = size;
     SPI_MasterTrans(SPI, &req);
-- 
GitLab