Scott Lahteine 5 år sedan
förälder
incheckning
15aa932aa6
Inget konto är kopplat till bidragsgivarens mejladress
45 ändrade filer med 3064 tillägg och 3 borttagningar
  1. 10
    1
      .travis.yml
  2. 82
    0
      Marlin/src/HAL/HAL_LINUX/HAL.cpp
  3. 109
    0
      Marlin/src/HAL/HAL_LINUX/HAL.h
  4. 73
    0
      Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp
  5. 91
    0
      Marlin/src/HAL/HAL_LINUX/HAL_timers.h
  6. 67
    0
      Marlin/src/HAL/HAL_LINUX/SanityCheck.h
  7. 116
    0
      Marlin/src/HAL/HAL_LINUX/arduino.cpp
  8. 123
    0
      Marlin/src/HAL/HAL_LINUX/fastio.h
  9. 32
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp
  10. 89
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Clock.h
  11. 30
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Gpio.cpp
  12. 141
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Gpio.h
  13. 61
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Heater.cpp
  14. 47
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Heater.h
  15. 50
    0
      Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.cpp
  16. 40
    0
      Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.h
  17. 66
    0
      Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.cpp
  18. 45
    0
      Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.h
  19. 118
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Timer.cpp
  20. 76
    0
      Marlin/src/HAL/HAL_LINUX/hardware/Timer.h
  21. 125
    0
      Marlin/src/HAL/HAL_LINUX/include/Arduino.h
  22. 70
    0
      Marlin/src/HAL/HAL_LINUX/include/pinmapping.cpp
  23. 59
    0
      Marlin/src/HAL/HAL_LINUX/include/pinmapping.h
  24. 207
    0
      Marlin/src/HAL/HAL_LINUX/include/serial.h
  25. 137
    0
      Marlin/src/HAL/HAL_LINUX/main.cpp
  26. 101
    0
      Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp
  27. 63
    0
      Marlin/src/HAL/HAL_LINUX/pinsDebug.h
  28. 80
    0
      Marlin/src/HAL/HAL_LINUX/servo_private.h
  29. 53
    0
      Marlin/src/HAL/HAL_LINUX/spi_pins.h
  30. 46
    0
      Marlin/src/HAL/HAL_LINUX/watchdog.cpp
  31. 34
    0
      Marlin/src/HAL/HAL_LINUX/watchdog.h
  32. 2
    0
      Marlin/src/HAL/platforms.h
  33. 4
    0
      Marlin/src/HAL/shared/Delay.h
  34. 6
    0
      Marlin/src/core/boards.h
  35. 7
    0
      Marlin/src/pins/pins.h
  36. 572
    0
      Marlin/src/pins/pins_RAMPS_LINUX.h
  37. 0
    0
      buildroot/share/tests/DUE-tests
  38. 0
    0
      buildroot/share/tests/LPC1768-tests
  39. 0
    0
      buildroot/share/tests/LPC1769-tests
  40. 0
    0
      buildroot/share/tests/STM32F1-tests
  41. 16
    0
      buildroot/share/tests/linux_native-tests
  42. 0
    0
      buildroot/share/tests/megaatmega2560-tests
  43. 2
    2
      buildroot/share/tests/run_tests
  44. 0
    0
      buildroot/share/tests/teensy35-tests
  45. 14
    0
      platformio.ini

+ 10
- 1
.travis.yml Visa fil

@@ -1,5 +1,5 @@
1 1
 dist: trusty
2
-sudo: false
2
+sudo: require
3 3
 
4 4
 language: python
5 5
 python:
@@ -22,8 +22,17 @@ env:
22 22
   - TEST_PLATFORM="LPC1769"
23 23
   - TEST_PLATFORM="STM32F1"
24 24
   - TEST_PLATFORM="teensy35"
25
+  - TEST_PLATFORM="linux_native"
26
+
27
+addons:
28
+  apt:
29
+    sources:
30
+      - ubuntu-toolchain-r-test
31
+    packages:
32
+      - g++-7
25 33
 
26 34
 before_install:
35
+  - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90
27 36
   #
28 37
   # Fetch the tag information for the current branch
29 38
   - git fetch origin --tags

+ 82
- 0
Marlin/src/HAL/HAL_LINUX/HAL.cpp Visa fil

@@ -0,0 +1,82 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+#include "../shared/Delay.h"
27
+
28
+HalSerial usb_serial;
29
+
30
+// U8glib required functions
31
+extern "C" void u8g_xMicroDelay(uint16_t val) {
32
+  DELAY_US(val);
33
+}
34
+extern "C" void u8g_MicroDelay(void) {
35
+  u8g_xMicroDelay(1);
36
+}
37
+extern "C" void u8g_10MicroDelay(void) {
38
+  u8g_xMicroDelay(10);
39
+}
40
+extern "C" void u8g_Delay(uint16_t val) {
41
+  delay(val);
42
+}
43
+//************************//
44
+
45
+// return free heap space
46
+int freeMemory() {
47
+  return 0;
48
+}
49
+
50
+// --------------------------------------------------------------------------
51
+// ADC
52
+// --------------------------------------------------------------------------
53
+
54
+void HAL_adc_init(void) {
55
+
56
+}
57
+
58
+void HAL_adc_enable_channel(int ch) {
59
+
60
+}
61
+
62
+uint8_t active_ch = 0;
63
+void HAL_adc_start_conversion(const uint8_t ch) {
64
+  active_ch = ch;
65
+}
66
+
67
+bool HAL_adc_finished(void) {
68
+  return true;
69
+}
70
+
71
+uint16_t HAL_adc_get_result(void) {
72
+  pin_t pin = analogInputToDigitalPin(active_ch);
73
+  if (!VALID_PIN(pin)) return 0;
74
+  uint16_t data = ((Gpio::get(pin) >> 2) & 0x3FF);
75
+  return data;    // return 10bit value as Marlin expects
76
+}
77
+
78
+void HAL_pwm_init(void) {
79
+
80
+}
81
+
82
+#endif // __PLAT_LINUX__

+ 109
- 0
Marlin/src/HAL/HAL_LINUX/HAL.h Visa fil

@@ -0,0 +1,109 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#define CPU_32_BIT
25
+
26
+// --------------------------------------------------------------------------
27
+// Includes
28
+// --------------------------------------------------------------------------
29
+
30
+#define F_CPU 100000000
31
+#define SystemCoreClock F_CPU
32
+#include <iostream>
33
+#include <stdint.h>
34
+#include <stdarg.h>
35
+
36
+#undef min
37
+#undef max
38
+
39
+#include <algorithm>
40
+
41
+void _printf (const  char *format, ...);
42
+void _putc(uint8_t c);
43
+uint8_t _getc();
44
+
45
+//extern "C" volatile uint32_t _millis;
46
+
47
+//arduino: Print.h
48
+#define DEC 10
49
+#define HEX 16
50
+#define OCT 8
51
+#define BIN 2
52
+//arduino: binary.h (weird defines)
53
+#define B01 1
54
+#define B10 2
55
+
56
+#include "hardware/Clock.h"
57
+
58
+#include <Arduino.h>
59
+
60
+#include "../shared/math_32bit.h"
61
+#include "../shared/HAL_SPI.h"
62
+#include "fastio.h"
63
+#include "watchdog.h"
64
+#include "HAL_timers.h"
65
+#include "serial.h"
66
+
67
+extern HalSerial usb_serial;
68
+#define MYSERIAL0 usb_serial
69
+#define NUM_SERIAL 1
70
+
71
+#define ST7920_DELAY_1 DELAY_NS(600)
72
+#define ST7920_DELAY_2 DELAY_NS(750)
73
+#define ST7920_DELAY_3 DELAY_NS(750)
74
+
75
+//
76
+// Interrupts
77
+//
78
+#define CRITICAL_SECTION_START
79
+#define CRITICAL_SECTION_END
80
+#define ISRS_ENABLED()
81
+#define ENABLE_ISRS()
82
+#define DISABLE_ISRS()
83
+
84
+//Utility functions
85
+int freeMemory(void);
86
+
87
+// SPI: Extended functions which take a channel number (hardware SPI only)
88
+/** Write single byte to specified SPI channel */
89
+void spiSend(uint32_t chan, byte b);
90
+/** Write buffer to specified SPI channel */
91
+void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
92
+/** Read single byte from specified SPI channel */
93
+uint8_t spiRec(uint32_t chan);
94
+
95
+// ADC
96
+#define HAL_ANALOG_SELECT(pin) HAL_adc_enable_channel(pin)
97
+#define HAL_START_ADC(pin)     HAL_adc_start_conversion(pin)
98
+#define HAL_READ_ADC()         HAL_adc_get_result()
99
+#define HAL_ADC_READY()        true
100
+
101
+void HAL_adc_init(void);
102
+void HAL_adc_enable_channel(int pin);
103
+void HAL_adc_start_conversion(const uint8_t adc_pin);
104
+uint16_t HAL_adc_get_result(void);
105
+
106
+/* ---------------- Delay in cycles */
107
+FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
108
+  Clock::delayCycles(x);
109
+}

+ 73
- 0
Marlin/src/HAL/HAL_LINUX/HAL_timers.cpp Visa fil

@@ -0,0 +1,73 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "hardware/Timer.h"
26
+
27
+#include "../../inc/MarlinConfig.h"
28
+#include "HAL_timers.h"
29
+
30
+/**
31
+ * Use POSIX signals to attempt to emulate Interrupts
32
+ * This has many limitations and is not fit for the purpose
33
+ */
34
+
35
+HAL_STEP_TIMER_ISR;
36
+HAL_TEMP_TIMER_ISR;
37
+
38
+Timer timers[2];
39
+
40
+void HAL_timer_init(void) {
41
+  timers[0].init(0, STEPPER_TIMER_RATE, TIMER0_IRQHandler);
42
+  timers[1].init(1, TEMP_TIMER_RATE, TIMER1_IRQHandler);
43
+}
44
+
45
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
46
+  timers[timer_num].start(frequency);
47
+}
48
+
49
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
50
+  timers[timer_num].enable();
51
+}
52
+
53
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
54
+  timers[timer_num].disable();
55
+}
56
+
57
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
58
+  return timers[timer_num].enabled();
59
+}
60
+
61
+void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
62
+  timers[timer_num].setCompare(compare);
63
+}
64
+
65
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
66
+  return timers[timer_num].getCompare();
67
+}
68
+
69
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
70
+  return timers[timer_num].getCount();
71
+}
72
+
73
+#endif // __PLAT_LINUX__

+ 91
- 0
Marlin/src/HAL/HAL_LINUX/HAL_timers.h Visa fil

@@ -0,0 +1,91 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
19
+ *
20
+ */
21
+#pragma once
22
+
23
+/**
24
+ * HAL timers for Linux X86_64
25
+ */
26
+
27
+// --------------------------------------------------------------------------
28
+// Includes
29
+// --------------------------------------------------------------------------
30
+
31
+#include <stdint.h>
32
+
33
+// --------------------------------------------------------------------------
34
+// Defines
35
+// --------------------------------------------------------------------------
36
+
37
+#define FORCE_INLINE __attribute__((always_inline)) inline
38
+
39
+typedef uint32_t hal_timer_t;
40
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
41
+
42
+#define HAL_TIMER_RATE         ((SystemCoreClock) / 4)  // frequency of timers peripherals
43
+
44
+#define STEP_TIMER_NUM 0  // Timer Index for Stepper
45
+#define TEMP_TIMER_NUM 1  // Timer Index for Temperature
46
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
47
+
48
+#define TEMP_TIMER_RATE        1000000
49
+#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
50
+
51
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
52
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
53
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
54
+
55
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
56
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
57
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
58
+
59
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
60
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
61
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
62
+
63
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
64
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
65
+
66
+#define HAL_STEP_TIMER_ISR  extern "C" void TIMER0_IRQHandler(void)
67
+#define HAL_TEMP_TIMER_ISR  extern "C" void TIMER1_IRQHandler(void)
68
+
69
+// PWM timer
70
+#define HAL_PWM_TIMER
71
+#define HAL_PWM_TIMER_ISR  extern "C" void TIMER3_IRQHandler(void)
72
+#define HAL_PWM_TIMER_IRQn
73
+
74
+
75
+void HAL_timer_init(void);
76
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
77
+
78
+void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare);
79
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
80
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
81
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
82
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
83
+  if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
84
+}
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)

+ 67
- 0
Marlin/src/HAL/HAL_LINUX/SanityCheck.h Visa fil

@@ -0,0 +1,67 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Test X86_64 configuration values for errors at compile-time.
25
+ */
26
+
27
+#if ENABLED(SPINDLE_LASER_ENABLE)
28
+  #if !PIN_EXISTS(SPINDLE_LASER_ENABLE)
29
+    #error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENABLE_PIN."
30
+  #elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
31
+    #error "SPINDLE_DIR_PIN not defined."
32
+  #elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
33
+    #if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
34
+      #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
35
+    #elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
36
+      #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
37
+    #elif SPINDLE_LASER_POWERUP_DELAY < 1
38
+      #error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
39
+    #elif SPINDLE_LASER_POWERDOWN_DELAY < 1
40
+      #error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
41
+    #elif !defined(SPINDLE_LASER_PWM_INVERT)
42
+      #error "SPINDLE_LASER_PWM_INVERT missing."
43
+    #elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
44
+      #error "SPINDLE_LASER_PWM equation constant(s) missing."
45
+    #elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
46
+      #error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
47
+    #elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
48
+      #error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
49
+    #elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
50
+      #error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
51
+    #elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
52
+      #error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
53
+    #elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
54
+      #error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
55
+    #elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
56
+      #error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
57
+    #elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
58
+      #error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
59
+    #elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
60
+      #error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
61
+    #elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
62
+      #error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
63
+    #elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
64
+      #error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
65
+    #endif
66
+  #endif
67
+#endif // SPINDLE_LASER_ENABLE

+ 116
- 0
Marlin/src/HAL/HAL_LINUX/arduino.cpp Visa fil

@@ -0,0 +1,116 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include <iostream>
26
+#include "../../inc/MarlinConfig.h"
27
+#include "hardware/Clock.h"
28
+#include "../shared/Delay.h"
29
+
30
+// Interrupts
31
+void cli(void) { } // Disable
32
+void sei(void) { }  // Enable
33
+
34
+// Time functions
35
+void _delay_ms(const int delay_ms) {
36
+  delay(delay_ms);
37
+}
38
+
39
+uint32_t millis() {
40
+  return (uint32_t)Clock::millis();
41
+}
42
+
43
+// This is required for some Arduino libraries we are using
44
+void delayMicroseconds(uint32_t us) {
45
+  Clock::delayMicros(us);
46
+}
47
+
48
+extern "C" void delay(const int msec) {
49
+  Clock::delayMillis(msec);
50
+}
51
+
52
+// IO functions
53
+// As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
54
+void pinMode(const pin_t pin, const uint8_t mode) {
55
+  if (!VALID_PIN(pin)) return;
56
+  Gpio::setMode(pin, mode);
57
+}
58
+
59
+void digitalWrite(pin_t pin, uint8_t pin_status) {
60
+  if (!VALID_PIN(pin)) return;
61
+  Gpio::set(pin, pin_status);
62
+}
63
+
64
+bool digitalRead(pin_t pin) {
65
+  if (!VALID_PIN(pin)) return false;
66
+  return Gpio::get(pin);
67
+}
68
+
69
+void analogWrite(pin_t pin, int pwm_value) {  // 1 - 254: pwm_value, 0: LOW, 255: HIGH
70
+  if (!VALID_PIN(pin)) return;
71
+  Gpio::set(pin, pwm_value);
72
+}
73
+
74
+uint16_t analogRead(pin_t adc_pin) {
75
+  if (!VALID_PIN(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin))) return 0;
76
+  return Gpio::get(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin));
77
+}
78
+
79
+// **************************
80
+// Persistent Config Storage
81
+// **************************
82
+
83
+void eeprom_write_byte(unsigned char *pos, unsigned char value) {
84
+
85
+}
86
+
87
+unsigned char eeprom_read_byte(uint8_t * pos) { return '\0'; }
88
+
89
+void eeprom_read_block(void *__dst, const void *__src, size_t __n) { }
90
+
91
+void eeprom_update_block(const void *__src, void *__dst, size_t __n) { }
92
+
93
+char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s) {
94
+  char format_string[20];
95
+  snprintf(format_string, 20, "%%%d.%df", __width, __prec);
96
+  sprintf(__s, format_string, __val);
97
+  return __s;
98
+}
99
+
100
+int32_t random(int32_t max) {
101
+  return rand() % max;
102
+}
103
+
104
+int32_t random(int32_t min, int32_t max) {
105
+  return min + rand() % (max - min);
106
+}
107
+
108
+void randomSeed(uint32_t value) {
109
+  srand(value);
110
+}
111
+
112
+int map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) {
113
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
114
+}
115
+
116
+#endif // __PLAT_LINUX__

+ 123
- 0
Marlin/src/HAL/HAL_LINUX/fastio.h Visa fil

@@ -0,0 +1,123 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * Fast I/O Routines for X86_64
26
+ */
27
+
28
+#include <Arduino.h>
29
+#include <pinmapping.h>
30
+
31
+#define USEABLE_HARDWARE_PWM(pin) false
32
+
33
+#define SET_DIR_INPUT(IO)   Gpio::setDir(IO, 1)
34
+#define SET_DIR_OUTPUT(IO)  Gpio::setDir(IO, 0)
35
+
36
+#define SET_MODE(IO, mode)  Gpio::setMode(IO, mode)
37
+
38
+#define WRITE_PIN_SET(IO)   Gpio::set(IO)
39
+#define WRITE_PIN_CLR(IO)   Gpio::clear(IO)
40
+
41
+#define READ_PIN(IO)        Gpio::get(IO)
42
+#define WRITE_PIN(IO,V)     Gpio::set(IO, V)
43
+
44
+/**
45
+ * Magic I/O routines
46
+ *
47
+ * Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
48
+ *
49
+ * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
50
+ */
51
+
52
+/// Read a pin
53
+#define _READ(IO)         READ_PIN(IO)
54
+
55
+/// Write to a pin
56
+#define _WRITE_VAR(IO,V)  digitalWrite(IO,V)
57
+
58
+#define _WRITE(IO,V)      WRITE_PIN(IO,V)
59
+
60
+/// toggle a pin
61
+#define _TOGGLE(IO)       _WRITE(IO, !READ(IO))
62
+
63
+/// set pin as input
64
+#define _SET_INPUT(IO)    SET_DIR_INPUT(IO)
65
+
66
+/// set pin as output
67
+#define _SET_OUTPUT(IO)   SET_DIR_OUTPUT(IO)
68
+
69
+/// set pin as input with pullup mode
70
+#define _PULLUP(IO,V)     pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
71
+
72
+/// set pin as input with pulldown mode
73
+#define _PULLDOWN(IO,V)   pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
74
+
75
+// hg42: all pins can be input or output (I hope)
76
+// hg42: undefined pins create compile error (IO, is no pin)
77
+// hg42: currently not used, but was used by pinsDebug
78
+
79
+/// check if pin is an input
80
+#define _GET_INPUT(IO)    (LPC1768_PIN_PIN(IO) >= 0)
81
+
82
+/// check if pin is an output
83
+#define _GET_OUTPUT(IO)   (LPC1768_PIN_PIN(IO) >= 0)
84
+
85
+// hg42: GET_TIMER is used only to check if it's a PWM pin
86
+// hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
87
+// hg42: instead use PWM bit from the #define
88
+
89
+/// check if pin is a timer
90
+#define _GET_TIMER(IO)    TRUE  // could be LPC1768_PIN_PWM(IO), but there
91
+// hg42: could be this:
92
+// #define _GET_TIMER(IO)        LPC1768_PIN_PWM(IO)
93
+// but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
94
+
95
+/// Read a pin wrapper
96
+#define READ(IO)          _READ(IO)
97
+
98
+/// Write to a pin wrapper
99
+#define WRITE_VAR(IO,V)   _WRITE_VAR(IO,V)
100
+#define WRITE(IO,V)       _WRITE(IO,V)
101
+
102
+/// toggle a pin wrapper
103
+#define TOGGLE(IO)        _TOGGLE(IO)
104
+
105
+/// set pin as input wrapper
106
+#define SET_INPUT(IO)     _SET_INPUT(IO)
107
+/// set pin as input with pullup wrapper
108
+#define SET_INPUT_PULLUP(IO)    do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
109
+/// set pin as input with pulldown wrapper
110
+#define SET_INPUT_PULLDOWN(IO)  do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
111
+/// set pin as output wrapper  -  reads the pin and sets the output to that value
112
+#define SET_OUTPUT(IO)          do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
113
+
114
+/// check if pin is an input wrapper
115
+#define GET_INPUT(IO)     _GET_INPUT(IO)
116
+/// check if pin is an output wrapper
117
+#define GET_OUTPUT(IO)    _GET_OUTPUT(IO)
118
+
119
+/// check if pin is a timer (wrapper)
120
+#define GET_TIMER(IO)     _GET_TIMER(IO)
121
+
122
+// Shorthand
123
+#define OUT_WRITE(IO,V)   do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)

+ 32
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Clock.cpp Visa fil

@@ -0,0 +1,32 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "../../../inc/MarlinConfig.h"
26
+#include "Clock.h"
27
+
28
+std::chrono::nanoseconds Clock::startup = std::chrono::high_resolution_clock::now().time_since_epoch();
29
+uint32_t Clock::frequency = F_CPU;
30
+double Clock::time_multiplier = 1.0;
31
+
32
+#endif // __PLAT_LINUX__

+ 89
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Clock.h Visa fil

@@ -0,0 +1,89 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <chrono>
25
+#include <thread>
26
+
27
+class Clock {
28
+public:
29
+  static uint64_t ticks(uint32_t frequency = Clock::frequency) {
30
+    return (Clock::nanos() - Clock::startup.count()) / (1000000000ULL / frequency);
31
+  }
32
+
33
+  static uint64_t nanosToTicks(uint64_t ns, uint32_t frequency = Clock::frequency) {
34
+    return ns / (1000000000ULL / frequency);
35
+  }
36
+
37
+  // Time acceleration compensated
38
+  static uint64_t ticksToNanos(uint64_t tick, uint32_t frequency = Clock::frequency) {
39
+    return (tick * (1000000000ULL / frequency)) / Clock::time_multiplier;
40
+  }
41
+
42
+  static void setFrequency(uint32_t freq) {
43
+    Clock::frequency = freq;
44
+  }
45
+
46
+  // Time Acceleration compensated
47
+  static uint64_t nanos() {
48
+    auto now = std::chrono::high_resolution_clock::now().time_since_epoch();
49
+    return (now.count() - Clock::startup.count()) * Clock::time_multiplier;
50
+  }
51
+
52
+  static uint64_t micros() {
53
+    return Clock::nanos() / 1000;
54
+  }
55
+
56
+  static uint64_t millis() {
57
+    return Clock::micros() / 1000;
58
+  }
59
+
60
+  static double seconds() {
61
+    return Clock::nanos() / 1000000000.0;
62
+  }
63
+
64
+  static void delayCycles(uint64_t cycles) {
65
+    std::this_thread::sleep_for(std::chrono::nanoseconds( (1000000000L / frequency) * cycles) / Clock::time_multiplier );
66
+  }
67
+
68
+  static void delayMicros(uint64_t micros) {
69
+    std::this_thread::sleep_for(std::chrono::microseconds( micros ) / Clock::time_multiplier);
70
+  }
71
+
72
+  static void delayMillis(uint64_t millis) {
73
+    std::this_thread::sleep_for(std::chrono::milliseconds( millis ) / Clock::time_multiplier);
74
+  }
75
+
76
+  static void delaySeconds(double secs) {
77
+    std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(secs * 1000) / Clock::time_multiplier);
78
+  }
79
+
80
+  // Will reduce timer resolution increasing likelihood of overflows
81
+  static void setTimeMultiplier(double tm) {
82
+    Clock::time_multiplier = tm;
83
+  }
84
+
85
+private:
86
+  static std::chrono::nanoseconds startup;
87
+  static uint32_t frequency;
88
+  static double time_multiplier;
89
+};

+ 30
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Gpio.cpp Visa fil

@@ -0,0 +1,30 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "Gpio.h"
26
+
27
+pin_data Gpio::pin_map[Gpio::pin_count+1] = {};
28
+IOLogger* Gpio::logger = nullptr;
29
+
30
+#endif // __PLAT_LINUX__

+ 141
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Gpio.h Visa fil

@@ -0,0 +1,141 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "Clock.h"
25
+#include "../../../inc/MarlinConfigPre.h"
26
+#include <stdint.h>
27
+
28
+typedef int16_t pin_type;
29
+
30
+struct GpioEvent {
31
+  enum Type {
32
+    NOP,
33
+    FALL,
34
+    RISE,
35
+    SET_VALUE,
36
+    SETM,
37
+    SETD
38
+  };
39
+  uint64_t timestamp;
40
+  pin_type pin_id;
41
+  GpioEvent::Type event;
42
+
43
+  GpioEvent(uint64_t timestamp, pin_type pin_id, GpioEvent::Type event){
44
+    this->timestamp = timestamp;
45
+    this->pin_id = pin_id;
46
+    this->event = event;
47
+  }
48
+};
49
+
50
+class IOLogger {
51
+public:
52
+  virtual ~IOLogger(){};
53
+  virtual void log(GpioEvent ev) = 0;
54
+};
55
+
56
+class Peripheral {
57
+public:
58
+  virtual ~Peripheral(){};
59
+  virtual void interrupt(GpioEvent ev) = 0;
60
+  virtual void update() = 0;
61
+};
62
+
63
+struct pin_data {
64
+  uint8_t dir;
65
+  uint8_t mode;
66
+  uint16_t value;
67
+  Peripheral* cb;
68
+};
69
+
70
+class Gpio {
71
+public:
72
+
73
+  static const pin_type pin_count = 255;
74
+  static pin_data pin_map[pin_count+1];
75
+
76
+  static bool valid_pin(pin_type pin) {
77
+    return pin >= 0 && pin <= pin_count;
78
+  }
79
+
80
+  static void set(pin_type pin) {
81
+    set(pin, 1);
82
+  }
83
+
84
+  static void set(pin_type pin, uint16_t value) {
85
+    if (!valid_pin(pin)) return;
86
+    GpioEvent::Type evt_type = value > 1 ? GpioEvent::SET_VALUE : value > pin_map[pin].value ? GpioEvent::RISE : value < pin_map[pin].value ? GpioEvent::FALL : GpioEvent::NOP;
87
+    pin_map[pin].value = value;
88
+    GpioEvent evt(Clock::nanos(), pin, evt_type);
89
+    if (pin_map[pin].cb != nullptr) {
90
+      pin_map[pin].cb->interrupt(evt);
91
+    }
92
+    if (Gpio::logger != nullptr) Gpio::logger->log(evt);
93
+  }
94
+
95
+  static uint16_t get(pin_type pin) {
96
+    if (!valid_pin(pin)) return 0;
97
+    return pin_map[pin].value;
98
+  }
99
+
100
+  static void clear(pin_type pin) {
101
+    set(pin, 0);
102
+  }
103
+
104
+  static void setMode(pin_type pin, uint8_t value) {
105
+    if (!valid_pin(pin)) return;
106
+    pin_map[pin].mode = value;
107
+    GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETM);
108
+    if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt);
109
+    if (Gpio::logger != nullptr) Gpio::logger->log(evt);
110
+  }
111
+
112
+  static uint8_t getMode(pin_type pin) {
113
+    if (!valid_pin(pin)) return 0;
114
+    return pin_map[pin].mode;
115
+  }
116
+
117
+  static void setDir(pin_type pin, uint8_t value) {
118
+    if (!valid_pin(pin)) return;
119
+    pin_map[pin].dir = value;
120
+    GpioEvent evt(Clock::nanos(), pin, GpioEvent::Type::SETD);
121
+    if (pin_map[pin].cb != nullptr) pin_map[pin].cb->interrupt(evt);
122
+    if (Gpio::logger != nullptr) Gpio::logger->log(evt);
123
+  }
124
+
125
+  static uint8_t getDir(pin_type pin) {
126
+    if (!valid_pin(pin)) return 0;
127
+    return pin_map[pin].dir;
128
+  }
129
+
130
+  static void attachPeripheral(pin_type pin, Peripheral* per) {
131
+    if (!valid_pin(pin)) return;
132
+    pin_map[pin].cb = per;
133
+  }
134
+
135
+  static void attachLogger(IOLogger* logger) {
136
+    Gpio::logger = logger;
137
+  }
138
+
139
+private:
140
+  static IOLogger* logger;
141
+};

+ 61
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Heater.cpp Visa fil

@@ -0,0 +1,61 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "Clock.h"
26
+#include <stdio.h>
27
+#include "../../../inc/MarlinConfig.h"
28
+
29
+#include "Heater.h"
30
+
31
+Heater::Heater(pin_t heater, pin_t adc) {
32
+  heater_state = 0;
33
+  room_temp_raw = 150;
34
+  last = Clock::micros();
35
+  heater_pin = heater;
36
+  adc_pin = adc;
37
+  heat = 0.0;
38
+}
39
+
40
+Heater::~Heater() {
41
+}
42
+
43
+void Heater::update() {
44
+  // crude pwm read and cruder heat simulation
45
+  auto now = Clock::micros();
46
+  double delta = (now - last);
47
+  if (delta > 1000 ) {
48
+    heater_state = pwmcap.update(0xFFFF * Gpio::pin_map[heater_pin].value);
49
+    last = now;
50
+    heat += (heater_state - heat) * (delta / 1000000000.0);
51
+
52
+    if (heat < room_temp_raw) heat = room_temp_raw;
53
+    Gpio::pin_map[analogInputToDigitalPin(adc_pin)].value = 0xFFFF - (uint16_t)heat;
54
+  }
55
+}
56
+
57
+void Heater::interrupt(GpioEvent ev) {
58
+  // ununsed
59
+}
60
+
61
+#endif // __PLAT_LINUX__

+ 47
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Heater.h Visa fil

@@ -0,0 +1,47 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "Gpio.h"
25
+
26
+struct LowpassFilter {
27
+  uint64_t data_delay = 0;
28
+  uint16_t update(uint16_t value) {
29
+    data_delay = data_delay - (data_delay >> 6) + value;
30
+    return (uint16_t)(data_delay >> 6);
31
+  }
32
+};
33
+
34
+class Heater: public Peripheral {
35
+public:
36
+  Heater(pin_t heater, pin_t adc);
37
+  virtual ~Heater();
38
+  void interrupt(GpioEvent ev);
39
+  void update();
40
+
41
+  pin_t heater_pin, adc_pin;
42
+  uint16_t room_temp_raw;
43
+  uint16_t heater_state;
44
+  LowpassFilter pwmcap;
45
+  double heat;
46
+  uint64_t last;
47
+};

+ 50
- 0
Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.cpp Visa fil

@@ -0,0 +1,50 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "IOLoggerCSV.h"
26
+
27
+IOLoggerCSV::IOLoggerCSV(std::string filename) {
28
+  file.open(filename);
29
+}
30
+
31
+IOLoggerCSV::~IOLoggerCSV() {
32
+  file.close();
33
+}
34
+
35
+void IOLoggerCSV::log(GpioEvent ev) {
36
+  std::lock_guard<std::mutex> lock(vector_lock);
37
+  events.push_back(ev); //minimal impact to signal handler
38
+}
39
+
40
+void IOLoggerCSV::flush() {
41
+  { std::lock_guard<std::mutex> lock(vector_lock);
42
+    while (!events.empty()) {
43
+      file << events.front().timestamp << ", "<< events.front().pin_id << ", " << events.front().event << std::endl;
44
+      events.pop_front();
45
+    }
46
+  }
47
+  file.flush();
48
+}
49
+
50
+#endif // __PLAT_LINUX__

+ 40
- 0
Marlin/src/HAL/HAL_LINUX/hardware/IOLoggerCSV.h Visa fil

@@ -0,0 +1,40 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <mutex>
25
+#include <list>
26
+#include <fstream>
27
+#include "Gpio.h"
28
+
29
+class IOLoggerCSV: public IOLogger {
30
+public:
31
+  IOLoggerCSV(std::string filename);
32
+  virtual ~IOLoggerCSV();
33
+  void flush();
34
+  void log(GpioEvent ev);
35
+
36
+private:
37
+  std::ofstream file;
38
+  std::list<GpioEvent> events;
39
+  std::mutex vector_lock;
40
+};

+ 66
- 0
Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.cpp Visa fil

@@ -0,0 +1,66 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include <random>
26
+#include <stdio.h>
27
+#include "Clock.h"
28
+#include "LinearAxis.h"
29
+
30
+LinearAxis::LinearAxis(pin_type enable, pin_type dir, pin_type step, pin_type end_min, pin_type end_max) {
31
+  enable_pin = enable;
32
+  dir_pin = dir;
33
+  step_pin = step;
34
+  min_pin = end_min;
35
+  max_pin = end_max;
36
+
37
+  min_position = 50;
38
+  max_position = (200*80) + min_position;
39
+  position = rand() % ((max_position - 40) - min_position) + (min_position + 20);
40
+  last_update = Clock::nanos();
41
+
42
+  Gpio::attachPeripheral(step_pin, this);
43
+
44
+}
45
+
46
+LinearAxis::~LinearAxis() {
47
+
48
+}
49
+
50
+void LinearAxis::update() {
51
+
52
+}
53
+
54
+void LinearAxis::interrupt(GpioEvent ev) {
55
+  if (ev.pin_id == step_pin && !Gpio::pin_map[enable_pin].value){
56
+    if (ev.event == GpioEvent::RISE) {
57
+      last_update = ev.timestamp;
58
+      position += -1 + 2 * Gpio::pin_map[dir_pin].value;
59
+      Gpio::pin_map[min_pin].value = (position < min_position);
60
+      //Gpio::pin_map[max_pin].value = (position > max_position);
61
+      //if(position < min_position) printf("axis(%d) endstop : pos: %d, mm: %f, min: %d\n", step_pin, position, position / 80.0, Gpio::pin_map[min_pin].value);
62
+    }
63
+  }
64
+}
65
+
66
+#endif // __PLAT_LINUX__

+ 45
- 0
Marlin/src/HAL/HAL_LINUX/hardware/LinearAxis.h Visa fil

@@ -0,0 +1,45 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <chrono>
25
+#include "Gpio.h"
26
+
27
+class LinearAxis: public Peripheral {
28
+public:
29
+  LinearAxis(pin_type enable, pin_type dir, pin_type step, pin_type end_min, pin_type end_max);
30
+  virtual ~LinearAxis();
31
+  void update();
32
+  void interrupt(GpioEvent ev);
33
+
34
+  pin_type enable_pin;
35
+  pin_type dir_pin;
36
+  pin_type step_pin;
37
+  pin_type min_pin;
38
+  pin_type max_pin;
39
+
40
+  int32_t position;
41
+  int32_t min_position;
42
+  int32_t max_position;
43
+  uint64_t last_update;
44
+
45
+};

+ 118
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Timer.cpp Visa fil

@@ -0,0 +1,118 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "Timer.h"
26
+#include <stdio.h>
27
+
28
+Timer::Timer() {
29
+  active = false;
30
+  compare = 0;
31
+  frequency = 0;
32
+  overruns = 0;
33
+  timerid = 0;
34
+  cbfn = nullptr;
35
+  period = 0;
36
+  start_time = 0;
37
+  avg_error = 0;
38
+}
39
+
40
+Timer::~Timer() {
41
+  timer_delete(timerid);
42
+}
43
+
44
+void Timer::init(uint32_t sig_id, uint32_t sim_freq, callback_fn* fn) {
45
+  struct sigaction sa;
46
+  struct sigevent sev;
47
+
48
+  frequency = sim_freq;
49
+  cbfn = fn;
50
+
51
+  sa.sa_flags = SA_SIGINFO;
52
+  sa.sa_sigaction = Timer::handler;
53
+  sigemptyset(&sa.sa_mask);
54
+  if (sigaction(SIGRTMIN, &sa, NULL) == -1) {
55
+    return; // todo: handle error
56
+  }
57
+
58
+  sigemptyset(&mask);
59
+  sigaddset(&mask, SIGRTMIN);
60
+
61
+  disable();
62
+
63
+  sev.sigev_notify = SIGEV_SIGNAL;
64
+  sev.sigev_signo = SIGRTMIN;
65
+  sev.sigev_value.sival_ptr = (void*)this;
66
+  if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) {
67
+    return; // todo: handle error
68
+  }
69
+}
70
+
71
+void Timer::start(uint32_t frequency) {
72
+  setCompare(this->frequency / frequency);
73
+  //printf("timer(%ld) started\n", getID());
74
+}
75
+
76
+void Timer::enable() {
77
+  if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) {
78
+    return; // todo: handle error
79
+  }
80
+  active = true;
81
+  //printf("timer(%ld) enabled\n", getID());
82
+}
83
+
84
+void Timer::disable() {
85
+  if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
86
+    return; // todo: handle error
87
+  }
88
+  active = false;
89
+}
90
+
91
+void Timer::setCompare(uint32_t compare) {
92
+  uint32_t nsec_offset = 0;
93
+  if (active) {
94
+    nsec_offset = Clock::nanos() - this->start_time; // calculate how long the timer would have been running for
95
+    nsec_offset = nsec_offset < 1000 ? nsec_offset : 0; // constrain, this shouldn't be needed but apparently Marlin enables interrupts on the stepper timer before initialising it, todo: investigate ?bug?
96
+  }
97
+  this->compare = compare;
98
+  uint64_t ns = Clock::ticksToNanos(compare, frequency) - nsec_offset;
99
+  struct itimerspec its;
100
+  its.it_value.tv_sec = ns / 1000000000;
101
+  its.it_value.tv_nsec = ns % 1000000000;
102
+  its.it_interval.tv_sec = its.it_value.tv_sec;
103
+  its.it_interval.tv_nsec = its.it_value.tv_nsec;
104
+
105
+  if (timer_settime(timerid, 0, &its, NULL) == -1) {
106
+    printf("timer(%ld) failed, compare: %d(%ld)\n", getID(), compare, its.it_value.tv_nsec);
107
+    return; // todo: handle error
108
+  }
109
+  //printf("timer(%ld) started, compare: %d(%d)\n", getID(), compare, its.it_value.tv_nsec);
110
+  this->period = its.it_value.tv_nsec;
111
+  this->start_time = Clock::nanos();
112
+}
113
+
114
+uint32_t Timer::getCount() {
115
+  return Clock::nanosToTicks(Clock::nanos() - this->start_time, frequency);
116
+}
117
+
118
+#endif // __PLAT_LINUX__

+ 76
- 0
Marlin/src/HAL/HAL_LINUX/hardware/Timer.h Visa fil

@@ -0,0 +1,76 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <stdint.h>
25
+#include <stdlib.h>
26
+#include <unistd.h>
27
+#include <signal.h>
28
+#include <time.h>
29
+#include <stdio.h>
30
+
31
+#include "Clock.h"
32
+
33
+class Timer {
34
+public:
35
+  Timer();
36
+  virtual ~Timer();
37
+
38
+  typedef void (callback_fn)();
39
+
40
+  void init(uint32_t sig_id, uint32_t sim_freq, callback_fn* fn);
41
+  void start(uint32_t frequency);
42
+  void enable();
43
+  bool enabled() {return active;}
44
+  void disable();
45
+  void setCompare(uint32_t compare);
46
+  uint32_t getCount();
47
+  uint32_t getCompare() {return compare;}
48
+  uint32_t getOverruns() {return overruns;}
49
+  uint32_t getAvgError() {return avg_error;}
50
+
51
+  intptr_t getID() {
52
+    return (*(intptr_t*)timerid);
53
+  }
54
+
55
+  static void handler(int sig, siginfo_t *si, void *uc){
56
+    Timer* _this = (Timer*)si->si_value.sival_ptr;
57
+    _this->avg_error += (Clock::nanos() - _this->start_time) - _this->period; //high_resolution_clock is also limited in precision, but best we have
58
+    _this->avg_error /= 2; //very crude precision analysis (actually within +-500ns usually)
59
+    _this->start_time = Clock::nanos(); // wrap
60
+    _this->cbfn();
61
+    _this->overruns += timer_getoverrun(_this->timerid); // even at 50Khz this doesn't stay zero, again demonstrating the limitations
62
+                                                         // using a realtime linux kernel would help somewhat
63
+  }
64
+
65
+private:
66
+  bool active;
67
+  uint32_t compare;
68
+  uint32_t frequency;
69
+  uint32_t overruns;
70
+  timer_t timerid;
71
+  sigset_t mask;
72
+  callback_fn* cbfn;
73
+  uint64_t period;
74
+  uint64_t avg_error;
75
+  uint64_t start_time;
76
+};

+ 125
- 0
Marlin/src/HAL/HAL_LINUX/include/Arduino.h Visa fil

@@ -0,0 +1,125 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include <stddef.h>
25
+#include <stdint.h>
26
+#include <math.h>
27
+#include <cstring>
28
+
29
+#include <pinmapping.h>
30
+
31
+#define HIGH         0x01
32
+#define LOW          0x00
33
+
34
+#define INPUT          0x00
35
+#define OUTPUT         0x01
36
+#define INPUT_PULLUP   0x02
37
+#define INPUT_PULLDOWN 0x03
38
+
39
+#define LSBFIRST     0
40
+#define MSBFIRST     1
41
+
42
+#define CHANGE       0x02
43
+#define FALLING      0x03
44
+#define RISING       0x04
45
+
46
+#define E2END 0xFFF // EEPROM end address
47
+
48
+typedef uint8_t byte;
49
+#define PROGMEM
50
+#define PSTR(v) (v)
51
+#define PGM_P const char *
52
+
53
+// Used for libraries, preprocessor, and constants
54
+#define min(a,b) ((a)<(b)?(a):(b))
55
+#define max(a,b) ((a)>(b)?(a):(b))
56
+#define abs(x) ((x)>0?(x):-(x))
57
+
58
+#ifndef isnan
59
+  #define isnan std::isnan
60
+#endif
61
+#ifndef isinf
62
+  #define isinf std::isinf
63
+#endif
64
+
65
+#define sq(v) ((v) * (v))
66
+#define square(v) sq(v)
67
+#define constrain(value, arg_min, arg_max) ((value) < (arg_min) ? (arg_min) :((value) > (arg_max) ? (arg_max) : (value)))
68
+
69
+//Interrupts
70
+void cli(void); // Disable
71
+void sei(void); // Enable
72
+void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);
73
+void detachInterrupt(uint32_t pin);
74
+extern "C" void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode);
75
+extern "C" void GpioDisableInt(uint32_t port, uint32_t pin);
76
+
77
+// Program Memory
78
+#define pgm_read_ptr(addr)        (*((void**)(addr)))
79
+#define pgm_read_byte_near(addr)  (*((uint8_t*)(addr)))
80
+#define pgm_read_float_near(addr) (*((float*)(addr)))
81
+#define pgm_read_word_near(addr)  (*((uint16_t*)(addr)))
82
+#define pgm_read_dword_near(addr) (*((uint32_t*)(addr)))
83
+#define pgm_read_byte(addr)       pgm_read_byte_near(addr)
84
+#define pgm_read_float(addr)      pgm_read_float_near(addr)
85
+#define pgm_read_word(addr)       pgm_read_word_near(addr)
86
+#define pgm_read_dword(addr)      pgm_read_dword_near(addr)
87
+
88
+using std::memcpy;
89
+#define memcpy_P memcpy
90
+#define sprintf_P sprintf
91
+#define strstr_P strstr
92
+#define strncpy_P strncpy
93
+#define vsnprintf_P vsnprintf
94
+#define strcpy_P strcpy
95
+#define snprintf_P snprintf
96
+#define strlen_P strlen
97
+
98
+// Time functions
99
+extern "C" {
100
+  void delay(const int milis);
101
+}
102
+void _delay_ms(const int delay);
103
+void delayMicroseconds(unsigned long);
104
+uint32_t millis();
105
+
106
+//IO functions
107
+void pinMode(const pin_t, const uint8_t);
108
+void digitalWrite(pin_t, uint8_t);
109
+bool digitalRead(pin_t);
110
+void analogWrite(pin_t, int);
111
+uint16_t analogRead(pin_t);
112
+
113
+// EEPROM
114
+void eeprom_write_byte(unsigned char *pos, unsigned char value);
115
+unsigned char eeprom_read_byte(unsigned char *pos);
116
+void eeprom_read_block (void *__dst, const void *__src, size_t __n);
117
+void eeprom_update_block (const void *__src, void *__dst, size_t __n);
118
+
119
+int32_t random(int32_t);
120
+int32_t random(int32_t, int32_t);
121
+void randomSeed(uint32_t);
122
+
123
+char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);
124
+
125
+int map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);

+ 70
- 0
Marlin/src/HAL/HAL_LINUX/include/pinmapping.cpp Visa fil

@@ -0,0 +1,70 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include <pinmapping.h>
26
+
27
+#include "../../../gcode/parser.h"
28
+
29
+uint8_t analog_offset = NUM_DIGITAL_PINS - NUM_ANALOG_INPUTS;
30
+
31
+// Get the digital pin for an analog index
32
+pin_t analogInputToDigitalPin(const int8_t p) {
33
+  return (WITHIN(p, 0, NUM_ANALOG_INPUTS) ? analog_offset + p : P_NC);
34
+}
35
+
36
+// Return the index of a pin number
37
+int16_t GET_PIN_MAP_INDEX(const pin_t pin) {
38
+  return pin;
39
+}
40
+
41
+// Test whether the pin is valid
42
+bool VALID_PIN(const pin_t p) {
43
+  return WITHIN(p, 0, NUM_DIGITAL_PINS);
44
+}
45
+
46
+// Get the analog index for a digital pin
47
+int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p) {
48
+  return (WITHIN(p, analog_offset, NUM_DIGITAL_PINS) ? p - analog_offset : P_NC);
49
+}
50
+
51
+// Test whether the pin is PWM
52
+bool PWM_PIN(const pin_t p) {
53
+  return false;
54
+}
55
+
56
+// Test whether the pin is interruptable
57
+bool INTERRUPT_PIN(const pin_t p) {
58
+  return false;
59
+}
60
+
61
+// Get the pin number at the given index
62
+pin_t GET_PIN_MAP_PIN(const int16_t ind) {
63
+  return ind;
64
+}
65
+
66
+int16_t PARSED_PIN_INDEX(const char code, const int16_t dval) {
67
+  return parser.intval(code, dval);
68
+}
69
+
70
+#endif // __PLAT_LINUX__

+ 59
- 0
Marlin/src/HAL/HAL_LINUX/include/pinmapping.h Visa fil

@@ -0,0 +1,59 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../../inc/MarlinConfigPre.h"
25
+
26
+#include <stdint.h>
27
+#include "../hardware/Gpio.h"
28
+
29
+typedef pin_type pin_t;
30
+
31
+#define P_NC -1
32
+constexpr uint16_t NUM_DIGITAL_PINS = Gpio::pin_count;
33
+constexpr uint8_t NUM_ANALOG_INPUTS = 16;
34
+
35
+#define HAL_SENSITIVE_PINS
36
+
37
+// Get the digital pin for an analog index
38
+pin_t analogInputToDigitalPin(const int8_t p);
39
+
40
+// Return the index of a pin number
41
+int16_t GET_PIN_MAP_INDEX(const pin_t pin);
42
+
43
+// Test whether the pin is valid
44
+bool VALID_PIN(const pin_t p);
45
+
46
+// Get the analog index for a digital pin
47
+int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p);
48
+
49
+// Test whether the pin is PWM
50
+bool PWM_PIN(const pin_t p);
51
+
52
+// Test whether the pin is interruptable
53
+bool INTERRUPT_PIN(const pin_t p);
54
+
55
+// Get the pin number at the given index
56
+pin_t GET_PIN_MAP_PIN(const int16_t ind);
57
+
58
+// Parse a G-code word into a pin index
59
+int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);

+ 207
- 0
Marlin/src/HAL/HAL_LINUX/include/serial.h Visa fil

@@ -0,0 +1,207 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../../inc/MarlinConfigPre.h"
25
+#if ENABLED(EMERGENCY_PARSER)
26
+  #include "../../../feature/emergency_parser.h"
27
+#endif
28
+
29
+#include <stdarg.h>
30
+#include <stdio.h>
31
+
32
+/**
33
+ * Generic RingBuffer
34
+ * T type of the buffer array
35
+ * S size of the buffer (must be power of 2)
36
+ *
37
+ */
38
+template <typename T, uint32_t S> class RingBuffer {
39
+public:
40
+  RingBuffer() { index_read = index_write = 0; }
41
+  uint32_t available() volatile { return index_write - index_read; }
42
+  uint32_t free() volatile      { return buffer_size - available(); }
43
+  bool empty() volatile         { return index_read == index_write; }
44
+  bool full() volatile          { return available() == buffer_size; }
45
+  void clear() volatile         { index_read = index_write = 0; }
46
+
47
+  bool peek(T *value) volatile {
48
+    if (value == 0 || available() == 0)
49
+      return false;
50
+    *value = buffer[mask(index_read)];
51
+    return true;
52
+  }
53
+
54
+  int read() volatile {
55
+    if (empty()) return -1;
56
+    return buffer[mask(index_read++)];
57
+  }
58
+
59
+  bool write(T value) volatile {
60
+    if (full()) return false;
61
+    buffer[mask(index_write++)] = value;
62
+    return true;
63
+  }
64
+
65
+private:
66
+  uint32_t mask(uint32_t val) volatile {
67
+    return buffer_mask & val;
68
+  }
69
+
70
+  static const uint32_t buffer_size = S;
71
+  static const uint32_t buffer_mask = buffer_size - 1;
72
+  volatile T buffer[buffer_size];
73
+  volatile uint32_t index_write;
74
+  volatile uint32_t index_read;
75
+};
76
+
77
+class HalSerial {
78
+public:
79
+
80
+  #if ENABLED(EMERGENCY_PARSER)
81
+    EmergencyParser::State emergency_state;
82
+  #endif
83
+
84
+  HalSerial() { host_connected = true; }
85
+
86
+  void begin(int32_t baud) {
87
+  }
88
+
89
+  int peek() {
90
+    uint8_t value;
91
+    return receive_buffer.peek(&value) ? value : -1;
92
+  }
93
+
94
+  int read() { return receive_buffer.read(); }
95
+
96
+  size_t write(char c) {
97
+    if (!host_connected) return 0;
98
+    while (!transmit_buffer.free());
99
+    return transmit_buffer.write(c);
100
+  }
101
+
102
+  operator bool() { return host_connected; }
103
+
104
+  uint16_t available() {
105
+    return (uint16_t)receive_buffer.available();
106
+  }
107
+
108
+  void flush() { receive_buffer.clear(); }
109
+
110
+  uint8_t availableForWrite(void){
111
+    return transmit_buffer.free() > 255 ? 255 : (uint8_t)transmit_buffer.free();
112
+  }
113
+
114
+  void flushTX(void){
115
+    if (host_connected)
116
+      while (transmit_buffer.available()) { /* nada */ }
117
+  }
118
+
119
+  void printf(const char *format, ...) {
120
+    static char buffer[256];
121
+    va_list vArgs;
122
+    va_start(vArgs, format);
123
+    int length = vsnprintf((char *) buffer, 256, (char const *) format, vArgs);
124
+    va_end(vArgs);
125
+    if (length > 0 && length < 256) {
126
+      if (host_connected) {
127
+        for (int i = 0; i < length;) {
128
+          if (transmit_buffer.write(buffer[i])) {
129
+            ++i;
130
+          }
131
+        }
132
+      }
133
+    }
134
+  }
135
+
136
+  #define DEC 10
137
+  #define HEX 16
138
+  #define OCT 8
139
+  #define BIN 2
140
+
141
+  void print_bin(uint32_t value, uint8_t num_digits) {
142
+    uint32_t mask = 1 << (num_digits -1);
143
+    for (uint8_t i = 0; i < num_digits; i++) {
144
+      if (!(i % 4) && i)    write(' ');
145
+      if (!(i % 16)  && i)  write(' ');
146
+      if (value & mask)     write('1');
147
+      else                  write('0');
148
+      value <<= 1;
149
+    }
150
+  }
151
+
152
+  void print(const char value[]) { printf("%s" , value); }
153
+  void print(char value, int nbase = 0) {
154
+    if (nbase == BIN) print_bin(value, 8);
155
+    else if (nbase == OCT) printf("%3o", value);
156
+    else if (nbase == HEX) printf("%2X", value);
157
+    else if (nbase == DEC ) printf("%d", value);
158
+    else printf("%c" , value);
159
+  }
160
+  void print(unsigned char value, int nbase = 0) {
161
+    if (nbase == BIN) print_bin(value, 8);
162
+    else if (nbase == OCT) printf("%3o", value);
163
+    else if (nbase == HEX) printf("%2X", value);
164
+    else printf("%u" , value);
165
+  }
166
+  void print(int value, int nbase = 0) {
167
+    if (nbase == BIN) print_bin(value, 16);
168
+    else if (nbase == OCT) printf("%6o", value);
169
+    else if (nbase == HEX) printf("%4X", value);
170
+    else printf("%d", value);
171
+  }
172
+  void print(unsigned int value, int nbase = 0) {
173
+    if (nbase == BIN) print_bin(value, 16);
174
+    else if (nbase == OCT) printf("%6o", value);
175
+    else if (nbase == HEX) printf("%4X", value);
176
+    else printf("%u" , value);
177
+  }
178
+  void print(long value, int nbase = 0) {
179
+    if (nbase == BIN) print_bin(value, 32);
180
+    else if (nbase == OCT) printf("%11o", value);
181
+    else if (nbase == HEX) printf("%8X", value);
182
+    else printf("%ld" , value);
183
+  }
184
+  void print(unsigned long value, int nbase = 0) {
185
+    if (nbase == BIN) print_bin(value, 32);
186
+    else if (nbase == OCT) printf("%11o", value);
187
+    else if (nbase == HEX) printf("%8X", value);
188
+    else printf("%lu" , value);
189
+  }
190
+  void print(float value, int round = 6)  { printf("%f" , value); }
191
+  void print(double value, int round = 6) { printf("%f" , value); }
192
+
193
+  void println(const char value[]) { printf("%s\n" , value); }
194
+  void println(char value, int nbase = 0) { print(value, nbase); println(); }
195
+  void println(unsigned char value, int nbase = 0) { print(value, nbase); println(); }
196
+  void println(int value, int nbase = 0) { print(value, nbase); println(); }
197
+  void println(unsigned int value, int nbase = 0) { print(value, nbase); println(); }
198
+  void println(long value, int nbase = 0) { print(value, nbase); println(); }
199
+  void println(unsigned long value, int nbase = 0) { print(value, nbase); println(); }
200
+  void println(float value, int round = 6) { printf("%f\n" , value); }
201
+  void println(double value, int round = 6) { printf("%f\n" , value); }
202
+  void println(void) { print('\n'); }
203
+
204
+  volatile RingBuffer<uint8_t, 128> receive_buffer;
205
+  volatile RingBuffer<uint8_t, 128> transmit_buffer;
206
+  volatile bool host_connected;
207
+};

+ 137
- 0
Marlin/src/HAL/HAL_LINUX/main.cpp Visa fil

@@ -0,0 +1,137 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+ *
19
+ */
20
+
21
+#ifdef __PLAT_LINUX__
22
+
23
+extern void setup();
24
+extern void loop();
25
+
26
+#include <thread>
27
+
28
+#include <iostream>
29
+#include <fstream>
30
+
31
+#include "../../inc/MarlinConfig.h"
32
+#include <stdio.h>
33
+#include <stdarg.h>
34
+#include "../shared/Delay.h"
35
+#include "hardware/IOLoggerCSV.h"
36
+#include "hardware/Heater.h"
37
+#include "hardware/LinearAxis.h"
38
+
39
+// simple stdout / stdin implementation for fake serial port
40
+void write_serial_thread() {
41
+  for (;;) {
42
+    for (std::size_t i = usb_serial.transmit_buffer.available(); i > 0; i--) {
43
+      fputc(usb_serial.transmit_buffer.read(), stdout);
44
+    }
45
+    std::this_thread::yield();
46
+  }
47
+}
48
+
49
+void read_serial_thread() {
50
+  char buffer[255] = {};
51
+  for (;;) {
52
+    std::size_t len = MIN(usb_serial.receive_buffer.free(), 254U);
53
+    if (fgets(buffer, len, stdin))
54
+      for (std::size_t i = 0; i < strlen(buffer); i++)
55
+        usb_serial.receive_buffer.write(buffer[i]);
56
+    std::this_thread::yield();
57
+  }
58
+}
59
+
60
+void simulation_loop() {
61
+  Heater hotend(HEATER_0_PIN, TEMP_0_PIN);
62
+  Heater bed(HEATER_BED_PIN, TEMP_BED_PIN);
63
+  LinearAxis x_axis(X_ENABLE_PIN, X_DIR_PIN, X_STEP_PIN, X_MIN_PIN, X_MAX_PIN);
64
+  LinearAxis y_axis(Y_ENABLE_PIN, Y_DIR_PIN, Y_STEP_PIN, Y_MIN_PIN, Y_MAX_PIN);
65
+  LinearAxis z_axis(Z_ENABLE_PIN, Z_DIR_PIN, Z_STEP_PIN, Z_MIN_PIN, Z_MAX_PIN);
66
+  LinearAxis extruder0(E0_ENABLE_PIN, E0_DIR_PIN, E0_STEP_PIN, P_NC, P_NC);
67
+
68
+  //#define GPIO_LOGGING // Full GPIO and Positional Logging
69
+
70
+  #ifdef GPIO_LOGGING
71
+    IOLoggerCSV logger("all_gpio_log.csv");
72
+    Gpio::attachLogger(&logger);
73
+
74
+    std::ofstream position_log;
75
+    position_log.open("axis_position_log.csv");
76
+
77
+    int32_t x,y,z;
78
+  #endif
79
+
80
+  for (;;) {
81
+
82
+    hotend.update();
83
+    bed.update();
84
+
85
+    x_axis.update();
86
+    y_axis.update();
87
+    z_axis.update();
88
+    extruder0.update();
89
+
90
+    #ifdef GPIO_LOGGING
91
+      if (x_axis.position != x || y_axis.position != y || z_axis.position != z) {
92
+        uint64_t update = MAX3(x_axis.last_update, y_axis.last_update, z_axis.last_update);
93
+        position_log << update << ", " << x_axis.position << ", " << y_axis.position << ", " << z_axis.position << std::endl;
94
+        position_log.flush();
95
+        x = x_axis.position;
96
+        y = y_axis.position;
97
+        z = z_axis.position;
98
+      }
99
+      // flush the logger
100
+      logger.flush();
101
+    #endif
102
+
103
+    std::this_thread::yield();
104
+  }
105
+}
106
+
107
+int main(void) {
108
+  std::thread write_serial (write_serial_thread);
109
+  std::thread read_serial (read_serial_thread);
110
+
111
+  #if NUM_SERIAL > 0
112
+    MYSERIAL0.begin(BAUDRATE);
113
+    SERIAL_PRINTF("x86_64 Initialised\n");
114
+    SERIAL_FLUSHTX();
115
+  #endif
116
+
117
+  Clock::setFrequency(F_CPU);
118
+  Clock::setTimeMultiplier(1.0); // some testing at 10x
119
+
120
+  HAL_timer_init();
121
+
122
+  std::thread simulation (simulation_loop);
123
+
124
+  DELAY_US(10000);
125
+
126
+  setup();
127
+  for (;;) {
128
+    loop();
129
+    std::this_thread::yield();
130
+  }
131
+
132
+  simulation.join();
133
+  write_serial.join();
134
+  read_serial.join();
135
+}
136
+
137
+#endif // __PLAT_LINUX__

+ 101
- 0
Marlin/src/HAL/HAL_LINUX/persistent_store_impl.cpp Visa fil

@@ -0,0 +1,101 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if ENABLED(EEPROM_SETTINGS)
28
+
29
+#include "../shared/persistent_store_api.h"
30
+#include <stdio.h>
31
+
32
+uint8_t buffer[E2END];
33
+char filename[] = "eeprom.dat";
34
+
35
+bool PersistentStore::access_start() {
36
+  const char eeprom_erase_value = 0xFF;
37
+  FILE * eeprom_file = fopen(filename, "rb");
38
+  if (eeprom_file == NULL) return false;
39
+
40
+  fseek(eeprom_file, 0L, SEEK_END);
41
+  std::size_t file_size = ftell(eeprom_file);
42
+
43
+  if (file_size < E2END) {
44
+    memset(buffer + file_size, eeprom_erase_value, E2END - file_size);
45
+  }
46
+  else {
47
+    fseek(eeprom_file, 0L, SEEK_SET);
48
+    fread(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file);
49
+  }
50
+
51
+  fclose(eeprom_file);
52
+  return true;
53
+}
54
+
55
+bool PersistentStore::access_finish() {
56
+  FILE * eeprom_file = fopen(filename, "wb");
57
+  if (eeprom_file == NULL) return false;
58
+  fwrite(buffer, sizeof(uint8_t), sizeof(buffer), eeprom_file);
59
+  fclose(eeprom_file);
60
+  return true;
61
+}
62
+
63
+bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
64
+  std::size_t bytes_written = 0;
65
+
66
+  for (std::size_t i = 0; i < size; i++) {
67
+    buffer[pos+i] = value[i];
68
+    bytes_written ++;
69
+  }
70
+
71
+  crc16(crc, value, size);
72
+  pos = pos + size;
73
+  return (bytes_written != size);  // return true for any error
74
+}
75
+
76
+bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
77
+  std::size_t bytes_read = 0;
78
+  if (writing) {
79
+    for (std::size_t i = 0; i < size; i++) {
80
+      value[i] = buffer[pos+i];
81
+      bytes_read ++;
82
+    }
83
+    crc16(crc, value, size);
84
+  }
85
+  else {
86
+    uint8_t temp[size];
87
+    for (std::size_t i = 0; i < size; i++) {
88
+      temp[i] = buffer[pos+i];
89
+      bytes_read ++;
90
+    }
91
+    crc16(crc, temp, size);
92
+  }
93
+
94
+  pos = pos + size;
95
+  return bytes_read != size;  // return true for any error
96
+}
97
+
98
+size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
99
+
100
+#endif // EEPROM_SETTINGS
101
+#endif // __PLAT_LINUX__

+ 63
- 0
Marlin/src/HAL/HAL_LINUX/pinsDebug.h Visa fil

@@ -0,0 +1,63 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Support routines for X86_64
25
+ */
26
+
27
+/**
28
+ * Translation of routines & variables used by pinsDebug.h
29
+ */
30
+
31
+#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
32
+#define pwm_details(pin) pin = pin    // do nothing  // print PWM details
33
+#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
34
+#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
35
+#define digitalRead_mod(p)  digitalRead(p)
36
+#define PRINT_PORT(p)
37
+#define GET_ARRAY_PIN(p) pin_array[p].pin
38
+#define NAME_FORMAT(p) PSTR("%-##p##s")
39
+#define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
40
+#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer);} while (0)
41
+#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
42
+
43
+// active ADC function/mode/code values for PINSEL registers
44
+constexpr int8_t ADC_pin_mode(pin_t pin) {
45
+  return (-1);
46
+}
47
+
48
+int8_t get_pin_mode(pin_t pin) {
49
+  if (!VALID_PIN(pin)) return -1;
50
+  return 0;
51
+}
52
+
53
+bool GET_PINMODE(pin_t pin) {
54
+  int8_t pin_mode = get_pin_mode(pin);
55
+  if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
56
+    return false;
57
+
58
+  return (Gpio::getMode(pin) != 0); //input/output state
59
+}
60
+
61
+bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
62
+  return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
63
+}

+ 80
- 0
Marlin/src/HAL/HAL_LINUX/servo_private.h Visa fil

@@ -0,0 +1,80 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://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];

+ 53
- 0
Marlin/src/HAL/HAL_LINUX/spi_pins.h Visa fil

@@ -0,0 +1,53 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "src/core/macros.h"
25
+
26
+#if ENABLED(SDSUPPORT) && ENABLED(DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
27
+  #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
28
+                            // needed due to the speed and mode requred for communicating with each device being different.
29
+                            // This requirement can be removed if the SPI access to these devices is updated to use
30
+                            // spiBeginTransaction.
31
+#endif
32
+
33
+/** onboard SD card */
34
+//#define SCK_PIN           P0_07
35
+//#define MISO_PIN          P0_08
36
+//#define MOSI_PIN          P0_09
37
+//#define SS_PIN            P0_06
38
+/** external */
39
+#ifndef SCK_PIN
40
+  #define SCK_PIN           50
41
+#endif
42
+#ifndef MISO_PIN
43
+  #define MISO_PIN          51
44
+#endif
45
+#ifndef MOSI_PIN
46
+  #define MOSI_PIN          52
47
+#endif
48
+#ifndef SS_PIN
49
+  #define SS_PIN            53
50
+#endif
51
+#ifndef SDSS
52
+  #define SDSS              SS_PIN
53
+#endif

+ 46
- 0
Marlin/src/HAL/HAL_LINUX/watchdog.cpp Visa fil

@@ -0,0 +1,46 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef __PLAT_LINUX__
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if ENABLED(USE_WATCHDOG)
28
+
29
+#include "watchdog.h"
30
+
31
+void watchdog_init(void) {}
32
+
33
+void HAL_clear_reset_source(void) {}
34
+
35
+uint8_t HAL_get_reset_source(void) {
36
+  return RST_POWER_ON;
37
+}
38
+
39
+void watchdog_reset() {}
40
+
41
+#else
42
+  void HAL_clear_reset_source(void) {}
43
+  uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
44
+#endif // USE_WATCHDOG
45
+
46
+#endif // __PLAT_LINUX__

+ 34
- 0
Marlin/src/HAL/HAL_LINUX/watchdog.h Visa fil

@@ -0,0 +1,34 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#define RST_POWER_ON   1
25
+#define RST_EXTERNAL   2
26
+#define RST_BROWN_OUT  4
27
+#define RST_WATCHDOG   8
28
+
29
+#define WDT_TIMEOUT   4000000 // 4 second timeout
30
+
31
+void watchdog_init(void);
32
+void watchdog_reset(void);
33
+void HAL_clear_reset_source(void);
34
+uint8_t HAL_get_reset_source(void);

+ 2
- 0
Marlin/src/HAL/platforms.h Visa fil

@@ -41,6 +41,8 @@
41 41
   #define HAL_PLATFORM HAL_STM32
42 42
 #elif defined(ARDUINO_ARCH_ESP32)
43 43
   #define HAL_PLATFORM HAL_ESP32
44
+#elif defined(__PLAT_LINUX__)
45
+  #define HAL_PLATFORM HAL_LINUX
44 46
 #else
45 47
   #error "Unsupported Platform!"
46 48
 #endif

+ 4
- 0
Marlin/src/HAL/shared/Delay.h Visa fil

@@ -158,6 +158,10 @@
158 158
     }
159 159
   }
160 160
 
161
+#elif defined(__PLAT_LINUX__)
162
+
163
+  // specified inside platform
164
+
161 165
 #else
162 166
 
163 167
   #error "Unsupported MCU architecture"

+ 6
- 0
Marlin/src/core/boards.h Visa fil

@@ -259,4 +259,10 @@
259 259
 //
260 260
 #define BOARD_ESP32            1900
261 261
 
262
+//
263
+// Simulations
264
+//
265
+
266
+#define BOARD_LINUX_RAMPS      2000
267
+
262 268
 #define MB(board) (defined(BOARD_##board) && MOTHERBOARD==BOARD_##board)

+ 7
- 0
Marlin/src/pins/pins.h Visa fil

@@ -448,6 +448,13 @@
448 448
 #elif MB(ESP32)
449 449
   #include "pins_ESP32.h"
450 450
 
451
+//
452
+// Linux Native Debug board
453
+//
454
+
455
+#elif MB(LINUX_RAMPS)
456
+  #include "pins_RAMPS_LINUX.h"       // Linux                                      env:linux_native
457
+
451 458
 #else
452 459
   #error "Unknown MOTHERBOARD value set in Configuration.h"
453 460
 #endif

+ 572
- 0
Marlin/src/pins/pins_RAMPS_LINUX.h Visa fil

@@ -0,0 +1,572 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Arduino Mega with RAMPS v1.4 (or v1.3) pin assignments
25
+ *
26
+ * Applies to the following boards:
27
+ *
28
+ *  RAMPS_14_EFB (Hotend, Fan, Bed)
29
+ *  RAMPS_14_EEB (Hotend0, Hotend1, Bed)
30
+ *  RAMPS_14_EFF (Hotend, Fan0, Fan1)
31
+ *  RAMPS_14_EEF (Hotend0, Hotend1, Fan)
32
+ *  RAMPS_14_SF  (Spindle, Controller Fan)
33
+ *
34
+ *  RAMPS_13_EFB (Hotend, Fan, Bed)
35
+ *  RAMPS_13_EEB (Hotend0, Hotend1, Bed)
36
+ *  RAMPS_13_EFF (Hotend, Fan0, Fan1)
37
+ *  RAMPS_13_EEF (Hotend0, Hotend1, Fan)
38
+ *  RAMPS_13_SF  (Spindle, Controller Fan)
39
+ *
40
+ *  Other pins_MYBOARD.h files may override these defaults
41
+ *
42
+ *  Differences between
43
+ *  RAMPS_13 | RAMPS_14
44
+ *         7 | 11
45
+ */
46
+
47
+#ifndef BOARD_NAME
48
+  #define BOARD_NAME "RAMPS 1.4"
49
+#endif
50
+
51
+#define IS_RAMPS_EFB
52
+
53
+//
54
+// Servos
55
+//
56
+#ifdef IS_RAMPS_13
57
+  #define SERVO0_PIN        7   // RAMPS_13 // Will conflict with BTN_EN2 on LCD_I2C_VIKI
58
+#else
59
+  #define SERVO0_PIN       11
60
+#endif
61
+#define SERVO1_PIN          6
62
+#define SERVO2_PIN          5
63
+#ifndef SERVO3_PIN
64
+  #define SERVO3_PIN        4
65
+#endif
66
+
67
+//
68
+// Limit Switches
69
+//
70
+#define X_MIN_PIN           3
71
+#ifndef X_MAX_PIN
72
+  #define X_MAX_PIN         2
73
+#endif
74
+#define Y_MIN_PIN          14
75
+#define Y_MAX_PIN          15
76
+#define Z_MIN_PIN          18
77
+#define Z_MAX_PIN          19
78
+
79
+//
80
+// Z Probe (when not Z_MIN_PIN)
81
+//
82
+#ifndef Z_MIN_PROBE_PIN
83
+  #define Z_MIN_PROBE_PIN  32
84
+#endif
85
+
86
+//
87
+// Steppers
88
+//
89
+#define X_STEP_PIN         54
90
+#define X_DIR_PIN          55
91
+#define X_ENABLE_PIN       38
92
+#ifndef X_CS_PIN
93
+  #define X_CS_PIN         53
94
+#endif
95
+
96
+#define Y_STEP_PIN         60
97
+#define Y_DIR_PIN          61
98
+#define Y_ENABLE_PIN       56
99
+#ifndef Y_CS_PIN
100
+  #define Y_CS_PIN         49
101
+#endif
102
+
103
+#define Z_STEP_PIN         46
104
+#define Z_DIR_PIN          48
105
+#define Z_ENABLE_PIN       62
106
+#ifndef Z_CS_PIN
107
+  #define Z_CS_PIN         40
108
+#endif
109
+
110
+#define E0_STEP_PIN        26
111
+#define E0_DIR_PIN         28
112
+#define E0_ENABLE_PIN      24
113
+#ifndef E0_CS_PIN
114
+  #define E0_CS_PIN        42
115
+#endif
116
+
117
+#define E1_STEP_PIN        36
118
+#define E1_DIR_PIN         34
119
+#define E1_ENABLE_PIN      30
120
+#ifndef E1_CS_PIN
121
+  #define E1_CS_PIN        44
122
+#endif
123
+
124
+//
125
+// Temperature Sensors
126
+//
127
+#define TEMP_0_PIN            0   // Analog Input
128
+#define TEMP_1_PIN            1   // Analog Input
129
+#define TEMP_BED_PIN          2   // Analog Input
130
+
131
+// SPI for Max6675 or Max31855 Thermocouple
132
+#if DISABLED(SDSUPPORT)
133
+  #define MAX6675_SS_PIN     66   // Do not use pin 53 if there is even the remote possibility of using Display/SD card
134
+#else
135
+  #define MAX6675_SS_PIN     66   // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
136
+#endif
137
+
138
+//
139
+// Augmentation for auto-assigning RAMPS plugs
140
+//
141
+#if DISABLED(IS_RAMPS_EEB) && DISABLED(IS_RAMPS_EEF) && DISABLED(IS_RAMPS_EFB) && DISABLED(IS_RAMPS_EFF) && DISABLED(IS_RAMPS_SF) && !PIN_EXISTS(MOSFET_D)
142
+  #if HOTENDS > 1
143
+    #if TEMP_SENSOR_BED
144
+      #define IS_RAMPS_EEB
145
+    #else
146
+      #define IS_RAMPS_EEF
147
+    #endif
148
+  #elif TEMP_SENSOR_BED
149
+    #define IS_RAMPS_EFB
150
+  #else
151
+    #define IS_RAMPS_EFF
152
+  #endif
153
+#endif
154
+
155
+//
156
+// Heaters / Fans
157
+//
158
+#ifndef MOSFET_D_PIN
159
+  #define MOSFET_D_PIN  -1
160
+#endif
161
+#ifndef RAMPS_D8_PIN
162
+  #define RAMPS_D8_PIN   8
163
+#endif
164
+#ifndef RAMPS_D9_PIN
165
+  #define RAMPS_D9_PIN   9
166
+#endif
167
+#ifndef RAMPS_D10_PIN
168
+  #define RAMPS_D10_PIN 10
169
+#endif
170
+
171
+#define HEATER_0_PIN     RAMPS_D10_PIN
172
+
173
+#if ENABLED(IS_RAMPS_EFB)                      // Hotend, Fan, Bed
174
+  #define FAN_PIN        RAMPS_D9_PIN
175
+  #define HEATER_BED_PIN RAMPS_D8_PIN
176
+#elif ENABLED(IS_RAMPS_EEF)                    // Hotend, Hotend, Fan
177
+  #define HEATER_1_PIN   RAMPS_D9_PIN
178
+  #define FAN_PIN        RAMPS_D8_PIN
179
+#elif ENABLED(IS_RAMPS_EEB)                    // Hotend, Hotend, Bed
180
+  #define HEATER_1_PIN   RAMPS_D9_PIN
181
+  #define HEATER_BED_PIN RAMPS_D8_PIN
182
+#elif ENABLED(IS_RAMPS_EFF)                    // Hotend, Fan, Fan
183
+  #define FAN_PIN        RAMPS_D9_PIN
184
+  #define FAN1_PIN       RAMPS_D8_PIN
185
+#elif ENABLED(IS_RAMPS_SF)                     // Spindle, Fan
186
+  #define FAN_PIN        RAMPS_D8_PIN
187
+#else                                          // Non-specific are "EFB" (i.e., "EFBF" or "EFBE")
188
+  #define FAN_PIN        RAMPS_D9_PIN
189
+  #define HEATER_BED_PIN RAMPS_D8_PIN
190
+  #if HOTENDS == 1
191
+    #define FAN1_PIN     MOSFET_D_PIN
192
+  #else
193
+    #define HEATER_1_PIN MOSFET_D_PIN
194
+  #endif
195
+#endif
196
+
197
+#ifndef FAN_PIN
198
+  #define FAN_PIN           4   // IO pin. Buffer needed
199
+#endif
200
+
201
+//
202
+// Misc. Functions
203
+//
204
+#define SDSS               53
205
+#define LED_PIN            13
206
+
207
+#ifndef FILWIDTH_PIN
208
+  #define FILWIDTH_PIN      5   // Analog Input on AUX2
209
+#endif
210
+
211
+// define digital pin 4 for the filament runout sensor. Use the RAMPS 1.4 digital input 4 on the servos connector
212
+#ifndef FIL_RUNOUT_PIN
213
+  #define FIL_RUNOUT_PIN    4
214
+#endif
215
+
216
+#ifndef PS_ON_PIN
217
+  #define PS_ON_PIN        12
218
+#endif
219
+
220
+#if ENABLED(CASE_LIGHT_ENABLE) && !defined(CASE_LIGHT_PIN) && !defined(SPINDLE_LASER_ENABLE_PIN)
221
+  #if NUM_SERVOS <= 1 // try to use servo connector first
222
+    #define CASE_LIGHT_PIN    6   // MUST BE HARDWARE PWM
223
+  #elif !(ENABLED(ULTRA_LCD) && ENABLED(NEWPANEL) \
224
+      && (ENABLED(PANEL_ONE) || ENABLED(VIKI2) || ENABLED(miniVIKI) || ENABLED(MINIPANEL) || ENABLED(REPRAPWORLD_KEYPAD)))  // try to use AUX 2
225
+    #define CASE_LIGHT_PIN   44   // MUST BE HARDWARE PWM
226
+  #endif
227
+#endif
228
+
229
+//
230
+// M3/M4/M5 - Spindle/Laser Control
231
+//
232
+#if ENABLED(SPINDLE_LASER_ENABLE) && !PIN_EXISTS(SPINDLE_LASER_ENABLE)
233
+  #if !defined(NUM_SERVOS) || NUM_SERVOS == 0 // try to use servo connector first
234
+    #define SPINDLE_LASER_ENABLE_PIN  4   // Pin should have a pullup/pulldown!
235
+    #define SPINDLE_LASER_PWM_PIN     6   // MUST BE HARDWARE PWM
236
+    #define SPINDLE_DIR_PIN           5
237
+  #elif !(ENABLED(ULTRA_LCD) && ENABLED(NEWPANEL) \
238
+      && (ENABLED(PANEL_ONE) || ENABLED(VIKI2) || ENABLED(miniVIKI) || ENABLED(MINIPANEL) || ENABLED(REPRAPWORLD_KEYPAD)))  // try to use AUX 2
239
+    #define SPINDLE_LASER_ENABLE_PIN 40   // Pin should have a pullup/pulldown!
240
+    #define SPINDLE_LASER_PWM_PIN    44   // MUST BE HARDWARE PWM
241
+    #define SPINDLE_DIR_PIN          65
242
+  #endif
243
+#endif
244
+
245
+//
246
+// Průša i3 MK2 Multiplexer Support
247
+//
248
+#ifndef E_MUX0_PIN
249
+  #define E_MUX0_PIN 40   // Z_CS_PIN
250
+#endif
251
+#ifndef E_MUX1_PIN
252
+  #define E_MUX1_PIN 42   // E0_CS_PIN
253
+#endif
254
+#ifndef E_MUX2_PIN
255
+  #define E_MUX2_PIN 44   // E1_CS_PIN
256
+#endif
257
+
258
+/**
259
+ * Default pins for TMC software SPI
260
+ */
261
+#if ENABLED(TMC_USE_SW_SPI)
262
+  #ifndef TMC_SW_MOSI
263
+    #define TMC_SW_MOSI    66
264
+  #endif
265
+  #ifndef TMC_SW_MISO
266
+    #define TMC_SW_MISO    44
267
+  #endif
268
+  #ifndef TMC_SW_SCK
269
+    #define TMC_SW_SCK     64
270
+  #endif
271
+#endif
272
+
273
+#if ENABLED(HAVE_TMC2208)
274
+  /**
275
+   * TMC2208 stepper drivers
276
+   *
277
+   * Hardware serial communication ports.
278
+   * If undefined software serial is used according to the pins below
279
+   */
280
+  //#define X_HARDWARE_SERIAL  Serial1
281
+  //#define X2_HARDWARE_SERIAL Serial1
282
+  //#define Y_HARDWARE_SERIAL  Serial1
283
+  //#define Y2_HARDWARE_SERIAL Serial1
284
+  //#define Z_HARDWARE_SERIAL  Serial1
285
+  //#define Z2_HARDWARE_SERIAL Serial1
286
+  //#define E0_HARDWARE_SERIAL Serial1
287
+  //#define E1_HARDWARE_SERIAL Serial1
288
+  //#define E2_HARDWARE_SERIAL Serial1
289
+  //#define E3_HARDWARE_SERIAL Serial1
290
+  //#define E4_HARDWARE_SERIAL Serial1
291
+
292
+  /**
293
+   * Software serial
294
+   */
295
+
296
+  #define X_SERIAL_TX_PIN    40
297
+  #define X_SERIAL_RX_PIN    63
298
+  #define X2_SERIAL_TX_PIN   -1
299
+  #define X2_SERIAL_RX_PIN   -1
300
+
301
+  #define Y_SERIAL_TX_PIN    59
302
+  #define Y_SERIAL_RX_PIN    64
303
+  #define Y2_SERIAL_TX_PIN   -1
304
+  #define Y2_SERIAL_RX_PIN   -1
305
+
306
+  #define Z_SERIAL_TX_PIN    42
307
+  #define Z_SERIAL_RX_PIN    65
308
+  #define Z2_SERIAL_TX_PIN   -1
309
+  #define Z2_SERIAL_RX_PIN   -1
310
+
311
+  #define E0_SERIAL_TX_PIN   44
312
+  #define E0_SERIAL_RX_PIN   66
313
+  #define E1_SERIAL_TX_PIN   -1
314
+  #define E1_SERIAL_RX_PIN   -1
315
+  #define E2_SERIAL_TX_PIN   -1
316
+  #define E2_SERIAL_RX_PIN   -1
317
+  #define E3_SERIAL_TX_PIN   -1
318
+  #define E3_SERIAL_RX_PIN   -1
319
+  #define E4_SERIAL_TX_PIN   -1
320
+  #define E4_SERIAL_RX_PIN   -1
321
+#endif
322
+
323
+//////////////////////////
324
+// LCDs and Controllers //
325
+//////////////////////////
326
+
327
+#if ENABLED(ULTRA_LCD)
328
+
329
+  //
330
+  // LCD Display output pins
331
+  //
332
+  #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
333
+
334
+    #define LCD_PINS_RS         49   // CS chip select /SS chip slave select
335
+    #define LCD_PINS_ENABLE     51   // SID (MOSI)
336
+    #define LCD_PINS_D4         52   // SCK (CLK) clock
337
+
338
+  #elif ENABLED(NEWPANEL) && ENABLED(PANEL_ONE)
339
+
340
+    #define LCD_PINS_RS         40
341
+    #define LCD_PINS_ENABLE     42
342
+    #define LCD_PINS_D4         65
343
+    #define LCD_PINS_D5         66
344
+    #define LCD_PINS_D6         44
345
+    #define LCD_PINS_D7         64
346
+
347
+  #else
348
+
349
+    #if ENABLED(CR10_STOCKDISPLAY)
350
+
351
+      #define LCD_PINS_RS       27
352
+      #define LCD_PINS_ENABLE   29
353
+      #define LCD_PINS_D4       25
354
+
355
+      #if DISABLED(NEWPANEL)
356
+        #define BEEPER_PIN      37
357
+      #endif
358
+
359
+    #elif ENABLED(ZONESTAR_LCD)
360
+
361
+      #define LCD_PINS_RS       64
362
+      #define LCD_PINS_ENABLE   44
363
+      #define LCD_PINS_D4       63
364
+      #define LCD_PINS_D5       40
365
+      #define LCD_PINS_D6       42
366
+      #define LCD_PINS_D7       65
367
+
368
+    #else
369
+
370
+      #if ENABLED(MKS_12864OLED) || ENABLED(MKS_12864OLED_SSD1306)
371
+        #define LCD_PINS_DC     25   // Set as output on init
372
+        #define LCD_PINS_RS     27   // Pull low for 1s to init
373
+        // DOGM SPI LCD Support
374
+        #define DOGLCD_CS       16
375
+        #define DOGLCD_MOSI     17
376
+        #define DOGLCD_SCK      23
377
+        #define DOGLCD_A0       LCD_PINS_DC
378
+      #else
379
+        #define LCD_PINS_RS     16
380
+        #define LCD_PINS_ENABLE 17
381
+        #define LCD_PINS_D4     23
382
+        #define LCD_PINS_D5     25
383
+        #define LCD_PINS_D6     27
384
+      #endif
385
+
386
+      #define LCD_PINS_D7       29
387
+
388
+      #if DISABLED(NEWPANEL)
389
+        #define BEEPER_PIN      33
390
+      #endif
391
+
392
+    #endif
393
+
394
+    #if DISABLED(NEWPANEL)
395
+      // Buttons are attached to a shift register
396
+      // Not wired yet
397
+      //#define SHIFT_CLK       38
398
+      //#define SHIFT_LD        42
399
+      //#define SHIFT_OUT       40
400
+      //#define SHIFT_EN        17
401
+    #endif
402
+
403
+  #endif
404
+
405
+  //
406
+  // LCD Display input pins
407
+  //
408
+  #if ENABLED(NEWPANEL)
409
+
410
+    #if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER)
411
+
412
+      #define BEEPER_PIN        37
413
+
414
+      #if ENABLED(CR10_STOCKDISPLAY)
415
+        #define BTN_EN1         17
416
+        #define BTN_EN2         23
417
+      #else
418
+        #define BTN_EN1         31
419
+        #define BTN_EN2         33
420
+      #endif
421
+
422
+      #define BTN_ENC           35
423
+      #define SD_DETECT_PIN     49
424
+      #define KILL_PIN          41
425
+
426
+      #if ENABLED(BQ_LCD_SMART_CONTROLLER)
427
+        #define LCD_BACKLIGHT_PIN 39
428
+      #endif
429
+
430
+    #elif ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
431
+
432
+      #define BTN_EN1           64
433
+      #define BTN_EN2           59
434
+      #define BTN_ENC           63
435
+      #define SD_DETECT_PIN     42
436
+
437
+    #elif ENABLED(LCD_I2C_PANELOLU2)
438
+
439
+      #define BTN_EN1           47
440
+      #define BTN_EN2           43
441
+      #define BTN_ENC           32
442
+      #define LCD_SDSS          SDSS
443
+      #define KILL_PIN          41
444
+
445
+    #elif ENABLED(LCD_I2C_VIKI)
446
+
447
+      #define BTN_EN1           22   // http://files.panucatt.com/datasheets/viki_wiring_diagram.pdf explains 40/42.
448
+      #define BTN_EN2            7   // 22/7 are unused on RAMPS_14. 22 is unused and 7 the SERVO0_PIN on RAMPS_13.
449
+      #define BTN_ENC           -1
450
+
451
+      #define LCD_SDSS          SDSS
452
+      #define SD_DETECT_PIN     49
453
+
454
+    #elif ENABLED(VIKI2) || ENABLED(miniVIKI)
455
+
456
+      #define DOGLCD_CS         45
457
+      #define DOGLCD_A0         44
458
+      #define LCD_SCREEN_ROT_180
459
+
460
+      #define BEEPER_PIN        33
461
+      #define STAT_LED_RED_PIN  32
462
+      #define STAT_LED_BLUE_PIN 35
463
+
464
+      #define BTN_EN1           22
465
+      #define BTN_EN2            7
466
+      #define BTN_ENC           39
467
+
468
+      #define SD_DETECT_PIN     -1   // Pin 49 for display sd interface, 72 for easy adapter board
469
+      #define KILL_PIN          31
470
+
471
+    #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
472
+
473
+      #define DOGLCD_CS         29
474
+      #define DOGLCD_A0         27
475
+
476
+      #define BEEPER_PIN        23
477
+      #define LCD_BACKLIGHT_PIN 33
478
+
479
+      #define BTN_EN1           35
480
+      #define BTN_EN2           37
481
+      #define BTN_ENC           31
482
+
483
+      #define LCD_SDSS          SDSS
484
+      #define SD_DETECT_PIN     49
485
+      #define KILL_PIN          41
486
+
487
+    #elif ENABLED(MKS_MINI_12864)   // Added in Marlin 1.1.6
488
+
489
+      #define DOGLCD_A0         27
490
+      #define DOGLCD_CS         25
491
+
492
+      // GLCD features
493
+      //#define LCD_CONTRAST   190
494
+      // Uncomment screen orientation
495
+      //#define LCD_SCREEN_ROT_90
496
+      //#define LCD_SCREEN_ROT_180
497
+      //#define LCD_SCREEN_ROT_270
498
+
499
+      #define BEEPER_PIN        37
500
+      // not connected to a pin
501
+      #define LCD_BACKLIGHT_PIN 65   // backlight LED on A11/D65
502
+
503
+      #define BTN_EN1           31
504
+      #define BTN_EN2           33
505
+      #define BTN_ENC           35
506
+
507
+      #define SD_DETECT_PIN     49
508
+      #define KILL_PIN          64
509
+
510
+    #elif ENABLED(MINIPANEL)
511
+
512
+      #define BEEPER_PIN        42
513
+      // not connected to a pin
514
+      #define LCD_BACKLIGHT_PIN 65   // backlight LED on A11/D65
515
+
516
+      #define DOGLCD_A0         44
517
+      #define DOGLCD_CS         66
518
+
519
+      // GLCD features
520
+      //#define LCD_CONTRAST   190
521
+      // Uncomment screen orientation
522
+      //#define LCD_SCREEN_ROT_90
523
+      //#define LCD_SCREEN_ROT_180
524
+      //#define LCD_SCREEN_ROT_270
525
+
526
+      #define BTN_EN1           40
527
+      #define BTN_EN2           63
528
+      #define BTN_ENC           59
529
+
530
+      #define SD_DETECT_PIN     49
531
+      #define KILL_PIN          64
532
+
533
+    #elif ENABLED(ZONESTAR_LCD)
534
+
535
+      #define ADC_KEYPAD_PIN    12
536
+
537
+    #elif ENABLED(AZSMZ_12864)
538
+
539
+      // Pins only defined for RAMPS_SMART currently
540
+
541
+    #else
542
+
543
+      // Beeper on AUX-4
544
+      #define BEEPER_PIN        33
545
+
546
+      // Buttons are directly attached using AUX-2
547
+      #if ENABLED(REPRAPWORLD_KEYPAD)
548
+        #define SHIFT_OUT       40
549
+        #define SHIFT_CLK       44
550
+        #define SHIFT_LD        42
551
+        #define BTN_EN1         64
552
+        #define BTN_EN2         59
553
+        #define BTN_ENC         63
554
+      #elif ENABLED(PANEL_ONE)
555
+        #define BTN_EN1         59   // AUX2 PIN 3
556
+        #define BTN_EN2         63   // AUX2 PIN 4
557
+        #define BTN_ENC         49   // AUX3 PIN 7
558
+      #else
559
+        #define BTN_EN1         37
560
+        #define BTN_EN2         35
561
+        #define BTN_ENC         31
562
+      #endif
563
+
564
+      #if ENABLED(G3D_PANEL)
565
+        #define SD_DETECT_PIN   49
566
+        #define KILL_PIN        41
567
+      #endif
568
+
569
+    #endif
570
+  #endif // NEWPANEL
571
+
572
+#endif // ULTRA_LCD

buildroot/share/tests/DUE_tests → buildroot/share/tests/DUE-tests Visa fil


buildroot/share/tests/LPC1768_tests → buildroot/share/tests/LPC1768-tests Visa fil


buildroot/share/tests/LPC1769_tests → buildroot/share/tests/LPC1769-tests Visa fil


buildroot/share/tests/STM32F1_tests → buildroot/share/tests/STM32F1-tests Visa fil


+ 16
- 0
buildroot/share/tests/linux_native-tests Visa fil

@@ -0,0 +1,16 @@
1
+#!/usr/bin/env bash
2
+#
3
+# Build tests for Linux x86_64
4
+#
5
+
6
+# exit on first failure
7
+set -e
8
+
9
+restore_configs
10
+opt_set MOTHERBOARD BOARD_LINUX_RAMPS
11
+opt_set TEMP_SENSOR_BED 1
12
+opt_enable PIDTEMPBED EEPROM_SETTINGS
13
+exec_test $1 $2 "Linux with EEPROM"
14
+
15
+# cleanup
16
+restore_configs

buildroot/share/tests/megaatmega2560_tests → buildroot/share/tests/megaatmega2560-tests Visa fil


+ 2
- 2
buildroot/share/tests/run_tests Visa fil

@@ -33,7 +33,7 @@ if [[ $2 = "ALL" ]]; then
33 33
   declare -a tests=(${dir_list[@]/*run_tests/})
34 34
   for f in "${tests[@]}"; do
35 35
     env_backup
36
-    testenv=$(basename $f | cut -d"_" -f1)
36
+    testenv=$(basename $f | cut -d"-" -f1)
37 37
     printf "Running \033[0;32m$f\033[0m Tests\n"
38 38
     exec_test $1 "$testenv --target clean" "Setup Build Environment"
39 39
     $f $1 $testenv
@@ -42,7 +42,7 @@ if [[ $2 = "ALL" ]]; then
42 42
 else
43 43
   env_backup
44 44
   exec_test $1 "$2 --target clean" "Setup Build Environment"
45
-  $2_tests $1 $2
45
+  $2-tests $1 $2
46 46
   env_restore
47 47
 fi
48 48
 printf "\033[0;32mAll tests completed successfully\033[0m\n"

buildroot/share/tests/teensy35_tests → buildroot/share/tests/teensy35-tests Visa fil


+ 14
- 0
platformio.ini Visa fil

@@ -381,3 +381,17 @@ board_build.f_cpu = 16000000L
381 381
 lib_deps          = ${common.lib_deps}
382 382
 src_filter        = ${common.default_src_filter} +<src/HAL/HAL_AVR>
383 383
 monitor_speed     = 250000
384
+
385
+#
386
+# Native
387
+# No supported Arduino libraries, base Marlin only
388
+#
389
+[env:linux_native]
390
+platform        = native
391
+build_flags     = -D__PLAT_LINUX__ -std=gnu++17 -ggdb -g -lrt -lpthread
392
+src_build_flags = -Wall -IMarlin/src/HAL/HAL_LINUX/include
393
+build_unflags   = -Wall
394
+lib_ldf_mode    = off
395
+lib_deps        =
396
+extra_scripts   =
397
+src_filter      = ${common.default_src_filter} +<src/HAL/HAL_LINUX>

Laddar…
Avbryt
Spara