Marlin_Firmware/Marlin/src/HAL/TEENSY35_36/Servo.cpp

60 lines
1.8 KiB
C++
Raw Normal View History

2019-09-25 08:29:59 -05:00
/**
* Marlin 3D Printer Firmware
2020-02-03 08:00:57 -06:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2019-09-25 08:29:59 -05:00
*
* 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
2020-07-22 22:20:14 -05:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-09-25 08:29:59 -05:00
*
*/
2020-10-02 17:05:45 -05:00
/**
* HAL Servo for Teensy 3.5 (MK64FX512) and Teensy 3.6 (MK66FX1M0)
*/
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2017-09-06 06:28:32 -05:00
#include "../../inc/MarlinConfig.h"
#if HAS_SERVOS
2019-09-02 19:49:58 -05:00
#include "Servo.h"
uint8_t servoPin[MAX_SERVOS] = { 0 };
2019-09-25 08:29:59 -05:00
int8_t libServo::attach(const int inPin) {
if (servoIndex >= MAX_SERVOS) return -1;
if (inPin > 0) servoPin[servoIndex] = inPin;
return super::attach(servoPin[servoIndex]);
}
2019-09-25 08:29:59 -05:00
int8_t libServo::attach(const int inPin, const int inMin, const int inMax) {
if (inPin > 0) servoPin[servoIndex] = inPin;
return super::attach(servoPin[servoIndex], inMin, inMax);
}
2017-09-27 03:33:29 -05:00
void libServo::move(const int value) {
constexpr uint16_t servo_delay[] = SERVO_DELAY;
static_assert(COUNT(servo_delay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
2019-09-25 08:29:59 -05:00
if (attach(0) >= 0) {
write(value);
safe_delay(servo_delay[servoIndex]);
2020-04-22 16:35:03 -05:00
TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
#endif // HAS_SERVOS
2017-09-27 03:33:29 -05:00
#endif // __MK64FX512__ || __MK66FX1M0__