Browse Source

✨ Simulator HAL and build targets (#22418)

Chris Pepper 3 years ago
parent
commit
21011eefa8
No account linked to committer's email address
37 changed files with 1847 additions and 16 deletions
  1. 5
    1
      .gitignore
  2. 217
    0
      Marlin/src/HAL/NATIVE_SIM/HAL.h
  3. 26
    0
      Marlin/src/HAL/NATIVE_SIM/MarlinSPI.h
  4. 111
    0
      Marlin/src/HAL/NATIVE_SIM/fastio.h
  5. 22
    0
      Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_LCD.h
  6. 31
    0
      Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_adv.h
  7. 22
    0
      Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_post.h
  8. 43
    0
      Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h
  9. 59
    0
      Marlin/src/HAL/NATIVE_SIM/pinsDebug.h
  10. 80
    0
      Marlin/src/HAL/NATIVE_SIM/servo_private.h
  11. 55
    0
      Marlin/src/HAL/NATIVE_SIM/spi_pins.h
  12. 64
    0
      Marlin/src/HAL/NATIVE_SIM/tft/tft_spi.h
  13. 80
    0
      Marlin/src/HAL/NATIVE_SIM/tft/xpt2046.h
  14. 91
    0
      Marlin/src/HAL/NATIVE_SIM/timers.h
  15. 52
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/LCD_I2C_routines.cpp
  16. 37
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/LCD_I2C_routines.h
  17. 44
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/LCD_defines.h
  18. 43
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/LCD_delay.h
  19. 52
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/LCD_pin_routines.cpp
  20. 46
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/LCD_pin_routines.h
  21. 171
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_st7920_sw_spi.cpp
  22. 215
    0
      Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_sw_spi.cpp
  23. 27
    0
      Marlin/src/HAL/NATIVE_SIM/watchdog.h
  24. 2
    0
      Marlin/src/HAL/platforms.h
  25. 1
    1
      Marlin/src/HAL/shared/Delay.h
  26. 3
    0
      Marlin/src/core/serial.h
  27. 5
    0
      Marlin/src/lcd/dogm/HAL_LCD_com_defines.h
  28. 2
    2
      Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp
  29. 4
    4
      Marlin/src/lcd/extui/mks_ui/draw_ui.cpp
  30. 7
    1
      Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
  31. 59
    3
      Marlin/src/pins/linux/pins_RAMPS_LINUX.h
  32. 1
    1
      Marlin/src/pins/pins.h
  33. 1
    1
      Marlin/src/sd/SdFatUtil.cpp
  34. 1
    1
      Marlin/src/sd/cardreader.cpp
  35. 9
    1
      buildroot/share/PlatformIO/scripts/common-dependencies.py
  36. 52
    0
      buildroot/share/PlatformIO/scripts/simulator.py
  37. 107
    0
      ini/native.ini

+ 5
- 1
.gitignore View File

@@ -143,7 +143,11 @@ vc-fileutils.settings
143 143
 .vscode/launch.json
144 144
 .vscode/*.db
145 145
 
146
-# cmake
146
+#Simulation
147
+imgui.ini
148
+eeprom.dat
149
+
150
+#cmake
147 151
 CMakeLists.txt
148 152
 src/CMakeLists.txt
149 153
 CMakeListsPrivate.txt

+ 217
- 0
Marlin/src/HAL/NATIVE_SIM/HAL.h View File

@@ -0,0 +1,217 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#define CPU_32_BIT
25
+#define HAL_IDLETASK
26
+void HAL_idletask();
27
+
28
+#define F_CPU 100000000
29
+#define SystemCoreClock F_CPU
30
+#include <stdint.h>
31
+#include <stdarg.h>
32
+
33
+#undef min
34
+#undef max
35
+
36
+#include <algorithm>
37
+#include "pinmapping.h"
38
+
39
+void _printf (const  char *format, ...);
40
+void _putc(uint8_t c);
41
+uint8_t _getc();
42
+
43
+//extern "C" volatile uint32_t _millis;
44
+
45
+//arduino: Print.h
46
+#define DEC 10
47
+#define HEX 16
48
+#define OCT  8
49
+#define BIN  2
50
+//arduino: binary.h (weird defines)
51
+#define B01 1
52
+#define B10 2
53
+
54
+#include "../shared/Marduino.h"
55
+#include "../shared/math_32bit.h"
56
+#include "../shared/HAL_SPI.h"
57
+#include "fastio.h"
58
+#include "watchdog.h"
59
+#include "serial.h"
60
+
61
+#define SHARED_SERVOS HAS_SERVOS
62
+
63
+extern MSerialT serial_stream_0;
64
+extern MSerialT serial_stream_1;
65
+extern MSerialT serial_stream_2;
66
+extern MSerialT serial_stream_3;
67
+
68
+#define _MSERIAL(X) serial_stream_##X
69
+#define MSERIAL(X) _MSERIAL(X)
70
+
71
+#if WITHIN(SERIAL_PORT, 0, 3)
72
+  #define MYSERIAL1 MSERIAL(SERIAL_PORT)
73
+#else
74
+  #error "SERIAL_PORT must be from 0 to 3. Please update your configuration."
75
+#endif
76
+
77
+#ifdef SERIAL_PORT_2
78
+  #if WITHIN(SERIAL_PORT_2, 0, 3)
79
+    #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
80
+  #else
81
+    #error "SERIAL_PORT_2 must be from 0 to 3. Please update your configuration."
82
+  #endif
83
+#endif
84
+
85
+#ifdef MMU2_SERIAL_PORT
86
+  #if WITHIN(MMU2_SERIAL_PORT, 0, 3)
87
+    #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
88
+  #else
89
+    #error "MMU2_SERIAL_PORT must be from 0 to 3. Please update your configuration."
90
+  #endif
91
+#endif
92
+
93
+#ifdef LCD_SERIAL_PORT
94
+  #if WITHIN(LCD_SERIAL_PORT, 0, 3)
95
+    #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
96
+  #else
97
+    #error "LCD_SERIAL_PORT must be from 0 to 3. Please update your configuration."
98
+  #endif
99
+#endif
100
+
101
+
102
+#define ST7920_DELAY_1 DELAY_NS(600)
103
+#define ST7920_DELAY_2 DELAY_NS(750)
104
+#define ST7920_DELAY_3 DELAY_NS(750)
105
+
106
+//
107
+// Interrupts
108
+//
109
+#define CRITICAL_SECTION_START()
110
+#define CRITICAL_SECTION_END()
111
+#define ISRS_ENABLED()
112
+#define ENABLE_ISRS()
113
+#define DISABLE_ISRS()
114
+
115
+inline void HAL_init() {}
116
+
117
+// Utility functions
118
+#pragma GCC diagnostic push
119
+#pragma GCC diagnostic ignored "-Wunused-function"
120
+int freeMemory();
121
+#pragma GCC diagnostic pop
122
+
123
+// ADC
124
+#define HAL_ADC_VREF           5.0
125
+#define HAL_ADC_RESOLUTION    10
126
+#define HAL_ANALOG_SELECT(ch) HAL_adc_enable_channel(ch)
127
+#define HAL_START_ADC(ch)     HAL_adc_start_conversion(ch)
128
+#define HAL_READ_ADC()        HAL_adc_get_result()
129
+#define HAL_ADC_READY()       true
130
+
131
+void HAL_adc_init();
132
+void HAL_adc_enable_channel(const uint8_t ch);
133
+void HAL_adc_start_conversion(const uint8_t ch);
134
+uint16_t HAL_adc_get_result();
135
+
136
+// Reset source
137
+inline void HAL_clear_reset_source(void) {}
138
+inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
139
+
140
+/* ---------------- Delay in cycles */
141
+
142
+#define DELAY_CYCLES(x) Kernel::delayCycles(x)
143
+#define SYSTEM_YIELD() Kernel::yield()
144
+
145
+// Maple Compatibility
146
+typedef void (*systickCallback_t)(void);
147
+void systick_attach_callback(systickCallback_t cb);
148
+extern volatile uint32_t systick_uptime_millis;
149
+
150
+// Marlin uses strstr in constexpr context, this is not supported, workaround by defining constexpr versions of the required functions.
151
+#define strstr(a, b) strstr_constexpr((a), (b))
152
+
153
+constexpr inline std::size_t strlen_constexpr(const char* str) {
154
+  // https://github.com/gcc-mirror/gcc/blob/5c7634a0e5f202935aa6c11b6ea953b8bf80a00a/libstdc%2B%2B-v3/include/bits/char_traits.h#L329
155
+  if (str != nullptr) {
156
+    std::size_t i = 0;
157
+    while (str[i] != '\0') {
158
+      ++i;
159
+    }
160
+
161
+    return i;
162
+  }
163
+
164
+  return 0;
165
+}
166
+
167
+constexpr inline int strncmp_constexpr(const char* lhs, const char* rhs, std::size_t count) {
168
+  // https://github.com/gcc-mirror/gcc/blob/13b9cbfc32fe3ac4c81c4dd9c42d141c8fb95db4/libstdc%2B%2B-v3/include/bits/char_traits.h#L655
169
+  if (lhs == nullptr || rhs == nullptr) {
170
+    return rhs != nullptr ? -1 : 1;
171
+  }
172
+
173
+  for (std::size_t i = 0; i < count; ++i) {
174
+    if (lhs[i] != rhs[i]) {
175
+      return lhs[i] < rhs[i] ? -1 : 1;
176
+    } else if (lhs[i] == '\0') {
177
+      return 0;
178
+    }
179
+  }
180
+
181
+  return 0;
182
+}
183
+
184
+constexpr inline const char* strstr_constexpr(const char* str, const char* target) {
185
+  // https://github.com/freebsd/freebsd/blob/master/sys/libkern/strstr.c
186
+  if (char c = target != nullptr ? *target++ : '\0'; c != '\0' && str != nullptr) {
187
+    std::size_t len = strlen_constexpr(target);
188
+    do {
189
+      char sc = {};
190
+      do {
191
+        if ((sc = *str++) == '\0') {
192
+          return nullptr;
193
+        }
194
+      } while (sc != c);
195
+    } while (strncmp_constexpr(str, target, len) != 0);
196
+    --str;
197
+  }
198
+
199
+  return str;
200
+}
201
+
202
+constexpr inline char* strstr_constexpr(char* str, const char* target) {
203
+  // https://github.com/freebsd/freebsd/blob/master/sys/libkern/strstr.c
204
+  if (char c = target != nullptr ? *target++ : '\0'; c != '\0' && str != nullptr) {
205
+    std::size_t len = strlen_constexpr(target);
206
+    do {
207
+      char sc = {};
208
+      do {
209
+        if ((sc = *str++) == '\0') {
210
+          return nullptr;
211
+        }
212
+      } while (sc != c);
213
+    } while (strncmp_constexpr(str, target, len) != 0);
214
+    --str;
215
+  }
216
+  return str;
217
+}

+ 26
- 0
Marlin/src/HAL/NATIVE_SIM/MarlinSPI.h View File

@@ -0,0 +1,26 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <SPI.h>
25
+
26
+using MarlinSPI = SPIClass;

+ 111
- 0
Marlin/src/HAL/NATIVE_SIM/fastio.h View File

@@ -0,0 +1,111 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Fast I/O Routines for X86_64
26
+ */
27
+
28
+#include "../shared/Marduino.h"
29
+#include <pinmapping.h>
30
+
31
+#define SET_DIR_INPUT(IO)     Gpio::setDir(IO, 1)
32
+#define SET_DIR_OUTPUT(IO)    Gpio::setDir(IO, 0)
33
+
34
+#define SET_MODE(IO, mode)    Gpio::setMode(IO, mode)
35
+
36
+#define WRITE_PIN_SET(IO)     Gpio::set(IO)
37
+#define WRITE_PIN_CLR(IO)     Gpio::clear(IO)
38
+
39
+#define READ_PIN(IO)          Gpio::get(IO)
40
+#define WRITE_PIN(IO,V)       Gpio::set(IO, V)
41
+
42
+/**
43
+ * Magic I/O routines
44
+ *
45
+ * Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
46
+ *
47
+ * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
48
+ */
49
+
50
+/// Read a pin
51
+#define _READ(IO)             READ_PIN(IO)
52
+
53
+/// Write to a pin
54
+#define _WRITE(IO,V)          WRITE_PIN(IO,V)
55
+
56
+/// toggle a pin
57
+#define _TOGGLE(IO)          _WRITE(IO, !READ(IO))
58
+
59
+/// set pin as input
60
+#define _SET_INPUT(IO)        SET_DIR_INPUT(IO)
61
+
62
+/// set pin as output
63
+#define _SET_OUTPUT(IO)       SET_DIR_OUTPUT(IO)
64
+
65
+/// set pin as input with pullup mode
66
+#define _PULLUP(IO,V)         pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
67
+
68
+/// set pin as input with pulldown mode
69
+#define _PULLDOWN(IO,V)       pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
70
+
71
+// hg42: all pins can be input or output (I hope)
72
+// hg42: undefined pins create compile error (IO, is no pin)
73
+// hg42: currently not used, but was used by pinsDebug
74
+
75
+/// check if pin is an input
76
+#define _IS_INPUT(IO)         (IO >= 0)
77
+
78
+/// check if pin is an output
79
+#define _IS_OUTPUT(IO)        (IO >= 0)
80
+
81
+/// Read a pin wrapper
82
+#define READ(IO)             _READ(IO)
83
+
84
+/// Write to a pin wrapper
85
+#define WRITE(IO,V)          _WRITE(IO,V)
86
+
87
+/// toggle a pin wrapper
88
+#define TOGGLE(IO)           _TOGGLE(IO)
89
+
90
+/// set pin as input wrapper
91
+#define SET_INPUT(IO)        _SET_INPUT(IO)
92
+/// set pin as input with pullup wrapper
93
+#define SET_INPUT_PULLUP(IO)  do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
94
+/// set pin as input with pulldown wrapper
95
+#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
96
+/// set pin as output wrapper  -  reads the pin and sets the output to that value
97
+#define SET_OUTPUT(IO)        do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
98
+// set pin as PWM
99
+#define SET_PWM(IO)           SET_OUTPUT(IO)
100
+
101
+/// check if pin is an input wrapper
102
+#define IS_INPUT(IO)         _IS_INPUT(IO)
103
+/// check if pin is an output wrapper
104
+#define IS_OUTPUT(IO)        _IS_OUTPUT(IO)
105
+
106
+// Shorthand
107
+#define OUT_WRITE(IO,V)       do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
108
+
109
+// digitalRead/Write wrappers
110
+#define extDigitalRead(IO)    digitalRead(IO)
111
+#define extDigitalWrite(IO,V) digitalWrite(IO,V)

+ 22
- 0
Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_LCD.h View File

@@ -0,0 +1,22 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once

+ 31
- 0
Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_adv.h View File

@@ -0,0 +1,31 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+// Add strcmp_P if missing
25
+#ifndef strcmp_P
26
+  #define strcmp_P(a, b) strcmp((a), (b))
27
+#endif
28
+
29
+#ifndef strcat_P
30
+  #define strcat_P(dest, src) strcat((dest), (src))
31
+#endif

+ 22
- 0
Marlin/src/HAL/NATIVE_SIM/inc/Conditionals_post.h View File

@@ -0,0 +1,22 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once

+ 43
- 0
Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h View File

@@ -0,0 +1,43 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Test X86_64-specific configuration values for errors at compile-time.
26
+ */
27
+
28
+// Emulating RAMPS
29
+#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
30
+  #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
31
+#endif
32
+
33
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
34
+  #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on LINUX."
35
+#endif
36
+
37
+#if HAS_TMC_SW_SERIAL
38
+  #error "TMC220x Software Serial is not supported on LINUX."
39
+#endif
40
+
41
+#if ENABLED(POSTMORTEM_DEBUGGING)
42
+  #error "POSTMORTEM_DEBUGGING is not yet supported on LINUX."
43
+#endif

+ 59
- 0
Marlin/src/HAL/NATIVE_SIM/pinsDebug.h View File

@@ -0,0 +1,59 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+/**
21
+ * Support routines for X86_64
22
+ */
23
+
24
+/**
25
+ * Translation of routines & variables used by pinsDebug.h
26
+ */
27
+
28
+#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
29
+#define pwm_details(pin) pin = pin    // do nothing  // print PWM details
30
+#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
31
+#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
32
+#define digitalRead_mod(p)  digitalRead(p)
33
+#define PRINT_PORT(p)
34
+#define GET_ARRAY_PIN(p) pin_array[p].pin
35
+#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
36
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
37
+#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
38
+
39
+// active ADC function/mode/code values for PINSEL registers
40
+constexpr int8_t ADC_pin_mode(pin_t pin) {
41
+  return (-1);
42
+}
43
+
44
+int8_t get_pin_mode(pin_t pin) {
45
+  if (!VALID_PIN(pin)) return -1;
46
+  return 0;
47
+}
48
+
49
+bool GET_PINMODE(pin_t pin) {
50
+  int8_t pin_mode = get_pin_mode(pin);
51
+  if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
52
+    return false;
53
+
54
+  return (Gpio::getMode(pin) != 0); //input/output state
55
+}
56
+
57
+bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
58
+  return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
59
+}

+ 80
- 0
Marlin/src/HAL/NATIVE_SIM/servo_private.h View File

@@ -0,0 +1,80 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
26
+ * Copyright (c) 2009 Michael Margolis.  All right reserved.
27
+ *
28
+ * This library is free software; you can redistribute it and/or
29
+ * modify it under the terms of the GNU Lesser General Public
30
+ * License as published by the Free Software Foundation; either
31
+ * version 2.1 of the License, or (at your option) any later version.
32
+ *
33
+ * This library is distributed in the hope that it will be useful,
34
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36
+ * Lesser General Public License for more details.
37
+ *
38
+ * You should have received a copy of the GNU Lesser General Public
39
+ * License along with this library; if not, write to the Free Software
40
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
41
+ */
42
+
43
+/**
44
+ * Based on "servo.h - Interrupt driven Servo library for Arduino using 16 bit timers -
45
+ *           Version 2 Copyright (c) 2009 Michael Margolis.  All right reserved.
46
+ *
47
+ * The only modification was to update/delete macros to match the LPC176x.
48
+ *
49
+ */
50
+
51
+#include <stdint.h>
52
+
53
+// Macros
54
+//values in microseconds
55
+#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo
56
+#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo
57
+#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached
58
+#define REFRESH_INTERVAL    20000     // minimum time to refresh servos in microseconds
59
+
60
+#define MAX_SERVOS             4
61
+
62
+#define INVALID_SERVO         255     // flag indicating an invalid servo index
63
+
64
+
65
+// Types
66
+
67
+typedef struct {
68
+  uint8_t nbr        : 8 ;            // a pin number from 0 to 254 (255 signals invalid pin)
69
+  uint8_t isActive   : 1 ;            // true if this channel is enabled, pin not pulsed if false
70
+} ServoPin_t;
71
+
72
+typedef struct {
73
+  ServoPin_t Pin;
74
+  unsigned int pulse_width;           // pulse width in microseconds
75
+} ServoInfo_t;
76
+
77
+// Global variables
78
+
79
+extern uint8_t ServoCount;
80
+extern ServoInfo_t servo_info[MAX_SERVOS];

+ 55
- 0
Marlin/src/HAL/NATIVE_SIM/spi_pins.h View File

@@ -0,0 +1,55 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../core/macros.h"
25
+#include "../../inc/MarlinConfigPre.h"
26
+
27
+#if BOTH(HAS_MARLINUI_U8GLIB, SDSUPPORT) && (LCD_PINS_D4 == SD_SCK_PIN || LCD_PINS_ENABLE == SD_MOSI_PIN || DOGLCD_SCK == SD_SCK_PIN || DOGLCD_MOSI == SD_MOSI_PIN)
28
+  #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
29
+                            // needed due to the speed and mode required for communicating with each device being different.
30
+                            // This requirement can be removed if the SPI access to these devices is updated to use
31
+                            // spiBeginTransaction.
32
+#endif
33
+
34
+// Onboard SD
35
+//#define SD_SCK_PIN     P0_07
36
+//#define SD_MISO_PIN    P0_08
37
+//#define SD_MOSI_PIN    P0_09
38
+//#define SD_SS_PIN      P0_06
39
+
40
+// External SD
41
+#ifndef SD_SCK_PIN
42
+  #define SD_SCK_PIN        50
43
+#endif
44
+#ifndef SD_MISO_PIN
45
+  #define SD_MISO_PIN       51
46
+#endif
47
+#ifndef SD_MOSI_PIN
48
+  #define SD_MOSI_PIN       52
49
+#endif
50
+#ifndef SD_SS_PIN
51
+  #define SD_SS_PIN         53
52
+#endif
53
+#ifndef SDSS
54
+  #define SDSS       SD_SS_PIN
55
+#endif

+ 64
- 0
Marlin/src/HAL/NATIVE_SIM/tft/tft_spi.h View File

@@ -0,0 +1,64 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../../inc/MarlinConfig.h"
25
+
26
+#ifndef LCD_READ_ID
27
+  #define LCD_READ_ID  0x04   // Read display identification information (0xD3 on ILI9341)
28
+#endif
29
+#ifndef LCD_READ_ID4
30
+  #define LCD_READ_ID4 0xD3   // Read display identification information (0xD3 on ILI9341)
31
+#endif
32
+
33
+#define DATASIZE_8BIT    8
34
+#define DATASIZE_16BIT   16
35
+#define TFT_IO_DRIVER TFT_SPI
36
+
37
+#define DMA_MINC_ENABLE 1
38
+#define DMA_MINC_DISABLE 0
39
+
40
+class TFT_SPI {
41
+private:
42
+  static uint32_t ReadID(uint16_t Reg);
43
+  static void Transmit(uint16_t Data);
44
+  static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
45
+
46
+public:
47
+  // static SPIClass SPIx;
48
+
49
+  static void Init();
50
+  static uint32_t GetID();
51
+  static bool isBusy();
52
+  static void Abort();
53
+
54
+  static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT);
55
+  static void DataTransferEnd();
56
+  static void DataTransferAbort();
57
+
58
+  static void WriteData(uint16_t Data);
59
+  static void WriteReg(uint16_t Reg);
60
+
61
+  static void WriteSequence(uint16_t *Data, uint16_t Count);
62
+  // static void WriteMultiple(uint16_t Color, uint16_t Count);
63
+  static void WriteMultiple(uint16_t Color, uint32_t Count);
64
+};

+ 80
- 0
Marlin/src/HAL/NATIVE_SIM/tft/xpt2046.h View File

@@ -0,0 +1,80 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+#pragma once
20
+
21
+#include "../../../inc/MarlinConfig.h"
22
+
23
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
24
+  #include <SPI.h>
25
+#endif
26
+
27
+#ifndef TOUCH_MISO_PIN
28
+  #define TOUCH_MISO_PIN SD_MISO_PIN
29
+#endif
30
+#ifndef TOUCH_MOSI_PIN
31
+  #define TOUCH_MOSI_PIN SD_MOSI_PIN
32
+#endif
33
+#ifndef TOUCH_SCK_PIN
34
+  #define TOUCH_SCK_PIN  SD_SCK_PIN
35
+#endif
36
+#ifndef TOUCH_CS_PIN
37
+  #define TOUCH_CS_PIN   SD_SS_PIN
38
+#endif
39
+#ifndef TOUCH_INT_PIN
40
+  #define TOUCH_INT_PIN  -1
41
+#endif
42
+
43
+#define XPT2046_DFR_MODE        0x00
44
+#define XPT2046_SER_MODE        0x04
45
+#define XPT2046_CONTROL         0x80
46
+
47
+enum XPTCoordinate : uint8_t {
48
+  XPT2046_X  = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
49
+  XPT2046_Y  = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
50
+  XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
51
+  XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
52
+};
53
+
54
+#if !defined(XPT2046_Z1_THRESHOLD)
55
+  #define XPT2046_Z1_THRESHOLD 10
56
+#endif
57
+
58
+class XPT2046 {
59
+private:
60
+  static bool isBusy() { return false; }
61
+
62
+  static uint16_t getRawData(const XPTCoordinate coordinate);
63
+  static bool isTouched();
64
+
65
+  static inline void DataTransferBegin();
66
+  static inline void DataTransferEnd();
67
+  #if ENABLED(TOUCH_BUTTONS_HW_SPI)
68
+    static uint16_t HardwareIO(uint16_t data);
69
+  #endif
70
+  static uint16_t SoftwareIO(uint16_t data);
71
+  static uint16_t IO(uint16_t data = 0);
72
+
73
+public:
74
+  #if ENABLED(TOUCH_BUTTONS_HW_SPI)
75
+    static SPIClass SPIx;
76
+  #endif
77
+
78
+  static void Init();
79
+  static bool getRawPoint(int16_t *x, int16_t *y);
80
+};

+ 91
- 0
Marlin/src/HAL/NATIVE_SIM/timers.h View File

@@ -0,0 +1,91 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
+ *
20
+ */
21
+#pragma once
22
+
23
+/**
24
+ * HAL timers for Linux X86_64
25
+ */
26
+
27
+#include <stdint.h>
28
+
29
+// ------------------------
30
+// Defines
31
+// ------------------------
32
+
33
+#define FORCE_INLINE __attribute__((always_inline)) inline
34
+
35
+typedef uint64_t hal_timer_t;
36
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFF
37
+
38
+#define HAL_TIMER_RATE         ((SystemCoreClock) / 4)  // frequency of timers peripherals
39
+
40
+#ifndef STEP_TIMER_NUM
41
+  #define STEP_TIMER_NUM        0  // Timer Index for Stepper
42
+#endif
43
+#ifndef PULSE_TIMER_NUM
44
+  #define PULSE_TIMER_NUM       STEP_TIMER_NUM
45
+#endif
46
+#ifndef TEMP_TIMER_NUM
47
+  #define TEMP_TIMER_NUM        1  // Timer Index for Temperature
48
+#endif
49
+#ifndef SYSTICK_TIMER_NUM
50
+  #define SYSTICK_TIMER_NUM     2 // Timer Index for Systick
51
+#endif
52
+#define SYSTICK_TIMER_FREQUENCY 1000
53
+
54
+#define TEMP_TIMER_RATE        1000000
55
+#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
56
+
57
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
58
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
59
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
60
+
61
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
62
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
63
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
64
+
65
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
66
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
67
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
68
+
69
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
70
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
71
+
72
+#ifndef HAL_STEP_TIMER_ISR
73
+  #define HAL_STEP_TIMER_ISR()  extern "C" void TIMER0_IRQHandler()
74
+#endif
75
+#ifndef HAL_TEMP_TIMER_ISR
76
+  #define HAL_TEMP_TIMER_ISR()  extern "C" void TIMER1_IRQHandler()
77
+#endif
78
+
79
+void HAL_timer_init();
80
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
81
+
82
+void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare);
83
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
84
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
85
+
86
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
87
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
88
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
89
+
90
+#define HAL_timer_isr_prologue(TIMER_NUM)
91
+#define HAL_timer_isr_epilogue(TIMER_NUM)

+ 52
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/LCD_I2C_routines.cpp View File

@@ -0,0 +1,52 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+// adapted from  I2C/master/master.c example
24
+//   https://www-users.cs.york.ac.uk/~pcc/MCP/HAPR-Course-web/CMSIS/examples/html/master_8c_source.html
25
+
26
+#ifdef __PLAT_NATIVE_SIM__
27
+
28
+#include <cstdint>
29
+
30
+#ifdef __cplusplus
31
+  extern "C" {
32
+#endif
33
+
34
+uint8_t u8g_i2c_start(const uint8_t sla) {
35
+  return 1;
36
+}
37
+
38
+void u8g_i2c_init(const uint8_t clock_option) {
39
+}
40
+
41
+uint8_t u8g_i2c_send_byte(uint8_t data) {
42
+  return 1;
43
+}
44
+
45
+void u8g_i2c_stop() {
46
+}
47
+
48
+#ifdef __cplusplus
49
+  }
50
+#endif
51
+
52
+#endif // __PLAT_NATIVE_SIM__

+ 37
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/LCD_I2C_routines.h View File

@@ -0,0 +1,37 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#ifdef __cplusplus
25
+  extern "C" {
26
+#endif
27
+
28
+void u8g_i2c_init(const uint8_t clock_options);
29
+//uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos);
30
+uint8_t u8g_i2c_start(uint8_t sla);
31
+uint8_t u8g_i2c_send_byte(uint8_t data);
32
+void u8g_i2c_stop();
33
+
34
+#ifdef __cplusplus
35
+  }
36
+#endif
37
+

+ 44
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/LCD_defines.h View File

@@ -0,0 +1,44 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+void usleep(uint64_t microsec);
25
+// The following are optional depending on the platform.
26
+
27
+// definitions of HAL specific com and device drivers.
28
+uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
29
+uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
30
+
31
+// connect U8g com generic com names to the desired driver
32
+#define U8G_COM_SW_SPI u8g_com_sw_spi_fn
33
+#define U8G_COM_ST7920_SW_SPI u8g_com_ST7920_sw_spi_fn
34
+
35
+// let these default for now
36
+#define U8G_COM_HW_SPI u8g_com_null_fn
37
+#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn
38
+#define U8G_COM_SSD_I2C u8g_com_null_fn
39
+#define U8G_COM_PARALLEL u8g_com_null_fn
40
+#define U8G_COM_T6963 u8g_com_null_fn
41
+#define U8G_COM_FAST_PARALLEL u8g_com_null_fn
42
+#define U8G_COM_UC_I2C u8g_com_null_fn
43
+
44
+

+ 43
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/LCD_delay.h View File

@@ -0,0 +1,43 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * LCD delay routines - used by all the drivers.
26
+ *
27
+ * These are based on the LPC1768 routines.
28
+ *
29
+ * Couldn't just call exact copies because the overhead
30
+ * results in a one microsecond delay taking about 4µS.
31
+ */
32
+
33
+#ifdef __cplusplus
34
+  extern "C" {
35
+#endif
36
+
37
+void U8g_delay(int msec);
38
+void u8g_MicroDelay();
39
+void u8g_10MicroDelay();
40
+
41
+#ifdef __cplusplus
42
+  }
43
+#endif

+ 52
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/LCD_pin_routines.cpp View File

@@ -0,0 +1,52 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Low level pin manipulation routines - used by all the drivers.
25
+ *
26
+ * These are based on the LPC1768 pinMode, digitalRead & digitalWrite routines.
27
+ *
28
+ * Couldn't just call exact copies because the overhead killed the LCD update speed
29
+ * With an intermediate level the softspi was running in the 10-20kHz range which
30
+ * resulted in using about about 25% of the CPU's time.
31
+ */
32
+
33
+#ifdef __PLAT_NATIVE_SIM__
34
+
35
+#include "../fastio.h"
36
+#include "LCD_pin_routines.h"
37
+
38
+#ifdef __cplusplus
39
+  extern "C" {
40
+#endif
41
+void u8g_SetPinOutput(uint8_t internal_pin_number){SET_DIR_OUTPUT(internal_pin_number);}
42
+void u8g_SetPinInput(uint8_t internal_pin_number){SET_DIR_INPUT(internal_pin_number);}
43
+void u8g_SetPinLevel(uint8_t  pin, uint8_t  pin_status){WRITE_PIN(pin, pin_status);}
44
+uint8_t u8g_GetPinLevel(uint8_t pin){return READ_PIN(pin);}
45
+void usleep(uint64_t microsec){
46
+assert(false); // why we here?
47
+}
48
+#ifdef __cplusplus
49
+  }
50
+#endif
51
+
52
+#endif // __PLAT_NATIVE_SIM__

+ 46
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/LCD_pin_routines.h View File

@@ -0,0 +1,46 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Low level pin manipulation routines - used by all the drivers.
26
+ *
27
+ * These are based on the LPC1768 pinMode, digitalRead & digitalWrite routines.
28
+ *
29
+ * Couldn't just call exact copies because the overhead killed the LCD update speed
30
+ * With an intermediate level the softspi was running in the 10-20kHz range which
31
+ * resulted in using about about 25% of the CPU's time.
32
+ */
33
+
34
+
35
+#ifdef __cplusplus
36
+  extern "C" {
37
+#endif
38
+
39
+void u8g_SetPinOutput(uint8_t internal_pin_number);
40
+void u8g_SetPinInput(uint8_t internal_pin_number);
41
+void u8g_SetPinLevel(uint8_t  pin, uint8_t  pin_status);
42
+uint8_t u8g_GetPinLevel(uint8_t pin);
43
+
44
+#ifdef __cplusplus
45
+  }
46
+#endif

+ 171
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_st7920_sw_spi.cpp View File

@@ -0,0 +1,171 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Based on u8g_com_st7920_hw_spi.c
25
+ *
26
+ * Universal 8bit Graphics Library
27
+ *
28
+ * Copyright (c) 2011, olikraus@gmail.com
29
+ * All rights reserved.
30
+ *
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
+ *
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
+ *
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
+ *
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
+
56
+#ifdef __PLAT_NATIVE_SIM__
57
+
58
+#include "../../../inc/MarlinConfig.h"
59
+
60
+#if ENABLED(U8GLIB_ST7920)
61
+
62
+#include <U8glib.h>
63
+#include "../../shared/Delay.h"
64
+
65
+#undef SPI_SPEED
66
+#define SPI_SPEED 6
67
+#define SPI_DELAY_CYCLES (1 + SPI_SPEED * 10)
68
+
69
+static pin_t SCK_pin_ST7920_HAL, MOSI_pin_ST7920_HAL_HAL;
70
+static uint8_t SPI_speed = 0;
71
+
72
+static uint8_t swSpiTransfer(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin) {
73
+  for (uint8_t i = 0; i < 8; i++) {
74
+    WRITE_PIN(mosi_pin, !!(b & 0x80));
75
+    DELAY_CYCLES(SPI_SPEED);
76
+    WRITE_PIN(sck_pin, HIGH);
77
+    DELAY_CYCLES(SPI_SPEED);
78
+    b <<= 1;
79
+    if (miso_pin >= 0 && READ_PIN(miso_pin)) b |= 1;
80
+    WRITE_PIN(sck_pin, LOW);
81
+    DELAY_CYCLES(SPI_SPEED);
82
+  }
83
+  return b;
84
+}
85
+
86
+static uint8_t swSpiInit(const uint8_t spiRate, const pin_t sck_pin, const pin_t mosi_pin) {
87
+  WRITE_PIN(mosi_pin, HIGH);
88
+  WRITE_PIN(sck_pin, LOW);
89
+  return spiRate;
90
+}
91
+
92
+static void u8g_com_st7920_write_byte_sw_spi(uint8_t rs, uint8_t val) {
93
+  static uint8_t rs_last_state = 255;
94
+  if (rs != rs_last_state) {
95
+    // Transfer Data (FA) or Command (F8)
96
+    swSpiTransfer(rs ? 0x0FA : 0x0F8, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
97
+    rs_last_state = rs;
98
+    DELAY_US(40); // Give the controller time to process the data: 20 is bad, 30 is OK, 40 is safe
99
+  }
100
+  swSpiTransfer(val & 0x0F0, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
101
+  swSpiTransfer(val << 4, SPI_speed, SCK_pin_ST7920_HAL, -1, MOSI_pin_ST7920_HAL_HAL);
102
+}
103
+#ifdef __cplusplus
104
+  extern "C" {
105
+#endif
106
+
107
+uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
108
+  switch (msg) {
109
+    case U8G_COM_MSG_INIT:
110
+      SCK_pin_ST7920_HAL = u8g->pin_list[U8G_PI_SCK];
111
+      MOSI_pin_ST7920_HAL_HAL = u8g->pin_list[U8G_PI_MOSI];
112
+
113
+      u8g_SetPIOutput(u8g, U8G_PI_CS);
114
+      u8g_SetPIOutput(u8g, U8G_PI_SCK);
115
+      u8g_SetPIOutput(u8g, U8G_PI_MOSI);
116
+      u8g_Delay(5);
117
+
118
+      SPI_speed = swSpiInit(SPI_SPEED, SCK_pin_ST7920_HAL, MOSI_pin_ST7920_HAL_HAL);
119
+
120
+      u8g_SetPILevel(u8g, U8G_PI_CS, 0);
121
+      u8g_SetPILevel(u8g, U8G_PI_SCK, 0);
122
+      u8g_SetPILevel(u8g, U8G_PI_MOSI, 0);
123
+
124
+      u8g->pin_list[U8G_PI_A0_STATE] = 0;       /* initial RS state: command mode */
125
+      break;
126
+
127
+    case U8G_COM_MSG_STOP:
128
+      break;
129
+
130
+    case U8G_COM_MSG_RESET:
131
+       if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
132
+      break;
133
+
134
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
135
+      u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
136
+      break;
137
+
138
+    case U8G_COM_MSG_CHIP_SELECT:
139
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_CS]) u8g_SetPILevel(u8g, U8G_PI_CS, arg_val);  //note: the st7920 has an active high chip select
140
+      break;
141
+
142
+    case U8G_COM_MSG_WRITE_BYTE:
143
+      u8g_com_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], arg_val);
144
+      break;
145
+
146
+    case U8G_COM_MSG_WRITE_SEQ: {
147
+        uint8_t *ptr = (uint8_t*) arg_ptr;
148
+        while (arg_val > 0) {
149
+          u8g_com_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
150
+          arg_val--;
151
+        }
152
+      }
153
+      break;
154
+
155
+      case U8G_COM_MSG_WRITE_SEQ_P: {
156
+        uint8_t *ptr = (uint8_t*) arg_ptr;
157
+        while (arg_val > 0) {
158
+          u8g_com_st7920_write_byte_sw_spi(u8g->pin_list[U8G_PI_A0_STATE], *ptr++);
159
+          arg_val--;
160
+        }
161
+      }
162
+      break;
163
+  }
164
+  return 1;
165
+}
166
+#ifdef __cplusplus
167
+  }
168
+#endif
169
+
170
+#endif // U8GLIB_ST7920
171
+#endif // TARGET_LPC1768

+ 215
- 0
Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_sw_spi.cpp View File

@@ -0,0 +1,215 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Based on u8g_com_std_sw_spi.c
25
+ *
26
+ * Universal 8bit Graphics Library
27
+ *
28
+ * Copyright (c) 2015, olikraus@gmail.com
29
+ * All rights reserved.
30
+ *
31
+ * Redistribution and use in source and binary forms, with or without modification,
32
+ * are permitted provided that the following conditions are met:
33
+ *
34
+ *  * Redistributions of source code must retain the above copyright notice, this list
35
+ *    of conditions and the following disclaimer.
36
+ *
37
+ *  * Redistributions in binary form must reproduce the above copyright notice, this
38
+ *    list of conditions and the following disclaimer in the documentation and/or other
39
+ *    materials provided with the distribution.
40
+ *
41
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
46
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54
+ */
55
+
56
+#ifdef __PLAT_NATIVE_SIM__
57
+
58
+#include "../../../inc/MarlinConfig.h"
59
+
60
+#if HAS_MARLINUI_U8GLIB && DISABLED(U8GLIB_ST7920)
61
+
62
+#undef SPI_SPEED
63
+#define SPI_SPEED 2  // About 2 MHz
64
+
65
+#include <Arduino.h>
66
+#include <U8glib.h>
67
+
68
+#ifdef __cplusplus
69
+  extern "C" {
70
+#endif
71
+
72
+uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
73
+  LOOP_L_N(i, 8) {
74
+    if (spi_speed == 0) {
75
+      WRITE_PIN(mosi_pin, !!(b & 0x80));
76
+      WRITE_PIN(sck_pin, HIGH);
77
+      b <<= 1;
78
+      if (miso_pin >= 0 && READ_PIN(miso_pin)) b |= 1;
79
+      WRITE_PIN(sck_pin, LOW);
80
+    }
81
+    else {
82
+      const uint8_t state = (b & 0x80) ? HIGH : LOW;
83
+      LOOP_L_N(j, spi_speed)
84
+        WRITE_PIN(mosi_pin, state);
85
+
86
+      LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
87
+        WRITE_PIN(sck_pin, HIGH);
88
+
89
+      b <<= 1;
90
+      if (miso_pin >= 0 && READ_PIN(miso_pin)) b |= 1;
91
+
92
+      LOOP_L_N(j, spi_speed)
93
+        WRITE_PIN(sck_pin, LOW);
94
+    }
95
+  }
96
+
97
+  return b;
98
+}
99
+
100
+uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin ) {
101
+
102
+  LOOP_L_N(i, 8) {
103
+    const uint8_t state = (b & 0x80) ? HIGH : LOW;
104
+    if (spi_speed == 0) {
105
+      WRITE_PIN(sck_pin, LOW);
106
+      WRITE_PIN(mosi_pin, state);
107
+      WRITE_PIN(mosi_pin, state);  // need some setup time
108
+      WRITE_PIN(sck_pin, HIGH);
109
+    }
110
+    else {
111
+      LOOP_L_N(j, spi_speed + (miso_pin >= 0 ? 0 : 1))
112
+        WRITE_PIN(sck_pin, LOW);
113
+
114
+      LOOP_L_N(j, spi_speed)
115
+        WRITE_PIN(mosi_pin, state);
116
+
117
+      LOOP_L_N(j, spi_speed)
118
+        WRITE_PIN(sck_pin, HIGH);
119
+    }
120
+    b <<= 1;
121
+    if (miso_pin >= 0 && READ_PIN(miso_pin)) b |= 1;
122
+  }
123
+
124
+  return b;
125
+}
126
+
127
+static uint8_t SPI_speed = 0;
128
+
129
+static uint8_t swSpiInit(const uint8_t spi_speed, const uint8_t clk_pin, const uint8_t mosi_pin) {
130
+    return spi_speed;
131
+}
132
+
133
+static void u8g_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) {
134
+  #if EITHER(FYSETC_MINI_12864, MKS_MINI_12864)
135
+    swSpiTransfer_mode_3(val, SPI_speed, clockPin, -1, dataPin);
136
+  #else
137
+    swSpiTransfer_mode_0(val, SPI_speed, clockPin, -1, dataPin);
138
+  #endif
139
+}
140
+
141
+uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
142
+  switch (msg) {
143
+    case U8G_COM_MSG_INIT:
144
+      u8g_SetPIOutput(u8g, U8G_PI_SCK);
145
+      u8g_SetPIOutput(u8g, U8G_PI_MOSI);
146
+      u8g_SetPIOutput(u8g, U8G_PI_CS);
147
+      u8g_SetPIOutput(u8g, U8G_PI_A0);
148
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPIOutput(u8g, U8G_PI_RESET);
149
+      SPI_speed = swSpiInit(SPI_SPEED, u8g->pin_list[U8G_PI_SCK], u8g->pin_list[U8G_PI_MOSI]);
150
+      u8g_SetPILevel(u8g, U8G_PI_SCK, 0);
151
+      u8g_SetPILevel(u8g, U8G_PI_MOSI, 0);
152
+      break;
153
+
154
+    case U8G_COM_MSG_STOP:
155
+      break;
156
+
157
+    case U8G_COM_MSG_RESET:
158
+      if (U8G_PIN_NONE != u8g->pin_list[U8G_PI_RESET]) u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
159
+      break;
160
+
161
+    case U8G_COM_MSG_CHIP_SELECT:
162
+      #if EITHER(FYSETC_MINI_12864, MKS_MINI_12864)  // LCD SPI is running mode 3 while SD card is running mode 0
163
+        if (arg_val) {                               //   SCK idle state needs to be set to the proper idle state before
164
+                                                     //   the next chip select goes active
165
+          u8g_SetPILevel(u8g, U8G_PI_SCK, 1);        // Set SCK to mode 3 idle state before CS goes active
166
+          u8g_SetPILevel(u8g, U8G_PI_CS, LOW);
167
+        }
168
+        else {
169
+          u8g_SetPILevel(u8g, U8G_PI_CS, HIGH);
170
+          u8g_SetPILevel(u8g, U8G_PI_SCK, 0);  // Set SCK to mode 0 idle state after CS goes inactive
171
+        }
172
+      #else
173
+        u8g_SetPILevel(u8g, U8G_PI_CS, !arg_val);
174
+      #endif
175
+      break;
176
+
177
+    case U8G_COM_MSG_WRITE_BYTE:
178
+      u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
179
+      break;
180
+
181
+    case U8G_COM_MSG_WRITE_SEQ: {
182
+        uint8_t *ptr = (uint8_t *)arg_ptr;
183
+        while (arg_val > 0) {
184
+          u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++);
185
+          arg_val--;
186
+        }
187
+      }
188
+      break;
189
+
190
+      case U8G_COM_MSG_WRITE_SEQ_P: {
191
+        uint8_t *ptr = (uint8_t *)arg_ptr;
192
+        while (arg_val > 0) {
193
+          u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr));
194
+          ptr++;
195
+          arg_val--;
196
+        }
197
+      }
198
+      break;
199
+
200
+    case U8G_COM_MSG_ADDRESS:                     /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
201
+      u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
202
+      break;
203
+  }
204
+  return 1;
205
+}
206
+
207
+#ifdef __cplusplus
208
+  }
209
+#endif
210
+
211
+#elif !ANY(TFT_COLOR_UI, TFT_CLASSIC_UI, TFT_LVGL_UI, HAS_MARLINUI_HD44780) && HAS_MARLINUI_U8GLIB
212
+  #include <U8glib.h>
213
+  uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {return 0;}
214
+#endif // HAS_MARLINUI_U8GLIB && !U8GLIB_ST7920
215
+#endif // __PLAT_NATIVE_SIM__

+ 27
- 0
Marlin/src/HAL/NATIVE_SIM/watchdog.h View File

@@ -0,0 +1,27 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 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
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#define WDT_TIMEOUT   4000000 // 4 second timeout
25
+
26
+void watchdog_init();
27
+void HAL_watchdog_refresh();

+ 2
- 0
Marlin/src/HAL/platforms.h View File

@@ -43,6 +43,8 @@
43 43
   #define HAL_PATH(PATH, NAME) XSTR(PATH/ESP32/NAME)
44 44
 #elif defined(__PLAT_LINUX__)
45 45
   #define HAL_PATH(PATH, NAME) XSTR(PATH/LINUX/NAME)
46
+#elif defined(__PLAT_NATIVE_SIM__)
47
+  #define HAL_PATH(PATH, NAME) XSTR(PATH/NATIVE_SIM/NAME)
46 48
 #elif defined(__SAMD51__)
47 49
   #define HAL_PATH(PATH, NAME) XSTR(PATH/SAMD51/NAME)
48 50
 #else

+ 1
- 1
Marlin/src/HAL/shared/Delay.h View File

@@ -160,7 +160,7 @@ void calibrate_delay_loop();
160 160
   // Delay in microseconds
161 161
   #define DELAY_US(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL))
162 162
 
163
-#elif defined(__PLAT_LINUX__) || defined(ESP32)
163
+#elif defined(ESP32) || defined(__PLAT_LINUX__) || defined(__PLAT_NATIVE_SIM__)
164 164
 
165 165
   // DELAY_CYCLES specified inside platform
166 166
 

+ 3
- 0
Marlin/src/core/serial.h View File

@@ -304,6 +304,9 @@ void serial_echopair_PGM(PGM_P const s_P, unsigned int v);
304 304
 void serial_echopair_PGM(PGM_P const s_P, unsigned long v);
305 305
 inline void serial_echopair_PGM(PGM_P const s_P, bool v)    { serial_echopair_PGM(s_P, (int)v); }
306 306
 inline void serial_echopair_PGM(PGM_P const s_P, void *v)   { serial_echopair_PGM(s_P, (uintptr_t)v); }
307
+#if __INTPTR_WIDTH__ != __SIZE_WIDTH__
308
+  inline void serial_echopair_PGM(PGM_P const s_P, size_t v)   { serial_echopair_PGM(s_P, (long int)v); }
309
+#endif
307 310
 
308 311
 void serial_echo_start();
309 312
 void serial_error_start();

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

@@ -97,6 +97,11 @@
97 97
   #define U8G_COM_ST7920_HAL_HW_SPI   u8g_com_HAL_LPC1768_ST7920_hw_spi_fn
98 98
   #define U8G_COM_SSD_I2C_HAL         u8g_com_HAL_LPC1768_ssd_hw_i2c_fn
99 99
 
100
+#elif defined(__PLAT_NATIVE_SIM__)
101
+  uint8_t u8g_com_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
102
+  uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
103
+  #define U8G_COM_HAL_SW_SPI_FN       u8g_com_sw_spi_fn
104
+  #define U8G_COM_ST7920_HAL_SW_SPI   u8g_com_ST7920_sw_spi_fn
100 105
 #endif
101 106
 
102 107
 #ifndef U8G_COM_HAL_SW_SPI_FN

+ 2
- 2
Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp View File

@@ -360,7 +360,7 @@ void disp_gcode_icon(uint8_t file_num) {
360 360
 uint32_t lv_open_gcode_file(char *path) {
361 361
   #if ENABLED(SDSUPPORT)
362 362
     uint32_t *ps4;
363
-    uint32_t pre_sread_cnt = UINT32_MAX;
363
+    uintptr_t pre_sread_cnt = UINTPTR_MAX;
364 364
     char *cur_name;
365 365
 
366 366
     cur_name = strrchr(path, '/');
@@ -370,7 +370,7 @@ uint32_t lv_open_gcode_file(char *path) {
370 370
     ps4 = (uint32_t *)strstr((char *)public_buf, ";simage:");
371 371
     // Ignore the beginning message of gcode file
372 372
     if (ps4) {
373
-      pre_sread_cnt = (uint32_t)ps4 - (uint32_t)((uint32_t *)(&public_buf[0]));
373
+      pre_sread_cnt = (uintptr_t)ps4 - (uintptr_t)((uint32_t *)(&public_buf[0]));
374 374
       card.setIndex(pre_sread_cnt);
375 375
     }
376 376
     return pre_sread_cnt;

+ 4
- 4
Marlin/src/lcd/extui/mks_ui/draw_ui.cpp View File

@@ -560,11 +560,11 @@ char *creat_title_text() {
560 560
 
561 561
 #if HAS_GCODE_PREVIEW
562 562
 
563
-  uint32_t gPicturePreviewStart = 0;
563
+  uintptr_t gPicturePreviewStart = 0;
564 564
 
565 565
   void preview_gcode_prehandle(char *path) {
566 566
     #if ENABLED(SDSUPPORT)
567
-      uint32_t pre_read_cnt = 0;
567
+      uintptr_t pre_read_cnt = 0;
568 568
       uint32_t *p1;
569 569
       char *cur_name;
570 570
 
@@ -575,7 +575,7 @@ char *creat_title_text() {
575 575
       p1 = (uint32_t *)strstr((char *)public_buf, ";simage:");
576 576
 
577 577
       if (p1) {
578
-        pre_read_cnt = (uint32_t)p1 - (uint32_t)((uint32_t *)(&public_buf[0]));
578
+        pre_read_cnt = (uintptr_t)p1 - (uintptr_t)((uint32_t *)(&public_buf[0]));
579 579
 
580 580
         To_pre_view              = pre_read_cnt;
581 581
         gcode_preview_over       = true;
@@ -606,7 +606,7 @@ char *creat_title_text() {
606 606
           uint32_t br  = card.read(public_buf, 400);
607 607
           uint32_t *p1 = (uint32_t *)strstr((char *)public_buf, ";gimage:");
608 608
           if (p1) {
609
-            gPicturePreviewStart += (uint32_t)p1 - (uint32_t)((uint32_t *)(&public_buf[0]));
609
+            gPicturePreviewStart += (uintptr_t)p1 - (uintptr_t)((uint32_t *)(&public_buf[0]));
610 610
             break;
611 611
           }
612 612
           else {

+ 7
- 1
Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp View File

@@ -398,7 +398,7 @@ lv_fs_res_t sd_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_
398 398
   // find small image size
399 399
   card.read(public_buf, 512);
400 400
   public_buf[511] = '\0';
401
-  char* eol = strpbrk((const char*)public_buf, "\n\r");
401
+  const char* eol = strpbrk((const char*)public_buf, "\n\r");
402 402
   small_image_size = (uintptr_t)eol - (uintptr_t)((uint32_t *)(&public_buf[0])) + 1;
403 403
   return LV_FS_RES_OK;
404 404
 }
@@ -530,4 +530,10 @@ void lv_encoder_pin_init() {
530 530
 
531 531
 #endif // HAS_ENCODER_ACTION
532 532
 
533
+#if __PLAT_NATIVE_SIM__
534
+  #include <lv_misc/lv_log.h>
535
+  typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *);
536
+  extern "C" void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb) {}
537
+#endif
538
+
533 539
 #endif // HAS_TFT_LVGL_UI

+ 59
- 3
Marlin/src/pins/linux/pins_RAMPS_LINUX.h View File

@@ -49,6 +49,10 @@
49 49
   #define BOARD_INFO_NAME "RAMPS 1.4"
50 50
 #endif
51 51
 
52
+#ifndef DEFAULT_MACHINE_NAME
53
+  #define DEFAULT_MACHINE_NAME "SimRap 1.4"
54
+#endif
55
+
52 56
 #ifndef MARLIN_EEPROM_SIZE
53 57
   #define MARLIN_EEPROM_SIZE              0x1000  // 4KB
54 58
 #endif
@@ -208,6 +212,7 @@
208 212
 //
209 213
 #define SDSS                                  53
210 214
 #define LED_PIN                               13
215
+#define NEOPIXEL_PIN                          71
211 216
 
212 217
 #ifndef FILWIDTH_PIN
213 218
   #define FILWIDTH_PIN                         5  // Analog Input on AUX2
@@ -215,7 +220,7 @@
215 220
 
216 221
 // define digital pin 4 for the filament runout sensor. Use the RAMPS 1.4 digital input 4 on the servos connector
217 222
 #ifndef FIL_RUNOUT_PIN
218
-  #define FIL_RUNOUT_PIN                       4
223
+  #define FIL_RUNOUT_PIN                      21
219 224
 #endif
220 225
 
221 226
 #ifndef PS_ON_PIN
@@ -389,7 +394,54 @@
389 394
 // LCDs and Controllers //
390 395
 //////////////////////////
391 396
 
392
-#if HAS_WIRED_LCD
397
+#if ANY(TFT_COLOR_UI, TFT_CLASSIC_UI, TFT_LVGL_UI)
398
+
399
+  #define TFT_A0_PIN                          43
400
+  #define TFT_CS_PIN                          49
401
+  #define TFT_DC_PIN                          43
402
+  #define TFT_SCK_PIN                 SD_SCK_PIN
403
+  #define TFT_MOSI_PIN               SD_MOSI_PIN
404
+  #define TFT_MISO_PIN               SD_MISO_PIN
405
+  #define LCD_USE_DMA_SPI
406
+
407
+  #define BTN_EN1                             40
408
+  #define BTN_EN2                             63
409
+  #define BTN_ENC                             59
410
+  #define BEEPER_PIN                          42
411
+
412
+  #define TOUCH_CS_PIN                        33
413
+  #define SD_DETECT_PIN                       41
414
+
415
+  #define HAS_SPI_FLASH                        1
416
+  #if HAS_SPI_FLASH
417
+    #define SPI_DEVICE                         1
418
+    #define SPI_FLASH_SIZE             0x1000000  // 16MB
419
+    #define W25QXX_CS_PIN                     31
420
+    #define W25QXX_MOSI_PIN          SD_MOSI_PIN
421
+    #define W25QXX_MISO_PIN          SD_MISO_PIN
422
+    #define W25QXX_SCK_PIN            SD_SCK_PIN
423
+  #endif
424
+
425
+  #define TFT_BUFFER_SIZE                 0xFFFF
426
+  #ifndef TFT_DRIVER
427
+    #define TFT_DRIVER                    ST7796
428
+  #endif
429
+  #ifndef XPT2046_X_CALIBRATION
430
+    #define XPT2046_X_CALIBRATION            63934
431
+  #endif
432
+  #ifndef XPT2046_Y_CALIBRATION
433
+    #define XPT2046_Y_CALIBRATION            63598
434
+  #endif
435
+  #ifndef XPT2046_X_OFFSET
436
+    #define XPT2046_X_OFFSET                  -1
437
+  #endif
438
+  #ifndef XPT2046_Y_OFFSET
439
+    #define XPT2046_Y_OFFSET                 -20
440
+  #endif
441
+
442
+  #define BTN_BACK                            70
443
+
444
+#elif HAS_WIRED_LCD
393 445
 
394 446
   //
395 447
   // LCD Display output pins
@@ -622,14 +674,18 @@
622 674
         #define BTN_EN1                       37
623 675
         #define BTN_EN2                       35
624 676
         #define BTN_ENC                       31
677
+        #define SD_DETECT_PIN                 41
625 678
       #endif
626 679
 
627 680
       #if ENABLED(G3D_PANEL)
628 681
         #define SD_DETECT_PIN                 49
629 682
         #define KILL_PIN                      41
630 683
       #endif
631
-
632 684
     #endif
685
+
686
+    // CUSTOM SIMULATOR INPUTS
687
+    #define BTN_BACK                          70
688
+
633 689
   #endif // IS_NEWPANEL
634 690
 
635 691
 #endif // HAS_WIRED_LCD

+ 1
- 1
Marlin/src/pins/pins.h View File

@@ -681,7 +681,7 @@
681 681
 //
682 682
 
683 683
 #elif MB(LINUX_RAMPS)
684
-  #include "linux/pins_RAMPS_LINUX.h"           // Linux                                  env:linux_native
684
+  #include "linux/pins_RAMPS_LINUX.h"           // Native or Simulation                   lin:linux_native mac:simulator_macos_debug mac:simulator_macos_release win:simulator_windows lin:simulator_linux_debug lin:simulator_linux_release
685 685
 
686 686
 #else
687 687
 

+ 1
- 1
Marlin/src/sd/SdFatUtil.cpp View File

@@ -48,7 +48,7 @@
48 48
     return &top - reinterpret_cast<char*>(sbrk(0));
49 49
   }
50 50
 
51
-#else
51
+#elif defined(__AVR__)
52 52
 
53 53
   extern char* __brkval;
54 54
   extern char __bss_end;

+ 1
- 1
Marlin/src/sd/cardreader.cpp View File

@@ -939,7 +939,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, con
939 939
 
940 940
   while (atom_ptr) {
941 941
     // Find next subdirectory delimiter
942
-    char * const name_end = strchr(atom_ptr, '/');
942
+    const char * const name_end = strchr(atom_ptr, '/');
943 943
 
944 944
     // Last atom in the path? Item found.
945 945
     if (name_end <= atom_ptr) break;

+ 9
- 1
buildroot/share/PlatformIO/scripts/common-dependencies.py View File

@@ -215,7 +215,13 @@ def search_compiler():
215 215
 	# Find the current platform compiler by searching the $PATH
216 216
 	# which will be in a platformio toolchain bin folder
217 217
 	path_regex = re.escape(env['PROJECT_PACKAGES_DIR'])
218
-	gcc = "g++"
218
+
219
+	# See if the environment provides a default compiler
220
+	try:
221
+		gcc = env.GetProjectOption('custom_deps_gcc')
222
+	except:
223
+		gcc = "g++"
224
+
219 225
 	if env['PLATFORM'] == 'win32':
220 226
 		path_separator = ';'
221 227
 		path_regex += r'.*\\bin'
@@ -241,6 +247,8 @@ def search_compiler():
241 247
 			return filepath
242 248
 
243 249
 	filepath = env.get('CXX')
250
+	if filepath == 'CC':
251
+		filepath = gcc
244 252
 	blab("Couldn't find a compiler! Fallback to %s" % filepath)
245 253
 	return filepath
246 254
 

+ 52
- 0
buildroot/share/PlatformIO/scripts/simulator.py View File

@@ -0,0 +1,52 @@
1
+#
2
+# PlatformIO pre: script for simulator builds
3
+#
4
+
5
+# Get the environment thus far for the build
6
+Import("env")
7
+
8
+#print(env.Dump())
9
+
10
+#
11
+# Give the binary a distinctive name
12
+#
13
+
14
+env['PROGNAME'] = "MarlinSimulator"
15
+
16
+#
17
+# If Xcode is installed add the path to its Frameworks folder,
18
+# or if Mesa is installed try to use its GL/gl.h.
19
+#
20
+
21
+import sys
22
+if sys.platform == 'darwin':
23
+
24
+  #
25
+  # Silence half of the ranlib warnings. (No equivalent for 'ARFLAGS')
26
+  #
27
+  env['RANLIBFLAGS'] += [ "-no_warning_for_no_symbols" ]
28
+
29
+  # Default paths for Xcode and a lucky GL/gl.h dropped by Mesa
30
+  xcode_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
31
+  mesa_path = "/opt/local/include/GL/gl.h"
32
+
33
+  import os.path
34
+
35
+  if os.path.exists(xcode_path):
36
+
37
+    env['BUILD_FLAGS'] += [ "-F" + xcode_path ]
38
+    print("Using OpenGL framework headers from Xcode.app")
39
+
40
+  elif os.path.exists(mesa_path):
41
+
42
+    env['BUILD_FLAGS'] += [ '-D__MESA__' ]
43
+    print("Using OpenGL header from", mesa_path)
44
+
45
+  else:
46
+
47
+    print("\n\nNo OpenGL headers found. Install Xcode for matching headers, or use 'sudo port install mesa' to get a GL/gl.h.\n\n")
48
+
49
+    # Break out of the PIO build immediately
50
+    sys.exit(1)
51
+
52
+env.AddCustomTarget("upload", "$BUILD_DIR/${PROGNAME}", "$BUILD_DIR/${PROGNAME}")

+ 107
- 0
ini/native.ini View File

@@ -21,3 +21,110 @@ build_unflags   = -Wall
21 21
 lib_ldf_mode    = off
22 22
 lib_deps        =
23 23
 src_filter      = ${common.default_src_filter} +<src/HAL/LINUX>
24
+
25
+#
26
+# Native Simulation
27
+# Builds with a small subset of available features
28
+# Required system libraries: SDL2, SDL2-net, OpenGL, GLM
29
+#
30
+# Tested with Linux (Mint 20) : gcc [9.3.0, 10.2.0]: libsdl2-dev[2.0.10], libsdl2-net-dev[2.0.1], libglm-dev[0.9.9.7, 0.9.9.8]
31
+#
32
+# Debugging with gdb in vscode is as easy as adding the launch task as usual, but platformio
33
+# will randomly remove your task when it recreates its tasks from a template. Add your gdb
34
+# launch task to '~/.platformio/penv/lib/python{PYTHON_VERSION}/site-packages/platformio/ide/tpls/vscode/.vscode'
35
+# to avoid this until platformio updates.
36
+#
37
+[simulator_common]
38
+platform          = native
39
+framework         =
40
+build_flags       = ${common.build_flags} -std=gnu++17 -D__PLAT_NATIVE_SIM__ -DU8G_HAL_LINKS -I/usr/include/SDL2 -IMarlin -IMarlin/src/HAL/NATIVE_SIM/include -IMarlin/src/HAL/NATIVE_SIM/u8g
41
+src_build_flags   = -Wall -Wno-expansion-to-defined -Wcast-align
42
+release_flags     = -g0 -O3 -flto
43
+debug_build_flags = -fstack-protector-strong -g -g3 -ggdb
44
+lib_compat_mode   = off
45
+src_filter        = ${common.default_src_filter} +<src/HAL/NATIVE_SIM>
46
+
47
+lib_deps          = ${common.lib_deps}
48
+  MarlinSimUI=https://github.com/p3p/MarlinSimUI.git
49
+  Adafruit NeoPixel=https://github.com/p3p/Adafruit_NeoPixel/archive/marlin_sim_native.zip
50
+  LiquidCrystal=https://github.com/p3p/LiquidCrystal/archive/master.zip
51
+extra_scripts = ${common.extra_scripts}
52
+  pre:buildroot/share/PlatformIO/scripts/simulator.py
53
+
54
+
55
+[simulator_linux]
56
+extends     = simulator_common
57
+build_flags = ${simulator_common.build_flags} -ldl -lpthread -lSDL2 -lSDL2_net -lGL
58
+
59
+[env:simulator_linux_debug]
60
+platform   = ${simulator_linux.platform}
61
+extends    = simulator_linux
62
+build_type = debug
63
+
64
+[env:simulator_linux_release]
65
+platform    = ${simulator_linux.platform}
66
+extends     = simulator_linux
67
+build_type  = release
68
+build_flags = ${simulator_linux.build_flags} ${simulator_linux.release_flags}
69
+
70
+#
71
+# Simulator for macOS (MacPorts)
72
+#
73
+#  sudo port install gcc10 gdb glm libsdl2 freetype
74
+#  sudo port install ld64 @3_3 +ld64_xcode
75
+#  sudo port uninstall ld64 ld64-latest
76
+#  cd /opt/local/bin
77
+#  sudo rm -f gcc g++ cc
78
+#  sudo ln gcc-mp-10 gcc ; sudo ln g++-mp-10 g++ ; sudo ln g++ cc
79
+#  cd -
80
+#
81
+# Use 'sudo port install mesa' to get a <GL/gl.h> if no Xcode is installed.
82
+# If Xcode is installed be sure to run `xcode-select --install` first.
83
+#
84
+# For VSCode debugging paste the block below near the top of launch.json.
85
+# NOTE: The PlatformIO VSCode extension will remove it when regenerating launch.json.
86
+#
87
+# { "name": "Debug Sim",
88
+#   "type": "cppdbg",
89
+#   "request": "launch",
90
+#   "program": "${workspaceFolder}/.pio/build/simulator_macos/MarlinSimulator",
91
+#   "miDebuggerPath": "/opt/local/bin/ggdb",
92
+#   "MIMode": "gdb",
93
+#   "cwd": "${workspaceFolder}/.pio/build/simulator_macos" },
94
+#
95
+[simulator_macos]
96
+build_unflags     = -lGL
97
+custom_verbose    = 0
98
+build_flags       =
99
+  -I/opt/local/include
100
+  -I/opt/local/include/freetype2
101
+  -I/opt/local/include/SDL2/
102
+  -L/opt/local/lib
103
+  -Wl,-framework,OpenGl
104
+  -Wl,-framework,CoreFoundation
105
+  -lSDL2
106
+
107
+[env:simulator_macos_debug]
108
+platform        = ${env:simulator_linux_release.platform}
109
+extends         = env:simulator_linux_debug
110
+build_flags     = ${env:simulator_linux_debug.build_flags} ${simulator_macos.build_flags} -ggdb -Og -D_THREAD_SAFE
111
+build_unflags   = ${simulator_macos.build_unflags}
112
+
113
+[env:simulator_macos_release]
114
+platform        = ${env:simulator_linux_release.platform}
115
+extends         = env:simulator_linux_release
116
+build_flags     = ${env:simulator_linux_release.build_flags} ${simulator_macos.build_flags}
117
+build_unflags   = ${simulator_macos.build_unflags}
118
+
119
+#
120
+# Simulator for Windows 10
121
+#
122
+#  MSYS2 mingw-w64-x86_64 with these packages:
123
+#  pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-glm mingw64/mingw-w64-x86_64-SDL2 mingw64/mingw-w64-x86_64-SDL2_net
124
+#
125
+[env:simulator_windows]
126
+platform    = ${simulator_common.platform}
127
+extends     = simulator_common
128
+src_build_flags = ${simulator_common.src_build_flags} -fpermissive
129
+build_flags = ${simulator_common.build_flags} ${simulator_common.debug_build_flags} -fno-stack-protector -Wl,-subsystem,windows -ldl -lmingw32 -lSDL2main -lSDL2 -lSDL2_net -lopengl32 -lssp
130
+build_type = debug

Loading…
Cancel
Save