My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Servo.cpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. * Copyright (c) 2017 Victor Perez
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  24. #include "../../inc/MarlinConfig.h"
  25. #if HAS_SERVOS
  26. #include "Servo.h"
  27. static uint_fast8_t servoCount = 0;
  28. constexpr millis_t servoDelay[] = SERVO_DELAY;
  29. static_assert(COUNT(servoDelay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
  30. libServo::libServo()
  31. : delay(servoDelay[servoCount++])
  32. {}
  33. int8_t libServo::attach(const int pin) {
  34. if (servoCount >= MAX_SERVOS) return -1;
  35. if (pin > 0) servo_pin = pin;
  36. return super::attach(servo_pin);
  37. }
  38. int8_t libServo::attach(const int pin, const int min, const int max) {
  39. if (servoCount >= MAX_SERVOS) return -1;
  40. if (pin > 0) servo_pin = pin;
  41. return super::attach(servo_pin, min, max);
  42. }
  43. void libServo::move(const int value) {
  44. if (attach(0) >= 0) {
  45. write(value);
  46. safe_delay(delay);
  47. TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
  48. }
  49. }
  50. #endif // HAS_SERVOS
  51. #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC