diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 0b22e745bb..2d42dbaae0 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -84,6 +84,7 @@ #if ENABLED(EXPERIMENTAL_I2CBUS) #include "feature/twibus.h" + TWIBus i2c; #endif #if ENABLED(I2C_POSITION_ENCODERS) @@ -98,10 +99,6 @@ CardReader card; #endif -#if ENABLED(EXPERIMENTAL_I2CBUS) - TWIBus i2c; -#endif - #if ENABLED(G38_PROBE_TARGET) bool G38_move = false, G38_endstop_hit = false; @@ -355,10 +352,6 @@ bool pin_is_protected(const int8_t pin) { return false; } -#if ENABLED(EXPERIMENTAL_I2CBUS) - #include "gcode/feature/i2c/M260_M261.h" -#endif - #if HAS_SERVOS #include "gcode/control/M280.h" #endif diff --git a/Marlin/src/Marlin.h b/Marlin/src/Marlin.h index 84bb67ba97..ba37ccd598 100644 --- a/Marlin/src/Marlin.h +++ b/Marlin/src/Marlin.h @@ -143,6 +143,11 @@ void manage_inactivity(bool ignore_stepper_queue = false); #endif // !MIXING_EXTRUDER +#if ENABLED(EXPERIMENTAL_I2CBUS) + #include "feature/twibus.h" + extern TWIBus i2c; +#endif + #if ENABLED(G38_PROBE_TARGET) extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active diff --git a/Marlin/src/gcode/feature/i2c/M260_M261.h b/Marlin/src/gcode/feature/i2c/M260_M261.cpp similarity index 91% rename from Marlin/src/gcode/feature/i2c/M260_M261.h rename to Marlin/src/gcode/feature/i2c/M260_M261.cpp index c66d19c52b..fdfa5804d6 100644 --- a/Marlin/src/gcode/feature/i2c/M260_M261.h +++ b/Marlin/src/gcode/feature/i2c/M260_M261.cpp @@ -20,6 +20,14 @@ * */ +#include "../../../inc/MarlinConfig.h" + +#if ENABLED(EXPERIMENTAL_I2CBUS) + +#include "../../gcode.h" + +#include "../../../Marlin.h" // for i2c + /** * M260: Send data to a I2C slave device * @@ -36,7 +44,7 @@ * M260 R1 ; Reset the buffer without sending data * */ -void gcode_M260() { +void GcodeSuite::M260() { // Set the target address if (parser.seen('A')) i2c.address(parser.value_byte()); @@ -55,7 +63,7 @@ void gcode_M260() { * * Usage: M261 A B */ -void gcode_M261() { +void GcodeSuite::M261() { if (parser.seen('A')) i2c.address(parser.value_byte()); uint8_t bytes = parser.byteval('B', 1); @@ -68,3 +76,5 @@ void gcode_M261() { SERIAL_ERRORLN("Bad i2c request"); } } + +#endif diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 79dd5e3bc7..7de00309e0 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -121,8 +121,6 @@ extern void gcode_M164(); extern void gcode_M165(); extern void gcode_M240(); extern void gcode_M250(); -extern void gcode_M260(); -extern void gcode_M261(); extern void gcode_M280(); extern void gcode_M300(); extern void gcode_M301(); @@ -602,16 +600,9 @@ void GcodeSuite::process_next_command() { #endif // HAS_LCD_CONTRAST #if ENABLED(EXPERIMENTAL_I2CBUS) - - case 260: // M260: Send data to an i2c slave - gcode_M260(); - break; - - case 261: // M261: Request data from an i2c slave - gcode_M261(); - break; - - #endif // EXPERIMENTAL_I2CBUS + case 260: M260(); break; // M260: Send data to an i2c slave + case 261: M261(); break; // M261: Request data from an i2c slave + #endif #if ENABLED(PREVENT_COLD_EXTRUSION) case 302: // M302: Allow cold extrudes (set the minimum extrude temperature)