arduino / arduino/ArduinoCore-mbed

Raspberry Pi Pico pinMode question.

Open
#1,101 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Apologies if I'm talking rubbish here, however....

The `.arduno15/packages/arduino/hardware/mbed_rp2040/4.4.1/variants/RASPBERRY_PI_PICO/pinmode_arduino.h` file defines the following enumeration for the allowable pin modes. I have added comments to show the actual values the enumeration entries represent.

```
typedef enum {
/* 0 */ PullNone = TempPullNone,
/* 1 */ PullUp = TempPullUp,
/* 2 */ PullDown = TempPullDown,
/* 3 */ OpenDrainPullUp = TempOpenDrainPullUp,
/* 4 */ OpenDrainNoPull = TempOpenDrainNoPull,
/* 5 */ OpenDrainPullDown = TempOpenDrainPullDown,
/* 0 */ PushPullNoPull = TempPushPullNoPull,
/* 1 */ PushPullPullUp = TempPushPullPullUp,
/* 2 */ PushPullPullDown = TempPushPullPullDown,
/* 3 */ OpenDrain = TempOpenDrain,
/* 0 */ PullDefault = TempPullDefault,
/* 0 */ INPUT = TempINPUT,
/* 1 */ OUTPUT = TempOUTPUT,
/* 2 */ INPUT_PULLUP = TempINPUT_PULLUP,
/* 3 */ INPUT_PULLDOWN = TempINPUT_PULLDOWN
} PinMode;
```
As far as I can see, any of these `enum` values can be used in the `pinMode()` function. However, the cross correspondence for some of them makes no sense.

For example,

INPUT = PullNone = PushPullNoPull.
OUTPUT = PullUp = PushPullPullUp.
INPUT_PULLUP = PullDown = PushPullPullDown.
INPUT_PULLDOWN = OpenDrainPullUp = OpenDrain.

Here we have `OUTPUT` pins with the same name as inputs with pull ups enabled; `INPUT_PULLUP` pins with the same name as pull down pins and so on.

Has there been some error made in the transcribing of these enumeration values, or am I completely barking mad? :wink:

I mean, the following Blink sketch works perfectly, but is obviously confusing!

```
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, PullUp);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
```

Regards,
Norman.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with .arduno15/packages/arduino/hardware/mbed_rp2040/4.4.1/variants/RASPBERRY_PI_PICO/pinmode_arduino.h and trace how pinMode() uses PinMode. Compare the listed enum values with the Blink sketch and determine whether the overlapping names are transcription errors or intentional aliases; done means the mapping is verified and the confusing behavior is clarified or corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.