From dc24cf0f2ab996ccccfd86d8fb544eea0c5993f7 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Mon, 2 Sep 2024 18:37:04 +0530 Subject: [PATCH] Arduino.h: Add digitalPinToInterrupt - This does not seem to be present in ArduinoCoreAPI but defined for all Arduino boards (and microblocks has started using it). - Also present in arduino docs. Signed-off-by: Ayush Singh --- cores/arduino/Arduino.h | 2 ++ cores/arduino/zephyrCommon.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 69390481..e9399e72 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -100,6 +100,8 @@ enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), void interrupts(void); void noInterrupts(void); +int digitalPinToInterrupt(pin_size_t pin); + #include #ifdef __cplusplus #include diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 6a8a8ebe..6fa94bc4 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -480,3 +480,10 @@ void noInterrupts(void) { interrupts_disabled = true; } } + +int digitalPinToInterrupt(pin_size_t pin) { + struct gpio_port_callback *pcb = + find_gpio_port_callback(arduino_pins[pin].port); + + return (pcb) ? pin : -1; +}