arduino / arduino/ArduinoCore-API

refactor the use of g_APinDescription ?

Aperta
#106 1 commento 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
306
Fork
150
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia confrontando le macro di accesso di variant.h e Arduino.h con l’uso diretto degli array in cores/arduino/Tone.cpp, inclusi g_APinDescription e digital_pin_to_xxx. Mappa i dati relativi ai pin a cui si accede attualmente in modo diretto, quindi definisci l’ambito di un’API formale sovrascrivibile; il lavoro è completato quando il codice del core e delle librerie usa tali definizioni senza presumere un’implementazione specifica.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
embedded-iot
Tipo di issue
Refactoring
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.