Browse Source

Move servo code to modules/servo.*

Scott Lahteine 6 years ago
parent
commit
c0000a0cdc

+ 5
- 30
Marlin/src/Marlin.cpp View File

@@ -75,7 +75,7 @@
75 75
 #endif
76 76
 
77 77
 #if HAS_SERVOS
78
-  #include "HAL/servo.h"
78
+  #include "module/servo.h"
79 79
 #endif
80 80
 
81 81
 #if HAS_DIGIPOTSS
@@ -247,35 +247,6 @@ void setup_powerhold() {
247 247
   #endif
248 248
 }
249 249
 
250
-#if HAS_SERVOS
251
-
252
-  HAL_SERVO_LIB servo[NUM_SERVOS];
253
-
254
-  void servo_init() {
255
-    #if NUM_SERVOS >= 1 && HAS_SERVO_0
256
-      servo[0].attach(SERVO0_PIN);
257
-      servo[0].detach(); // Just set up the pin. We don't have a position yet. Don't move to a random position.
258
-    #endif
259
-    #if NUM_SERVOS >= 2 && HAS_SERVO_1
260
-      servo[1].attach(SERVO1_PIN);
261
-      servo[1].detach();
262
-    #endif
263
-    #if NUM_SERVOS >= 3 && HAS_SERVO_2
264
-      servo[2].attach(SERVO2_PIN);
265
-      servo[2].detach();
266
-    #endif
267
-    #if NUM_SERVOS >= 4 && HAS_SERVO_3
268
-      servo[3].attach(SERVO3_PIN);
269
-      servo[3].detach();
270
-    #endif
271
-
272
-    #if HAS_Z_SERVO_ENDSTOP
273
-      servo_probe_init();
274
-    #endif
275
-  }
276
-
277
-#endif // HAS_SERVOS
278
-
279 250
 /**
280 251
  * Stepper Reset (RigidBoard, et.al.)
281 252
  */
@@ -745,6 +716,10 @@ void setup() {
745 716
     servo_init();
746 717
   #endif
747 718
 
719
+  #if HAS_Z_SERVO_ENDSTOP
720
+    servo_probe_init();
721
+  #endif
722
+
748 723
   #if HAS_PHOTOGRAPH
749 724
     OUT_WRITE(PHOTOGRAPH_PIN, LOW);
750 725
   #endif

+ 0
- 10
Marlin/src/Marlin.h View File

@@ -186,16 +186,6 @@ extern volatile bool wait_for_heatup;
186 186
 // Inactivity shutdown timer
187 187
 extern millis_t max_inactive_time, stepper_inactive_time;
188 188
 
189
-#if HAS_SERVOS
190
-  #include "HAL/servo.h"
191
-  extern HAL_SERVO_LIB servo[NUM_SERVOS];
192
-  #define MOVE_SERVO(I, P) servo[I].move(P)
193
-  #if HAS_Z_SERVO_ENDSTOP
194
-    #define DEPLOY_Z_SERVO() MOVE_SERVO(Z_ENDSTOP_SERVO_NR, z_servo_angle[0])
195
-    #define STOW_Z_SERVO() MOVE_SERVO(Z_ENDSTOP_SERVO_NR, z_servo_angle[1])
196
-  #endif
197
-#endif
198
-
199 189
 #if FAN_COUNT > 0
200 190
   extern int16_t fanSpeeds[FAN_COUNT];
201 191
   #if ENABLED(EXTRA_FAN_SPEED)

+ 1
- 0
Marlin/src/gcode/config/M43.cpp View File

@@ -31,6 +31,7 @@
31 31
 
32 32
 #if HAS_Z_SERVO_ENDSTOP
33 33
   #include "../../module/probe.h"
34
+  #include "../../module/servo.h"
34 35
 #endif
35 36
 
36 37
 inline void toggle_pins() {

+ 1
- 1
Marlin/src/gcode/control/M280.cpp View File

@@ -25,7 +25,7 @@
25 25
 #if HAS_SERVOS
26 26
 
27 27
 #include "../gcode.h"
28
-#include "../../Marlin.h" // for servo[]
28
+#include "../../module/servo.h"
29 29
 
30 30
 /**
31 31
  * M280: Get or set servo position. P<index> [S<angle>]

+ 1
- 0
Marlin/src/module/probe.cpp View File

@@ -53,6 +53,7 @@
53 53
 float zprobe_zoffset; // Initialized by settings.load()
54 54
 
55 55
 #if HAS_Z_SERVO_ENDSTOP
56
+  #include "../module/servo.h"
56 57
   const int z_servo_angle[2] = Z_SERVO_ANGLES;
57 58
 #endif
58 59
 

+ 54
- 0
Marlin/src/module/servo.cpp View File

@@ -0,0 +1,54 @@
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
+/**
24
+ * module/servo.cpp
25
+ */
26
+
27
+#include "../inc/MarlinConfig.h"
28
+
29
+#if HAS_SERVOS
30
+
31
+#include "servo.h"
32
+
33
+HAL_SERVO_LIB servo[NUM_SERVOS];
34
+
35
+void servo_init() {
36
+  #if NUM_SERVOS >= 1 && HAS_SERVO_0
37
+    servo[0].attach(SERVO0_PIN);
38
+    servo[0].detach(); // Just set up the pin. We don't have a position yet. Don't move to a random position.
39
+  #endif
40
+  #if NUM_SERVOS >= 2 && HAS_SERVO_1
41
+    servo[1].attach(SERVO1_PIN);
42
+    servo[1].detach();
43
+  #endif
44
+  #if NUM_SERVOS >= 3 && HAS_SERVO_2
45
+    servo[2].attach(SERVO2_PIN);
46
+    servo[2].detach();
47
+  #endif
48
+  #if NUM_SERVOS >= 4 && HAS_SERVO_3
49
+    servo[3].attach(SERVO3_PIN);
50
+    servo[3].detach();
51
+  #endif
52
+}
53
+
54
+#endif // HAS_SERVOS

+ 44
- 0
Marlin/src/module/servo.h View File

@@ -0,0 +1,44 @@
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
+/**
24
+ * module/servo.h
25
+ */
26
+
27
+#ifndef _SERVO_H_
28
+#define _SERVO_H_
29
+
30
+#include "../HAL/servo.h"
31
+
32
+extern HAL_SERVO_LIB servo[NUM_SERVOS];
33
+extern void servo_init();
34
+
35
+#define MOVE_SERVO(I, P) servo[I].move(P)
36
+
37
+#include "../inc/MarlinConfig.h"
38
+
39
+#if HAS_Z_SERVO_ENDSTOP
40
+  #define DEPLOY_Z_SERVO() MOVE_SERVO(Z_ENDSTOP_SERVO_NR, z_servo_angle[0])
41
+  #define STOW_Z_SERVO() MOVE_SERVO(Z_ENDSTOP_SERVO_NR, z_servo_angle[1])
42
+#endif
43
+
44
+#endif // _SERVO_H_

+ 4
- 0
Marlin/src/module/tool_change.cpp View File

@@ -34,6 +34,10 @@
34 34
   #include "../gcode/gcode.h" // for dwell()
35 35
 #endif
36 36
 
37
+#if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
38
+  #include "../module/servo.h"
39
+#endif
40
+
37 41
 #if ENABLED(EXT_SOLENOID) && !ENABLED(PARKING_EXTRUDER)
38 42
   #include "../feature/solenoid.h"
39 43
 #endif

Loading…
Cancel
Save