]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Yet another try to fix the LCD corruption
authorFred Sundvik <fsundvik@gmail.com>
Fri, 7 Apr 2017 07:51:53 +0000 (10:51 +0300)
committerFred Sundvik <fsundvik@gmail.com>
Sun, 9 Apr 2017 15:34:59 +0000 (18:34 +0300)
It turns out that the ChibiOS K20 SPI driver doesn't handle the
chip select, so it needs to be done manually. Acquiring the bus is
not enough since the pin was in the wrong mode. This is now fixed.

Also increase the frequency of the SPI from around 200kHz to nearly
20 Mhz.

keyboards/ergodox/infinity/drivers/gdisp/st7565ergodox/board_ST7565.h

index c2092b5e8d3bf4595592662a6555d001980fc74a..e8c17e6e336c0a89cff12624170d25cf4213209e 100644 (file)
@@ -45,15 +45,28 @@ static const SPIConfig spi1config = {
   .sspad=ST7565_SS_PIN,
    // SPI initialization data.
   .tar0 =
-    SPIx_CTARn_FMSZ(7)
-    | SPIx_CTARn_ASC(7)
-    | SPIx_CTARn_DT(7)
-    | SPIx_CTARn_CSSCK(7)
-    | SPIx_CTARn_PBR(0)
-    | SPIx_CTARn_BR(7)
-       //SPI_CR1_BR_0
+    SPIx_CTARn_FMSZ(7) // Frame size = 8 bytes
+    | SPIx_CTARn_ASC(1) // After SCK Delay Scaler (min 50 ns) = 55.56ns
+    | SPIx_CTARn_DT(0) // Delay After Transfer Scaler (no minimum)= 27.78ns
+    | SPIx_CTARn_CSSCK(0) // PCS to SCK Delay Scaler (min 20 ns) = 27.78ns
+    | SPIx_CTARn_PBR(0) // Baud Rate Prescaler = 2
+    | SPIx_CTARn_BR(0) // Baud rate (min 50ns) = 55.56ns
 };
 
+static GFXINLINE void acquire_bus(GDisplay *g) {
+    (void) g;
+    // Only the LCD is using the SPI bus, so no need to acquire
+    // spiAcquireBus(&SPID1);
+    spiSelect(&SPID1);
+}
+
+static GFXINLINE void release_bus(GDisplay *g) {
+    (void) g;
+    // Only the LCD is using the SPI bus, so no need to release
+    //spiReleaseBus(&SPID1);
+    spiUnselect(&SPID1);
+}
+
 static GFXINLINE void init_board(GDisplay *g) {
     (void) g;
     palSetPadModeNamed(A0, PAL_MODE_OUTPUT_PUSHPULL);
@@ -62,10 +75,11 @@ static GFXINLINE void init_board(GDisplay *g) {
     palSetPad(ST7565_GPIOPORT, ST7565_RST_PIN);
     palSetPadModeRaw(MOSI, ST7565_SPI_MODE);
     palSetPadModeRaw(SLCK, ST7565_SPI_MODE);
-    palSetPadModeRaw(SS, ST7565_SPI_MODE);
+    palSetPadModeRaw(SS, PAL_MODE_OUTPUT_PUSHPULL);
 
     spiInit();
     spiStart(&SPID1, &spi1config);
+    release_bus(g);
 }
 
 static GFXINLINE void post_init_board(GDisplay *g) {
@@ -82,20 +96,6 @@ static GFXINLINE void setpin_reset(GDisplay *g, bool_t state) {
     }
 }
 
-static GFXINLINE void acquire_bus(GDisplay *g) {
-    (void) g;
-    // Only the LCD is using the SPI bus, so no need to acquire
-    // spiAcquireBus(&SPID1);
-    spiSelect(&SPID1);
-}
-
-static GFXINLINE void release_bus(GDisplay *g) {
-    (void) g;
-    // Only the LCD is using the SPI bus, so no need to release
-    //spiReleaseBus(&SPID1);
-    spiUnselect(&SPID1);
-}
-
 static GFXINLINE void enter_data_mode(GDisplay *g) {
     palSetPad(ST7565_GPIOPORT, ST7565_A0_PIN);
 }