-
Notifications
You must be signed in to change notification settings - Fork 59
cores: arduino: zephyrCommon Specify port/pin instead of gpio_dt_spec
#148
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| #include <Arduino.h> | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "zephyrInternal.h" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| static const struct gpio_dt_spec arduino_pins[] = {DT_FOREACH_PROP_ELEM_SEP( | ||||||||||||||||||||||||||||||||||||||||||||||
| static constexpr struct gpio_dt_spec arduino_pins[] = {DT_FOREACH_PROP_ELEM_SEP( | ||||||||||||||||||||||||||||||||||||||||||||||
| DT_PATH(zephyr_user), digital_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, ))}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| namespace { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +56,18 @@ constexpr const size_t is_first_appearance(const size_t &idx, const size_t &at, | |||||||||||||||||||||||||||||||||||||||||||||
| tail...); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| constexpr inline const struct device *local_gpio_port(pin_size_t gpin) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return arduino_pins[gpin].port; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| constexpr inline pin_size_t local_gpio_pin(pin_size_t gpin) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return arduino_pins[gpin].pin; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+59
to
+66
|
||||||||||||||||||||||||||||||||||||||||||||||
| constexpr inline const struct device *local_gpio_port(pin_size_t gpin) { | |
| return arduino_pins[gpin].port; | |
| } | |
| constexpr inline pin_size_t local_gpio_pin(pin_size_t gpin) { | |
| return arduino_pins[gpin].pin; | |
| } | |
| constexpr inline const struct gpio_dt_spec &local_gpio_dt_spec(pin_size_t gpin) { | |
| return arduino_pins[gpin]; | |
| } | |
| inline int local_gpio_pin_set(pin_size_t gpin, int value) { | |
| return gpio_pin_set_dt(&arduino_pins[gpin], value); | |
| } | |
| inline int local_gpio_pin_get(pin_size_t gpin) { | |
| return gpio_pin_get_dt(&arduino_pins[gpin]); | |
| } | |
| inline int local_gpio_pin_toggle(pin_size_t gpin) { | |
| return gpio_pin_toggle_dt(&arduino_pins[gpin]); | |
| } |
Copilot
AI
Feb 5, 2026
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.
Switching from gpio_pin_set_dt() to gpio_pin_set() loses the GPIO_ACTIVE_LOW flag handling. For pins configured with GPIO_ACTIVE_LOW in devicetree (present in nrf52840dk_nrf52840.overlay and nrf9160dk_nrf9160.overlay), digitalWrite(pin, HIGH) will now drive the physical line high instead of low, inverting the intended behavior. Either use gpio_pin_set_dt() to preserve dt_flags handling, or manually invert the status parameter based on arduino_pins[pinNumber].dt_flags.
| gpio_pin_set(local_gpio_port(pinNumber), local_gpio_pin(pinNumber), status); | |
| gpio_pin_set_dt(&arduino_pins[pinNumber], status); |
soburi marked this conversation as resolved.
Show resolved
Hide resolved
soburi marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 5, 2026
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.
Switching from gpio_pin_set_dt() to gpio_pin_set() in the tone stop path loses GPIO_ACTIVE_LOW flag handling. For active-low pins, setting value 0 may actually assert the pin instead of de-asserting it. Either use gpio_pin_set_dt() or manually account for dt_flags inversion.
soburi marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 5, 2026
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.
Switching from gpio_pin_toggle_dt() to gpio_pin_toggle() loses GPIO_ACTIVE_LOW flag handling. For active-low pins, the toggle behavior may be inverted. Either use gpio_pin_toggle_dt() or manually account for dt_flags.
| gpio_pin_toggle(local_gpio_port(pt->pin), local_gpio_pin(pt->pin)); | |
| gpio_pin_toggle_dt(&arduino_pins[pt->pin]); |
Copilot
AI
Feb 5, 2026
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.
Switching from gpio_pin_set_dt() to gpio_pin_set() loses GPIO_ACTIVE_LOW flag handling. For active-low pins, the initial reset behavior will be incorrect. Either use gpio_pin_set_dt() or manually account for dt_flags inversion.
soburi marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 5, 2026
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.
Switching from gpio_pin_set_dt() to gpio_pin_set() loses GPIO_ACTIVE_LOW flag handling. For active-low pins, the timer start reset behavior will be incorrect. Either use gpio_pin_set_dt() or manually account for dt_flags inversion.
Copilot
AI
Feb 5, 2026
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.
Switching from gpio_pin_set_dt() to gpio_pin_set() loses GPIO_ACTIVE_LOW flag handling. For active-low pins, the noTone reset behavior will be incorrect. Either use gpio_pin_set_dt() or manually account for dt_flags inversion.
soburi marked this conversation as resolved.
Show resolved
Hide resolved
soburi marked this conversation as resolved.
Show resolved
Hide resolved
soburi marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 5, 2026
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.
Switching from device_is_ready(spec->port) via gpio_is_ready_dt() to device_is_ready(port) is correct for checking port readiness. However, the subsequent gpio_pin_get() calls on lines 462, 467, and 473 lose GPIO_ACTIVE_LOW flag handling. For active-low pins, the state comparisons will be inverted. Either use gpio_pin_get_dt() or manually invert based on dt_flags.
Uh oh!
There was an error while loading. Please reload this page.