-
Notifications
You must be signed in to change notification settings - Fork 44
zephyrCommon: Improved tone
implemetation
#133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cores/arduino/zephyrCommon.cpp
Outdated
gpio_pin_set_dt(spec, 0); | ||
} else { | ||
gpio_pin_toggle_dt(spec); | ||
if (pt->count != UINT32_MAX) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b78e5b1
to
4534934
Compare
cores/arduino/zephyrCommon.cpp
Outdated
struct k_timer timer; | ||
pin_size_t pin; | ||
bool infinity; | ||
uint32_t count; |
There was a problem hiding this comment.
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).
There was a problem hiding this 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
cores/arduino/zephyrCommon.cpp
Outdated
} | ||
|
||
arduino_pin_timers[pinNumber].infinity = (duration == 0); | ||
arduino_pin_timers[pinNumber].count = ((uint64_t)duration * frequency) / 500ULL; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
…log-level Removed llext log level setting in variant config file
1565d9b
to
9071c2c
Compare
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]>
9071c2c
to
50ce83d
Compare
There was a problem hiding this 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?
Yes, I verified build and run with my arduino_mkrzero. |
Improved to align more closely with the standard Arduino implementation.