Skip to content

Commit 5cd4785

Browse files
facchinmDhruvaG2000
authored andcommitted
core: Introduce digitalPinTo(PortDevice|PinIndex)
Add digitalPinToPortDevice() and digitalPinToPinIndex(). Co-authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 9521617 commit 5cd4785

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

cores/arduino/Arduino.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ void noInterrupts(void);
131131

132132
int digitalPinToInterrupt(pin_size_t pin);
133133

134+
// These defines can be overridden by variant.h if implemented
134135
#define digitalPinToPort(x) (x)
135136
#define digitalPinToBitMask(x) (x)
136137
#define portOutputRegister(x) (x)
137138
#define portInputRegister(x) (x)
138139

140+
const struct device *digitalPinToPortDevice(pin_size_t pinNumber);
141+
int digitalPinToPinIndex(pin_size_t pinNumber);
142+
139143
#if defined(CONFIG_PWM) || defined(CONFIG_DAC)
140144
void analogWriteResolution(int bits);
141145
#endif

cores/arduino/zephyrCommon.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ void yield(void) {
218218
k_yield();
219219
}
220220

221+
const struct device *digitalPinToPortDevice(pin_size_t pinNumber) {
222+
RETURN_ON_INVALID_PIN(pinNumber, nullptr);
223+
224+
return arduino_pins[pinNumber].port;
225+
}
226+
227+
int digitalPinToPinIndex(pin_size_t pinNumber) {
228+
RETURN_ON_INVALID_PIN(pinNumber, -1);
229+
230+
return arduino_pins[pinNumber].pin;
231+
}
232+
221233
/*
222234
* The ACTIVE_HIGH flag is set so that A low physical
223235
* level on the pin will be interpreted as value 0.

0 commit comments

Comments
 (0)