|
@@ -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
|