Skip to content

Commit

Permalink
Move some MarlinCore and MarlinUI code (MarlinFirmware#20832)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and kpishere committed Feb 19, 2021
1 parent 4cc48fa commit 0d8bf94
Show file tree
Hide file tree
Showing 38 changed files with 178 additions and 206 deletions.
118 changes: 23 additions & 95 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <math.h>

#include "core/utility.h"

#include "module/motion.h"
#include "module/planner.h"
#include "module/endstops.h"
Expand All @@ -57,6 +58,7 @@
#include "gcode/parser.h"
#include "gcode/queue.h"

#include "feature/pause.h"
#include "sd/cardreader.h"

#include "lcd/marlinui.h"
Expand Down Expand Up @@ -139,7 +141,6 @@

#if ENABLED(EXPERIMENTAL_I2CBUS)
#include "feature/twibus.h"
TWIBus i2c;
#endif

#if ENABLED(I2C_POSITION_ENCODERS)
Expand Down Expand Up @@ -173,10 +174,6 @@
#include "feature/bedlevel/bedlevel.h"
#endif

#if BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT)
#include "feature/pause.h"
#endif

#if ENABLED(GCODE_REPEAT_MARKERS)
#include "feature/repeat.h"
#endif
Expand Down Expand Up @@ -267,40 +264,12 @@ bool wait_for_heatup = true;

#endif

#if PIN_EXISTS(CHDK)
extern millis_t chdk_timeout;
#endif

#if ENABLED(I2C_POSITION_ENCODERS)
I2CPositionEncodersMgr I2CPEM;
#endif

/**
* ***************************************************************************
* ******************************** FUNCTIONS ********************************
* ***************************************************************************
*/

void setup_killpin() {
#if HAS_KILL
#if KILL_PIN_STATE
SET_INPUT_PULLDOWN(KILL_PIN);
#else
SET_INPUT_PULLUP(KILL_PIN);
#endif
#endif
}

void setup_powerhold() {
#if HAS_SUICIDE
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
#endif
#if ENABLED(PSU_CONTROL)
powersupply_on = ENABLED(PSU_DEFAULT_OFF);
if (ENABLED(PSU_DEFAULT_OFF)) PSU_OFF(); else PSU_ON();
#endif
}

/**
* Stepper Reset (RigidBoard, et.al.)
*/
Expand All @@ -309,18 +278,6 @@ void setup_powerhold() {
void enableStepperDrivers() { SET_INPUT(STEPPER_RESET_PIN); } // Set to input, allowing pullups to pull the pin high
#endif

#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0

void i2c_on_receive(int bytes) { // just echo all bytes received to serial
i2c.receive(bytes);
}

void i2c_on_request() { // just send dummy data for now
i2c.reply("Hello World!\n");
}

#endif

/**
* Sensitive pin test for M42, M226
*/
Expand All @@ -342,17 +299,6 @@ bool pin_is_protected(const pin_t pin) {

#pragma GCC diagnostic pop

void protected_pin_err() {
SERIAL_ERROR_MSG(STR_ERR_PROTECTED_PIN);
}

void quickstop_stepper() {
planner.quick_stop();
planner.synchronize();
set_current_from_steppers_for_axis(ALL_AXES);
sync_plan_position();
}

void enable_e_steppers() {
#define _ENA_E(N) ENABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _ENA_E)
Expand Down Expand Up @@ -389,41 +335,6 @@ void disable_all_steppers() {
TERN_(EXTENSIBLE_UI, ExtUI::onSteppersDisabled());
}

#if ENABLED(G29_RETRY_AND_RECOVER)

void event_probe_failure() {
#ifdef ACTION_ON_G29_FAILURE
host_action(PSTR(ACTION_ON_G29_FAILURE));
#endif
#ifdef G29_FAILURE_COMMANDS
gcode.process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
#endif
#if ENABLED(G29_HALT_ON_FAILURE)
#ifdef ACTION_ON_CANCEL
host_action_cancel();
#endif
kill(GET_TEXT(MSG_LCD_PROBING_FAILED));
#endif
}

void event_probe_recover() {
TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"), DISMISS_STR));
#ifdef ACTION_ON_G29_RECOVER
host_action(PSTR(ACTION_ON_G29_RECOVER));
#endif
#ifdef G29_RECOVER_COMMANDS
gcode.process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
#endif
}

#endif

#if ENABLED(ADVANCED_PAUSE_FEATURE)
#include "feature/pause.h"
#else
constexpr bool did_pause_print = false;
#endif

/**
* A Print Job exists when the timer is running or SD printing
*/
Expand Down Expand Up @@ -511,8 +422,8 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {

// Prevent steppers timing-out in the middle of M600
// unless PAUSE_PARK_NO_STEPPER_TIMEOUT is disabled
const bool parked_or_ignoring = ignore_stepper_queue ||
(BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) && did_pause_print);
const bool parked_or_ignoring = ignore_stepper_queue
|| TERN0(PAUSE_PARK_NO_STEPPER_TIMEOUT, did_pause_print);

// Reset both the M18/M84 activity timeout and the M85 max 'kill' timeout
if (parked_or_ignoring) gcode.reset_stepper_timeout(ms);
Expand Down Expand Up @@ -550,6 +461,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}

#if PIN_EXISTS(CHDK) // Check if pin should be set to LOW (after M240 set it HIGH)
extern millis_t chdk_timeout;
if (chdk_timeout && ELAPSED(ms, chdk_timeout)) {
chdk_timeout = 0;
WRITE(CHDK_PIN, LOW);
Expand Down Expand Up @@ -1038,13 +950,29 @@ void setup() {
SETUP_RUN(recovery.setup());
#endif

SETUP_RUN(setup_killpin());
#if HAS_KILL
SETUP_LOG("KILL_PIN");
#if KILL_PIN_STATE
SET_INPUT_PULLDOWN(KILL_PIN);
#else
SET_INPUT_PULLUP(KILL_PIN);
#endif
#endif

#if HAS_TMC220x
SETUP_RUN(tmc_serial_begin());
#endif

SETUP_RUN(setup_powerhold());
#if HAS_SUICIDE
SETUP_LOG("SUICIDE_PIN")
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
#endif

#if ENABLED(PSU_CONTROL)
SETUP_LOG("PSU_CONTROL");
powersupply_on = ENABLED(PSU_DEFAULT_OFF);
if (ENABLED(PSU_DEFAULT_OFF)) PSU_OFF(); else PSU_ON();
#endif

#if HAS_STEPPER_RESET
SETUP_RUN(disableStepperDrivers());
Expand Down
13 changes: 0 additions & 13 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ void stop();
void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep=false));
inline void idle_no_sleep() { idle(TERN_(ADVANCED_PAUSE_FEATURE, true)); }

#if ENABLED(EXPERIMENTAL_I2CBUS)
#include "feature/twibus.h"
extern TWIBus i2c;
#endif

#if ENABLED(G38_PROBE_TARGET)
extern uint8_t G38_move; // Flag to tell the ISR that G38 is in progress, and the type
extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop changed
Expand All @@ -59,8 +54,6 @@ void disable_all_steppers();
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
void minkill(const bool steppers_off=false);

void quickstop_stepper();

// Global State of the firmware
enum MarlinState : uint8_t {
MF_INITIALIZING = 0,
Expand Down Expand Up @@ -103,7 +96,6 @@ extern bool wait_for_heatup;
#endif

bool pin_is_protected(const pin_t pin);
void protected_pin_err();

#if HAS_SUICIDE
inline void suicide() { OUT_WRITE(SUICIDE_PIN, SUICIDE_PIN_INVERTING); }
Expand All @@ -116,11 +108,6 @@ void protected_pin_err();
inline bool kill_state() { return READ(KILL_PIN) == KILL_PIN_STATE; }
#endif

#if ENABLED(G29_RETRY_AND_RECOVER)
void event_probe_recover();
void event_probe_failure();
#endif

extern const char NUL_STR[], M112_KILL_STR[], G28_STR[], M21_STR[], M23_STR[], M24_STR[],
SP_A_STR[], SP_B_STR[], SP_C_STR[],
SP_P_STR[], SP_T_STR[], SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[],
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/feature/e_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

// External references
extern bool wait_for_user, wait_for_heatup;
void quickstop_stepper();

class EmergencyParser {

Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/feature/encoder_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

#include <Wire.h>

I2CPositionEncodersMgr I2CPEM;

void I2CPositionEncoder::init(const uint8_t address, const AxisEnum axis) {
encoderAxis = axis;
i2cAddress = address;
Expand Down
Loading

0 comments on commit 0d8bf94

Please sign in to comment.