optimisation: set enum types explictly to uint8_t

This commit produces the same savings as the compiler options -fshort-enums. Except by setting the types manually we save also 2 bytes of SRAM.

By default, the enum type is 2 bytes, with we can explictly set it to one byte when applicable to reduce code size.

Almost all the savings from from 'enum Mode' in leds.h.

Change in memory:
Flash: -116 bytes
SRAM: -2 bytes
pull/328/head
Guðni Már Gilbert 2024-07-29 22:22:55 +00:00
parent 3c8663d900
commit ccb7d31920
11 changed files with 12 additions and 12 deletions

View File

@ -17,7 +17,7 @@ namespace logic {
/// To prevent constant EEPROM updates only significant changes are recorded. /// To prevent constant EEPROM updates only significant changes are recorded.
struct FeedToBondtech { struct FeedToBondtech {
/// internal states of the state machine /// internal states of the state machine
enum { enum : uint8_t {
EngagingIdler, EngagingIdler,
PushingFilamentFast, PushingFilamentFast,
PushingFilamentToFSensor, PushingFilamentToFSensor,

View File

@ -12,7 +12,7 @@ namespace logic {
/// Leaves the Pulley axis enabled for chaining potential next operations /// Leaves the Pulley axis enabled for chaining potential next operations
struct FeedToFinda { struct FeedToFinda {
/// internal states of the state machine /// internal states of the state machine
enum { enum : uint8_t {
EngagingIdler, EngagingIdler,
PushingFilament, PushingFilament,
PushingFilamentUnlimited, PushingFilamentUnlimited,

View File

@ -32,7 +32,7 @@ bool HWSanity::Reset(uint8_t param) {
return true; return true;
} }
enum pin_bits { enum pin_bits : uint8_t {
BIT_STEP = 0b001, BIT_STEP = 0b001,
BIT_DIR = 0b010, BIT_DIR = 0b010,
BIT_ENA = 0b100, BIT_ENA = 0b100,

View File

@ -7,7 +7,7 @@
/// therefore the error codes have been extracted to one place. /// therefore the error codes have been extracted to one place.
/// ///
/// Please note that currently only LoadFilament can return something else than "OK" /// Please note that currently only LoadFilament can return something else than "OK"
enum class ResultCode : uint_fast16_t { enum class ResultCode : uint_fast8_t {
OK = 0, OK = 0,
Cancelled = 1 Cancelled = 1
}; };

View File

@ -13,7 +13,7 @@ namespace logic {
/// - leaves idler engaged for chaining operations /// - leaves idler engaged for chaining operations
struct RetractFromFinda { struct RetractFromFinda {
/// internal states of the state machine /// internal states of the state machine
enum { enum : uint8_t {
EngagingIdler, EngagingIdler,
UnloadBackToPTFE, UnloadBackToPTFE,
OK, OK,

View File

@ -13,7 +13,7 @@ namespace logic {
/// - load/unload to finda /// - load/unload to finda
struct UnloadToFinda { struct UnloadToFinda {
/// internal states of the state machine /// internal states of the state machine
enum { enum : uint8_t {
EngagingIdler, EngagingIdler,
UnloadingToFinda, UnloadingToFinda,
WaitingForFINDA, WaitingForFINDA,

View File

@ -20,7 +20,7 @@ private:
}; };
/// Enum of buttons - used also as indices in an array of buttons to keep the code size tight. /// Enum of buttons - used also as indices in an array of buttons to keep the code size tight.
enum { enum : uint8_t {
Right = 0, Right = 0,
Middle, Middle,
Left Left

View File

@ -28,7 +28,7 @@ private:
/// Intentionally not modeled as an enum class /// Intentionally not modeled as an enum class
/// as it would impose additional casts which do not play well with the struct Flags /// as it would impose additional casts which do not play well with the struct Flags
/// and would make the code less readable /// and would make the code less readable
enum State { enum State : uint8_t {
Waiting = 0, Waiting = 0,
Detected, Detected,
WaitForRelease, WaitForRelease,

View File

@ -20,7 +20,7 @@ namespace leds {
/// Enum of LED modes /// Enum of LED modes
/// blink0 and blink1 allow for interlaced blinking of LEDs (one is on and the other off) /// blink0 and blink1 allow for interlaced blinking of LEDs (one is on and the other off)
enum Mode { enum Mode : uint8_t {
off, off,
on, on,
blink0, ///< start blinking at even periods blink0, ///< start blinking at even periods
@ -28,7 +28,7 @@ enum Mode {
}; };
/// Enum of LEDs color - green or red /// Enum of LEDs color - green or red
enum Color { enum Color : uint8_t {
red = 0, red = 0,
green = 1 green = 1
}; };

View File

@ -11,7 +11,7 @@ namespace motion {
class MovableBase { class MovableBase {
public: public:
/// Internal states of the state machine /// Internal states of the state machine
enum { enum : uint8_t {
Ready = 0, // intentionally set as zero in order to allow zeroing the Idler structure upon startup -> avoid explicit initialization code Ready = 0, // intentionally set as zero in order to allow zeroing the Idler structure upon startup -> avoid explicit initialization code
Moving = 1, Moving = 1,
PlannedHome = 2, PlannedHome = 2,

View File

@ -68,7 +68,7 @@ public:
static bool set(uint8_t filament); static bool set(uint8_t filament);
private: private:
enum Key { enum Key : uint8_t {
KeyFront1, KeyFront1,
KeyReverse1, KeyReverse1,
KeyFront2, KeyFront2,