Skip to content

Commit

Permalink
Optional M42/M226; Add more features filters (MarlinFirmware#19664)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 16, 2020
1 parent 59b6b32 commit 454f9d6
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 78 deletions.
5 changes: 5 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3559,6 +3559,11 @@
//
//#define M100_FREE_MEMORY_WATCHER

//
// M42 - Set pin states
//
//#define DIRECT_PIN_CONTROL

//
// M43 - display pin status, toggle pins, watch pins, watch endstops & toggle LED, test servo probe
//
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/gcode/control/M226.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*
*/

#include "../../inc/MarlinConfig.h"

#if ENABLED(DIRECT_PIN_CONTROL)

#include "../gcode.h"
#include "../../MarlinCore.h" // for pin_is_protected and idle()
#include "../../module/stepper.h"
Expand Down Expand Up @@ -50,3 +54,5 @@ void GcodeSuite::M226() {
} // pin_state -1 0 1 && pin > -1
} // parser.seen('P')
}

#endif // DIRECT_PIN_CONTROL
7 changes: 6 additions & 1 deletion Marlin/src/gcode/control/M42.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
*
*/

#include "../../inc/MarlinConfig.h"

#if ENABLED(DIRECT_PIN_CONTROL)

#include "../gcode.h"
#include "../../MarlinCore.h" // for pin_is_protected
#include "../../inc/MarlinConfig.h"

#if HAS_FAN
#include "../../module/temperature.h"
Expand Down Expand Up @@ -96,3 +99,5 @@ void GcodeSuite::M42() {
extDigitalWrite(pin, pin_status);
analogWrite(pin, pin_status);
}

#endif // DIRECT_PIN_CONTROL
9 changes: 7 additions & 2 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
#endif // SDSUPPORT

case 31: M31(); break; // M31: Report time since the start of SD print or last M109
case 42: M42(); break; // M42: Change pin state

#if ENABLED(DIRECT_PIN_CONTROL)
case 42: M42(); break; // M42: Change pin state
#endif

#if ENABLED(PINS_DEBUGGING)
case 43: M43(); break; // M43: Read pin state
Expand Down Expand Up @@ -620,7 +623,9 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 221: M221(); break; // M221: Set Flow Percentage
#endif

case 226: M226(); break; // M226: Wait until a pin reaches a state
#if ENABLED(DIRECT_PIN_CONTROL)
case 226: M226(); break; // M226: Wait until a pin reaches a state
#endif

#if HAS_SERVOS
case 280: M280(); break; // M280: Set servo position absolute
Expand Down
9 changes: 4 additions & 5 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
* The '#' is necessary when calling from within sd files, as it stops buffer prereading
* M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT)
* M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA)
* M42 - Change pin status via gcode: M42 P<pin> S<value>. LED pin assumed if P is omitted.
* M42 - Change pin status via gcode: M42 P<pin> S<value>. LED pin assumed if P is omitted. (Requires DIRECT_PIN_CONTROL)
* M43 - Display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
* M48 - Measure Z Probe repeatability: M48 P<points> X<pos> Y<pos> V<level> E<engage> L<legs> S<chizoid>. (Requires Z_MIN_PROBE_REPEATABILITY_TEST)
* M73 - Set the progress percentage. (Requires LCD_SET_PROGRESS_MANUALLY)
Expand Down Expand Up @@ -183,7 +183,7 @@
* M220 - Set Feedrate Percentage: "M220 S<percent>" (i.e., "FR" on the LCD)
* Use "M220 B" to back up the Feedrate Percentage and "M220 R" to restore it. (Requires PRUSA_MMU2)
* M221 - Set Flow Percentage: "M221 S<percent>"
* M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>"
* M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
* M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
* M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
* M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
Expand Down Expand Up @@ -544,8 +544,7 @@ class GcodeSuite {
#endif
#endif

static void M42();

TERN_(DIRECT_PIN_CONTROL, static void M42());
TERN_(PINS_DEBUGGING, static void M43());

TERN_(Z_MIN_PROBE_REPEATABILITY_TEST, static void M48());
Expand Down Expand Up @@ -673,7 +672,7 @@ class GcodeSuite {
static void M221();
#endif

static void M226();
TERN_(DIRECT_PIN_CONTROL, static void M226());

TERN_(PHOTO_GCODE, static void M240());

Expand Down
32 changes: 21 additions & 11 deletions Marlin/src/inc/MarlinConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,31 @@

#include "MarlinConfigPre.h"

#include "../HAL/HAL.h"
#ifndef __MARLIN_DEPS__
#include "../HAL/HAL.h"
#endif

#include "../pins/pins.h"
#include HAL_PATH(../HAL, timers.h)
#include HAL_PATH(../HAL, spi_pins.h)

#ifndef __MARLIN_DEPS__
#include HAL_PATH(../HAL, timers.h)
#include HAL_PATH(../HAL, spi_pins.h)
#endif

#include "Conditionals_post.h"
#include HAL_PATH(../HAL, inc/Conditionals_post.h)

#include "../core/types.h" // Ahead of sanity-checks
#ifndef __MARLIN_DEPS__

#include HAL_PATH(../HAL, inc/Conditionals_post.h)

#include "../core/types.h" // Ahead of sanity-checks

#include "SanityCheck.h"
#include HAL_PATH(../HAL, inc/SanityCheck.h)

#include "SanityCheck.h"
#include HAL_PATH(../HAL, inc/SanityCheck.h)
// Include all core headers
#include "../core/language.h"
#include "../core/utility.h"
#include "../core/serial.h"

// Include all core headers
#include "../core/language.h"
#include "../core/utility.h"
#include "../core/serial.h"
#endif
14 changes: 11 additions & 3 deletions Marlin/src/inc/MarlinConfigPre.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
//
#include <stdint.h>

#include "../HAL/platforms.h"
#ifndef __MARLIN_DEPS__
#include "../HAL/platforms.h"
#endif

#include "../core/boards.h"
#include "../core/macros.h"
Expand All @@ -45,10 +47,16 @@
#include "Version.h"

#include "Conditionals_LCD.h"
#include HAL_PATH(../HAL, inc/Conditionals_LCD.h)

#ifndef __MARLIN_DEPS__
#include HAL_PATH(../HAL, inc/Conditionals_LCD.h)
#endif

#include "../core/drivers.h"
#include "../../Configuration_adv.h"

#include "Conditionals_adv.h"
#include HAL_PATH(../HAL, inc/Conditionals_adv.h)

#ifndef __MARLIN_DEPS__
#include HAL_PATH(../HAL, inc/Conditionals_adv.h)
#endif
2 changes: 1 addition & 1 deletion Marlin/src/pins/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#define HAS_FREE_AUX2_PINS !(BOTH(ULTRA_LCD, NEWPANEL) && ANY(PANEL_ONE, VIKI2, miniVIKI, MINIPANEL, REPRAPWORLD_KEYPAD))

// Test the target within the included pins file
#ifdef __MARLIN_PREBUILD__
#ifdef __MARLIN_DEPS__
#define NOT_TARGET(V...) 0
#else
#define NOT_TARGET(V...) NONE(V)
Expand Down
47 changes: 6 additions & 41 deletions buildroot/share/PlatformIO/scripts/common-dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

/**
* The purpose of this file is just include Marlin Configuration files,
* to discover which FEATURES are enabled, without any HAL include.
* Used by common-dependencies.py
*/

#include <stdint.h>
#define NUM_SERIAL 1 // Normally provided by HAL/HAL.h

// Include platform headers
//#include "../../../../Marlin/src/HAL/platforms.h"

#include "../../../../Marlin/src/core/boards.h"
#include "../../../../Marlin/src/core/macros.h"
#include "../../../../Marlin/Configuration.h"

#include "../../../../Marlin/Version.h"

#include "../../../../Marlin/src/inc/Conditionals_LCD.h"

#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_LCD.h)
#endif

#include "../../../../Marlin/src/core/drivers.h"
#include "../../../../Marlin/Configuration_adv.h"

#include "../../../../Marlin/src/inc/Conditionals_adv.h"

#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_adv.h)
#endif

//#include "../../../../Marlin/src/pins/pins.h"

#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, timers.h)
#include HAL_PATH(../../../../Marlin/src/HAL, spi_pins.h)
#endif

#include "../../../../Marlin/src/inc/Conditionals_post.h"

#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_post.h)
#endif
#include "../../../../Marlin/src/inc/MarlinConfig.h"

//
// Conditionals only used for [features]
Expand All @@ -89,6 +53,10 @@
#define HAS_EXTRUDERS
#endif

#if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
#define HAS_SMART_EFF_MOD
#endif

#if HAS_LCD_MENU
#if ENABLED(BACKLASH_GCODE)
#define HAS_MENU_BACKLASH
Expand Down Expand Up @@ -145,6 +113,3 @@
#define HAS_MENU_UBL
#endif
#endif

// Include pins for the current board. Platform tests will be skipped. No HAL-defined pins.
#include "../../../../Marlin/src/pins/pins.h"
8 changes: 7 additions & 1 deletion buildroot/share/PlatformIO/scripts/common-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def parse_pkg_uri(spec):
FEATURE_CONFIG = {}

def add_to_feat_cnf(feature, flines):

try:
feat = FEATURE_CONFIG[feature]
except:
FEATURE_CONFIG[feature] = {}

feat = FEATURE_CONFIG[feature]
atoms = re.sub(',\\s*', '\n', flines).strip().split('\n')
for dep in atoms:
Expand Down Expand Up @@ -238,7 +244,7 @@ def load_marlin_features():
else:
cmd += ['-D' + s]

cmd += ['-D__MARLIN_PREBUILD__ -w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h']
cmd += ['-D__MARLIN_DEPS__ -w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h']
cmd = ' '.join(cmd)
blab(cmd)
define_list = subprocess.check_output(cmd, shell=True).splitlines()
Expand Down
Loading

0 comments on commit 454f9d6

Please sign in to comment.