arduino / arduino/ArduinoCore-API
refactor the use of g_APinDescription ?
- Langage dominant
- C++
- Étoiles
- 306
- Forks
- 150
- Métriques de merge des PR
- Aucune PR mergée en 30 j
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.
1. if such definitions are defined in core-wide functions, it should be possible to override them in variant-specific files.
1. 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.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par comparer les macros d’accès de variant.h et Arduino.h avec l’utilisation directe de tableaux dans cores/arduino/Tone.cpp, notamment g_APinDescription et digital_pin_to_xxx. Recensez les données liées aux broches actuellement utilisées directement, puis définissez le périmètre d’une API formelle surchargeable ; le travail est terminé lorsque le code du core et des bibliothèques utilise ces définitions sans supposer une implémentation particulière.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- cpp
- Domaine
- embedded-iot
- Type d'issue
- Refactorisation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100