2017-11-19 13:39:46 -06:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-11-19 13:39:46 -06:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-11-19 13:39:46 -06:00
|
|
|
*
|
|
|
|
* 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
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-11-19 13:39:46 -06:00
|
|
|
*
|
|
|
|
*/
|
2018-11-04 02:25:55 -06:00
|
|
|
#pragma once
|
2017-11-19 13:39:46 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* module/servo.h
|
|
|
|
*/
|
|
|
|
|
2018-09-21 05:24:53 -05:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2018-08-14 03:28:52 -05:00
|
|
|
#include "../HAL/shared/servo.h"
|
2017-11-19 13:39:46 -06:00
|
|
|
|
2018-11-30 12:31:42 -06:00
|
|
|
#if HAS_SERVO_ANGLES
|
|
|
|
|
|
|
|
#if ENABLED(SWITCHING_EXTRUDER)
|
2020-02-26 06:26:54 -06:00
|
|
|
// Switching extruder can have 2 or 4 angles
|
2018-11-30 12:31:42 -06:00
|
|
|
#if EXTRUDERS > 3
|
|
|
|
#define REQ_ANGLES 4
|
|
|
|
#else
|
|
|
|
#define REQ_ANGLES 2
|
|
|
|
#endif
|
2020-02-26 06:26:54 -06:00
|
|
|
constexpr uint16_t sase[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
|
|
|
|
static_assert(COUNT(sase) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
|
|
|
|
#else
|
|
|
|
constexpr uint16_t sase[4] = { 0 };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(SWITCHING_NOZZLE)
|
|
|
|
constexpr uint16_t sasn[] = SWITCHING_NOZZLE_SERVO_ANGLES;
|
|
|
|
static_assert(COUNT(sasn) == 2, "SWITCHING_NOZZLE_SERVO_ANGLES needs 2 angles.");
|
|
|
|
#else
|
|
|
|
constexpr uint16_t sasn[2] = { 0 };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Z_PROBE_SERVO_NR
|
2019-03-17 05:57:25 -05:00
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
#include "../feature/bltouch.h"
|
2020-02-26 06:26:54 -06:00
|
|
|
#undef Z_SERVO_ANGLES
|
|
|
|
#define Z_SERVO_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
|
2019-03-17 05:57:25 -05:00
|
|
|
#endif
|
2020-02-26 06:26:54 -06:00
|
|
|
constexpr uint16_t sazp[] = Z_SERVO_ANGLES;
|
|
|
|
static_assert(COUNT(sazp) == 2, "Z_SERVO_ANGLES needs 2 angles.");
|
|
|
|
#else
|
|
|
|
constexpr uint16_t sazp[2] = { 0 };
|
2018-11-30 12:31:42 -06:00
|
|
|
#endif
|
|
|
|
|
2020-02-26 06:26:54 -06:00
|
|
|
#ifndef SWITCHING_EXTRUDER_SERVO_NR
|
|
|
|
#define SWITCHING_EXTRUDER_SERVO_NR -1
|
|
|
|
#endif
|
|
|
|
#ifndef SWITCHING_EXTRUDER_E23_SERVO_NR
|
|
|
|
#define SWITCHING_EXTRUDER_E23_SERVO_NR -1
|
|
|
|
#endif
|
|
|
|
#ifndef SWITCHING_NOZZLE_SERVO_NR
|
|
|
|
#define SWITCHING_NOZZLE_SERVO_NR -1
|
|
|
|
#endif
|
|
|
|
#ifndef Z_PROBE_SERVO_NR
|
|
|
|
#define Z_PROBE_SERVO_NR -1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ASRC(N,I) ( \
|
|
|
|
N == SWITCHING_EXTRUDER_SERVO_NR ? sase[I] \
|
|
|
|
: N == SWITCHING_EXTRUDER_E23_SERVO_NR ? sase[I+2] \
|
|
|
|
: N == SWITCHING_NOZZLE_SERVO_NR ? sasn[I] \
|
|
|
|
: N == Z_PROBE_SERVO_NR ? sazp[I] \
|
|
|
|
: 0 )
|
|
|
|
|
2018-11-30 12:31:42 -06:00
|
|
|
#if ENABLED(EDITABLE_SERVO_ANGLES)
|
|
|
|
extern uint16_t servo_angles[NUM_SERVOS][2];
|
2020-02-26 06:26:54 -06:00
|
|
|
#define CONST_SERVO_ANGLES base_servo_angles
|
2018-11-30 12:31:42 -06:00
|
|
|
#else
|
2020-02-26 06:26:54 -06:00
|
|
|
#define CONST_SERVO_ANGLES servo_angles
|
2018-11-30 12:31:42 -06:00
|
|
|
#endif
|
|
|
|
|
2020-02-26 06:26:54 -06:00
|
|
|
constexpr uint16_t CONST_SERVO_ANGLES [NUM_SERVOS][2] = {
|
2018-11-30 12:31:42 -06:00
|
|
|
{ ASRC(0,0), ASRC(0,1) }
|
|
|
|
#if NUM_SERVOS > 1
|
|
|
|
, { ASRC(1,0), ASRC(1,1) }
|
|
|
|
#if NUM_SERVOS > 2
|
|
|
|
, { ASRC(2,0), ASRC(2,1) }
|
|
|
|
#if NUM_SERVOS > 3
|
|
|
|
, { ASRC(3,0), ASRC(3,1) }
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#if HAS_Z_SERVO_PROBE
|
|
|
|
#define DEPLOY_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][0])
|
|
|
|
#define STOW_Z_SERVO() MOVE_SERVO(Z_PROBE_SERVO_NR, servo_angles[Z_PROBE_SERVO_NR][1])
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // HAS_SERVO_ANGLES
|
2017-11-19 13:39:46 -06:00
|
|
|
|
|
|
|
#define MOVE_SERVO(I, P) servo[I].move(P)
|
|
|
|
|
2018-11-30 12:31:42 -06:00
|
|
|
extern HAL_SERVO_LIB servo[NUM_SERVOS];
|
2021-04-02 14:22:43 -05:00
|
|
|
void servo_init();
|