This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 7db1e10b1 examples/audio_rttl: Fix skipped pauses when playing through 
PWM.
7db1e10b1 is described below

commit 7db1e10b18fc430bd1b6cfef86f5e661c51b40ab
Author: Felix-LJY <[email protected]>
AuthorDate: Fri Nov 27 21:18:50 2026 +0800

    examples/audio_rttl: Fix skipped pauses when playing through PWM.
    
    A pause (the p note) is reported with a frequency of 0 and was passed
    to the PWM driver like any other note.  Drivers that refuse a 0 Hz
    frequency, such as the RA4 one, make PWMIOC_START fail with EINVAL.
    play_pwm() then printed an error and returned without waiting, so
    every pause was skipped, the following notes were played too early
    and one error line was printed per pause.
    
    Wait for the duration of the pause instead, with the output left
    stopped as it is after every note.
    
    Tested on a custom N32H760 board with a passive buzzer on a timer PWM
    output: a tune made of two pauses returns without an error after the
    expected delay and the timer stays stopped.
    
    Assisted-by: Claude Code:glm-5.4
    Signed-off-by: JingYue LIAO <[email protected]>
---
 examples/audio_rttl/audio_rttl_main.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/examples/audio_rttl/audio_rttl_main.c 
b/examples/audio_rttl/audio_rttl_main.c
index 6d1e29326..648351b55 100644
--- a/examples/audio_rttl/audio_rttl_main.c
+++ b/examples/audio_rttl/audio_rttl_main.c
@@ -124,6 +124,14 @@ static void play_pwm(struct rtttl_tone sound)
   struct pwm_info_s info;
   int fd = *((int *)g_player.arg);
 
+  /* A pause is silence for the given time; the previous tone is stopped */
+
+  if (sound.frequency_100hz == 0)
+    {
+      usleep(sound.duration_us);
+      return;
+    }
+
   info.channels[0].channel = 1;
   info.channels[0].duty = b16divi(uitoub16(50) - 1, 100); /* 50% duty cycle */
   info.channels[0].cpol = PWM_CPOL_NDEF;                  /* Default */

Reply via email to