/firmware/src/shared/StepperInterface.hh

http://github.com/makerbot/G3Firmware · C++ Header · 80 lines · 31 code · 15 blank · 34 comment · 0 complexity · a4821ba947c9bbed83fe4c933805bf36 MD5 · raw file

  1. /*
  2. * Copyright 2010 by Adam Mayer <adam@makerbot.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>
  16. */
  17. #ifndef STEPPERINTERFACE_HH_
  18. #define STEPPERINTERFACE_HH_
  19. #include <Pin.hh>
  20. /// The StepperInterface module represents a connection to a single stepper controller.
  21. /// \ingroup SoftwareLibraries
  22. class StepperInterface {
  23. private:
  24. /// Default constructor
  25. StepperInterface() {}
  26. StepperInterface(const Pin& dir,
  27. const Pin& step,
  28. const Pin& enable,
  29. const Pin& max,
  30. const Pin& min,
  31. uint16_t eeprom_base_in);
  32. friend class Motherboard;
  33. private:
  34. /// Initialize the pins for the interface
  35. /// \param[in] idx Stepper index that this interface refers to (used to look up
  36. /// it's settings in the EEPROM)
  37. void init(uint8_t idx);
  38. Pin dir_pin; ///< Pin (output) that the direction line is connected to
  39. Pin step_pin; ///< Pin (output) that the step line is connected to
  40. Pin enable_pin; ///< Pin (output) that the enable line is connected to
  41. Pin max_pin; ///< Pin (input) that the maximum endstop is connected to.
  42. Pin min_pin; ///< Pin (input) that the minimum endstop is connected to.
  43. bool invert_endstops; ///< True if endstops input polarity is inverted for
  44. ///< this axis.
  45. bool invert_axis; ///< True if motions for this axis should be inverted
  46. uint16_t eeprom_base; ///< Base address to read EEPROM configuration from
  47. public:
  48. /// Set the direction for the stepper to move
  49. /// \param[in] forward True to move the stepper forward, false otherwise.
  50. void setDirection(bool forward);
  51. /// Set the value of the step line
  52. /// \param[in] value True to enable, false to disable. This should be toggled
  53. /// back and fourth to effect stepping.
  54. void step(bool value);
  55. /// Enable or disable the stepper motor on this axis
  56. /// \param[in] True to enable the motor
  57. void setEnabled(bool enabled);
  58. /// Check if the maximum endstop has been triggered for this axis.
  59. /// \return True if the axis has triggered its maximum endstop
  60. bool isAtMaximum();
  61. /// Check if the minimum endstop has been triggered for this axis.
  62. /// \return True if the axis has triggered its minimum endstop
  63. bool isAtMinimum();
  64. };
  65. #endif // STEPPERINTERFACE_HH_