|
@@ -0,0 +1,59 @@
|
|
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
|
+ * Copypaste of 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
|
+/**
|
|
26
|
+ * Description: Tone function for ESP32
|
|
27
|
+ * Derived from https://forum.arduino.cc/index.php?topic=136500.msg2903012#msg2903012
|
|
28
|
+ */
|
|
29
|
+
|
|
30
|
+#ifdef ARDUINO_ARCH_ESP32
|
|
31
|
+
|
|
32
|
+#include "../../inc/MarlinConfig.h"
|
|
33
|
+#include "HAL.h"
|
|
34
|
+
|
|
35
|
+static pin_t tone_pin;
|
|
36
|
+volatile static int32_t toggles;
|
|
37
|
+
|
|
38
|
+void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration) {
|
|
39
|
+ tone_pin = _pin;
|
|
40
|
+ toggles = 2 * frequency * duration / 1000;
|
|
41
|
+ HAL_timer_start(TONE_TIMER_NUM, 2 * frequency);
|
|
42
|
+}
|
|
43
|
+
|
|
44
|
+void noTone(const pin_t _pin) {
|
|
45
|
+ HAL_timer_disable_interrupt(TONE_TIMER_NUM);
|
|
46
|
+ WRITE(_pin, LOW);
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+HAL_TONE_TIMER_ISR() {
|
|
50
|
+ HAL_timer_isr_prologue(TONE_TIMER_NUM);
|
|
51
|
+
|
|
52
|
+ if (toggles) {
|
|
53
|
+ toggles--;
|
|
54
|
+ TOGGLE(tone_pin);
|
|
55
|
+ }
|
|
56
|
+ else noTone(tone_pin); // turn off interrupt
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+#endif // ARDUINO_ARCH_ESP32
|