Browse Source

Add M42 M, improve M43 (#17173)

InsanityAutomation 5 years ago
parent
commit
84dec5da10
No account linked to committer's email address
2 changed files with 22 additions and 5 deletions
  1. 2
    0
      Marlin/src/gcode/config/M43.cpp
  2. 20
    5
      Marlin/src/gcode/control/M42.cpp

+ 2
- 0
Marlin/src/gcode/config/M43.cpp View File

@@ -67,6 +67,7 @@ inline void toggle_pins() {
67 67
     else {
68 68
       watchdog_refresh();
69 69
       report_pin_state_extended(pin, ignore_protection, true, PSTR("Pulsing   "));
70
+      const bool prior_mode = GET_PINMODE(pin);
70 71
       #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
71 72
         if (pin == TEENSY_E2) {
72 73
           SET_OUTPUT(TEENSY_E2);
@@ -95,6 +96,7 @@ inline void toggle_pins() {
95 96
           watchdog_refresh();
96 97
         }
97 98
       }
99
+      pinMode(pin, prior_mode);
98 100
     }
99 101
     SERIAL_EOL();
100 102
   }

+ 20
- 5
Marlin/src/gcode/control/M42.cpp View File

@@ -37,16 +37,33 @@
37 37
  *
38 38
  *  S<byte> Pin status from 0 - 255
39 39
  *  I       Flag to ignore Marlin's pin protection
40
+ *
41
+ *  M<mode> Pin mode: 0=INPUT  1=OUTPUT  2=INPUT_PULLUP  3=INPUT_PULLDOWN
40 42
  */
41 43
 void GcodeSuite::M42() {
42
-  if (!parser.seenval('S')) return;
43
-  const byte pin_status = parser.value_byte();
44
-
45 44
   const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
46 45
   if (pin_index < 0) return;
47 46
 
48 47
   const pin_t pin = GET_PIN_MAP_PIN(pin_index);
49 48
 
49
+  if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
50
+
51
+  if (parser.seenval('M')) {
52
+    switch (parser.value_byte()) {
53
+      case 0: pinMode(pin, INPUT); break;
54
+      case 1: pinMode(pin, OUTPUT); break;
55
+      case 2: pinMode(pin, INPUT_PULLUP); break;
56
+      #ifdef INPUT_PULLDOWN
57
+        case 3: pinMode(pin, INPUT_PULLDOWN); break;
58
+      #endif
59
+      default: SERIAL_ECHOLNPGM("Invalid Pin Mode");
60
+    }
61
+    return;
62
+  }
63
+
64
+  if (!parser.seenval('S')) return;
65
+  const byte pin_status = parser.value_byte();
66
+
50 67
   #if FAN_COUNT > 0
51 68
     switch (pin) {
52 69
       #if HAS_FAN0
@@ -76,8 +93,6 @@ void GcodeSuite::M42() {
76 93
     }
77 94
   #endif
78 95
 
79
-  if (!parser.boolval('I') && pin_is_protected(pin)) return protected_pin_err();
80
-
81 96
   pinMode(pin, OUTPUT);
82 97
   extDigitalWrite(pin, pin_status);
83 98
   analogWrite(pin, pin_status);

Loading…
Cancel
Save