From 784a9ca9225c6ca41a8b20cccba2de46caa8ddda Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 7 Apr 2026 18:32:00 +0200 Subject: [PATCH 1/2] core: Introduce digitalPinTo(PortDevice|PinIndex) Add digitalPinToPortDevice() and digitalPinToPinIndex(). Co-authored-by: Martino Facchin Signed-off-by: TOKITA Hiroshi --- cores/arduino/Arduino.h | 4 ++++ cores/arduino/zephyrCommon.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 44e5a9a45..c297598ef 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -131,11 +131,15 @@ void noInterrupts(void); int digitalPinToInterrupt(pin_size_t pin); +// These defines can be overridden by variant.h if implemented #define digitalPinToPort(x) (x) #define digitalPinToBitMask(x) (x) #define portOutputRegister(x) (x) #define portInputRegister(x) (x) +const struct device *digitalPinToPortDevice(pin_size_t pinNumber); +int digitalPinToPinIndex(pin_size_t pinNumber); + #if defined(CONFIG_PWM) || defined(CONFIG_DAC) void analogWriteResolution(int bits); #endif diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 894b6e8fc..8e8aa5052 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -218,6 +218,18 @@ void yield(void) { k_yield(); } +const struct device *digitalPinToPortDevice(pin_size_t pinNumber) { + RETURN_ON_INVALID_PIN(pinNumber, nullptr); + + return arduino_pins[pinNumber].port; +} + +int digitalPinToPinIndex(pin_size_t pinNumber) { + RETURN_ON_INVALID_PIN(pinNumber, -1); + + return arduino_pins[pinNumber].pin; +} + /* * The ACTIVE_HIGH flag is set so that A low physical * level on the pin will be interpreted as value 0. From c3d5921690259f5fe59c7abdfb2eaea4fa05b892 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Mon, 1 Jun 2026 13:57:29 +0900 Subject: [PATCH 2/2] core: Define F_CPU for ARM targets Add F_CPU definition for retrive CPU frequency. Co-authored-by: Martino Facchin Signed-off-by: TOKITA Hiroshi --- cores/arduino/Arduino.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index c297598ef..32ee32529 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -144,6 +144,10 @@ int digitalPinToPinIndex(pin_size_t pinNumber); void analogWriteResolution(int bits); #endif +#if defined(__arm__) +#define F_CPU (SystemCoreClock) +#endif + #include #if !defined(LED_BUILTIN) && defined(ZARD_LED_BUILTIN)