arduino / arduino/ArduinoCore-samd

Refactor to use digitalPinToXXX macros most places...

Open
#382 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
502
Forks
740
PR merge metrics
No merged PRs in 30d

Description

The core code should avoid referencing the **g_APinDescription[]** array (defined within the variants), in favor of using the **digitalPinToXXX** macros also defined in the variant. This would permit variants running on the same chips to use different pin-mapping schemes, and increase portability/orthogonality in general, which would be A Good Thing. (standard "data hiding" practice, more or less.)

For example, Tone.cpp:
```
portToggleRegister = &(PORT->Group[g_APinDescription[outputPin].ulPort].OUTTGL.reg);
portClearRegister = &(PORT->Group[g_APinDescription[outputPin].ulPort].OUTCLR.reg);
//Should be
portToggleRegister = &(digitalPinToPort(outputPin)->OUTTGL.reg);
portClearRegister = &(digitalPinToPort(outputPin)->OUTCLR.reg);
```

This may require defining some additional macros and/or moving them from Core to Variant files.

I actually have patched this in a fork, but I'll need to clean it up a little to separate it from other things I was doing.

(this is standard "data hiding" practice, more or less.)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the g_APinDescription[] references in the core, including the example in Tone.cpp, and compare them with the digitalPinToXXX macros defined by variants. Review which additional macros or Core-to-Variant moves are needed; done means core code uses the macros instead of directly accessing the pin-description array while preserving variant portability.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, c
Domain
embedded-iot
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 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.