arduino / arduino/ArduinoCore-API

force new enums for pinMode and pinStatus to 8 bits type instead of default int

Offen
#109 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C++
Sterne
306
Forks
150
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I've seen
```
typedef enum {
LOW = 0,
HIGH = 1,
CHANGE = 2,
FALLING = 3,
RISING = 4,
} PinStatus;

typedef enum {
INPUT = 0x0,
OUTPUT = 0x1,
INPUT_PULLUP = 0x2,
INPUT_PULLDOWN = 0x3,
} PinMode;
```

This will let the compiler decide how big the backend storage needs to be for those, and it will default to an int (16 or 32 bit depending on architecture). There is no need for this waste of memory and it prevents also some compiler optimization

I suggest forcing the uint8_t type, 256 values should be plenty to represent a pinMode or a pinStatus..

proposed changes:

```
typedef enum : uint8_t {
LOW = 0,
HIGH = 1,
CHANGE = 2,
FALLING = 3,
RISING = 4,
} PinStatus;

typedef enum : uint8_t {
INPUT = 0x0,
OUTPUT = 0x1,
INPUT_PULLUP = 0x2,
INPUT_PULLDOWN = 0x3,
} PinMode;
```

but in practice I would vote against getting these changes in production. There is no value added and tons of unwanted consequences for existing code out there to make this worthwhile.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginnen Sie damit, die Enum-Deklarationen von PinMode und PinStatus in der ArduinoCore-API-API zu finden, und bewerten Sie anschließend die Auswirkungen auf Quellcode- und Binärkompatibilität in bestehendem Arduino-Code. Als abgeschlossen gilt die Aufgabe, wenn eine Projektentscheidung darüber vorliegt, ob die vorgeschlagenen zugrunde liegenden Typen uint8_t akzeptabel sind; der Issue selbst rät von einer Übernahme in die Produktion ab.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Bereich
embedded-iot
Issue-Typ
Refactoring
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
18/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.