Skip to content

Commit 9d272a1

Browse files
committed
Fix digitalPinToPinName and pinNametoDigitalPin
digitalPinToPinName: deals only with pin number. pinNametoDigitalPin: chek if PinName is a valid one Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent ada7c5c commit 9d272a1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

cores/arduino/pins_arduino.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ void __libc_init_array(void);
2626

2727
WEAK uint32_t pinNametoDigitalPin(PinName p)
2828
{
29-
uint32_t i = 0;
30-
for(i = 0; i < NUM_DIGITAL_PINS; i++) {
31-
if (digitalPin[i] == p)
32-
break;
29+
uint32_t i = NC;
30+
if(STM_VALID_PINNAME(p)) {
31+
for(i = 0; i < NUM_DIGITAL_PINS; i++) {
32+
if (digitalPin[i] == p)
33+
break;
34+
}
3335
}
3436
return i;
3537
}

cores/arduino/pins_arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern "C" {
3939

4040
// Convert a digital pin number Dxx to a PinName Pxy
4141
// Note: Analog pin is also a digital pin.
42-
#define digitalPinToPinName(p) ((p < NUM_DIGITAL_PINS) ? digitalPin[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
42+
#define digitalPinToPinName(p) ((p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC)
4343
// Convert a PinName Pxy to a digital pin number
4444
uint32_t pinNametoDigitalPin(PinName p);
4545

0 commit comments

Comments
 (0)