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