arduino / arduino/ArduinoCore-API

Retrieve current pin mode

Open
#179 4 comments 13 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Description

There is currently no function to get the current pin mode. A possible implementation is:

```
int pinMode(uint8_t pin)
{
if (pin >= NUM_DIGITAL_PINS) return (-1);

uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg = portModeRegister(port);
if (*reg & bit) return (OUTPUT);

volatile uint8_t *out = portOutputRegister(port);
return ((*out & bit) ? INPUT_PULLUP : INPUT);
}
```

The return value is the pin mode or error code (-1) for illegal pin number.

Cheers!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the existing pinMode API and the digitalPinToBitMask, digitalPinToPort, portModeRegister, and portOutputRegister entry points shown in the issue. Check how the hardware-independent API exposes pin operations and how cores implement them. Done means a current pin mode can be retrieved, with the specified modes returned and -1 for an invalid pin.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
api, embedded-iot
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.