Browse Source

Move M907-M910 to cpp

Scott Lahteine 7 years ago
parent
commit
6e0503eab2

+ 4
- 15
Marlin/src/Marlin.cpp View File

@@ -58,6 +58,10 @@
58 58
   #include "module/tool_change.h"
59 59
 #endif
60 60
 
61
+#if ENABLED(DIGIPOT_I2C)
62
+  #include "feature/digipot/digipot.h"
63
+#endif
64
+
61 65
 #if ENABLED(BEZIER_CURVE_SUPPORT)
62 66
   #include "module/planner_bezier.h"
63 67
 #endif
@@ -206,11 +210,6 @@ millis_t max_inactive_time = 0,
206 210
  * ***************************************************************************
207 211
  */
208 212
 
209
-#if ENABLED(DIGIPOT_I2C)
210
-  extern void digipot_i2c_set_current(uint8_t channel, float current);
211
-  extern void digipot_i2c_init();
212
-#endif
213
-
214 213
 void setup_killpin() {
215 214
   #if HAS_KILL
216 215
     SET_INPUT_PULLUP(KILL_PIN);
@@ -359,16 +358,6 @@ void quickstop_stepper() {
359 358
   SYNC_PLAN_POSITION_KINEMATIC();
360 359
 }
361 360
 
362
-#include "gcode/feature/digipot/M907.h"
363
-
364
-#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
365
-  #include "gcode/feature/digipot/M908.h"
366
-  #if ENABLED(DAC_STEPPER_CURRENT) // As with Printrbot RevF
367
-    #include "gcode/feature/digipot/M909.h"
368
-    #include "gcode/feature/digipot/M910.h"
369
-  #endif
370
-#endif
371
-
372 361
 #if HAS_MICROSTEPS
373 362
   #include "gcode/control/M350.h"
374 363
   #include "gcode/control/M351.h"

Marlin/src/gcode/feature/digipot/M909.h → Marlin/src/feature/digipot/digipot.h View File

@@ -20,8 +20,10 @@
20 20
  *
21 21
  */
22 22
 
23
-void gcode_M909() {
23
+#ifndef __DIGIPOT_H__
24
+#define __DIGIPOT_H__
24 25
 
25
-  dac_print_values();
26
+void digipot_i2c_set_current(const uint8_t channel, const float current);
27
+void digipot_i2c_init();
26 28
 
27
-}
29
+#endif // __DIGIPOT_H__

Marlin/src/feature/digipot_mcp4018.cpp → Marlin/src/feature/digipot/digipot_mcp4018.cpp View File

@@ -20,11 +20,11 @@
20 20
  *
21 21
  */
22 22
 
23
-#include "../inc/MarlinConfig.h"
23
+#include "../../inc/MarlinConfig.h"
24 24
 
25 25
 #if ENABLED(DIGIPOT_I2C) && ENABLED(DIGIPOT_MCP4018)
26 26
 
27
-#include "../core/enum.h"
27
+#include "../../core/enum.h"
28 28
 #include "Stream.h"
29 29
 #include "utility/twi.h"
30 30
 #include <SlowSoftI2CMaster.h>  //https://github.com/stawel/SlowSoftI2CMaster
@@ -88,7 +88,7 @@ static void i2c_send(const uint8_t channel, const byte v) {
88 88
 }
89 89
 
90 90
 // This is for the MCP4018 I2C based digipot
91
-void digipot_i2c_set_current(uint8_t channel, float current) {
91
+void digipot_i2c_set_current(const uint8_t channel, const float current) {
92 92
   i2c_send(channel, current_to_wiper(min(max(current, 0.0f), float(DIGIPOT_A4988_MAX_CURRENT))));
93 93
 }
94 94
 

Marlin/src/feature/digipot_mcp4451.cpp → Marlin/src/feature/digipot/digipot_mcp4451.cpp View File

@@ -20,13 +20,13 @@
20 20
  *
21 21
  */
22 22
 
23
-#include "../inc/MarlinConfig.h"
23
+#include "../../inc/MarlinConfig.h"
24 24
 
25 25
 #if ENABLED(DIGIPOT_I2C) && DISABLED(DIGIPOT_MCP4018)
26 26
 
27 27
 #include "Stream.h"
28 28
 #include "utility/twi.h"
29
-#include "Wire.h"
29
+#include <Wire.h>
30 30
 
31 31
 // Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro
32 32
 #if MB(5DPRINT)
@@ -49,15 +49,10 @@ static void i2c_send(const byte addr, const byte a, const byte b) {
49 49
 }
50 50
 
51 51
 // This is for the MCP4451 I2C based digipot
52
-void digipot_i2c_set_current(uint8_t channel, float current) {
53
-  current = min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT);
52
+void digipot_i2c_set_current(const uint8_t channel, const float current) {
54 53
   // these addresses are specific to Azteeg X3 Pro, can be set to others,
55 54
   // In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1
56
-  byte addr = 0x2C; // channel 0-3
57
-  if (channel >= 4) {
58
-    addr = 0x2E; // channel 4-7
59
-    channel -= 4;
60
-  }
55
+  const byte addr = channel < 4 ? 0x2C : 0x2E; // channel 0-3 vs 4-7
61 56
 
62 57
   // Initial setup
63 58
   i2c_send(addr, 0x40, 0xFF);
@@ -65,7 +60,7 @@ void digipot_i2c_set_current(uint8_t channel, float current) {
65 60
 
66 61
   // Set actual wiper value
67 62
   byte addresses[4] = { 0x00, 0x10, 0x60, 0x70 };
68
-  i2c_send(addr, addresses[channel], current_to_wiper(current));
63
+  i2c_send(addr, addresses[channel & 0x3], current_to_wiper(min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT)));
69 64
 }
70 65
 
71 66
 void digipot_i2c_init() {

Marlin/src/gcode/feature/digipot/M907.h → Marlin/src/gcode/feature/digipot/M907.cpp View File

@@ -20,10 +20,24 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../gcode.h"
24
+
25
+#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
26
+  #include "../../../module/stepper.h"
27
+#endif
28
+
29
+#if ENABLED(DIGIPOT_I2C)
30
+  #include "../../../feature/digipot/digipot.h"
31
+#endif
32
+
33
+#if ENABLED(DAC_STEPPER_CURRENT)
34
+  #include "../../../feature/dac/stepper_dac.h"
35
+#endif
36
+
23 37
 /**
24 38
  * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
25 39
  */
26
-void gcode_M907() {
40
+void GcodeSuite::M907() {
27 41
   #if HAS_DIGIPOTSS
28 42
 
29 43
     LOOP_XYZE(i) if (parser.seen(axis_codes[i])) stepper.digipot_current(i, parser.value_int());

Marlin/src/gcode/feature/digipot/M908.h → Marlin/src/gcode/feature/digipot/M908.cpp View File

@@ -20,20 +20,36 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
26
+
27
+#include "../../gcode.h"
28
+
29
+#if HAS_DIGIPOTSS
30
+  #include "../../../module/stepper.h"
31
+#endif
32
+
33
+#if ENABLED(DAC_STEPPER_CURRENT)
34
+  #include "../../../feature/dac/stepper_dac.h"
35
+#endif
36
+
23 37
 /**
24 38
  * M908: Control digital trimpot directly (M908 P<pin> S<current>)
25 39
  */
26
-void gcode_M908() {
40
+void GcodeSuite::M908() {
27 41
   #if HAS_DIGIPOTSS
28 42
     stepper.digitalPotWrite(
29 43
       parser.intval('P'),
30 44
       parser.intval('S')
31 45
     );
32 46
   #endif
33
-  #ifdef DAC_STEPPER_CURRENT
47
+  #if ENABLED(DAC_STEPPER_CURRENT)
34 48
     dac_current_raw(
35 49
       parser.byteval('P', -1),
36 50
       parser.ushortval('S', 0)
37 51
     );
38 52
   #endif
39 53
 }
54
+
55
+#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT

+ 36
- 0
Marlin/src/gcode/feature/digipot/M909.cpp View File

@@ -0,0 +1,36 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(DAC_STEPPER_CURRENT)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/dac/stepper_dac.h"
29
+
30
+void GcodeSuite::M909() {
31
+
32
+  dac_print_values();
33
+
34
+}
35
+
36
+#endif // DAC_STEPPER_CURRENT

Marlin/src/gcode/feature/digipot/M910.h → Marlin/src/gcode/feature/digipot/M910.cpp View File

@@ -20,8 +20,17 @@
20 20
  *
21 21
  */
22 22
 
23
-void gcode_M910() {
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(DAC_STEPPER_CURRENT)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/dac/stepper_dac.h"
29
+
30
+void GcodeSuite::M910() {
24 31
 
25 32
   dac_commit_eeprom();
26 33
 
27 34
 }
35
+
36
+#endif // DAC_STEPPER_CURRENT

+ 5
- 23
Marlin/src/gcode/gcode.cpp View File

@@ -122,10 +122,6 @@ extern void gcode_M165();
122 122
 extern void gcode_M350();
123 123
 extern void gcode_M351();
124 124
 extern void gcode_M355();
125
-extern void gcode_M907();
126
-extern void gcode_M908();
127
-extern void gcode_M909();
128
-extern void gcode_M910();
129 125
 extern void gcode_M999();
130 126
 extern void gcode_T(uint8_t tmp_extruder);
131 127
 
@@ -655,29 +651,15 @@ void GcodeSuite::process_next_command() {
655 651
         case 900: M900(); break;  // M900: Set advance K factor.
656 652
       #endif
657 653
 
658
-      case 907: // M907: Set digital trimpot motor current using axis codes.
659
-        gcode_M907();
660
-        break;
654
+      case 907: M907(); break;      // M907: Set digital trimpot motor current using axis codes.
661 655
 
662 656
       #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
663
-
664
-        case 908: // M908: Control digital trimpot directly.
665
-          gcode_M908();
666
-          break;
667
-
657
+        case 908: M908(); break;    // M908: Control digital trimpot directly.
668 658
         #if ENABLED(DAC_STEPPER_CURRENT) // As with Printrbot RevF
669
-
670
-          case 909: // M909: Print digipot/DAC current value
671
-            gcode_M909();
672
-            break;
673
-
674
-          case 910: // M910: Commit digipot/DAC value to external EEPROM
675
-            gcode_M910();
676
-            break;
677
-
659
+          case 909: M909(); break;  // M909: Print digipot/DAC current value
660
+          case 910: M910(); break;  // M910: Commit digipot/DAC value to external EEPROM
678 661
         #endif
679
-
680
-      #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
662
+      #endif
681 663
 
682 664
       #if ENABLED(HAVE_TMC2130)
683 665
         case 906: M906(); break;    // M906: Set motor current in milliamps using axis codes X, Y, Z, E

Loading…
Cancel
Save