summaryrefslogtreecommitdiffstats
path: root/watch-library/shared/watch/watch_buzzer.h
diff options
context:
space:
mode:
authorTheOnePerson <a.nebinger@web.de>2023-01-11 21:26:33 +0100
committerGitHub <noreply@github.com>2023-01-11 15:26:33 -0500
commit47812f462d275ff62e3796d4064cdac66772f6c9 (patch)
treef9f21d36c4d88a77c4a28fc8b38780cd574afbae /watch-library/shared/watch/watch_buzzer.h
parentca7e70442930ad24285385291dc98c1437b9881b (diff)
downloadSensor-Watch-47812f462d275ff62e3796d4064cdac66772f6c9.tar.gz
Sensor-Watch-47812f462d275ff62e3796d4064cdac66772f6c9.tar.bz2
Sensor-Watch-47812f462d275ff62e3796d4064cdac66772f6c9.zip
Play sound sequences asynchronously (#122)
* buzzer sequences: first draft, does not work on hardware yet (but in simulator) * buzzer sequences: add changes to movement.c * buzzer sequences: add demo face to Makefile * buzzer sequences: fix problem of interrupted sounds. Add logic for repeating sub sequences. Tidy up (move logic to watch_buzzer files, remove buzzer_demo_face) * buzzer sequences: tidy up even more * buzzer sequences: disable registering a 32 Hz tick callback for watch faces, so it will be used exclusively by the buzzer sequences functionality * buzzer sequences: add callback slot functionality to watch_rtc and make watch_buzzer use it. Switch internal buzzer sequences tick frequency to 64 Hz. Revert changes to movement.c * buzzer sequences: fix parameter sanity check in watch_rtc code * buzzer sequences/watch_rtc: optimize calling tick callbacks in RTC_Handler * buzzer sequences/watch_rtc: fix error in calling callback functions * buzzer sequences: revert changes to watch_rtc logic. Instead, use TC3 as the source for timing the sound sequences. * buzzer sequences: fix frequency of callback * buzzer sequences: integrate changes from PR #162 (set both CCBUF and PERFBUF for correct buzzer tone)
Diffstat (limited to 'watch-library/shared/watch/watch_buzzer.h')
-rw-r--r--watch-library/shared/watch/watch_buzzer.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/watch-library/shared/watch/watch_buzzer.h b/watch-library/shared/watch/watch_buzzer.h
index 1b5d197c..7ba9a52e 100644
--- a/watch-library/shared/watch/watch_buzzer.h
+++ b/watch-library/shared/watch/watch_buzzer.h
@@ -160,5 +160,28 @@ void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms);
/// @brief An array of periods for all the notes on a piano, corresponding to the names in BuzzerNote.
extern const uint16_t NotePeriods[108];
+/** @brief Plays the given sequence of notes in a non-blocking way.
+ * @param note_sequence A pointer to the sequence of buzzer note & duration tuples, ending with a zero. A simple
+ * RLE logic is implemented: a negative number instead of a buzzer note means that the sequence
+ * is rewound by the given number of notes. The byte following a negative number determines the number
+ * of loops. I.e. if you want to repeat the last three notes of the sequence one time, you should provide
+ * the tuple -3, 1. The repeated notes must not contain any other repeat markers, or you will end up with
+ * an eternal loop.
+ * @param callback_on_end A pointer to a callback function to be invoked when the sequence has finished playing.
+ * @note This function plays the sequence asynchronously, so the UI will not be blocked.
+ * Hint: It is not possible to play the lowest note BUZZER_NOTE_A1 (55.00 Hz). The note is represented by a
+ * zero byte, which is used here as the end-of-sequence marker. But hey, a frequency that low cannot be
+ * played properly by the watch's buzzer, anyway.
+ */
+void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(void));
+
+/** @brief Aborts a playing sequence.
+ */
+void watch_buzzer_abort_sequence(void);
+
+#ifndef __EMSCRIPTEN__
+void TC3_Handler(void);
+#endif
+
/// @}
#endif