From 3cbade7abd7ddb4ded2f14f7f4f2380832ef1a10 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 1 Jan 2024 10:47:34 -0600 Subject: [PATCH 01/14] super high level intent of the define removal --- src/config_utils.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 37aa209f2..052069270 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -1539,16 +1539,21 @@ static bool loadConfigInner(Config& config) return pb_decode(&inputStream, Config_fields, &config); } -void ConfigUtils::load(Config& config) +static bool loadBoardDefault(Config& config) { - // First try to load from Protobuf storage, if that fails fall back to legacy storage. - const bool loaded = loadConfigInner(config) | fromLegacyStorage(config); + // TODO --- read from a new area of flash, which is presumed to have been populated + // by gp2040ce-binary-tools with a board config + return false; +} - if (!loaded) - { - // We could neither deserialize Protobuf config data nor legacy config data. - // We are probably dealing with a new device and therefore initialize the config to default values. - config = Config Config_init_default; +void ConfigUtils::load(Config& config) +{ + // first try to load from the user config, then from the read-only board config, + // and fall back to defaults + if (!loadConfigInner(config)) { + if (!loadBoardDefault(config)) { + config = Config Config_init_default; + } } // run migrations @@ -1578,7 +1583,7 @@ void ConfigUtils::load(Config& config) // Migrate old JS slider add-on to core migrateJSliderToCore(config); - // Update boardVersion, in case we migrated from an older version + // Update boardVersion strncpy(config.boardVersion, GP2040VERSION, sizeof(config.boardVersion)); config.boardVersion[sizeof(config.boardVersion) - 1] = '\0'; config.has_boardVersion = true; From 14b42cc29a9fee318fcfa833d69565ac64ba41b5 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 1 Jan 2024 10:53:30 -0600 Subject: [PATCH 02/14] remove support for legacy configs users should migrate to the previous release first, if they want to be supported without redoing their config --- CMakeLists.txt | 1 - headers/config_utils.h | 1 - src/config_legacy.cpp | 1123 ---------------------------------------- 3 files changed, 1125 deletions(-) delete mode 100644 src/config_legacy.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b192867b..bde018a6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,7 +204,6 @@ src/storagemanager.cpp src/system.cpp src/usbdriver.cpp src/usbhostmanager.cpp -src/config_legacy.cpp src/config_utils.cpp src/configs/webconfig.cpp src/addons/analog.cpp diff --git a/headers/config_utils.h b/headers/config_utils.h index 4bca7d0e9..559868052 100644 --- a/headers/config_utils.h +++ b/headers/config_utils.h @@ -12,7 +12,6 @@ namespace ConfigUtils { std::string toJSON(const Config& config); bool fromJSON(Config& config, const char* data, size_t dataLen); - bool fromLegacyStorage(Config& config); } #endif diff --git a/src/config_legacy.cpp b/src/config_legacy.cpp deleted file mode 100644 index d0af3ab2f..000000000 --- a/src/config_legacy.cpp +++ /dev/null @@ -1,1123 +0,0 @@ -#include "config_utils.h" - -#include "FlashPROM.h" -#include "CRC32.h" -#include "helper.h" - -#include "config.pb.h" -#include "GamepadState.h" - -#include "mbedtls/rsa.h" - -const size_t GAMEPAD_STORAGE_INDEX = 0; // 1024 bytes for gamepad options -const size_t BOARD_STORAGE_INDEX = 1024; // 512 bytes for hardware options -const size_t LED_STORAGE_INDEX = 1536; // 512 bytes for LED configuration -const size_t ANIMATION_STORAGE_INDEX = 2048; // 1024 bytes for LED animations -const size_t ADDON_STORAGE_INDEX = 3072; // 1024 bytes for Add-Ons -const size_t PS4_STORAGE_INDEX = 4096; // 2048 bytes for PS4 options -const size_t SPLASH_IMAGE_STORAGE_INDEX = 6144; // 1032 bytes for Display Config - -const uint32_t CHECKSUM_MAGIC = 0; -const uint32_t NOCHECKSUM_MAGIC = 0xDEADBEEF; // No checksum CRC; - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// Do not change the structs or enums in the ConfigLegacy namespace! -// They represent the structure of our legacy configuration storage, and any -// change will break the migration process. -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -namespace ConfigLegacy -{ - enum InputMode - { - INPUT_MODE_XINPUT, - INPUT_MODE_SWITCH, - INPUT_MODE_PS3, - INPUT_MODE_KEYBOARD, - INPUT_MODE_PS4, - INPUT_MODE_CONFIG = 255, - }; - - enum DpadMode - { - DPAD_MODE_DIGITAL, - DPAD_MODE_LEFT_ANALOG, - DPAD_MODE_RIGHT_ANALOG, - }; - - enum SOCDMode - { - SOCD_MODE_UP_PRIORITY, - SOCD_MODE_NEUTRAL, - SOCD_MODE_SECOND_INPUT_PRIORITY, - SOCD_MODE_FIRST_INPUT_PRIORITY, - SOCD_MODE_BYPASS, - }; - - enum DpadDirection - { - DIRECTION_NONE, - DIRECTION_UP, - DIRECTION_DOWN, - DIRECTION_LEFT, - DIRECTION_RIGHT, - }; - - enum GamepadHotkey - { - HOTKEY_NONE, - HOTKEY_DPAD_DIGITAL, - HOTKEY_DPAD_LEFT_ANALOG, - HOTKEY_DPAD_RIGHT_ANALOG, - HOTKEY_HOME_BUTTON, - HOTKEY_CAPTURE_BUTTON, - HOTKEY_SOCD_UP_PRIORITY, - HOTKEY_SOCD_NEUTRAL, - HOTKEY_SOCD_LAST_INPUT, - HOTKEY_INVERT_X_AXIS, - HOTKEY_INVERT_Y_AXIS, - HOTKEY_SOCD_FIRST_INPUT, - HOTKEY_SOCD_BYPASS, - }; - - enum OnBoardLedMode - { - BOARD_LED_OFF, - MODE_INDICATOR, - INPUT_TEST, - }; - - enum PLEDType - { - PLED_TYPE_NONE = -1, - PLED_TYPE_PWM = 0, - PLED_TYPE_RGB = 1, - }; - - enum ButtonLayout - { - BUTTON_LAYOUT_STICK, - BUTTON_LAYOUT_STICKLESS, - BUTTON_LAYOUT_BUTTONS_ANGLED, - BUTTON_LAYOUT_BUTTONS_BASIC, - BUTTON_LAYOUT_KEYBOARD_ANGLED, - BUTTON_LAYOUT_KEYBOARDA, - BUTTON_LAYOUT_DANCEPADA, - BUTTON_LAYOUT_TWINSTICKA, - BUTTON_LAYOUT_BLANKA, - BUTTON_LAYOUT_VLXA, - BUTTON_LAYOUT_FIGHTBOARD_STICK, - BUTTON_LAYOUT_FIGHTBOARD_MIRRORED, - BUTTON_LAYOUT_CUSTOMA, - BUTTON_LAYOUT_OPENCORE0WASDA, - BUTTON_LAYOUT_STICKLESS_13, - BUTTON_LAYOUT_STICKLESS_16, - BUTTON_LAYOUT_STICKLESS_14, - BUTTON_LAYOUT_STICKLESS_R16, - }; - - enum ButtonLayoutRight - { - BUTTON_LAYOUT_ARCADE, - BUTTON_LAYOUT_STICKLESSB, - BUTTON_LAYOUT_BUTTONS_ANGLEDB, - BUTTON_LAYOUT_VEWLIX, - BUTTON_LAYOUT_VEWLIX7, - BUTTON_LAYOUT_CAPCOM, - BUTTON_LAYOUT_CAPCOM6, - BUTTON_LAYOUT_SEGA2P, - BUTTON_LAYOUT_NOIR8, - BUTTON_LAYOUT_KEYBOARDB, - BUTTON_LAYOUT_DANCEPADB, - BUTTON_LAYOUT_TWINSTICKB, - BUTTON_LAYOUT_BLANKB, - BUTTON_LAYOUT_VLXB, - BUTTON_LAYOUT_FIGHTBOARD, - BUTTON_LAYOUT_FIGHTBOARD_STICK_MIRRORED, - BUTTON_LAYOUT_CUSTOMB, - BUTTON_LAYOUT_KEYBOARD8B, - BUTTON_LAYOUT_OPENCORE0WASDB, - BUTTON_LAYOUT_STICKLESS_13B, - BUTTON_LAYOUT_STICKLESS_16B, - BUTTON_LAYOUT_STICKLESS_14B, - BUTTON_LAYOUT_STICKLESS_R16B, - }; - - enum SplashMode - { - STATICSPLASH, - CLOSEIN, - CLOSEINCUSTOM, - NOSPLASH, - }; - - enum SplashChoice - { - MAIN, - X, - Y, - Z, - CUSTOM, - LEGACY - }; - - struct ButtonLayoutParams - { - union { - ButtonLayout layout; - ButtonLayoutRight layoutRight; - }; - int startX; - int startY; - int buttonRadius; - int buttonPadding; - }; - - struct ButtonLayoutCustomOptions - { - ButtonLayoutParams params; - ButtonLayoutParams paramsRight; - }; - - struct LEDOptions - { - bool useUserDefinedLEDs; - int dataPin; - LEDFormat ledFormat; - ButtonLayout ledLayout; - uint8_t ledsPerButton; - uint8_t brightnessMaximum; - uint8_t brightnessSteps; - int indexUp; - int indexDown; - int indexLeft; - int indexRight; - int indexB1; - int indexB2; - int indexB3; - int indexB4; - int indexL1; - int indexR1; - int indexL2; - int indexR2; - int indexS1; - int indexS2; - int indexL3; - int indexR3; - int indexA1; - int indexA2; - int pledType; - int pledPin1; - int pledPin2; - int pledPin3; - int pledPin4; - RGB pledColor; - uint32_t checksum; - }; - - struct PS4Options - { - uint8_t serial[16]; - uint8_t signature[256]; - mbedtls_mpi_uint rsa_n[64]; - mbedtls_mpi_uint rsa_e[1]; - mbedtls_mpi_uint rsa_d[64]; - mbedtls_mpi_uint rsa_p[32]; - mbedtls_mpi_uint rsa_q[32]; - mbedtls_mpi_uint rsa_dp[32]; - mbedtls_mpi_uint rsa_dq[32]; - mbedtls_mpi_uint rsa_qp[32]; - mbedtls_mpi_uint rsa_rn[64]; - uint32_t checksum; - }; - - struct AddonOptions - { - uint8_t pinButtonTurbo; - uint8_t pinButtonReverse; - uint8_t pinSliderLS; - uint8_t pinSliderRS; - uint8_t pinSliderSOCDOne; - uint8_t pinSliderSOCDTwo; - uint8_t turboShotCount; // Turbo - uint8_t pinTurboLED; // Turbo LED - uint8_t pinReverseLED; // Reverse LED - uint8_t reverseActionUp; - uint8_t reverseActionDown; - uint8_t reverseActionLeft; - uint8_t reverseActionRight; - uint8_t i2cAnalog1219SDAPin; - uint8_t i2cAnalog1219SCLPin; - int i2cAnalog1219Block; - uint32_t i2cAnalog1219Speed; - uint8_t i2cAnalog1219Address; - uint8_t pinDualDirUp; // Pins for Dual Directional Input - uint8_t pinDualDirDown; - uint8_t pinDualDirLeft; - uint8_t pinDualDirRight; - DpadMode dualDirDpadMode; // LS/DP/RS - uint8_t dualDirCombineMode; // Mix/Gamepad/Dual/None - OnBoardLedMode onBoardLedMode; - uint8_t analogAdcPinX; - uint8_t analogAdcPinY; - uint16_t bootselButtonMap; - uint8_t extraButtonPin; - uint32_t extraButtonMap; - uint8_t buzzerPin; - uint8_t buzzerVolume; - uint8_t playerNumber; - uint8_t shmupMode; // Turbo SHMUP Mode - uint8_t shmupMixMode; // How we mix turbo and non-turbo buttons - uint16_t shmupAlwaysOn1; - uint16_t shmupAlwaysOn2; - uint16_t shmupAlwaysOn3; - uint16_t shmupAlwaysOn4; - uint8_t pinShmupBtn1; - uint8_t pinShmupBtn2; - uint8_t pinShmupBtn3; - uint8_t pinShmupBtn4; - uint16_t shmupBtnMask1; - uint16_t shmupBtnMask2; - uint16_t shmupBtnMask3; - uint16_t shmupBtnMask4; - uint8_t pinShmupDial; - SOCDMode sliderSOCDModeOne; - SOCDMode sliderSOCDModeTwo; - SOCDMode sliderSOCDModeDefault; - uint8_t wiiExtensionSDAPin; - uint8_t wiiExtensionSCLPin; - int wiiExtensionBlock; - uint32_t wiiExtensionSpeed; - uint8_t AnalogInputEnabled; - uint8_t BoardLedAddonEnabled; - uint8_t BootselButtonAddonEnabled; - uint8_t BuzzerSpeakerAddonEnabled; - uint8_t DualDirectionalInputEnabled; - uint8_t ExtraButtonAddonEnabled; - uint8_t I2CAnalog1219InputEnabled; - //bool I2CDisplayAddonEnabled; // I2C is special case - //bool NeoPicoLEDAddonEnabled; // NeoPico is special case - //bool PlayerLEDAddonEnabled; // PlayerLED is special case - uint8_t PlayerNumAddonEnabled; - uint8_t PS4ModeAddonEnabled; - uint8_t ReverseInputEnabled; - uint8_t TurboInputEnabled; - uint8_t SliderSOCDInputEnabled; - uint8_t WiiExtensionAddonEnabled; - uint32_t checksum; - }; - - struct SplashImage - { - uint8_t data[16*64]; - uint32_t checksum; - }; - - struct GamepadHotkeyEntry - { - uint8_t dpadMask; - GamepadHotkey action; - }; - - struct GamepadOptions - { - InputMode inputMode {InputMode::INPUT_MODE_XINPUT}; - DpadMode dpadMode {DpadMode::DPAD_MODE_DIGITAL}; - SOCDMode socdMode {SOCDMode::SOCD_MODE_NEUTRAL}; - bool invertXAxis; - bool invertYAxis; - - uint8_t keyDpadUp; - uint8_t keyDpadDown; - uint8_t keyDpadLeft; - uint8_t keyDpadRight; - uint8_t keyButtonB1; - uint8_t keyButtonB2; - uint8_t keyButtonB3; - uint8_t keyButtonB4; - uint8_t keyButtonL1; - uint8_t keyButtonR1; - uint8_t keyButtonL2; - uint8_t keyButtonR2; - uint8_t keyButtonS1; - uint8_t keyButtonS2; - uint8_t keyButtonL3; - uint8_t keyButtonR3; - uint8_t keyButtonA1; - uint8_t keyButtonA2; - - GamepadHotkeyEntry hotkeyF1Up; - GamepadHotkeyEntry hotkeyF1Down; - GamepadHotkeyEntry hotkeyF1Left; - GamepadHotkeyEntry hotkeyF1Right; - GamepadHotkeyEntry hotkeyF2Up; - GamepadHotkeyEntry hotkeyF2Down; - GamepadHotkeyEntry hotkeyF2Left; - GamepadHotkeyEntry hotkeyF2Right; - - uint32_t checksum; - }; - - struct __attribute__ ((__packed__)) AnimationOptions - { - uint32_t checksum; - uint8_t baseAnimationIndex; - uint8_t brightness; - uint8_t staticColorIndex; - uint8_t buttonColorIndex; - int16_t chaseCycleTime; - int16_t rainbowCycleTime; - uint8_t themeIndex; - bool hasCustomTheme; - uint32_t customThemeUp; - uint32_t customThemeDown; - uint32_t customThemeLeft; - uint32_t customThemeRight; - uint32_t customThemeB1; - uint32_t customThemeB2; - uint32_t customThemeB3; - uint32_t customThemeB4; - uint32_t customThemeL1; - uint32_t customThemeR1; - uint32_t customThemeL2; - uint32_t customThemeR2; - uint32_t customThemeS1; - uint32_t customThemeS2; - uint32_t customThemeL3; - uint32_t customThemeR3; - uint32_t customThemeA1; - uint32_t customThemeA2; - uint32_t customThemeUpPressed; - uint32_t customThemeDownPressed; - uint32_t customThemeLeftPressed; - uint32_t customThemeRightPressed; - uint32_t customThemeB1Pressed; - uint32_t customThemeB2Pressed; - uint32_t customThemeB3Pressed; - uint32_t customThemeB4Pressed; - uint32_t customThemeL1Pressed; - uint32_t customThemeR1Pressed; - uint32_t customThemeL2Pressed; - uint32_t customThemeR2Pressed; - uint32_t customThemeS1Pressed; - uint32_t customThemeS2Pressed; - uint32_t customThemeL3Pressed; - uint32_t customThemeR3Pressed; - uint32_t customThemeA1Pressed; - uint32_t customThemeA2Pressed; - }; - - struct BoardOptions - { - bool hasBoardOptions; - uint8_t pinDpadUp; - uint8_t pinDpadDown; - uint8_t pinDpadLeft; - uint8_t pinDpadRight; - uint8_t pinButtonB1; - uint8_t pinButtonB2; - uint8_t pinButtonB3; - uint8_t pinButtonB4; - uint8_t pinButtonL1; - uint8_t pinButtonR1; - uint8_t pinButtonL2; - uint8_t pinButtonR2; - uint8_t pinButtonS1; - uint8_t pinButtonS2; - uint8_t pinButtonL3; - uint8_t pinButtonR3; - uint8_t pinButtonA1; - uint8_t pinButtonA2; - ButtonLayout buttonLayout; - ButtonLayoutRight buttonLayoutRight; - SplashMode splashMode; - SplashChoice splashChoice; - int splashDuration; // -1 = Always on - uint8_t i2cSDAPin; - uint8_t i2cSCLPin; - int i2cBlock; - uint32_t i2cSpeed; - bool hasI2CDisplay; - int displayI2CAddress; - uint8_t displaySize; - uint8_t displayFlip; - bool displayInvert; - int displaySaverTimeout; - ButtonLayoutCustomOptions buttonLayoutCustomOptions; - char boardVersion[32]; // 32-char limit to board name - uint32_t checksum; - }; -} - -#define PREPROCESSOR_JOIN2(x, y) x ## y -#define PREPROCESSOR_JOIN(x, y) PREPROCESSOR_JOIN2(x, y) - -#define SET_PROPERTY_BYTES(parent, property, byteArray) \ - parent.property.size = sizeof(byteArray); \ - memcpy(parent.property.bytes, byteArray, std::min(sizeof(byteArray), sizeof(parent.property.bytes))); \ - parent.PREPROCESSOR_JOIN(has_, property) = true; - -#define SET_PROPERTY(parent, property, value) \ - parent.property = value; \ - parent.PREPROCESSOR_JOIN(has_, property) = true; - -static uint32_t computeChecksum(const char* obj, size_t size, size_t checksumOffset) -{ - CRC32 crc32; - if (checksumOffset + sizeof(uint32_t) > size) - { - crc32.update(obj, size); - } - else - { - crc32.update(obj, checksumOffset); - const uint32_t checksumMagic = CHECKSUM_MAGIC; - crc32.update(&checksumMagic, 1); - crc32.update(obj + checksumOffset + sizeof(uint32_t), size - checksumOffset - sizeof(uint32_t)); - } - return crc32.finalize(); -} - -static bool isValidInputMode(ConfigLegacy::InputMode inputMode) -{ - switch (inputMode) - { - case INPUT_MODE_XINPUT: - case INPUT_MODE_SWITCH: - case INPUT_MODE_PS3: - case INPUT_MODE_KEYBOARD: - case INPUT_MODE_PS4: - return true; - default: - break; - } - return false; -} - -static bool isValidDpadMode(ConfigLegacy::DpadMode dpadMode) -{ - switch (dpadMode) - { - case DPAD_MODE_DIGITAL: - case DPAD_MODE_LEFT_ANALOG: - case DPAD_MODE_RIGHT_ANALOG: - return true; - } - return false; -} - -static bool isValidSOCDMode(ConfigLegacy::SOCDMode socdMode) -{ - switch (socdMode) - { - case SOCD_MODE_UP_PRIORITY: - case SOCD_MODE_NEUTRAL: - case SOCD_MODE_SECOND_INPUT_PRIORITY: - case SOCD_MODE_FIRST_INPUT_PRIORITY: - case SOCD_MODE_BYPASS: - return true; - } - return false; -} - -static bool isValidGamepadHotkey(ConfigLegacy::GamepadHotkey hotkey) -{ - switch (hotkey) - { - case HOTKEY_NONE: - case HOTKEY_DPAD_DIGITAL: - case HOTKEY_DPAD_LEFT_ANALOG: - case HOTKEY_DPAD_RIGHT_ANALOG: - case HOTKEY_HOME_BUTTON: - case HOTKEY_CAPTURE_BUTTON: - case HOTKEY_SOCD_UP_PRIORITY: - case HOTKEY_SOCD_NEUTRAL: - case HOTKEY_SOCD_LAST_INPUT: - case HOTKEY_INVERT_X_AXIS: - case HOTKEY_INVERT_Y_AXIS: - case HOTKEY_SOCD_FIRST_INPUT: - case HOTKEY_SOCD_BYPASS: - return true; - } - return false; -} - -static bool isValidButtonLayout(ConfigLegacy::ButtonLayout buttonLayout) -{ - switch (buttonLayout) - { - case BUTTON_LAYOUT_STICK: - case BUTTON_LAYOUT_STICKLESS: - case BUTTON_LAYOUT_BUTTONS_ANGLED: - case BUTTON_LAYOUT_BUTTONS_BASIC: - case BUTTON_LAYOUT_KEYBOARD_ANGLED: - case BUTTON_LAYOUT_KEYBOARDA: - case BUTTON_LAYOUT_DANCEPADA: - case BUTTON_LAYOUT_TWINSTICKA: - case BUTTON_LAYOUT_BLANKA: - case BUTTON_LAYOUT_VLXA: - case BUTTON_LAYOUT_FIGHTBOARD_STICK: - case BUTTON_LAYOUT_FIGHTBOARD_MIRRORED: - case BUTTON_LAYOUT_CUSTOMA: - case BUTTON_LAYOUT_OPENCORE0WASDA: - case BUTTON_LAYOUT_STICKLESS_13: - case BUTTON_LAYOUT_STICKLESS_16: - case BUTTON_LAYOUT_STICKLESS_R16: - case BUTTON_LAYOUT_STICKLESS_14: - return true; - } - return false; -} - -static bool isValidButtonLayoutRight(ConfigLegacy::ButtonLayoutRight buttonLayoutRight) -{ - switch (buttonLayoutRight) - { - case BUTTON_LAYOUT_ARCADE: - case BUTTON_LAYOUT_STICKLESSB: - case BUTTON_LAYOUT_BUTTONS_ANGLEDB: - case BUTTON_LAYOUT_VEWLIX: - case BUTTON_LAYOUT_VEWLIX7: - case BUTTON_LAYOUT_CAPCOM: - case BUTTON_LAYOUT_CAPCOM6: - case BUTTON_LAYOUT_SEGA2P: - case BUTTON_LAYOUT_NOIR8: - case BUTTON_LAYOUT_KEYBOARDB: - case BUTTON_LAYOUT_DANCEPADB: - case BUTTON_LAYOUT_TWINSTICKB: - case BUTTON_LAYOUT_BLANKB: - case BUTTON_LAYOUT_VLXB: - case BUTTON_LAYOUT_FIGHTBOARD: - case BUTTON_LAYOUT_FIGHTBOARD_STICK_MIRRORED: - case BUTTON_LAYOUT_CUSTOMB: - case BUTTON_LAYOUT_KEYBOARD8B: - case BUTTON_LAYOUT_OPENCORE0WASDB: - case BUTTON_LAYOUT_STICKLESS_13B: - case BUTTON_LAYOUT_STICKLESS_16B: - case BUTTON_LAYOUT_STICKLESS_R16B: - case BUTTON_LAYOUT_STICKLESS_14B: - return true; - } - return false; -} - -static bool isValidLEDFormat(LEDFormat ledFormat) -{ - switch (ledFormat) - { - case LED_FORMAT_GRB: - case LED_FORMAT_RGB: - case LED_FORMAT_GRBW: - case LED_FORMAT_RGBW: - return true; - } - return false; -} - -static bool isValidPLEDType(PLEDType pledType) -{ - switch (pledType) - { - case PLED_TYPE_NONE: - case PLED_TYPE_PWM: - case PLED_TYPE_RGB: - return true; - } - return false; -} - -static bool isValidOnBoardLedMode(ConfigLegacy::OnBoardLedMode onBoardLedMode) -{ - switch (onBoardLedMode) - { - case ConfigLegacy::BOARD_LED_OFF: - case ConfigLegacy::MODE_INDICATOR: - case ConfigLegacy::INPUT_TEST: - return true; - } - return false; -} - -static bool isValidSplashMode(ConfigLegacy::SplashMode splashMode) -{ - switch (splashMode) - { - case ConfigLegacy::STATICSPLASH: - case ConfigLegacy::CLOSEIN: - case ConfigLegacy::CLOSEINCUSTOM: - case ConfigLegacy::NOSPLASH: - return true; - } - return false; -} - -static bool isValidSplashChoice(ConfigLegacy::SplashChoice splashChoice) -{ - switch (splashChoice) - { - case ConfigLegacy::MAIN: - case ConfigLegacy::X: - case ConfigLegacy::Y: - case ConfigLegacy::Z: - case ConfigLegacy::CUSTOM: - case ConfigLegacy::LEGACY: - return true; - } - return false; -} - -bool ConfigUtils::fromLegacyStorage(Config& config) -{ - bool legacyConfigFound = false; - - const auto bytePinToIntPin = [](uint8_t pin) -> int32_t { return pin == 0xFF ? -1 : pin; }; - - const ConfigLegacy::GamepadOptions& legacyGamepadOptions = *reinterpret_cast(EEPROM_ADDRESS_START + GAMEPAD_STORAGE_INDEX); - if (legacyGamepadOptions.checksum == computeChecksum(reinterpret_cast(&legacyGamepadOptions), sizeof(ConfigLegacy::GamepadOptions), offsetof(ConfigLegacy::GamepadOptions, checksum))) - { - legacyConfigFound = true; - - GamepadOptions& gamepadOptions = config.gamepadOptions; - config.has_gamepadOptions = true; - if (isValidInputMode(legacyGamepadOptions.inputMode)) - { - SET_PROPERTY(gamepadOptions, inputMode, static_cast(legacyGamepadOptions.inputMode)); - } - if (isValidDpadMode(legacyGamepadOptions.dpadMode)) - { - SET_PROPERTY(gamepadOptions, dpadMode, static_cast(legacyGamepadOptions.dpadMode)); - } - if (isValidSOCDMode(legacyGamepadOptions.socdMode)) - { - SET_PROPERTY(gamepadOptions, socdMode, static_cast(legacyGamepadOptions.socdMode)); - } - SET_PROPERTY(gamepadOptions, invertXAxis, legacyGamepadOptions.invertXAxis); - SET_PROPERTY(gamepadOptions, invertYAxis, legacyGamepadOptions.invertYAxis); - - KeyboardMapping& keyboardMapping = config.keyboardMapping; - config.has_keyboardMapping = true; - SET_PROPERTY(keyboardMapping, keyDpadUp, legacyGamepadOptions.keyDpadUp); - SET_PROPERTY(keyboardMapping, keyDpadDown, legacyGamepadOptions.keyDpadDown); - SET_PROPERTY(keyboardMapping, keyDpadLeft, legacyGamepadOptions.keyDpadLeft); - SET_PROPERTY(keyboardMapping, keyDpadRight, legacyGamepadOptions.keyDpadRight); - SET_PROPERTY(keyboardMapping, keyButtonB1, legacyGamepadOptions.keyButtonB1); - SET_PROPERTY(keyboardMapping, keyButtonB2, legacyGamepadOptions.keyButtonB2); - SET_PROPERTY(keyboardMapping, keyButtonB3, legacyGamepadOptions.keyButtonB3); - SET_PROPERTY(keyboardMapping, keyButtonB4, legacyGamepadOptions.keyButtonB4); - SET_PROPERTY(keyboardMapping, keyButtonL1, legacyGamepadOptions.keyButtonL1); - SET_PROPERTY(keyboardMapping, keyButtonR1, legacyGamepadOptions.keyButtonR1); - SET_PROPERTY(keyboardMapping, keyButtonL2, legacyGamepadOptions.keyButtonL2); - SET_PROPERTY(keyboardMapping, keyButtonR2, legacyGamepadOptions.keyButtonR2); - SET_PROPERTY(keyboardMapping, keyButtonS1, legacyGamepadOptions.keyButtonS1); - SET_PROPERTY(keyboardMapping, keyButtonS2, legacyGamepadOptions.keyButtonS2); - SET_PROPERTY(keyboardMapping, keyButtonL3, legacyGamepadOptions.keyButtonL3); - SET_PROPERTY(keyboardMapping, keyButtonR3, legacyGamepadOptions.keyButtonR3); - SET_PROPERTY(keyboardMapping, keyButtonA1, legacyGamepadOptions.keyButtonA1); - SET_PROPERTY(keyboardMapping, keyButtonA2, legacyGamepadOptions.keyButtonA2); - - HotkeyOptions& hotkeyOptions = config.hotkeyOptions; - config.has_hotkeyOptions = true; - SET_PROPERTY(hotkeyOptions.hotkey01, dpadMask, legacyGamepadOptions.hotkeyF1Up.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey01, buttonsMask, GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF1Up.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey01, action, static_cast(legacyGamepadOptions.hotkeyF1Up.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey02, dpadMask, legacyGamepadOptions.hotkeyF1Down.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey02, buttonsMask, GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF1Down.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey02, action, static_cast(legacyGamepadOptions.hotkeyF1Down.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey03, dpadMask, legacyGamepadOptions.hotkeyF1Left.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey03, buttonsMask, GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF1Left.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey03, action, static_cast(legacyGamepadOptions.hotkeyF1Left.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey04, dpadMask, legacyGamepadOptions.hotkeyF1Right.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey04, buttonsMask, GAMEPAD_MASK_S1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF1Right.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey04, action, static_cast(legacyGamepadOptions.hotkeyF1Right.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey05, dpadMask, legacyGamepadOptions.hotkeyF2Up.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey05, buttonsMask, GAMEPAD_MASK_A1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF2Up.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey05, action, static_cast(legacyGamepadOptions.hotkeyF2Up.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey06, dpadMask, legacyGamepadOptions.hotkeyF2Down.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey06, buttonsMask, GAMEPAD_MASK_A1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF2Down.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey06, action, static_cast(legacyGamepadOptions.hotkeyF2Down.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey07, dpadMask, legacyGamepadOptions.hotkeyF2Left.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey07, buttonsMask, GAMEPAD_MASK_A1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF2Left.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey07, action, static_cast(legacyGamepadOptions.hotkeyF2Left.action)); - } - - SET_PROPERTY(hotkeyOptions.hotkey08, dpadMask, legacyGamepadOptions.hotkeyF2Right.dpadMask); - SET_PROPERTY(hotkeyOptions.hotkey08, buttonsMask, GAMEPAD_MASK_A1 | GAMEPAD_MASK_S2); - if (isValidGamepadHotkey(legacyGamepadOptions.hotkeyF2Right.action)) - { - SET_PROPERTY(hotkeyOptions.hotkey08, action, static_cast(legacyGamepadOptions.hotkeyF2Right.action)); - } - } - - const ConfigLegacy::BoardOptions& legacyBoardOptions = *reinterpret_cast(EEPROM_ADDRESS_START + BOARD_STORAGE_INDEX); - if (legacyBoardOptions.checksum == computeChecksum(reinterpret_cast(&legacyBoardOptions), sizeof(ConfigLegacy::BoardOptions), offsetof(ConfigLegacy::BoardOptions, checksum))) - { - legacyConfigFound = true; - - PinMappings& pinMappings = config.deprecatedPinMappings; - config.has_deprecatedPinMappings = true; - SET_PROPERTY(pinMappings, pinDpadUp, bytePinToIntPin(legacyBoardOptions.pinDpadUp)); - SET_PROPERTY(pinMappings, pinDpadDown, bytePinToIntPin(legacyBoardOptions.pinDpadDown)); - SET_PROPERTY(pinMappings, pinDpadLeft, bytePinToIntPin(legacyBoardOptions.pinDpadLeft)); - SET_PROPERTY(pinMappings, pinDpadRight, bytePinToIntPin(legacyBoardOptions.pinDpadRight)); - SET_PROPERTY(pinMappings, pinButtonB1, bytePinToIntPin(legacyBoardOptions.pinButtonB1)); - SET_PROPERTY(pinMappings, pinButtonB2, bytePinToIntPin(legacyBoardOptions.pinButtonB2)); - SET_PROPERTY(pinMappings, pinButtonB3, bytePinToIntPin(legacyBoardOptions.pinButtonB3)); - SET_PROPERTY(pinMappings, pinButtonB4, bytePinToIntPin(legacyBoardOptions.pinButtonB4)); - SET_PROPERTY(pinMappings, pinButtonL1, bytePinToIntPin(legacyBoardOptions.pinButtonL1)); - SET_PROPERTY(pinMappings, pinButtonR1, bytePinToIntPin(legacyBoardOptions.pinButtonR1)); - SET_PROPERTY(pinMappings, pinButtonL2, bytePinToIntPin(legacyBoardOptions.pinButtonL2)); - SET_PROPERTY(pinMappings, pinButtonR2, bytePinToIntPin(legacyBoardOptions.pinButtonR2)); - SET_PROPERTY(pinMappings, pinButtonS1, bytePinToIntPin(legacyBoardOptions.pinButtonS1)); - SET_PROPERTY(pinMappings, pinButtonS2, bytePinToIntPin(legacyBoardOptions.pinButtonS2)); - SET_PROPERTY(pinMappings, pinButtonL3, bytePinToIntPin(legacyBoardOptions.pinButtonL3)); - SET_PROPERTY(pinMappings, pinButtonR3, bytePinToIntPin(legacyBoardOptions.pinButtonR3)); - SET_PROPERTY(pinMappings, pinButtonA1, bytePinToIntPin(legacyBoardOptions.pinButtonA1)); - SET_PROPERTY(pinMappings, pinButtonA2, bytePinToIntPin(legacyBoardOptions.pinButtonA2)); - - DisplayOptions& displayOptions = config.displayOptions; - config.has_displayOptions = true; - SET_PROPERTY(displayOptions, enabled, legacyBoardOptions.hasI2CDisplay); - SET_PROPERTY(displayOptions, deprecatedI2cBlock, legacyBoardOptions.i2cBlock); - SET_PROPERTY(displayOptions, deprecatedI2cSDAPin, legacyBoardOptions.i2cSDAPin); - SET_PROPERTY(displayOptions, deprecatedI2cSCLPin, legacyBoardOptions.i2cSCLPin); - SET_PROPERTY(displayOptions, deprecatedI2cAddress, legacyBoardOptions.displayI2CAddress); - SET_PROPERTY(displayOptions, deprecatedI2cSpeed, legacyBoardOptions.i2cSpeed); - if (isValidButtonLayout(legacyBoardOptions.buttonLayout)) - { - SET_PROPERTY(displayOptions, buttonLayout, static_cast(legacyBoardOptions.buttonLayout)); - } - if (isValidButtonLayoutRight(legacyBoardOptions.buttonLayoutRight)) - { - SET_PROPERTY(displayOptions, buttonLayoutRight, static_cast(legacyBoardOptions.buttonLayoutRight)); - } - - const ConfigLegacy::ButtonLayoutParams& legacyParams = legacyBoardOptions.buttonLayoutCustomOptions.params; - ButtonLayoutParamsLeft& params = displayOptions.buttonLayoutCustomOptions.paramsLeft; - if (isValidButtonLayout(legacyParams.layout)) - { - SET_PROPERTY(params, layout, static_cast(legacyParams.layout)); - } - SET_PROPERTY(params.common, startX, legacyParams.startX); - SET_PROPERTY(params.common, startY, legacyParams.startY); - SET_PROPERTY(params.common, buttonRadius, legacyParams.buttonRadius); - SET_PROPERTY(params.common, buttonPadding, legacyParams.buttonPadding); - - const ConfigLegacy::ButtonLayoutParams& legacyParamsRight = legacyBoardOptions.buttonLayoutCustomOptions.paramsRight; - ButtonLayoutParamsRight& paramsRight = displayOptions.buttonLayoutCustomOptions.paramsRight; - if (isValidButtonLayoutRight(legacyParams.layoutRight)) - { - SET_PROPERTY(paramsRight, layout, static_cast(legacyParams.layoutRight)); - } - SET_PROPERTY(paramsRight.common, startX, legacyParamsRight.startX); - SET_PROPERTY(paramsRight.common, startY, legacyParamsRight.startY); - SET_PROPERTY(paramsRight.common, buttonRadius, legacyParamsRight.buttonRadius); - SET_PROPERTY(paramsRight.common, buttonPadding, legacyParamsRight.buttonPadding); - if (isValidSplashMode(legacyBoardOptions.splashMode)) - { - SET_PROPERTY(displayOptions, splashMode, static_cast(legacyBoardOptions.splashMode)); - } - if (isValidSplashChoice(legacyBoardOptions.splashChoice)) - { - SET_PROPERTY(displayOptions, splashChoice, static_cast(legacyBoardOptions.splashChoice)); - } - SET_PROPERTY(displayOptions, splashDuration, legacyBoardOptions.splashDuration); - SET_PROPERTY(displayOptions, size, legacyBoardOptions.displaySize); - SET_PROPERTY(displayOptions, flip, legacyBoardOptions.displayFlip); - SET_PROPERTY(displayOptions, invert, legacyBoardOptions.displayInvert); - SET_PROPERTY(displayOptions, displaySaverTimeout, legacyBoardOptions.displaySaverTimeout); - } - - const ConfigLegacy::LEDOptions& legacyLEDOptions = *reinterpret_cast(EEPROM_ADDRESS_START + LED_STORAGE_INDEX); - if (legacyLEDOptions.checksum == computeChecksum(reinterpret_cast(&legacyLEDOptions), sizeof(ConfigLegacy::LEDOptions), offsetof(ConfigLegacy::LEDOptions, checksum)) && - legacyLEDOptions.useUserDefinedLEDs) - { - legacyConfigFound = true; - - LEDOptions& ledOptions = config.ledOptions; - config.has_ledOptions = true; - SET_PROPERTY(ledOptions, dataPin, isValidPin(legacyLEDOptions.dataPin) ? legacyLEDOptions.dataPin : -1); - if (isValidLEDFormat(legacyLEDOptions.ledFormat)) - { - SET_PROPERTY(ledOptions, ledFormat, static_cast(legacyLEDOptions.ledFormat)); - } - if (isValidButtonLayout(legacyLEDOptions.ledLayout)) - { - SET_PROPERTY(ledOptions, ledLayout, static_cast(legacyLEDOptions.ledLayout)); - } - SET_PROPERTY(ledOptions, ledsPerButton, legacyLEDOptions.ledsPerButton); - SET_PROPERTY(ledOptions, brightnessMaximum, legacyLEDOptions.brightnessMaximum); - SET_PROPERTY(ledOptions, brightnessSteps, legacyLEDOptions.brightnessSteps); - SET_PROPERTY(ledOptions, indexUp, legacyLEDOptions.indexUp); - SET_PROPERTY(ledOptions, indexDown, legacyLEDOptions.indexDown); - SET_PROPERTY(ledOptions, indexLeft, legacyLEDOptions.indexLeft); - SET_PROPERTY(ledOptions, indexRight, legacyLEDOptions.indexRight); - SET_PROPERTY(ledOptions, indexB1, legacyLEDOptions.indexB1); - SET_PROPERTY(ledOptions, indexB2, legacyLEDOptions.indexB2); - SET_PROPERTY(ledOptions, indexB3, legacyLEDOptions.indexB3); - SET_PROPERTY(ledOptions, indexB4, legacyLEDOptions.indexB4); - SET_PROPERTY(ledOptions, indexL1, legacyLEDOptions.indexL1); - SET_PROPERTY(ledOptions, indexR1, legacyLEDOptions.indexR1); - SET_PROPERTY(ledOptions, indexL2, legacyLEDOptions.indexL2); - SET_PROPERTY(ledOptions, indexR2, legacyLEDOptions.indexR2); - SET_PROPERTY(ledOptions, indexS1, legacyLEDOptions.indexS1); - SET_PROPERTY(ledOptions, indexS2, legacyLEDOptions.indexS2); - SET_PROPERTY(ledOptions, indexL3, legacyLEDOptions.indexL3); - SET_PROPERTY(ledOptions, indexR3, legacyLEDOptions.indexR3); - SET_PROPERTY(ledOptions, indexA1, legacyLEDOptions.indexA1); - SET_PROPERTY(ledOptions, indexA2, legacyLEDOptions.indexA2); - if (isValidPLEDType(static_cast(legacyLEDOptions.pledType))) - { - SET_PROPERTY(ledOptions, pledType, static_cast(legacyLEDOptions.pledType)); - } - SET_PROPERTY(ledOptions, pledPin1, legacyLEDOptions.pledPin1); - SET_PROPERTY(ledOptions, pledPin2, legacyLEDOptions.pledPin2); - SET_PROPERTY(ledOptions, pledPin3, legacyLEDOptions.pledPin3); - SET_PROPERTY(ledOptions, pledPin4, legacyLEDOptions.pledPin4); - SET_PROPERTY(ledOptions, pledColor, legacyLEDOptions.pledColor.value(LED_FORMAT_RGB)); - } - - const ConfigLegacy::AnimationOptions& legacyAnimationOptions = *reinterpret_cast(EEPROM_ADDRESS_START + ANIMATION_STORAGE_INDEX); - if (legacyAnimationOptions.checksum == computeChecksum(reinterpret_cast(&legacyAnimationOptions), sizeof(ConfigLegacy::AnimationOptions), offsetof(ConfigLegacy::AnimationOptions, checksum))) - { - legacyConfigFound = true; - - AnimationOptions_Proto& animationOptions = config.animationOptions; - config.has_animationOptions = true; - SET_PROPERTY(animationOptions, baseAnimationIndex, legacyAnimationOptions.baseAnimationIndex); - SET_PROPERTY(animationOptions, brightness, legacyAnimationOptions.brightness); - SET_PROPERTY(animationOptions, staticColorIndex, legacyAnimationOptions.staticColorIndex); - SET_PROPERTY(animationOptions, buttonColorIndex, legacyAnimationOptions.buttonColorIndex); - SET_PROPERTY(animationOptions, chaseCycleTime, legacyAnimationOptions.chaseCycleTime); - SET_PROPERTY(animationOptions, rainbowCycleTime, legacyAnimationOptions.rainbowCycleTime); - SET_PROPERTY(animationOptions, themeIndex, legacyAnimationOptions.themeIndex); - SET_PROPERTY(animationOptions, hasCustomTheme, legacyAnimationOptions.hasCustomTheme); - SET_PROPERTY(animationOptions, customThemeUp, legacyAnimationOptions.customThemeUp); - SET_PROPERTY(animationOptions, customThemeDown, legacyAnimationOptions.customThemeDown); - SET_PROPERTY(animationOptions, customThemeLeft, legacyAnimationOptions.customThemeLeft); - SET_PROPERTY(animationOptions, customThemeRight, legacyAnimationOptions.customThemeRight); - SET_PROPERTY(animationOptions, customThemeB1, legacyAnimationOptions.customThemeB1); - SET_PROPERTY(animationOptions, customThemeB2, legacyAnimationOptions.customThemeB2); - SET_PROPERTY(animationOptions, customThemeB3, legacyAnimationOptions.customThemeB3); - SET_PROPERTY(animationOptions, customThemeB4, legacyAnimationOptions.customThemeB4); - SET_PROPERTY(animationOptions, customThemeL1, legacyAnimationOptions.customThemeL1); - SET_PROPERTY(animationOptions, customThemeR1, legacyAnimationOptions.customThemeR1); - SET_PROPERTY(animationOptions, customThemeL2, legacyAnimationOptions.customThemeL2); - SET_PROPERTY(animationOptions, customThemeR2, legacyAnimationOptions.customThemeR2); - SET_PROPERTY(animationOptions, customThemeS1, legacyAnimationOptions.customThemeS1); - SET_PROPERTY(animationOptions, customThemeS2, legacyAnimationOptions.customThemeS2); - SET_PROPERTY(animationOptions, customThemeL3, legacyAnimationOptions.customThemeL3); - SET_PROPERTY(animationOptions, customThemeR3, legacyAnimationOptions.customThemeR3); - SET_PROPERTY(animationOptions, customThemeA1, legacyAnimationOptions.customThemeA1); - SET_PROPERTY(animationOptions, customThemeA2, legacyAnimationOptions.customThemeA2); - SET_PROPERTY(animationOptions, customThemeUpPressed, legacyAnimationOptions.customThemeUpPressed); - SET_PROPERTY(animationOptions, customThemeDownPressed, legacyAnimationOptions.customThemeDownPressed); - SET_PROPERTY(animationOptions, customThemeLeftPressed, legacyAnimationOptions.customThemeLeftPressed); - SET_PROPERTY(animationOptions, customThemeRightPressed, legacyAnimationOptions.customThemeRightPressed); - SET_PROPERTY(animationOptions, customThemeB1Pressed, legacyAnimationOptions.customThemeB1Pressed); - SET_PROPERTY(animationOptions, customThemeB2Pressed, legacyAnimationOptions.customThemeB2Pressed); - SET_PROPERTY(animationOptions, customThemeB3Pressed, legacyAnimationOptions.customThemeB3Pressed); - SET_PROPERTY(animationOptions, customThemeB4Pressed, legacyAnimationOptions.customThemeB4Pressed); - SET_PROPERTY(animationOptions, customThemeL1Pressed, legacyAnimationOptions.customThemeL1Pressed); - SET_PROPERTY(animationOptions, customThemeR1Pressed, legacyAnimationOptions.customThemeR1Pressed); - SET_PROPERTY(animationOptions, customThemeL2Pressed, legacyAnimationOptions.customThemeL2Pressed); - SET_PROPERTY(animationOptions, customThemeR2Pressed, legacyAnimationOptions.customThemeR2Pressed); - SET_PROPERTY(animationOptions, customThemeS1Pressed, legacyAnimationOptions.customThemeS1Pressed); - SET_PROPERTY(animationOptions, customThemeS2Pressed, legacyAnimationOptions.customThemeS2Pressed); - SET_PROPERTY(animationOptions, customThemeL3Pressed, legacyAnimationOptions.customThemeL3Pressed); - SET_PROPERTY(animationOptions, customThemeR3Pressed, legacyAnimationOptions.customThemeR3Pressed); - SET_PROPERTY(animationOptions, customThemeA1Pressed, legacyAnimationOptions.customThemeA1Pressed); - SET_PROPERTY(animationOptions, customThemeA2Pressed, legacyAnimationOptions.customThemeA2Pressed); - } - - const ConfigLegacy::AddonOptions& legacyAddonOptions = *reinterpret_cast(EEPROM_ADDRESS_START + ADDON_STORAGE_INDEX); - if (legacyAddonOptions.checksum == computeChecksum(reinterpret_cast(&legacyAddonOptions), sizeof(ConfigLegacy::AddonOptions), offsetof(ConfigLegacy::AddonOptions, checksum))) - { - legacyConfigFound = true; - - config.has_addonOptions = true; - - AnalogOptions& analogOptions = config.addonOptions.analogOptions; - config.addonOptions.has_analogOptions = true; - SET_PROPERTY(analogOptions, enabled, legacyAddonOptions.AnalogInputEnabled); - SET_PROPERTY(analogOptions, analogAdc1PinX, bytePinToIntPin(legacyAddonOptions.analogAdcPinX)); - SET_PROPERTY(analogOptions, analogAdc1PinY, bytePinToIntPin(legacyAddonOptions.analogAdcPinY)); - - BootselButtonOptions& bootselButtonOptions = config.addonOptions.bootselButtonOptions; - config.addonOptions.has_bootselButtonOptions = true; - SET_PROPERTY(bootselButtonOptions, enabled, legacyAddonOptions.BootselButtonAddonEnabled); - SET_PROPERTY(bootselButtonOptions, buttonMap, legacyAddonOptions.bootselButtonMap); - - BuzzerOptions& buzzerOptions = config.addonOptions.buzzerOptions; - config.addonOptions.has_buzzerOptions = true; - SET_PROPERTY(buzzerOptions, enabled, legacyAddonOptions.BuzzerSpeakerAddonEnabled); - SET_PROPERTY(buzzerOptions, pin, bytePinToIntPin(legacyAddonOptions.buzzerPin)); - SET_PROPERTY(buzzerOptions, volume, legacyAddonOptions.buzzerVolume); - - DualDirectionalOptions& dualDirectionalOptions = config.addonOptions.dualDirectionalOptions; - config.addonOptions.has_dualDirectionalOptions = true; - SET_PROPERTY(dualDirectionalOptions, enabled, legacyAddonOptions.DualDirectionalInputEnabled); - SET_PROPERTY(dualDirectionalOptions, deprecatedUpPin, bytePinToIntPin(legacyAddonOptions.pinDualDirUp)); - SET_PROPERTY(dualDirectionalOptions, deprecatedDownPin, bytePinToIntPin(legacyAddonOptions.pinDualDirDown)); - SET_PROPERTY(dualDirectionalOptions, deprecatedLeftPin, bytePinToIntPin(legacyAddonOptions.pinDualDirLeft)); - SET_PROPERTY(dualDirectionalOptions, deprecatedRightPin, bytePinToIntPin(legacyAddonOptions.pinDualDirRight)); - if (isValidDpadMode(legacyAddonOptions.dualDirDpadMode)) - { - SET_PROPERTY(dualDirectionalOptions, dpadMode, static_cast(legacyAddonOptions.dualDirDpadMode)); - } - SET_PROPERTY(dualDirectionalOptions, combineMode, - static_cast(legacyAddonOptions.dualDirCombineMode)); - - ExtraButtonOptions& extraButtonOptions = config.addonOptions.deprecatedExtraButtonOptions; - config.addonOptions.has_deprecatedExtraButtonOptions = true; - SET_PROPERTY(extraButtonOptions, enabled, legacyAddonOptions.ExtraButtonAddonEnabled); - SET_PROPERTY(extraButtonOptions, pin, bytePinToIntPin(legacyAddonOptions.extraButtonPin)); - SET_PROPERTY(extraButtonOptions, buttonMap, legacyAddonOptions.extraButtonMap); - - AnalogADS1219Options& analogADS1219Options = config.addonOptions.analogADS1219Options; - config.addonOptions.has_analogADS1219Options = true; - SET_PROPERTY(analogADS1219Options, enabled, legacyAddonOptions.I2CAnalog1219InputEnabled); - SET_PROPERTY(analogADS1219Options, deprecatedI2cBlock, legacyAddonOptions.i2cAnalog1219Block); - SET_PROPERTY(analogADS1219Options, deprecatedI2cSDAPin, bytePinToIntPin(legacyAddonOptions.i2cAnalog1219SDAPin)); - SET_PROPERTY(analogADS1219Options, deprecatedI2cSCLPin, bytePinToIntPin(legacyAddonOptions.i2cAnalog1219SCLPin)); - SET_PROPERTY(analogADS1219Options, deprecatedI2cAddress, legacyAddonOptions.i2cAnalog1219Address); - SET_PROPERTY(analogADS1219Options, deprecatedI2cSpeed, legacyAddonOptions.i2cAnalog1219Speed); - - PlayerNumberOptions& playerNumberOptions = config.addonOptions.playerNumberOptions; - config.addonOptions.has_playerNumberOptions = true; - SET_PROPERTY(playerNumberOptions, enabled, legacyAddonOptions.PlayerNumAddonEnabled); - SET_PROPERTY(playerNumberOptions, number, legacyAddonOptions.playerNumber); - - ReverseOptions& reverseOptions = config.addonOptions.reverseOptions; - config.addonOptions.has_reverseOptions = true; - SET_PROPERTY(reverseOptions, enabled, legacyAddonOptions.ReverseInputEnabled); - SET_PROPERTY(reverseOptions, buttonPin, bytePinToIntPin(legacyAddonOptions.pinButtonReverse)); - SET_PROPERTY(reverseOptions, ledPin, bytePinToIntPin(legacyAddonOptions.pinReverseLED)); - SET_PROPERTY(reverseOptions, actionUp, legacyAddonOptions.reverseActionUp); - SET_PROPERTY(reverseOptions, actionDown, legacyAddonOptions.reverseActionDown); - SET_PROPERTY(reverseOptions, actionLeft, legacyAddonOptions.reverseActionLeft); - SET_PROPERTY(reverseOptions, actionRight, legacyAddonOptions.reverseActionRight); - - SOCDSliderOptions& socdSliderOptions = config.addonOptions.socdSliderOptions; - config.addonOptions.has_socdSliderOptions = true; - SET_PROPERTY(socdSliderOptions, enabled, legacyAddonOptions.SliderSOCDInputEnabled); - SET_PROPERTY(socdSliderOptions, deprecatedPinOne, bytePinToIntPin(legacyAddonOptions.pinSliderSOCDOne)); - SET_PROPERTY(socdSliderOptions, deprecatedPinTwo, bytePinToIntPin(legacyAddonOptions.pinSliderSOCDTwo)); - if (isValidSOCDMode(legacyAddonOptions.sliderSOCDModeDefault)) - { - SET_PROPERTY(socdSliderOptions, modeDefault, static_cast(legacyAddonOptions.sliderSOCDModeDefault)); - } - if (isValidSOCDMode(legacyAddonOptions.sliderSOCDModeOne)) - { - SET_PROPERTY(socdSliderOptions, deprecatedModeOne, static_cast(legacyAddonOptions.sliderSOCDModeOne)); - } - if (isValidSOCDMode(legacyAddonOptions.sliderSOCDModeTwo)) - { - SET_PROPERTY(socdSliderOptions, deprecatedModeTwo, static_cast(legacyAddonOptions.sliderSOCDModeTwo)); - } - - OnBoardLedOptions& onBoardLedOptions = config.addonOptions.onBoardLedOptions; - config.addonOptions.has_onBoardLedOptions = true; - SET_PROPERTY(onBoardLedOptions, enabled, legacyAddonOptions.BoardLedAddonEnabled); - if (isValidOnBoardLedMode(legacyAddonOptions.onBoardLedMode)) - { - SET_PROPERTY(onBoardLedOptions, mode, static_cast(legacyAddonOptions.onBoardLedMode)); - } - - TurboOptions& turboOptions = config.addonOptions.turboOptions; - config.addonOptions.has_turboOptions = true; - SET_PROPERTY(turboOptions, enabled, legacyAddonOptions.TurboInputEnabled); - SET_PROPERTY(turboOptions, deprecatedButtonPin, bytePinToIntPin(legacyAddonOptions.pinButtonTurbo)); - SET_PROPERTY(turboOptions, ledPin, bytePinToIntPin(legacyAddonOptions.pinTurboLED)); - SET_PROPERTY(turboOptions, shotCount, legacyAddonOptions.turboShotCount); - SET_PROPERTY(turboOptions, shmupDialPin, bytePinToIntPin(legacyAddonOptions.pinShmupDial)); - SET_PROPERTY(turboOptions, shmupModeEnabled, legacyAddonOptions.shmupMode); - SET_PROPERTY(turboOptions, shmupAlwaysOn1, legacyAddonOptions.shmupAlwaysOn1); - SET_PROPERTY(turboOptions, shmupAlwaysOn2, legacyAddonOptions.shmupAlwaysOn2); - SET_PROPERTY(turboOptions, shmupAlwaysOn3, legacyAddonOptions.shmupAlwaysOn3); - SET_PROPERTY(turboOptions, shmupAlwaysOn4, legacyAddonOptions.shmupAlwaysOn4); - SET_PROPERTY(turboOptions, shmupBtn1Pin, bytePinToIntPin(legacyAddonOptions.pinShmupBtn1)); - SET_PROPERTY(turboOptions, shmupBtn2Pin, bytePinToIntPin(legacyAddonOptions.pinShmupBtn2)); - SET_PROPERTY(turboOptions, shmupBtn3Pin, bytePinToIntPin(legacyAddonOptions.pinShmupBtn3)); - SET_PROPERTY(turboOptions, shmupBtn4Pin, bytePinToIntPin(legacyAddonOptions.pinShmupBtn4)); - SET_PROPERTY(turboOptions, shmupBtnMask1, legacyAddonOptions.shmupBtnMask1); - SET_PROPERTY(turboOptions, shmupBtnMask2, legacyAddonOptions.shmupBtnMask2); - SET_PROPERTY(turboOptions, shmupBtnMask3, legacyAddonOptions.shmupBtnMask3); - SET_PROPERTY(turboOptions, shmupBtnMask4, legacyAddonOptions.shmupBtnMask4); - if (legacyAddonOptions.shmupMixMode == 0 || legacyAddonOptions.shmupMixMode == 1) - { - SET_PROPERTY(turboOptions, shmupMixMode, static_cast(legacyAddonOptions.shmupMixMode)); - } - - WiiOptions& wiiOptions = config.addonOptions.wiiOptions; - config.addonOptions.has_wiiOptions = true; - SET_PROPERTY(wiiOptions, enabled, legacyAddonOptions.WiiExtensionAddonEnabled); - SET_PROPERTY(wiiOptions, deprecatedI2cBlock, legacyAddonOptions.wiiExtensionBlock); - SET_PROPERTY(wiiOptions, deprecatedI2cSDAPin, bytePinToIntPin(legacyAddonOptions.wiiExtensionSDAPin)); - SET_PROPERTY(wiiOptions, deprecatedI2cSCLPin, bytePinToIntPin(legacyAddonOptions.wiiExtensionSCLPin)); - SET_PROPERTY(wiiOptions, deprecatedI2cSpeed, legacyAddonOptions.wiiExtensionSpeed); - - PS4Options& ps4Options = config.addonOptions.ps4Options; - config.addonOptions.has_ps4Options = true; - SET_PROPERTY(ps4Options, enabled, legacyAddonOptions.PS4ModeAddonEnabled); - } - - const ConfigLegacy::PS4Options& legacyPS4Options = *reinterpret_cast(EEPROM_ADDRESS_START + PS4_STORAGE_INDEX); - if (legacyPS4Options.checksum == NOCHECKSUM_MAGIC) - { - legacyConfigFound = true; - - config.has_addonOptions = true; - - PS4Options& ps4Options = config.addonOptions.ps4Options; - config.addonOptions.has_ps4Options = true; - SET_PROPERTY_BYTES(ps4Options, serial, legacyPS4Options.serial); - SET_PROPERTY_BYTES(ps4Options, signature, legacyPS4Options.signature); - SET_PROPERTY_BYTES(ps4Options, rsaN, legacyPS4Options.rsa_n); - SET_PROPERTY_BYTES(ps4Options, rsaE, legacyPS4Options.rsa_e); - SET_PROPERTY_BYTES(ps4Options, rsaD, legacyPS4Options.rsa_d); - SET_PROPERTY_BYTES(ps4Options, rsaP, legacyPS4Options.rsa_p); - SET_PROPERTY_BYTES(ps4Options, rsaQ, legacyPS4Options.rsa_q); - SET_PROPERTY_BYTES(ps4Options, rsaDP, legacyPS4Options.rsa_dp); - SET_PROPERTY_BYTES(ps4Options, rsaDQ, legacyPS4Options.rsa_dq); - SET_PROPERTY_BYTES(ps4Options, rsaQP, legacyPS4Options.rsa_qp); - SET_PROPERTY_BYTES(ps4Options, rsaRN, legacyPS4Options.rsa_rn); - } - - const ConfigLegacy::SplashImage& legacySplashImage = *reinterpret_cast(EEPROM_ADDRESS_START + SPLASH_IMAGE_STORAGE_INDEX); - if (legacySplashImage.checksum == computeChecksum(reinterpret_cast(&legacySplashImage), sizeof(ConfigLegacy::SplashImage), offsetof(ConfigLegacy::SplashImage, checksum))) - { - legacyConfigFound = true; - - DisplayOptions& displayOptions = config.displayOptions; - config.has_displayOptions = true; - SET_PROPERTY_BYTES(displayOptions, splashImage, legacySplashImage.data); - } - - return legacyConfigFound; -} From 8b978db47dce4fee7794f399c1b3271e6858ea45 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 6 Jan 2024 17:24:13 -0600 Subject: [PATCH 03/14] support loading the board config if the user config is not present this also adds a sanity check for the now-expanded size of the storage sections in the flash --- src/config_utils.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 052069270..3470b0463 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -48,6 +48,8 @@ #include "pico/platform.h" +#define BOARD_CONFIG_EEPROM_ADDRESS_START EEPROM_ADDRESS_START - EEPROM_SIZE_BYTES + // ----------------------------------------------------- // Default values // ----------------------------------------------------- @@ -1502,12 +1504,12 @@ static const uint32_t FOOTER_MAGIC = 0xd2f1e365; // Verify that the maximum size of the serialized Config object fits into the allocated flash block #if defined(Config_size) - static_assert(Config_size + sizeof(ConfigFooter) <= EEPROM_SIZE_BYTES, "Maximum size of Config exceeds the maximum size allocated for FlashPROM"); + static_assert(Config_size + sizeof(ConfigFooter) <= EEPROM_SIZE_BYTES * 2, "Maximum size of Config exceeds the maximum size allocated for FlashPROM"); #else #error "Maximum size of Config cannot be determined statically, make sure that you do not use any dynamically sized arrays or strings" #endif -static bool loadConfigInner(Config& config) +static bool loadUserConfig(Config& config) { config = Config Config_init_zero; @@ -1539,19 +1541,44 @@ static bool loadConfigInner(Config& config) return pb_decode(&inputStream, Config_fields, &config); } -static bool loadBoardDefault(Config& config) +static bool loadBoardConfig(Config& config) { - // TODO --- read from a new area of flash, which is presumed to have been populated - // by gp2040ce-binary-tools with a board config - return false; + config = Config Config_init_zero; + + const uint8_t* flashEnd = reinterpret_cast(BOARD_CONFIG_EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES; + const ConfigFooter& footer = *reinterpret_cast(flashEnd - sizeof(ConfigFooter)); + + // Check for presence of magic value + if (footer.magic != FOOTER_MAGIC) + { + return false; + } + + // Check if dataSize exceeds the reserved space + if (footer.dataSize + sizeof(ConfigFooter) > EEPROM_SIZE_BYTES) + { + return false; + } + + const uint8_t* dataPtr = flashEnd - sizeof(ConfigFooter) - footer.dataSize; + + // Verify CRC32 hash + if (CRC32::calculate(dataPtr, footer.dataSize) != footer.dataCrc) + { + return false; + } + + // We are now sufficiently confident that the data is valid so we run the deserialization + pb_istream_t inputStream = pb_istream_from_buffer(dataPtr, footer.dataSize); + return pb_decode(&inputStream, Config_fields, &config); } void ConfigUtils::load(Config& config) { // first try to load from the user config, then from the read-only board config, // and fall back to defaults - if (!loadConfigInner(config)) { - if (!loadBoardDefault(config)) { + if (!loadUserConfig(config)) { + if (!loadBoardConfig(config)) { config = Config Config_init_default; } } From b1db8e27f4287dfcf16494d9c98e2e17f366f8fb Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Tue, 9 Jan 2024 11:26:09 -0600 Subject: [PATCH 04/14] remove the build_info for compile-time pin defines this is no longer relevant in the protobuf-as-board-config world --- headers/build_info.h | 5 ----- src/gp2040.cpp | 1 - 2 files changed, 6 deletions(-) delete mode 100644 headers/build_info.h diff --git a/headers/build_info.h b/headers/build_info.h deleted file mode 100644 index 23f075398..000000000 --- a/headers/build_info.h +++ /dev/null @@ -1,5 +0,0 @@ -/* generate build information (such as stuff auto-included in the .uf2) */ -#include "pico/binary_info.h" -#include "pico/binary_info/code.h" - -#include "BoardConfig.h" diff --git a/src/gp2040.cpp b/src/gp2040.cpp index 13c09a35f..823525f22 100644 --- a/src/gp2040.cpp +++ b/src/gp2040.cpp @@ -4,7 +4,6 @@ #include "system.h" #include "enums.pb.h" -#include "build_info.h" #include "configmanager.h" // Global Managers #include "peripheralmanager.h" #include "storagemanager.h" From d4372dfee13a1472941f8719bcbaf18aa2d15155 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 7 Apr 2024 21:12:16 -0500 Subject: [PATCH 05/14] break up the board/user config loaders and splice them together this lets a board config patched into the binary to specify values that are not in the user config, and have them be applied to the user config. essentially, on board boot, we now: 1. pb_decode in loadBoardConfig 2. this loads the defaults 3. this then populates the structure with values from the board config 4. pb_decode_ex in loadUserConfig 5. this does NOT load the defaults 6. this then splices values from the user config into the structure the BoardConfig.h files and initUnset... remain, but this will allow us to move off of that as we start getting tooling in place for the protobuf board configs --- src/config_utils.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 3470b0463..756ac5ef6 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -1509,10 +1509,11 @@ static const uint32_t FOOTER_MAGIC = 0xd2f1e365; #error "Maximum size of Config cannot be determined statically, make sure that you do not use any dynamically sized arrays or strings" #endif +/** + * @brief load user config, with no defaults in order to overlay on top of the board config + */ static bool loadUserConfig(Config& config) { - config = Config Config_init_zero; - const uint8_t* flashEnd = reinterpret_cast(EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES; const ConfigFooter& footer = *reinterpret_cast(flashEnd - sizeof(ConfigFooter)); @@ -1538,13 +1539,16 @@ static bool loadUserConfig(Config& config) // We are now sufficiently confident that the data is valid so we run the deserialization pb_istream_t inputStream = pb_istream_from_buffer(dataPtr, footer.dataSize); - return pb_decode(&inputStream, Config_fields, &config); + // PB_DECODE_NOINIT: "Do not initialize structure before decoding. This can be used to combine + // multiple messages, or if you have already initialized the message structure yourself." + return pb_decode_ex(&inputStream, Config_fields, &config, PB_DECODE_NOINIT); } +/** + * @brief - load board config, with nanopb loading the defaults + */ static bool loadBoardConfig(Config& config) { - config = Config Config_init_zero; - const uint8_t* flashEnd = reinterpret_cast(BOARD_CONFIG_EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES; const ConfigFooter& footer = *reinterpret_cast(flashEnd - sizeof(ConfigFooter)); @@ -1570,18 +1574,14 @@ static bool loadBoardConfig(Config& config) // We are now sufficiently confident that the data is valid so we run the deserialization pb_istream_t inputStream = pb_istream_from_buffer(dataPtr, footer.dataSize); + // reminder: this initializes the structure with defaults return pb_decode(&inputStream, Config_fields, &config); } void ConfigUtils::load(Config& config) { - // first try to load from the user config, then from the read-only board config, - // and fall back to defaults - if (!loadUserConfig(config)) { - if (!loadBoardConfig(config)) { - config = Config Config_init_default; - } - } + loadBoardConfig(config); + loadUserConfig(config); // run migrations if (!config.migrations.hotkeysMigrated) From 624a77a4b789c1dac20901b8f9cd20fd6d572a00 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 7 Apr 2024 23:52:12 -0500 Subject: [PATCH 06/14] DRY the config loader, and always start with initialized config it was possible to never call pb_decode to initialize the config with defaults (e.g. if both the board and user configs were empty), this avoids that, in which case the calls are essentially identical --- src/config_utils.cpp | 47 +++++++++++++------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 756ac5ef6..faee8fd2b 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -1509,12 +1509,9 @@ static const uint32_t FOOTER_MAGIC = 0xd2f1e365; #error "Maximum size of Config cannot be determined statically, make sure that you do not use any dynamically sized arrays or strings" #endif -/** - * @brief load user config, with no defaults in order to overlay on top of the board config - */ -static bool loadUserConfig(Config& config) +static bool loadConfig(Config& config, uint32_t start) { - const uint8_t* flashEnd = reinterpret_cast(EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES; + const uint8_t* flashEnd = reinterpret_cast(start) + EEPROM_SIZE_BYTES; const ConfigFooter& footer = *reinterpret_cast(flashEnd - sizeof(ConfigFooter)); // Check for presence of magic value @@ -1545,41 +1542,25 @@ static bool loadUserConfig(Config& config) } /** - * @brief - load board config, with nanopb loading the defaults + * @brief load user config (user settings and overrides) */ -static bool loadBoardConfig(Config& config) +static bool loadUserConfig(Config& config) { - const uint8_t* flashEnd = reinterpret_cast(BOARD_CONFIG_EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES; - const ConfigFooter& footer = *reinterpret_cast(flashEnd - sizeof(ConfigFooter)); - - // Check for presence of magic value - if (footer.magic != FOOTER_MAGIC) - { - return false; - } - - // Check if dataSize exceeds the reserved space - if (footer.dataSize + sizeof(ConfigFooter) > EEPROM_SIZE_BYTES) - { - return false; - } - - const uint8_t* dataPtr = flashEnd - sizeof(ConfigFooter) - footer.dataSize; - - // Verify CRC32 hash - if (CRC32::calculate(dataPtr, footer.dataSize) != footer.dataCrc) - { - return false; - } + return loadConfig(config, EEPROM_ADDRESS_START); +} - // We are now sufficiently confident that the data is valid so we run the deserialization - pb_istream_t inputStream = pb_istream_from_buffer(dataPtr, footer.dataSize); - // reminder: this initializes the structure with defaults - return pb_decode(&inputStream, Config_fields, &config); +/** + * @brief - load board config (customizations specific to a board/device model) + */ +static bool loadBoardConfig(Config& config) +{ + return loadConfig(config, BOARD_CONFIG_EEPROM_ADDRESS_START); } void ConfigUtils::load(Config& config) { + // load the config with defaults, and then overlay board and user configs on top + config = Config Config_init_default; loadBoardConfig(config); loadUserConfig(config); From 186ba99245a9dbc99fc540ce3fd1d8df2124150a Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 12 Apr 2024 20:44:39 -0500 Subject: [PATCH 07/14] start replacing some initUnset... with proto defaults I think this is going to be a long road, but this is the kind of thing that's possible even without a board config in place --- proto/config.proto | 4 ++-- src/config_utils.cpp | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/proto/config.proto b/proto/config.proto index b081f01ce..d3051e97f 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -6,8 +6,8 @@ import "enums.proto"; message GamepadOptions { optional InputMode inputMode = 1; - optional DpadMode dpadMode = 2; - optional SOCDMode socdMode = 3; + optional DpadMode dpadMode = 2 [default = DPAD_MODE_DIGITAL]; + optional SOCDMode socdMode = 3 [default = SOCD_MODE_NEUTRAL]; optional bool invertXAxis = 4; optional bool invertYAxis = 5; optional bool switchTpShareForDs4 = 6; diff --git a/src/config_utils.cpp b/src/config_utils.cpp index faee8fd2b..f67086506 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -107,12 +107,6 @@ #ifndef DEFAULT_INPUT_MODE_R2 #define DEFAULT_INPUT_MODE_R2 INPUT_MODE_KEYBOARD #endif -#ifndef DEFAULT_DPAD_MODE - #define DEFAULT_DPAD_MODE DPAD_MODE_DIGITAL -#endif -#ifndef DEFAULT_SOCD_MODE - #define DEFAULT_SOCD_MODE SOCD_MODE_NEUTRAL -#endif #ifndef DEFAULT_FORCED_SETUP_MODE #define DEFAULT_FORCED_SETUP_MODE FORCED_SETUP_MODE_OFF #endif @@ -258,8 +252,6 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // gamepadOptions INIT_UNSET_PROPERTY(config.gamepadOptions, inputMode, DEFAULT_INPUT_MODE); - INIT_UNSET_PROPERTY(config.gamepadOptions, dpadMode, DEFAULT_DPAD_MODE); - INIT_UNSET_PROPERTY(config.gamepadOptions, socdMode, DEFAULT_SOCD_MODE); INIT_UNSET_PROPERTY(config.gamepadOptions, invertXAxis, false); INIT_UNSET_PROPERTY(config.gamepadOptions, switchTpShareForDs4, false); INIT_UNSET_PROPERTY(config.gamepadOptions, lockHotkeys, DEFAULT_LOCK_HOTKEYS); From 026850db628234c534a470e3c251552fb25f89fb Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 13 Apr 2024 23:49:32 -0500 Subject: [PATCH 08/14] add a post-build command to patch board config into .bin/.uf2 this starts the replacement of BoardConfig.h + migration code with shipped protobuf configs. this should help cleanup some code, and one day will hopefully replace the need for per-board builds entirely, greatly speeding up the GitHub build/creation of board binaries --- CMakeLists.txt | 3 ++ compile_proto.cmake | 1 + configs/ARCController/board-config.json | 3 ++ configs/BentoBox/board-config.json | 3 ++ configs/Blank/board-config.json | 3 ++ configs/FightboardV3/board-config.json | 3 ++ .../FightboardV3Mirrored/board-config.json | 3 ++ configs/FlatboxRev4/board-config.json | 3 ++ configs/FlatboxRev5/board-config.json | 3 ++ configs/FlatboxRev5RGB/board-config.json | 3 ++ configs/FlatboxRev5Southpaw/board-config.json | 3 ++ configs/Granola/board-config.json | 3 ++ configs/Haute42COSMOX/board-config.json | 3 ++ configs/KB2040/board-config.json | 3 ++ configs/KeyboardConverter/board-config.json | 3 ++ configs/Liatris/board-config.json | 3 ++ configs/MavercadeRev1/board-config.json | 3 ++ configs/MavercadeRev2/board-config.json | 3 ++ configs/OpenCore0/board-config.json | 3 ++ configs/OpenCore0WASD/board-config.json | 3 ++ configs/Pico/board-config.json | 3 ++ configs/PicoAnn/board-config.json | 3 ++ configs/PicoFightingBoard/board-config.json | 3 ++ configs/PicoW/board-config.json | 3 ++ .../board-config.json | 3 ++ .../board-config.json | 3 ++ .../RP2040MiniBreakoutBoard/board-config.json | 3 ++ configs/RanaTadpole/board-config.json | 3 ++ configs/ReflexCtrlGenesis6/board-config.json | 3 ++ configs/ReflexCtrlNES/board-config.json | 3 ++ configs/ReflexCtrlSNES/board-config.json | 3 ++ configs/ReflexCtrlSaturn/board-config.json | 3 ++ configs/ReflexCtrlVB/board-config.json | 3 ++ configs/ReflexEncodeV1.2/board-config.json | 3 ++ configs/ReflexEncodeV2.0/board-config.json | 3 ++ configs/SGFDevices/board-config.json | 3 ++ configs/SparkFunProMicro/board-config.json | 3 ++ configs/Stress/board-config.json | 3 ++ configs/WaveshareZero/board-config.json | 3 ++ configs/ZeroRhythm/board-config.json | 3 ++ configs/ergoSHIFTRev2/board-config.json | 3 ++ patch_board_config.cmake | 29 +++++++++++++++++++ 42 files changed, 150 insertions(+) create mode 100644 configs/ARCController/board-config.json create mode 100644 configs/BentoBox/board-config.json create mode 100644 configs/Blank/board-config.json create mode 100644 configs/FightboardV3/board-config.json create mode 100644 configs/FightboardV3Mirrored/board-config.json create mode 100644 configs/FlatboxRev4/board-config.json create mode 100644 configs/FlatboxRev5/board-config.json create mode 100644 configs/FlatboxRev5RGB/board-config.json create mode 100644 configs/FlatboxRev5Southpaw/board-config.json create mode 100644 configs/Granola/board-config.json create mode 100644 configs/Haute42COSMOX/board-config.json create mode 100644 configs/KB2040/board-config.json create mode 100644 configs/KeyboardConverter/board-config.json create mode 100644 configs/Liatris/board-config.json create mode 100644 configs/MavercadeRev1/board-config.json create mode 100644 configs/MavercadeRev2/board-config.json create mode 100644 configs/OpenCore0/board-config.json create mode 100644 configs/OpenCore0WASD/board-config.json create mode 100644 configs/Pico/board-config.json create mode 100644 configs/PicoAnn/board-config.json create mode 100644 configs/PicoFightingBoard/board-config.json create mode 100644 configs/PicoW/board-config.json create mode 100644 configs/RP2040AdvancedBreakoutBoard/board-config.json create mode 100644 configs/RP2040AdvancedBreakoutBoardUSBPassthrough/board-config.json create mode 100644 configs/RP2040MiniBreakoutBoard/board-config.json create mode 100644 configs/RanaTadpole/board-config.json create mode 100644 configs/ReflexCtrlGenesis6/board-config.json create mode 100644 configs/ReflexCtrlNES/board-config.json create mode 100644 configs/ReflexCtrlSNES/board-config.json create mode 100644 configs/ReflexCtrlSaturn/board-config.json create mode 100644 configs/ReflexCtrlVB/board-config.json create mode 100644 configs/ReflexEncodeV1.2/board-config.json create mode 100644 configs/ReflexEncodeV2.0/board-config.json create mode 100644 configs/SGFDevices/board-config.json create mode 100644 configs/SparkFunProMicro/board-config.json create mode 100644 configs/Stress/board-config.json create mode 100644 configs/WaveshareZero/board-config.json create mode 100644 configs/ZeroRhythm/board-config.json create mode 100644 configs/ergoSHIFTRev2/board-config.json create mode 100644 patch_board_config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bde018a6f..ce668e198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,9 @@ add_compile_options(-Wall include(compile_proto.cmake) compile_proto() +include(patch_board_config.cmake) +patch_board_config() + #pull in tinyUSB set(PICO_TINYUSB_PATH "${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb") diff --git a/compile_proto.cmake b/compile_proto.cmake index 89966923f..2a35563e6 100644 --- a/compile_proto.cmake +++ b/compile_proto.cmake @@ -13,6 +13,7 @@ function (compile_proto) DEPENDS ${CMAKE_SOURCE_DIR}/lib/nanopb/extra/requirements.txt COMMAND ${Python3_EXECUTABLE} -m venv ${VENV} COMMAND ${VENV_BIN_DIR}/pip --disable-pip-version-check install -r ${CMAKE_SOURCE_DIR}/lib/nanopb/extra/requirements.txt + COMMAND ${VENV_BIN_DIR}/pip --disable-pip-version-check install gp2040ce-binary-tools COMMAND ${VENV_BIN_DIR}/pip freeze > ${VENV_FILE} OUTPUT ${VENV_FILE} COMMENT "Setting up Python Virtual Environment" diff --git a/configs/ARCController/board-config.json b/configs/ARCController/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ARCController/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/BentoBox/board-config.json b/configs/BentoBox/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/BentoBox/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/Blank/board-config.json b/configs/Blank/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/Blank/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/FightboardV3/board-config.json b/configs/FightboardV3/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FightboardV3/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/FightboardV3Mirrored/board-config.json b/configs/FightboardV3Mirrored/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FightboardV3Mirrored/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/FlatboxRev4/board-config.json b/configs/FlatboxRev4/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FlatboxRev4/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/FlatboxRev5/board-config.json b/configs/FlatboxRev5/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FlatboxRev5/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/FlatboxRev5RGB/board-config.json b/configs/FlatboxRev5RGB/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FlatboxRev5RGB/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/FlatboxRev5Southpaw/board-config.json b/configs/FlatboxRev5Southpaw/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FlatboxRev5Southpaw/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/Granola/board-config.json b/configs/Granola/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/Granola/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/Haute42COSMOX/board-config.json b/configs/Haute42COSMOX/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/Haute42COSMOX/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/KB2040/board-config.json b/configs/KB2040/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/KB2040/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/KeyboardConverter/board-config.json b/configs/KeyboardConverter/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/KeyboardConverter/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/Liatris/board-config.json b/configs/Liatris/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/Liatris/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/MavercadeRev1/board-config.json b/configs/MavercadeRev1/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/MavercadeRev1/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/MavercadeRev2/board-config.json b/configs/MavercadeRev2/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/MavercadeRev2/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/OpenCore0/board-config.json b/configs/OpenCore0/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/OpenCore0/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/OpenCore0WASD/board-config.json b/configs/OpenCore0WASD/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/OpenCore0WASD/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/Pico/board-config.json b/configs/Pico/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/Pico/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/PicoAnn/board-config.json b/configs/PicoAnn/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/PicoAnn/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/PicoFightingBoard/board-config.json b/configs/PicoFightingBoard/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/PicoFightingBoard/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/PicoW/board-config.json b/configs/PicoW/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/PicoW/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/RP2040AdvancedBreakoutBoard/board-config.json b/configs/RP2040AdvancedBreakoutBoard/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/RP2040AdvancedBreakoutBoard/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/RP2040AdvancedBreakoutBoardUSBPassthrough/board-config.json b/configs/RP2040AdvancedBreakoutBoardUSBPassthrough/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/RP2040AdvancedBreakoutBoardUSBPassthrough/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/RP2040MiniBreakoutBoard/board-config.json b/configs/RP2040MiniBreakoutBoard/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/RP2040MiniBreakoutBoard/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/RanaTadpole/board-config.json b/configs/RanaTadpole/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/RanaTadpole/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexCtrlGenesis6/board-config.json b/configs/ReflexCtrlGenesis6/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexCtrlGenesis6/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexCtrlNES/board-config.json b/configs/ReflexCtrlNES/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexCtrlNES/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexCtrlSNES/board-config.json b/configs/ReflexCtrlSNES/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexCtrlSNES/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexCtrlSaturn/board-config.json b/configs/ReflexCtrlSaturn/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexCtrlSaturn/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexCtrlVB/board-config.json b/configs/ReflexCtrlVB/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexCtrlVB/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexEncodeV1.2/board-config.json b/configs/ReflexEncodeV1.2/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexEncodeV1.2/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ReflexEncodeV2.0/board-config.json b/configs/ReflexEncodeV2.0/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ReflexEncodeV2.0/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/SGFDevices/board-config.json b/configs/SGFDevices/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/SGFDevices/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/SparkFunProMicro/board-config.json b/configs/SparkFunProMicro/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/SparkFunProMicro/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/Stress/board-config.json b/configs/Stress/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/Stress/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/WaveshareZero/board-config.json b/configs/WaveshareZero/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/WaveshareZero/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ZeroRhythm/board-config.json b/configs/ZeroRhythm/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ZeroRhythm/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/ergoSHIFTRev2/board-config.json b/configs/ergoSHIFTRev2/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/ergoSHIFTRev2/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/patch_board_config.cmake b/patch_board_config.cmake new file mode 100644 index 000000000..d8bd68e57 --- /dev/null +++ b/patch_board_config.cmake @@ -0,0 +1,29 @@ +function (patch_board_config) + find_package(Python3 REQUIRED COMPONENTS Interpreter) + + set(VENV ${CMAKE_CURRENT_BINARY_DIR}/venv) + if(CMAKE_HOST_WIN32) + set(VENV_BIN_DIR ${VENV}/Scripts) + else() + set(VENV_BIN_DIR ${VENV}/bin) + endif() + + add_custom_target( + PatchBoardConfig ALL + DEPENDS ${PROJECT_NAME} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${VENV_BIN_DIR}/concatenate + -P ./proto + -P ./lib/nanopb/generator/proto + ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin + --json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json + --new-filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 + COMMAND ${VENV_BIN_DIR}/concatenate + -P ./proto + -P ./lib/nanopb/generator/proto + ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin + --json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json + --new-filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin + COMMENT "Patching binary with board config" + ) +endfunction() From d240ae8934a09b16b81601bd5cf9b6ca4cb4f18a Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 14 Apr 2024 20:39:14 -0500 Subject: [PATCH 09/14] remove some inits that just set the protobuf default --- src/config_utils.cpp | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/config_utils.cpp b/src/config_utils.cpp index f67086506..fb81bb1ab 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -475,42 +475,6 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) INIT_UNSET_PROPERTY(config.animationOptions, rainbowCycleTime, LEDS_RAINBOW_CYCLE_TIME); INIT_UNSET_PROPERTY(config.animationOptions, themeIndex, LEDS_THEME_INDEX); INIT_UNSET_PROPERTY(config.animationOptions, hasCustomTheme, false); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeUp, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeDown, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeLeft, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeRight, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB1, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB2, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB3, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB4, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeL1, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeR1, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeL2, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeR2, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeS1, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeS2, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeL3, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeR3, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeA1, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeA2, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeUpPressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeDownPressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeLeftPressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeRightPressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB1Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB2Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB3Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeB4Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeL1Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeR1Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeL2Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeR2Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeS1Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeS2Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeL3Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeR3Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeA1Pressed, 0); - INIT_UNSET_PROPERTY(config.animationOptions, customThemeA2Pressed, 0); INIT_UNSET_PROPERTY(config.animationOptions, buttonPressColorCooldownTimeInMs, LEDS_PRESS_COLOR_COOLDOWN_TIME); // addonOptions.bootselButtonOptions From 14319517bf1e7bbaf2d7df17d312132a6fb2b228 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 15 Apr 2024 10:28:17 -0500 Subject: [PATCH 10/14] only patch the UF2, and keep a backup of the old one also spit out the summary info just so people can see what happened happened --- patch_board_config.cmake | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/patch_board_config.cmake b/patch_board_config.cmake index d8bd68e57..499e2cd8a 100644 --- a/patch_board_config.cmake +++ b/patch_board_config.cmake @@ -17,13 +17,10 @@ function (patch_board_config) -P ./lib/nanopb/generator/proto ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin --json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json + --backup --new-filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 - COMMAND ${VENV_BIN_DIR}/concatenate - -P ./proto - -P ./lib/nanopb/generator/proto - ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin - --json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json - --new-filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin + COMMAND ${VENV_BIN_DIR}/summarize-gp2040ce + --filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 COMMENT "Patching binary with board config" ) endfunction() From a69389c0853ef566c00f596322a4db2a69ea14c0 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Tue, 21 May 2024 13:59:20 -0500 Subject: [PATCH 11/14] copy the .proto files into one location before running concatenate something about the protoc compiler (maybe just on Python 3.12?) doesn't like multiple -P path arguments, and until that's fixed, it's easier to just copy the files into one spot, which works fine --- patch_board_config.cmake | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/patch_board_config.cmake b/patch_board_config.cmake index 499e2cd8a..3960f5339 100644 --- a/patch_board_config.cmake +++ b/patch_board_config.cmake @@ -8,13 +8,20 @@ function (patch_board_config) set(VENV_BIN_DIR ${VENV}/bin) endif() + set(PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto) + add_custom_target( PatchBoardConfig ALL DEPENDS ${PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + # something in the protobuf compiler doesn't like the multiple paths, + # so we'll copy all the .proto files into one location + COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto ${PROTO_OUTPUT_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/proto/enums.proto ${PROTO_OUTPUT_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/proto/config.proto ${PROTO_OUTPUT_DIR} COMMAND ${VENV_BIN_DIR}/concatenate - -P ./proto - -P ./lib/nanopb/generator/proto + -P ${PROTO_OUTPUT_DIR} ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin --json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json --backup From 0a37f1a447b2b54b9191a5fbdd3b59e60b740bd4 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 26 Sep 2024 13:05:50 -0500 Subject: [PATCH 12/14] add more board-config.json placeholders for newer boards --- configs/FlatboxRev5USBPassthrough/board-config.json | 3 +++ configs/MiSTercadeV2/board-config.json | 3 +++ configs/OSUMGP-RP2040/board-config.json | 3 +++ configs/PXPGamepad/board-config.json | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 configs/FlatboxRev5USBPassthrough/board-config.json create mode 100644 configs/MiSTercadeV2/board-config.json create mode 100644 configs/OSUMGP-RP2040/board-config.json create mode 100644 configs/PXPGamepad/board-config.json diff --git a/configs/FlatboxRev5USBPassthrough/board-config.json b/configs/FlatboxRev5USBPassthrough/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/FlatboxRev5USBPassthrough/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/MiSTercadeV2/board-config.json b/configs/MiSTercadeV2/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/MiSTercadeV2/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/OSUMGP-RP2040/board-config.json b/configs/OSUMGP-RP2040/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/OSUMGP-RP2040/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} diff --git a/configs/PXPGamepad/board-config.json b/configs/PXPGamepad/board-config.json new file mode 100644 index 000000000..00bf892c9 --- /dev/null +++ b/configs/PXPGamepad/board-config.json @@ -0,0 +1,3 @@ +{ + "boardVersion": "v0.7.8" +} From 9e17785d8145de2de7b38a264ca18413e366cb1b Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 16 Dec 2024 12:40:34 -0600 Subject: [PATCH 13/14] add -P to summarize-gp2040ce invocation and fix a cmake idiom --- patch_board_config.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/patch_board_config.cmake b/patch_board_config.cmake index 3960f5339..463085598 100644 --- a/patch_board_config.cmake +++ b/patch_board_config.cmake @@ -22,12 +22,13 @@ function (patch_board_config) COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/proto/config.proto ${PROTO_OUTPUT_DIR} COMMAND ${VENV_BIN_DIR}/concatenate -P ${PROTO_OUTPUT_DIR} - ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.bin --json-board-config-filename ./configs/${GP2040_BOARDCONFIG}/board-config.json --backup - --new-filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 + --new-filename ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 COMMAND ${VENV_BIN_DIR}/summarize-gp2040ce - --filename ./build/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 + -P ${PROTO_OUTPUT_DIR} + --filename ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_${CMAKE_PROJECT_VERSION}_${GP2040_BOARDCONFIG}.uf2 COMMENT "Patching binary with board config" ) endfunction() From 852cd323db6cb1600e797a6425bbc4ac71e9e507 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Wed, 18 Dec 2024 09:21:21 -0600 Subject: [PATCH 14/14] compile .proto files with protoc so gp2040ce-binary-tools doesn't have to this hopefully gets around the weird bug with Windows stuff that seems to be caused by gRPC and/or dynamically compiling the files as part of gp2040ce-binary-tools invocations --- compile_proto.cmake | 24 ++++++++++++++++++++++++ patch_board_config.cmake | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/compile_proto.cmake b/compile_proto.cmake index 2a35563e6..77eeb67a6 100644 --- a/compile_proto.cmake +++ b/compile_proto.cmake @@ -20,6 +20,7 @@ function (compile_proto) ) set(NANOPB_GENERATOR ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/nanopb_generator.py) + set(PYTHON_GENERATOR ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/protoc) set(PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto) set(PROTO_OUTPUT_DIR ${PROTO_OUTPUT_DIR} PARENT_SCOPE) @@ -42,4 +43,27 @@ function (compile_proto) OUTPUT ${PROTO_OUTPUT_DIR}/config.pb.c ${PROTO_OUTPUT_DIR}/config.pb.h ${PROTO_OUTPUT_DIR}/enums.pb.c ${PROTO_OUTPUT_DIR}/enums.pb.h COMMENT "Compiling enums.proto and config.proto" ) + + add_custom_command( + DEPENDS ${VENV_FILE} ${PYTHON_GENERATOR} ${CMAKE_SOURCE_DIR}/proto/enums.proto ${CMAKE_SOURCE_DIR}/proto/config.proto ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUTPUT_DIR} + COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR} + --python_out ${PROTO_OUTPUT_DIR} + -I ${CMAKE_SOURCE_DIR}/proto + -I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto + ${CMAKE_SOURCE_DIR}/proto/enums.proto + COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR} + --python_out ${PROTO_OUTPUT_DIR} + -I ${CMAKE_SOURCE_DIR}/proto + -I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto + ${CMAKE_SOURCE_DIR}/proto/config.proto + COMMAND ${VENV_BIN_DIR}/python ${PYTHON_GENERATOR} + --python_out ${PROTO_OUTPUT_DIR} + -I ${CMAKE_SOURCE_DIR}/proto + -I ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto + ${CMAKE_SOURCE_DIR}/lib/nanopb/generator/proto/nanopb.proto + OUTPUT ${PROTO_OUTPUT_DIR}/config_pb2.py ${PROTO_OUTPUT_DIR}/enums_pb2.py ${PROTO_OUTPUT_DIR}/nanopb_pb2.py + COMMENT "Compiling config_pb2.py, enums_pb2.py, and nanopb_pb2.py Python modules" + ) endfunction() diff --git a/patch_board_config.cmake b/patch_board_config.cmake index 463085598..50a547ceb 100644 --- a/patch_board_config.cmake +++ b/patch_board_config.cmake @@ -12,7 +12,7 @@ function (patch_board_config) add_custom_target( PatchBoardConfig ALL - DEPENDS ${PROJECT_NAME} + DEPENDS ${PROJECT_NAME} ${PROTO_OUTPUT_DIR}/config_pb2.py ${PROTO_OUTPUT_DIR}/enums_pb2.py ${PROTO_OUTPUT_DIR}/nanopb_pb2.py WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} # something in the protobuf compiler doesn't like the multiple paths, # so we'll copy all the .proto files into one location