Browse Source

🐛 Fix missing u8g_esp32_spi (#23562)

ellensp 2 years ago
parent
commit
a8f3810f39
No account linked to committer's email address
2 changed files with 104 additions and 0 deletions
  1. 99
    0
      Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp
  2. 5
    0
      Marlin/src/lcd/dogm/HAL_LCD_com_defines.h

+ 99
- 0
Marlin/src/HAL/ESP32/u8g_esp32_spi.cpp View File

@@ -0,0 +1,99 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * Copypaste of SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
9
+ *
10
+ * This program is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * This program is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
22
+ *
23
+ */
24
+#ifdef ARDUINO_ARCH_ESP32
25
+
26
+#include "../../inc/MarlinConfigPre.h"
27
+
28
+#if ENABLED(FYSETC_MINI_12864_2_1)
29
+
30
+#include <U8glib-HAL.h>
31
+#include "Arduino.h"
32
+#include "../shared/HAL_SPI.h"
33
+#include "SPI.h"
34
+
35
+static SPISettings spiConfig;
36
+
37
+#define MDOGLCD_MOSI    23
38
+#define MDOGLCD_SCK     18
39
+#define MLCD_RESET_PIN   0
40
+#define MLCD_PINS_DC     4
41
+#define MDOGLCD_CS      21
42
+#define MDOGLCD_A0       4
43
+
44
+#ifndef LCD_SPI_SPEED
45
+  #ifdef SD_SPI_SPEED
46
+    #define LCD_SPI_SPEED SD_SPI_SPEED    // Assume SPI speed shared with SD
47
+  #else
48
+    #define LCD_SPI_SPEED SPI_FULL_SPEED  // Use full speed if SD speed is not supplied
49
+  #endif
50
+#endif
51
+
52
+uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
53
+  static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
54
+  if (msgInitCount) {
55
+    if (msg == U8G_COM_MSG_INIT) msgInitCount--;
56
+    if (msgInitCount) return -1;
57
+  }
58
+
59
+  switch (msg) {
60
+    case U8G_COM_MSG_STOP: break;
61
+
62
+    case U8G_COM_MSG_INIT:
63
+      OUT_WRITE(MDOGLCD_CS, HIGH);
64
+      OUT_WRITE(MDOGLCD_A0, HIGH);
65
+      OUT_WRITE(MLCD_RESET_PIN, HIGH);
66
+      u8g_Delay(5);
67
+      spiBegin();
68
+      spiInit(LCD_SPI_SPEED);
69
+      break;
70
+
71
+    case U8G_COM_MSG_ADDRESS:           /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
72
+      WRITE(MDOGLCD_A0, arg_val ? HIGH : LOW);
73
+      break;
74
+
75
+    case U8G_COM_MSG_CHIP_SELECT:       /* arg_val == 0 means HIGH level of U8G_PI_CS */
76
+      WRITE(MDOGLCD_CS, arg_val ? LOW : HIGH);
77
+      break;
78
+
79
+    case U8G_COM_MSG_RESET:
80
+      WRITE(MLCD_RESET_PIN, arg_val);
81
+      break;
82
+
83
+    case U8G_COM_MSG_WRITE_BYTE:
84
+      spiSend((uint8_t)arg_val);
85
+      break;
86
+
87
+    case U8G_COM_MSG_WRITE_SEQ:
88
+      uint8_t *ptr = (uint8_t*) arg_ptr;
89
+      while (arg_val > 0) {
90
+        spiSend(*ptr++);
91
+        arg_val--;
92
+      }
93
+      break;
94
+  }
95
+  return 1;
96
+}
97
+
98
+#endif // FYSETC_MINI_12864_2_1
99
+#endif // ARDUINO_ARCH_ESP32

+ 5
- 0
Marlin/src/lcd/dogm/HAL_LCD_com_defines.h View File

@@ -57,6 +57,11 @@
57 57
     #define U8G_COM_HAL_SW_SPI_FN     u8g_com_std_sw_spi_fn
58 58
     #define U8G_COM_HAL_HW_SPI_FN     u8g_com_stm32duino_hw_spi_fn
59 59
 
60
+  #elif defined(ESP32)
61
+
62
+    uint8_t u8g_eps_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
63
+    #define U8G_COM_HAL_HW_SPI_FN     u8g_eps_hw_spi_fn
64
+
60 65
   #elif defined(__AVR__)
61 66
 
62 67
     uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);

Loading…
Cancel
Save