Skip to content

Conversation

@soburi
Copy link
Member

@soburi soburi commented Feb 1, 2026

  • Fixed a bug where tone() with duration=0 would stop the tone immediately instead of ringing infinitely.

  • Allows you to change the maximum number of notes that can be played with tone().

  • Add a tone_doremi sample to demonstrate how to sounding with tone API

@soburi soburi force-pushed the use_available_timer branch 4 times, most recently from d1fa1d4 to 41a8a6b Compare February 3, 2026 23:16
@soburi soburi marked this pull request as ready for review February 4, 2026 01:17
Copilot AI review requested due to automatic review settings February 4, 2026 01:17
@soburi soburi marked this pull request as draft February 4, 2026 01:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Zephyr Arduino core’s tone() implementation to support more flexible timer allocation by dynamically selecting unused timers, and adds a Kconfig option to control the maximum number of concurrent tones.

Changes:

  • Add CONFIG_ARDUINO_MAX_TONES (default -1) to configure the tone timer pool size.
  • Track timer usage via a per-timer pin field and allocate/release timers dynamically in tone()/noTone().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
cores/arduino/zephyrCommon.cpp Implements dynamic allocation/release of tone timers and makes the pool size configurable.
Kconfig Adds ARDUINO_MAX_TONES configuration option (default -1 for auto sizing).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi force-pushed the use_available_timer branch 5 times, most recently from f424836 to 2c4afe2 Compare February 5, 2026 11:53
@soburi soburi requested a review from Copilot February 5, 2026 11:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

cores/arduino/zephyrCommon.cpp:281

  • When frequency is 0, the function returns early without clearing the timer state (setting pt->pin = pin_size_t(-1)). This means the timer slot remains allocated to this pin even though it's no longer active. If this pin calls tone() again later, it will find and reuse the same timer, which is fine. However, if the maximum number of timers is reached and this pin's timer is not properly freed, it could prevent other pins from allocating timers. Consider adding pt->pin = pin_size_t(-1); before the return on line 281 to properly free the timer slot.
  if (frequency == 0) {
    gpio_pin_set_dt(spec, 0);
    return;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi changed the title zephyrCommon: Use available tone timers zephyrCommon: Make configurable the max number of tones Feb 5, 2026
@soburi soburi force-pushed the use_available_timer branch from ca91026 to 00dc900 Compare February 5, 2026 14:11
@soburi soburi force-pushed the use_available_timer branch 2 times, most recently from 4c268f9 to 1bd995c Compare February 9, 2026 13:30
@soburi soburi requested a review from Copilot February 9, 2026 13:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi marked this pull request as ready for review February 9, 2026 14:16
@soburi soburi requested a review from DhruvaG2000 February 9, 2026 14:19
@soburi soburi force-pushed the use_available_timer branch 2 times, most recently from 4c268f9 to 87ba62e Compare February 9, 2026 20:21
Fixed a bug where tone() with duration=0 would stop the tone immediately
instead of ringing infinitely.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the use_available_timer branch 2 times, most recently from 8bac16b to 05e7930 Compare February 9, 2026 20:29
@soburi soburi requested a review from Copilot February 9, 2026 20:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@soburi soburi force-pushed the use_available_timer branch from 05e7930 to 309b112 Compare February 9, 2026 21:35
Allows you to change the maximum number of notes that can be
played with `tone()`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add a tone_doremi sample to demonstrate how to sounding with tone API

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@DhruvaG2000 DhruvaG2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one final comment

pt->pin = pin_size_t(-1);
} else {
if (pin >= 0) {
if (pin != pin_size_t(-1)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these changes inside add tone_doremi sample? Can be very misleading, please split into another commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants