Skip to content

Commit

Permalink
v0.7.6-RC3 Fix: manage ASSIGNED_TO_ADDON profile pins as well as core…
Browse files Browse the repository at this point in the history
… pins (OpenStickCommunity#726)

manage ASSIGNED_TO_ADDON profile pins as well as core pins

docToPin and our USB D+/D- handling code only managed the core profile
configuration, but it also needs to set the fields in profiles.

fixes OpenStickCommunity#667
  • Loading branch information
bsstephan authored Dec 27, 2023
1 parent a03af7f commit 6f1af54
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,23 @@ static void __attribute__((noinline)) docToPin(Pin_t& pin, const DynamicJsonDocu
{
pin = doc[key];
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
if (isValidPin(pin))
{
gpioMappings[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[0].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
}
else
{
pin = -1;
if (isValidPin(oldPin))
{
gpioMappings[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPin].action = GpioAction::NONE;
}
}
}
Expand All @@ -136,14 +143,21 @@ static void __attribute__((noinline)) docToPin(Pin_t& pin, const DynamicJsonDocu
{
pin = doc[key0][key1];
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
if (isValidPin(pin))
{
gpioMappings[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[0].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
} else {
pin = -1;
if (isValidPin(oldPin))
{
gpioMappings[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPin].action = GpioAction::NONE;
}
}
}
Expand All @@ -157,14 +171,21 @@ static void __attribute__((noinline)) docToPin(Pin_t& pin, const DynamicJsonDocu
{
pin = doc[key0][key1][key2];
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
if (isValidPin(pin))
{
gpioMappings[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[0].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[pin].action = GpioAction::ASSIGNED_TO_ADDON;
} else {
pin = -1;
if (isValidPin(oldPin))
{
gpioMappings[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPin].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPin].action = GpioAction::NONE;
}
}
}
Expand Down Expand Up @@ -1102,16 +1123,27 @@ std::string setPeripheralOptions()

// need to reserve previous/next pin for dp
GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins;
ProfileOptions& profiles = Storage::getInstance().getProfileOptions();
uint8_t adjacent = peripheralOptions.blockUSB0.order ? -1 : 1;

Pin_t oldPinDplus = peripheralOptions.blockUSB0.dp;
docToPin(peripheralOptions.blockUSB0.dp, doc, "peripheral", "usb0", "dp");
if (isValidPin(peripheralOptions.blockUSB0.dp))
if (isValidPin(peripheralOptions.blockUSB0.dp)) {
// if D+ pin is now set, also set the pin that will be used for D-
gpioMappings[peripheralOptions.blockUSB0.dp+adjacent].action = GpioAction::ASSIGNED_TO_ADDON;
else if (isValidPin(oldPinDplus))
profiles.gpioMappingsSets[0].pins[peripheralOptions.blockUSB0.dp+adjacent].action =
GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[1].pins[peripheralOptions.blockUSB0.dp+adjacent].action =
GpioAction::ASSIGNED_TO_ADDON;
profiles.gpioMappingsSets[2].pins[peripheralOptions.blockUSB0.dp+adjacent].action =
GpioAction::ASSIGNED_TO_ADDON;
} else if (isValidPin(oldPinDplus)) {
// if D+ pin was set and is no longer, also unset the pin that was used for D-
gpioMappings[oldPinDplus+adjacent].action = GpioAction::NONE;
profiles.gpioMappingsSets[0].pins[oldPinDplus+adjacent].action = GpioAction::NONE;
profiles.gpioMappingsSets[1].pins[oldPinDplus+adjacent].action = GpioAction::NONE;
profiles.gpioMappingsSets[2].pins[oldPinDplus+adjacent].action = GpioAction::NONE;
}

Storage::getInstance().save();

Expand Down

0 comments on commit 6f1af54

Please sign in to comment.