Skip to content

Conversation

soburi
Copy link
Member

@soburi soburi commented Aug 23, 2025

Improved to align more closely with the standard Arduino implementation.

  • Eliminated the end timer and used counting to determine the end.
  • Improved to handle infinity correctly.
  • Added a guard to prevent the timeout value from reaching 0.
  • Set the GPIO value to 0 when the timer starts.

gpio_pin_set_dt(spec, 0);
} else {
gpio_pin_toggle_dt(spec);
if (pt->count != UINT32_MAX) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to add a bool infinite to struct pin_timer? Other than that, it looks good to me.
Using only a single timer is great, should help fix a lot of edge cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it would be better to add a bool infinite to struct pin_timer?

I applied your suggestion.

@soburi soburi force-pushed the improve_tone branch 2 times, most recently from b78e5b1 to 4534934 Compare September 8, 2025 10:01
@soburi soburi requested a review from Ayush1325 September 8, 2025 11:03
struct k_timer timer;
pin_size_t pin;
bool infinity;
uint32_t count;
Copy link
Member

@Ayush1325 Ayush1325 Sep 8, 2025

Choose a reason for hiding this comment

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

I think it would be better to place bool infinity after count. Decreasing order of size for efficient size: https://markaicode.com/ultimate-guide-to-c-structure-memory-alignment-and-padding/

struct pin_timer {
  struct k_timer timer;
  uint32_t count;
  pin_size_t pin;
  bool infinity;
} arduino_pin_timers[MAX_TONE_PINS];

Also moved pin down since it can either be 32bit (=count) or 8 bit (<count).

@soburi soburi requested a review from DhruvaG2000 September 9, 2025 00:42
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.

Also $subject should be imperative -> zephyrCommon: Improve tone implemetation

}

arduino_pin_timers[pinNumber].infinity = (duration == 0);
arduino_pin_timers[pinNumber].count = ((uint64_t)duration * frequency) / 500ULL;
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid usage of magic numbers, can you call out why this is / 500?

Copy link
Member

Choose a reason for hiding this comment

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

Something like this helps make it more readable

#define MS_PER_SECOND 1000ULL                                                                                                                                              
#define TOGGLES_PER_CYCLE 2ULL
#define TONE_COUNT_DIVISOR (MS_PER_SECOND / TOGGLES_PER_CYCLE)  // = 500

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed.

soburi pushed a commit to soburi/gsoc-2022-arduino-core that referenced this pull request Sep 24, 2025
…log-level

Removed llext log level setting in variant config file
Improved to align more closely with the standard Arduino implementation.

- Eliminated the end timer and used counting to determine the end.
- Improved to handle infinity correctly.
- Added a guard to prevent the timeout value from reaching 0.
- Set the GPIO value to 0 when the timer starts.

Signed-off-by: TOKITA Hiroshi <[email protected]>
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.

Sigh... all the CI failures seem to be github/ infra related :(
Ran checkpatch locally and saw no errors. So approving.
@soburi assuming you've had a chance to build test locally?

@soburi
Copy link
Member Author

soburi commented Sep 26, 2025

Sigh... all the CI failures seem to be github/ infra related :(
Ran checkpatch locally and saw no errors. So approving.
@soburi assuming you've had a chance to build test locally?

Yes, I verified build and run with my arduino_mkrzero.

@DhruvaG2000 DhruvaG2000 merged commit 00a01fa into zephyrproject-rtos:next Sep 26, 2025
1 of 4 checks passed
@soburi soburi deleted the improve_tone branch September 26, 2025 11:47
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.

3 participants