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_private.h 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. *
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * servo_private.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
  25. * Copyright (c) 2009 Michael Margolis. All right reserved.
  26. *
  27. * This library is free software; you can redistribute it and/or
  28. * modify it under the terms of the GNU Lesser General Public
  29. * License as published by the Free Software Foundation; either
  30. * version 2.1 of the License, or (at your option) any later version.
  31. *
  32. * This library is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  35. * Lesser General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU Lesser General Public
  38. * License along with this library; if not, write to the Free Software
  39. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  40. */
  41. #include <stdint.h>
  42. // Architecture specific include
  43. #ifdef __AVR__
  44. #include "../AVR/ServoTimers.h"
  45. #elif defined(ARDUINO_ARCH_SAM)
  46. #include "../DUE/ServoTimers.h"
  47. #elif defined(__SAMD51__)
  48. #include "../SAMD51/ServoTimers.h"
  49. #else
  50. #error "This library only supports boards with an AVR, SAM3X or SAMD51 processor."
  51. #endif
  52. // Macros
  53. #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
  54. #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
  55. #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
  56. #define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds
  57. #define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer
  58. #define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
  59. #define INVALID_SERVO 255 // flag indicating an invalid servo index
  60. // Convert microseconds to ticks and back (PRESCALER depends on architecture)
  61. #define usToTicks(_us) (clockCyclesPerMicrosecond() * (_us) / (SERVO_TIMER_PRESCALER))
  62. #define ticksToUs(_ticks) (unsigned(_ticks) * (SERVO_TIMER_PRESCALER) / clockCyclesPerMicrosecond())
  63. // convenience macros
  64. #define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo
  65. #define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % (SERVOS_PER_TIMER)) // returns the index of the servo on this timer
  66. #define SERVO_INDEX(_timer,_channel) ((_timer*(SERVOS_PER_TIMER)) + _channel) // macro to access servo index by timer and channel
  67. #define SERVO(_timer,_channel) (servo_info[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel
  68. // Types
  69. typedef struct {
  70. uint8_t nbr : 7 ; // a pin number from 0 to 127
  71. uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false
  72. } ServoPin_t;
  73. typedef struct {
  74. ServoPin_t Pin;
  75. unsigned int ticks;
  76. } ServoInfo_t;
  77. // Global variables
  78. extern uint8_t ServoCount;
  79. extern ServoInfo_t servo_info[MAX_SERVOS];
  80. // Public functions
  81. extern void initISR(timer16_Sequence_t timer);
  82. extern void finISR(timer16_Sequence_t timer);