arduino / arduino/ArduinoCore-API
Retrieve current pin mode
- 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