No, just remove the text encSwitch
after the struct
declaration as to not create a variable of that struct directly.
struct EncSwitch
{
const uint8_t pinSW = 13;
const uint8_t pinCLK = 26;
const uint8_t pinDT = 27;
uint16_t totalPress = 0;
uint16_t maxEncCount = 0;
volatile uint16_t curEncCount = 0;
volatile uint16_t oldEncCount = 0;
volatile uint16_t deBounceTime = 300;
bool swPressed = false;
} encSwitch;
^ declares the structure and directly instantiates one with the name encSwitch
→ if included from multiple .cpp files, will create multiple definitions → bad
struct EncSwitch
{
const uint8_t pinSW = 13;
const uint8_t pinCLK = 26;
const uint8_t pinDT = 27;
uint16_t totalPress = 0;
uint16_t maxEncCount = 0;
volatile uint16_t curEncCount = 0;
volatile uint16_t oldEncCount = 0;
volatile uint16_t deBounceTime = 300;
bool swPressed = false;
};
^ just declares the EncSwitch
structure, which is what you need.

You didn’t mention anything about:
portMUX_TYPE mux
You’re right, this has to be treated the same way. extern
in the header and without init value, and then no extern
and with init value in one .cpp
file.