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.

Tone.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. /**
  22. * Description: Tone function for Arduino Due and compatible (SAM3X8E)
  23. * Derived from http://forum.arduino.cc/index.php?topic=136500.msg2903012#msg2903012
  24. */
  25. #ifdef __SAMD51__
  26. #include "../../inc/MarlinConfig.h"
  27. #include "HAL_timers_SAMD51.h"
  28. static pin_t tone_pin;
  29. volatile static int32_t toggles;
  30. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration) {
  31. tone_pin = _pin;
  32. toggles = 2 * frequency * duration / 1000;
  33. HAL_timer_start(TONE_TIMER_NUM, 2 * frequency);
  34. }
  35. void noTone(const pin_t _pin) {
  36. HAL_timer_disable_interrupt(TONE_TIMER_NUM);
  37. extDigitalWrite(_pin, LOW);
  38. }
  39. HAL_TONE_TIMER_ISR() {
  40. static bool pin_state = false;
  41. HAL_timer_isr_prologue(TONE_TIMER_NUM);
  42. if (toggles) {
  43. toggles--;
  44. extDigitalWrite(tone_pin, (pin_state = !pin_state));
  45. }
  46. else noTone(tone_pin); // turn off interrupt
  47. HAL_timer_isr_epilogue(TONE_TIMER_NUM);
  48. }
  49. #endif // __SAMD51__