From 6e0503eab2329ee9664a3611b225e55559a97944 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 17 Sep 2017 18:45:21 -0500 Subject: [PATCH] Move M907-M910 to cpp --- Marlin/src/Marlin.cpp | 19 +++------- .../M909.h => feature/digipot/digipot.h} | 8 +++-- .../feature/{ => digipot}/digipot_mcp4018.cpp | 6 ++-- .../feature/{ => digipot}/digipot_mcp4451.cpp | 15 +++----- .../feature/digipot/{M907.h => M907.cpp} | 16 ++++++++- .../feature/digipot/{M908.h => M908.cpp} | 20 +++++++++-- Marlin/src/gcode/feature/digipot/M909.cpp | 36 +++++++++++++++++++ .../feature/digipot/{M910.h => M910.cpp} | 11 +++++- Marlin/src/gcode/gcode.cpp | 28 +++------------ 9 files changed, 101 insertions(+), 58 deletions(-) rename Marlin/src/{gcode/feature/digipot/M909.h => feature/digipot/digipot.h} (83%) rename Marlin/src/feature/{ => digipot}/digipot_mcp4018.cpp (96%) rename Marlin/src/feature/{ => digipot}/digipot_mcp4451.cpp (85%) rename Marlin/src/gcode/feature/digipot/{M907.h => M907.cpp} (88%) rename Marlin/src/gcode/feature/digipot/{M908.h => M908.cpp} (75%) create mode 100644 Marlin/src/gcode/feature/digipot/M909.cpp rename Marlin/src/gcode/feature/digipot/{M910.h => M910.cpp} (81%) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 6aaaa73c06..d371bf9b5f 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -58,6 +58,10 @@ #include "module/tool_change.h" #endif +#if ENABLED(DIGIPOT_I2C) + #include "feature/digipot/digipot.h" +#endif + #if ENABLED(BEZIER_CURVE_SUPPORT) #include "module/planner_bezier.h" #endif @@ -206,11 +210,6 @@ millis_t max_inactive_time = 0, * *************************************************************************** */ -#if ENABLED(DIGIPOT_I2C) - extern void digipot_i2c_set_current(uint8_t channel, float current); - extern void digipot_i2c_init(); -#endif - void setup_killpin() { #if HAS_KILL SET_INPUT_PULLUP(KILL_PIN); @@ -359,16 +358,6 @@ void quickstop_stepper() { SYNC_PLAN_POSITION_KINEMATIC(); } -#include "gcode/feature/digipot/M907.h" - -#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT) - #include "gcode/feature/digipot/M908.h" - #if ENABLED(DAC_STEPPER_CURRENT) // As with Printrbot RevF - #include "gcode/feature/digipot/M909.h" - #include "gcode/feature/digipot/M910.h" - #endif -#endif - #if HAS_MICROSTEPS #include "gcode/control/M350.h" #include "gcode/control/M351.h" diff --git a/Marlin/src/gcode/feature/digipot/M909.h b/Marlin/src/feature/digipot/digipot.h similarity index 83% rename from Marlin/src/gcode/feature/digipot/M909.h rename to Marlin/src/feature/digipot/digipot.h index 63951ce2af..f2cd00ba6e 100644 --- a/Marlin/src/gcode/feature/digipot/M909.h +++ b/Marlin/src/feature/digipot/digipot.h @@ -20,8 +20,10 @@ * */ -void gcode_M909() { +#ifndef __DIGIPOT_H__ +#define __DIGIPOT_H__ - dac_print_values(); +void digipot_i2c_set_current(const uint8_t channel, const float current); +void digipot_i2c_init(); -} +#endif // __DIGIPOT_H__ diff --git a/Marlin/src/feature/digipot_mcp4018.cpp b/Marlin/src/feature/digipot/digipot_mcp4018.cpp similarity index 96% rename from Marlin/src/feature/digipot_mcp4018.cpp rename to Marlin/src/feature/digipot/digipot_mcp4018.cpp index d57d2233e9..95295f1330 100644 --- a/Marlin/src/feature/digipot_mcp4018.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4018.cpp @@ -20,11 +20,11 @@ * */ -#include "../inc/MarlinConfig.h" +#include "../../inc/MarlinConfig.h" #if ENABLED(DIGIPOT_I2C) && ENABLED(DIGIPOT_MCP4018) -#include "../core/enum.h" +#include "../../core/enum.h" #include "Stream.h" #include "utility/twi.h" #include //https://github.com/stawel/SlowSoftI2CMaster @@ -88,7 +88,7 @@ static void i2c_send(const uint8_t channel, const byte v) { } // This is for the MCP4018 I2C based digipot -void digipot_i2c_set_current(uint8_t channel, float current) { +void digipot_i2c_set_current(const uint8_t channel, const float current) { i2c_send(channel, current_to_wiper(min(max(current, 0.0f), float(DIGIPOT_A4988_MAX_CURRENT)))); } diff --git a/Marlin/src/feature/digipot_mcp4451.cpp b/Marlin/src/feature/digipot/digipot_mcp4451.cpp similarity index 85% rename from Marlin/src/feature/digipot_mcp4451.cpp rename to Marlin/src/feature/digipot/digipot_mcp4451.cpp index 5e94898eac..0034050d82 100644 --- a/Marlin/src/feature/digipot_mcp4451.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4451.cpp @@ -20,13 +20,13 @@ * */ -#include "../inc/MarlinConfig.h" +#include "../../inc/MarlinConfig.h" #if ENABLED(DIGIPOT_I2C) && DISABLED(DIGIPOT_MCP4018) #include "Stream.h" #include "utility/twi.h" -#include "Wire.h" +#include // Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro #if MB(5DPRINT) @@ -49,15 +49,10 @@ static void i2c_send(const byte addr, const byte a, const byte b) { } // This is for the MCP4451 I2C based digipot -void digipot_i2c_set_current(uint8_t channel, float current) { - current = min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT); +void digipot_i2c_set_current(const uint8_t channel, const float current) { // these addresses are specific to Azteeg X3 Pro, can be set to others, // In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1 - byte addr = 0x2C; // channel 0-3 - if (channel >= 4) { - addr = 0x2E; // channel 4-7 - channel -= 4; - } + const byte addr = channel < 4 ? 0x2C : 0x2E; // channel 0-3 vs 4-7 // Initial setup i2c_send(addr, 0x40, 0xFF); @@ -65,7 +60,7 @@ void digipot_i2c_set_current(uint8_t channel, float current) { // Set actual wiper value byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 }; - i2c_send(addr, addresses[channel], current_to_wiper(current)); + i2c_send(addr, addresses[channel & 0x3], current_to_wiper(min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT))); } void digipot_i2c_init() { diff --git a/Marlin/src/gcode/feature/digipot/M907.h b/Marlin/src/gcode/feature/digipot/M907.cpp similarity index 88% rename from Marlin/src/gcode/feature/digipot/M907.h rename to Marlin/src/gcode/feature/digipot/M907.cpp index ebd4aa4c88..8a1062c10f 100644 --- a/Marlin/src/gcode/feature/digipot/M907.h +++ b/Marlin/src/gcode/feature/digipot/M907.cpp @@ -20,10 +20,24 @@ * */ +#include "../../gcode.h" + +#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM + #include "../../../module/stepper.h" +#endif + +#if ENABLED(DIGIPOT_I2C) + #include "../../../feature/digipot/digipot.h" +#endif + +#if ENABLED(DAC_STEPPER_CURRENT) + #include "../../../feature/dac/stepper_dac.h" +#endif + /** * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S */ -void gcode_M907() { +void GcodeSuite::M907() { #if HAS_DIGIPOTSS LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.digipot_current(i, parser.value_int()); diff --git a/Marlin/src/gcode/feature/digipot/M908.h b/Marlin/src/gcode/feature/digipot/M908.cpp similarity index 75% rename from Marlin/src/gcode/feature/digipot/M908.h rename to Marlin/src/gcode/feature/digipot/M908.cpp index f646fbd297..0422927e34 100644 --- a/Marlin/src/gcode/feature/digipot/M908.h +++ b/Marlin/src/gcode/feature/digipot/M908.cpp @@ -20,20 +20,36 @@ * */ +#include "../../../inc/MarlinConfig.h" + +#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT) + +#include "../../gcode.h" + +#if HAS_DIGIPOTSS + #include "../../../module/stepper.h" +#endif + +#if ENABLED(DAC_STEPPER_CURRENT) + #include "../../../feature/dac/stepper_dac.h" +#endif + /** * M908: Control digital trimpot directly (M908 P S) */ -void gcode_M908() { +void GcodeSuite::M908() { #if HAS_DIGIPOTSS stepper.digitalPotWrite( parser.intval('P'), parser.intval('S') ); #endif - #ifdef DAC_STEPPER_CURRENT + #if ENABLED(DAC_STEPPER_CURRENT) dac_current_raw( parser.byteval('P', -1), parser.ushortval('S', 0) ); #endif } + +#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT diff --git a/Marlin/src/gcode/feature/digipot/M909.cpp b/Marlin/src/gcode/feature/digipot/M909.cpp new file mode 100644 index 0000000000..f23b9afdc5 --- /dev/null +++ b/Marlin/src/gcode/feature/digipot/M909.cpp @@ -0,0 +1,36 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../inc/MarlinConfig.h" + +#if ENABLED(DAC_STEPPER_CURRENT) + +#include "../../gcode.h" +#include "../../../feature/dac/stepper_dac.h" + +void GcodeSuite::M909() { + + dac_print_values(); + +} + +#endif // DAC_STEPPER_CURRENT diff --git a/Marlin/src/gcode/feature/digipot/M910.h b/Marlin/src/gcode/feature/digipot/M910.cpp similarity index 81% rename from Marlin/src/gcode/feature/digipot/M910.h rename to Marlin/src/gcode/feature/digipot/M910.cpp index 4abe7972c3..1e717c6e26 100644 --- a/Marlin/src/gcode/feature/digipot/M910.h +++ b/Marlin/src/gcode/feature/digipot/M910.cpp @@ -20,8 +20,17 @@ * */ -void gcode_M910() { +#include "../../../inc/MarlinConfig.h" + +#if ENABLED(DAC_STEPPER_CURRENT) + +#include "../../gcode.h" +#include "../../../feature/dac/stepper_dac.h" + +void GcodeSuite::M910() { dac_commit_eeprom(); } + +#endif // DAC_STEPPER_CURRENT diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index a2dc0cec0c..f899f700e2 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -122,10 +122,6 @@ extern void gcode_M165(); extern void gcode_M350(); extern void gcode_M351(); extern void gcode_M355(); -extern void gcode_M907(); -extern void gcode_M908(); -extern void gcode_M909(); -extern void gcode_M910(); extern void gcode_M999(); extern void gcode_T(uint8_t tmp_extruder); @@ -655,29 +651,15 @@ void GcodeSuite::process_next_command() { case 900: M900(); break; // M900: Set advance K factor. #endif - case 907: // M907: Set digital trimpot motor current using axis codes. - gcode_M907(); - break; + case 907: M907(); break; // M907: Set digital trimpot motor current using axis codes. #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT) - - case 908: // M908: Control digital trimpot directly. - gcode_M908(); - break; - + case 908: M908(); break; // M908: Control digital trimpot directly. #if ENABLED(DAC_STEPPER_CURRENT) // As with Printrbot RevF - - case 909: // M909: Print digipot/DAC current value - gcode_M909(); - break; - - case 910: // M910: Commit digipot/DAC value to external EEPROM - gcode_M910(); - break; - + case 909: M909(); break; // M909: Print digipot/DAC current value + case 910: M910(); break; // M910: Commit digipot/DAC value to external EEPROM #endif - - #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT + #endif #if ENABLED(HAVE_TMC2130) case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E