Skip to content

Commit 994c723

Browse files
facchinmsoburi
authored andcommitted
core: Introduce digitalPinTo(PortDevice|PinIndex)
Add digitalPinToPortDevice() and digitalPinToPinIndex(). Also define F_CPU for ARM targets. Co-authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 701792a commit 994c723

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

cores/arduino/Arduino.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,23 @@ 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
142146

147+
#if defined(__arm__)
148+
#define F_CPU (SystemCoreClock)
149+
#endif
150+
143151
#include <variant.h>
144152

145153
#if !defined(LED_BUILTIN) && defined(ZARD_LED_BUILTIN)

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)