From 38eafc2a444cc5dea8cb225a29542c3a43e3b58b Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Wed, 27 Dec 2023 00:44:22 -0600 Subject: [PATCH] define a custom button combo to a GPIO pin this expands GpioMappingInfo to include dpad and button masks and uses those masks when setting up the button maps in Gamepad. this allows for a GPIO pin to trigger any arbitrary set of buttons --- proto/config.proto | 2 ++ proto/enums.proto | 1 + src/gamepad.cpp | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/proto/config.proto b/proto/config.proto index 34b4caac8..949396669 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -165,6 +165,8 @@ message PinMappings message GpioMappingInfo { optional GpioAction action = 1; + optional uint32 customDpadMask = 2; + optional uint32 customButtonMask = 3; } message GpioMappings diff --git a/proto/enums.proto b/proto/enums.proto index 1c4efbf35..3887d3169 100644 --- a/proto/enums.proto +++ b/proto/enums.proto @@ -169,6 +169,7 @@ enum GpioAction SUSTAIN_SOCD_MODE_SECOND_WIN = 29; SUSTAIN_SOCD_MODE_FIRST_WIN = 30; SUSTAIN_SOCD_MODE_BYPASS = 31; + CUSTOM_BUTTON_COMBO = 32; } enum GamepadHotkey diff --git a/src/gamepad.cpp b/src/gamepad.cpp index 5c2ef8107..3c977130e 100644 --- a/src/gamepad.cpp +++ b/src/gamepad.cpp @@ -247,6 +247,27 @@ void Gamepad::setup() mapButtonA2 = new GamepadButtonMapping(GAMEPAD_MASK_A2); mapButtonFn = new GamepadButtonMapping(AUX_MASK_FUNCTION); + const auto assignCustomMappingToMaps = [&](GpioMappingInfo mapInfo, Pin_t pin) -> void { + if (mapDpadUp->buttonMask & mapInfo.customDpadMask) mapDpadUp->pinMask |= 1 << pin; + if (mapDpadDown->buttonMask & mapInfo.customDpadMask) mapDpadDown->pinMask |= 1 << pin; + if (mapDpadLeft->buttonMask & mapInfo.customDpadMask) mapDpadLeft->pinMask |= 1 << pin; + if (mapDpadRight->buttonMask & mapInfo.customDpadMask) mapDpadRight->pinMask |= 1 << pin; + if (mapButtonB1->buttonMask & mapInfo.customButtonMask) mapButtonB1->pinMask |= 1 << pin; + if (mapButtonB2->buttonMask & mapInfo.customButtonMask) mapButtonB2->pinMask |= 1 << pin; + if (mapButtonB3->buttonMask & mapInfo.customButtonMask) mapButtonB3->pinMask |= 1 << pin; + if (mapButtonB4->buttonMask & mapInfo.customButtonMask) mapButtonB4->pinMask |= 1 << pin; + if (mapButtonL1->buttonMask & mapInfo.customButtonMask) mapButtonL1->pinMask |= 1 << pin; + if (mapButtonR1->buttonMask & mapInfo.customButtonMask) mapButtonR1->pinMask |= 1 << pin; + if (mapButtonL2->buttonMask & mapInfo.customButtonMask) mapButtonL2->pinMask |= 1 << pin; + if (mapButtonR2->buttonMask & mapInfo.customButtonMask) mapButtonR2->pinMask |= 1 << pin; + if (mapButtonS1->buttonMask & mapInfo.customButtonMask) mapButtonS1->pinMask |= 1 << pin; + if (mapButtonS2->buttonMask & mapInfo.customButtonMask) mapButtonS2->pinMask |= 1 << pin; + if (mapButtonL3->buttonMask & mapInfo.customButtonMask) mapButtonL3->pinMask |= 1 << pin; + if (mapButtonR3->buttonMask & mapInfo.customButtonMask) mapButtonR3->pinMask |= 1 << pin; + if (mapButtonA1->buttonMask & mapInfo.customButtonMask) mapButtonA1->pinMask |= 1 << pin; + if (mapButtonA2->buttonMask & mapInfo.customButtonMask) mapButtonA2->pinMask |= 1 << pin; + }; + for (Pin_t pin = 0; pin < (Pin_t)NUM_BANK0_GPIOS; pin++) { switch (pinMappings[pin].action) { @@ -269,6 +290,7 @@ void Gamepad::setup() case GpioAction::BUTTON_PRESS_A1: mapButtonA1->pinMask |= 1 << pin; break; case GpioAction::BUTTON_PRESS_A2: mapButtonA2->pinMask |= 1 << pin; break; case GpioAction::BUTTON_PRESS_FN: mapButtonFn->pinMask |= 1 << pin; break; + case GpioAction::CUSTOM_BUTTON_COMBO: assignCustomMappingToMaps(pinMappings[pin], pin); break; default: break; } }