Skip to content

Commit

Permalink
Use FastIO for constant pins
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 5, 2022
1 parent 18b9dc4 commit 7b24888
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 7b24888

Please sign in to comment.