Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

refactor the use of g_APinDescription ?

Open
#106 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
embedded-iot

Research direction

Start by comparing the variant.h and Arduino.h access macros with direct array use in cores/arduino/Tone.cpp, including g_APinDescription and digital_pin_to_xxx. Map the pin-related data currently accessed directly, then define the scope of an overridable formal API; done means core and library code uses those definitions without assuming a specific implementation.

Written by the indexing model from the issue text.

Description

It bothers me, in a sort of "Code Purity" sense, that so many core and library functions access
the g_APinDescription[] (for sam/samd) or digital_pin_to_xxx[] (for avr) arrays directly.
There are some macros in variant.h or Arduino.h (digitalPinToBitMask and similar), but they are not consistently used, not all functions have macros, and sometimes they aren't well-placed WRT redefining them for new board types.
Example:

variants/mkr1000/variant.h:47: #define digitalPinToBitMask(P)   (1 << g_APinDescription[P].ulPin)
cores/arduino/Tone.cpp:133:  portBitMask = (1ul << g_APinDescription[outputPin].ulPin);

The definition of a more formal API presents the opportunity to offer more formal rules:

  1. macros or inline functions to access all pin-related data should be defined in the variant-specific files, or perhaps WVariant.h for core-wide data.

  2. if such definitions are defined in core-wide functions, it should be possible to override them in variant-specific files.

  3. All other code should use these definitions, instead of assuming a particular implementation. (the tone.cpp example above should not exist, even now.)

The immediate practical benefit would be the possibility of more compact implementations for the "tiny" chips (avr tiny, SAMD11, etc), and greater portability of the functions in the "upper level" areas of code.

Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arduino/ArduinoCore-API

All issues in arduino/ArduinoCore-API

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.