Skip to content

Configure by connector def#4

Open
soburi wants to merge 45 commits intonextfrom
configure_by_connector_def
Open

Configure by connector def#4
soburi wants to merge 45 commits intonextfrom
configure_by_connector_def

Conversation

@soburi
Copy link
Copy Markdown
Owner

@soburi soburi commented Feb 10, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 10, 2026 22:20
Copy link
Copy Markdown

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 extends ArduinoCore-Zephyr’s board configuration model to support deriving Arduino pin behavior from connector devicetree definitions (when /zephyr,user/digital-pin-gpios isn’t provided), and adds documentation plus a new UNO R4 variant overlay for ADC channel setup.

Changes:

  • Add fallback “global GPIO numbering” logic and connector-derived mappings in the Arduino core (GPIO, PWM, ADC, interrupts).
  • Add new board configuration reference/guide documentation and clarify LED_BUILTIN derivation behavior.
  • Introduce an Arduino UNO R4 overlay enabling/configuring adc0 channels.

Reviewed changes

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

Show a summary per file
File Description
variants/arduino_uno_r4_r7fa4m1ab3cfm/arduino_uno_r4_r7fa4m1ab3cfm.overlay Adds ADC node/channel configuration for UNO R4.
documentation/variants.md Clarifies LED_BUILTIN behavior when digital-pin-gpios is absent.
documentation/configuration-reference.md Adds a detailed reference for /zephyr,user and connector-derived behavior.
documentation/configuration-guide.md Adds a practical guide describing support “levels” and how to reach them.
cores/arduino/zephyrCommon.cpp Implements connector/global-numbering GPIO access and connector-derived PWM/ADC fallback logic.
cores/arduino/Arduino.h Adds connector detection and derives D*/A* enums and LED_BUILTIN for global numbering mode.

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

Comment thread cores/arduino/zephyrCommon.cpp
Comment thread documentation/configuration-reference.md Outdated
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #5, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #6, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

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 5 comments.


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

Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #8, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #9, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #10, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

@soburi I've opened a new pull request, #11, to work on those changes. Once the pull request is ready, I'll request review from you.

@soburi soburi force-pushed the configure_by_connector_def branch from 5b861f1 to b3744ae Compare February 10, 2026 23:49
@soburi soburi requested a review from Copilot February 10, 2026 23:49
@soburi soburi force-pushed the configure_by_connector_def branch from b3744ae to 0dbaf95 Compare February 10, 2026 23:54
Copy link
Copy Markdown

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.

Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/Arduino.h Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Copy link
Copy Markdown

Copilot AI commented Feb 11, 2026

@soburi I've opened a new pull request, #12, to work on those changes. Once the pull request is ready, I'll request review from you.

@soburi
Copy link
Copy Markdown
Owner Author

soburi commented Feb 11, 2026

@copilot TODOを実装して。

Copy link
Copy Markdown

Copilot AI commented Feb 11, 2026

@soburi I've opened a new pull request, #13, to work on those changes. Once the pull request is ready, I'll request review from you.

@soburi soburi force-pushed the configure_by_connector_def branch from 33935c2 to 34d02a8 Compare April 25, 2026 05:31
soburi and others added 28 commits April 25, 2026 14:34
…ecycle

Rework tone/noTone internals to better match Arduino behavior while making
concurrent tone usage configurable and safer.

- Add CONFIG_ARDUINO_MAX_TONES (default: -1).
- Negative values fall back to the digital pin count from devicetree.
- Replace per-pin tone timer arrays with slot-based pin_timer entries.
- Remove the timeout companion timer and finish finite tones by counting
  remaining toggles in tone_expiry_cb().

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
experimental results here arduino#332 (comment)

On boards with different clock speed, function call overhead etc. the results may vary but will likely be consistent, given that all the boards share CONFIG_SYS_CLOCK_TICKS_PER_SEC

Co-authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Fixes compilation error found at https://www.cnx-software.com/2024/12/10/arduino-core-for-zephyr-beta-released/

Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Place the implementation for delay() and delayMicroseconds() in a
separate header file, and include it from Arduino.h. This allows the
functions to be properly inlined, which is important for performance,
especially for delayMicroseconds().

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Explicitly state the license in all source files to comply with SPDX
best practices. In addition, update the copyright notice to the new
format.

Note: Applied only cores/arduino/time_macros.h on cherry-pick time.

Co-Authored-by: Luca Burelli <l.burelli@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Co-Authored-by: Kurt Eckhardt <kurte@rockisland.com>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Take into account the analog switch

Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Formatting ADC/DAC codes.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
- Remove duplicated `analogReadResolution` declaration
- Add the same #ifdef conditions used in the implementation
  to the `analogWriteResolution` as well.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
- Fixed input max value calculation (Needs to be -1 after shift)
- Clamp calculations are performed first, eliminating cast

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
- Correct max value calculation
- Add guard for DAC entry is not defined case
- initialize only if DAC not initialized

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Co-Authored-by: Giovanni Bruno <g.bruno@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Explicitly state the license in all source files to comply with SPDX
best practices. In addition, update the copyright notice to the new
format.

Note: At the time of cherry-picking, this was applied only to
      cores/arduino/time_macros.h and
      cores/arduino/overloads.h.

Co-Authored-by: Luca Burelli <l.burelli@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
While we prepare a cleaner solution, this patch allows back and forth between pinmuxes.
Tested on UNO Q with next patch in the series and this sketch

void loop() {
  Serial.begin(115200);
  Serial.println("helloooooo");
  delay(20);
  Serial.end();
  delay(20);
  pinMode(1, OUTPUT);
  digitalWrite(1, HIGH);
  delay(10);
  digitalWrite(1, LOW);
  delay(100);
  analogWrite(1, 33);
}

Pin 1 correctly prints the string, muxes as GPIo and then produces the required PWM

Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
…ifdefs

Co-Authored-by: pennam <m.pennasilico@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Passing -1 to digital I/O functions may happen when libraries do not
properly sanitize their inputs, leading to undefined behavior. This
commit adds a check to ensure that the pin number is valid before
accessing the arduino_pins array.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Allows compatibility with a broad set of libraries, like Adafruit's NeoPixel

Co-Authored-by: Martino Facchin <m.facchin@arduino.cc>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
On Arduino Uno Q, calling analogWrite() on any pin silently returns
without doing anything in two cases:

1. When pwm_pin_index() cannot find the pin in the arduino_pwm_pins[]
   lookup table (idx >= ARRAY_SIZE(arduino_pwm))
2. When pwm_is_ready_dt() returns false for the PWM device

This causes analogWrite() to appear completely broken to users - no
output, no error, no warning. The function just silently does nothing.

The pwm-pin-gpios mapping in the Uno Q device tree overlay is missing
some pins (D0, D1, D4 are absent or commented out). This means
pwm_pin_index() returns (size_t)-1 for those pins, which is always
>= ARRAY_SIZE(arduino_pwm), causing an immediate silent return.

Added a digitalWrite() fallback in both early-return paths:
- If PWM lookup fails → fall back to digitalWrite HIGH/LOW
- If PWM device not ready → fall back to digitalWrite HIGH/LOW

This ensures analogWrite() always produces some output even when
hardware PWM is unavailable, which is consistent with how other
Arduino cores handle non-PWM pins.

Tested on Arduino Uno Q with:
- Motor driver (SmartElex L298N integrated board)
- Confirmed analogWrite() was completely silent before fix
- Confirmed digitalWrite() fallback works correctly after fix
- Pins tested: 3, 4, 5, 6, 7, 8, 9, 10

- No breaking changes
- Existing PWM functionality unchanged
- Non-PWM pins now behave like standard Arduino (HIGH if value > 127)
- Fixes user confusion when analogWrite() silently does nothing

Co-Authored-by: Satvik <145106491+vs11official@users.noreply.github.com>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Define `invalid_pin_number` and replace `pin_size_t(-1)`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
In preparation for improvements to allow the use of GPIOs without
device tree definitions,
the interface will be changed to specify port and pin instead of
`gpio_dt_spec`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
If digital-gpio-pins is not defined,
the pin configuration will be generated using the connector definition.

This allows ArduinoCore-Zephyr to be used on boards that have
arduino-header defined,
without requiring specific configuration in ArduinoCore-Zephyr.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
…nition

Like digital pins, PWMs are also defined from connectors.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
…nition

Like digital pins, ADCs are also defined from connectors.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add guide for adding new board configuration and configuration
reference.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
A new configuration method has been adopted, allowing support to be added
with less configuration than before.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the configure_by_connector_def branch from 34d02a8 to 949f58a Compare April 25, 2026 05: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.