From 7b24888d9ba2df85d2e7be480306e58ba3fb1eab Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 5 Feb 2022 10:46:13 -0600 Subject: [PATCH] Use FastIO for constant pins --- Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp | 40 +++++++++++--------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp b/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp index a0eb11856c4d..e454130d43f3 100644 --- a/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp +++ b/Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp @@ -33,14 +33,13 @@ #include "SPI.h" static SPISettings spiConfig; -static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT -#define MDOGLCD_MOSI 23 -#define MDOGLCD_SCK 18 -#define MLCD_RESET_PIN 0 -#define MLCD_PINS_DC 4 -#define MDOGLCD_CS 21 -#define MDOGLCD_A0 4 +#define MDOGLCD_MOSI 23 +#define MDOGLCD_SCK 18 +#define MLCD_RESET_PIN 0 +#define MLCD_PINS_DC 4 +#define MDOGLCD_CS 21 +#define MDOGLCD_A0 4 #ifndef LCD_SPI_SPEED #ifdef SD_SPI_SPEED @@ -50,40 +49,35 @@ static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_IN #endif #endif -uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr){ +uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { + static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT if (msgInitCount) { - if (msg == U8G_COM_MSG_INIT) msgInitCount --; + if (msg == U8G_COM_MSG_INIT) msgInitCount--; if (msgInitCount) return -1; } - switch(msg){ - case U8G_COM_MSG_STOP: - break; + switch (msg) { + case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_INIT: - pinMode(MDOGLCD_CS, OUTPUT); - pinMode(MDOGLCD_A0, OUTPUT); - pinMode(MLCD_RESET_PIN, OUTPUT); - - digitalWrite(MDOGLCD_CS, HIGH); - digitalWrite(MDOGLCD_A0, HIGH); - digitalWrite(MLCD_RESET_PIN, HIGH); + OUT_WRITE(MDOGLCD_CS, HIGH); + OUT_WRITE(MDOGLCD_A0, HIGH); + OUT_WRITE(MLCD_RESET_PIN, HIGH); u8g_Delay(5); spiBegin(); spiInit(LCD_SPI_SPEED); break; case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ - if(arg_val) digitalWrite(MDOGLCD_A0, HIGH); - else digitalWrite(MDOGLCD_A0, LOW); + WRITE(MDOGLCD_A0, arg_val ? HIGH : LOW); break; case U8G_COM_MSG_CHIP_SELECT: /* arg_val == 0 means HIGH level of U8G_PI_CS */ - digitalWrite(MDOGLCD_CS, arg_val ? LOW : HIGH); + WRITE(MDOGLCD_CS, arg_val ? LOW : HIGH); break; case U8G_COM_MSG_RESET: - digitalWrite(MLCD_RESET_PIN, arg_val); + WRITE(MLCD_RESET_PIN, arg_val); break; case U8G_COM_MSG_WRITE_BYTE: