mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
On nRF52 the buzzer advanced notes by polling millis() >= _note_end_ms in loop(). A blocking display refresh (e-ink endFrame) starves loop(), so a note boundary that falls inside a refresh is serviced late — the note plays long, or the next is skipped. The keypress-time 300 ms render delay only masked the first note. Advance notes from a hardware TIMER1 compare interrupt instead, scheduled for each note's exact duration, so timing is independent of render cadence. TIMER0 is the SoftDevice's; TIMER1 is free (tone() uses PWM2, nrfx TIMER1 driver is disabled). loop() becomes a no-op on nRF52; the UITask keypress render-delay workaround is removed. _disarmNoteTimer() clears the latched NVIC pending IRQ (not just the event) on stop()/_nrfBegin(), so a note-advance latched just before a stop can't fire spuriously — which would skip a new melody's first note or blip after an explicit stop. Event read-backs flush the write buffer per the nRF52 event anomaly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>