Prusa MINI Firmware overview
servo.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 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 #pragma once
23 
24 /**
25  * module/servo.h
26  */
27 
28 #include "../inc/MarlinConfig.h"
29 #include "../HAL/shared/servo.h"
30 
31 #if HAS_SERVO_ANGLES
32 
33  #if ENABLED(SWITCHING_EXTRUDER)
34  #ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
35  #define SWITCHING_EXTRUDER_E23_SERVO_NR -1
36  #endif
37  #if EXTRUDERS > 3
38  #define REQ_ANGLES 4
39  #else
40  #define REQ_ANGLES 2
41  #endif
42  #define SADATA SWITCHING_EXTRUDER_SERVO_ANGLES
43  #define ASRC(N,E) (SWITCHING_EXTRUDER_SERVO_NR == N ? asrc[E] : SWITCHING_EXTRUDER_E23_SERVO_NR == N ? asrc[E+2] : 0)
44  #elif ENABLED(SWITCHING_NOZZLE)
45  #define SADATA SWITCHING_NOZZLE_SERVO_ANGLES
46  #define ASRC(N,E) (SWITCHING_NOZZLE_SERVO_NR == N ? asrc[E] : 0)
47  #elif defined(Z_PROBE_SERVO_NR)
48  #define ASRC(N,E) (Z_PROBE_SERVO_NR == N ? asrc[E] : 0)
49  #if ENABLED(BLTOUCH)
50  #include "../feature/bltouch.h"
51  #endif
52  #ifdef BLTOUCH_ANGLES
53  #define SADATA BLTOUCH_ANGLES
54  #elif defined(Z_SERVO_ANGLES)
55  #define SADATA Z_SERVO_ANGLES
56  #else
57  #error "Servo angles are needed!"
58  #endif
59  #endif
60 
61  #if ENABLED(EDITABLE_SERVO_ANGLES)
62  extern uint16_t servo_angles[NUM_SERVOS][2];
63  #define BASE_SERVO_ANGLES base_servo_angles
64  #else
65  #define BASE_SERVO_ANGLES servo_angles
66  #endif
67 
68  constexpr uint16_t asrc[] = SADATA;
69  #if REQ_ANGLES
70  static_assert(COUNT(asrc) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
71  #endif
72 
73  constexpr uint16_t BASE_SERVO_ANGLES [NUM_SERVOS][2] = {
74  { ASRC(0,0), ASRC(0,1) }
75  #if NUM_SERVOS > 1
76  , { ASRC(1,0), ASRC(1,1) }
77  #if NUM_SERVOS > 2
78  , { ASRC(2,0), ASRC(2,1) }
79  #if NUM_SERVOS > 3
80  , { ASRC(3,0), ASRC(3,1) }
81  #endif
82  #endif
83  #endif
84  };
85 
86  #if HAS_Z_SERVO_PROBE
87  #define DEPLOY_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][0])
88  #define STOW_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][1])
89  #endif
90 
91 #endif // HAS_SERVO_ANGLES
92 
93 #define MOVE_SERVO(I, P) servo[I].move(P)
94 
95 extern HAL_SERVO_LIB servo[NUM_SERVOS];
96 extern void servo_init();
servo
HAL_SERVO_LIB servo[NUM_SERVOS]
BASE_SERVO_ANGLES
#define BASE_SERVO_ANGLES
Definition: servo.h:65
STRINGIFY
#define STRINGIFY(M)
Definition: macros.h:73
asrc
constexpr uint16_t asrc[]
Definition: servo.h:68
COUNT
#define COUNT(a)
Definition: macros.h:200
HAL_SERVO_LIB
#define HAL_SERVO_LIB
Definition: HAL.h:68
servo_init
void servo_init()