ArduinoCore-mbed icon indicating copy to clipboard operation
ArduinoCore-mbed copied to clipboard

Raspberry Pi Pico pinMode question.

Open NormanDunbar opened this issue 3 months ago • 0 comments

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.

NormanDunbar avatar Nov 26 '25 15:11 NormanDunbar