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.
struct FeedToBondtech {
/// internal states of the state machine
enum {
enum : uint8_t {
EngagingIdler,
PushingFilamentFast,
PushingFilamentToFSensor,

View File

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

View File

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

View File

@ -7,7 +7,7 @@
/// therefore the error codes have been extracted to one place.
///
/// 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,
Cancelled = 1
};

View File

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

View File

@ -13,7 +13,7 @@ namespace logic {
/// - load/unload to finda
struct UnloadToFinda {
/// internal states of the state machine
enum {
enum : uint8_t {
EngagingIdler,
UnloadingToFinda,
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 {
enum : uint8_t {
Right = 0,
Middle,
Left

View File

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

View File

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

View File

@ -11,7 +11,7 @@ namespace motion {
class MovableBase {
public:
/// 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
Moving = 1,
PlannedHome = 2,

View File

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