Skip to content

Commit

Permalink
Storage manager optimizations (OpenStickCommunity#205)
Browse files Browse the repository at this point in the history
* Build makefsdata for Linux w/ MUSL

* Restored deflate support to makefsdata

* WIP
  • Loading branch information
mthiesen authored and henrebotha committed May 3, 2023
1 parent 60a18cd commit 66568a8
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 110 deletions.
2 changes: 1 addition & 1 deletion headers/addons/i2cdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class I2CDisplayAddon : public GPAddon
bool pressedDown();
bool pressedLeft();
bool pressedRight();
BoardOptions getBoardOptions();
const BoardOptions& getBoardOptions();
bool isDisplayPowerOff();
void setDisplayPower(uint8_t status);
uint32_t displaySaverTimeout = 0;
Expand Down
5 changes: 3 additions & 2 deletions headers/addons/turbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define TURBO_SHMUP_MODE 0
#endif

enum ShmupMixMode {
enum ShmupMixMode {
TURBO_PRIORITY = 0,
CHARGE_PRIORITY
};
Expand Down Expand Up @@ -98,8 +98,9 @@ class TurboInput : public GPAddon {
virtual void process(); // TURBO Setting of buttons (Enable/Disable)
virtual std::string name() { return TurboName; }
private:
void read(AddonOptions&); // Read TURBO Buttons and Dials
void read(const AddonOptions&); // Read TURBO Buttons and Dials
void debounce(); // TURBO Button Debouncer
void updateTurboShotCount(uint8_t turboShotCount);
bool bDebState; // Debounce TURBO Button State
uint32_t uDebTime; // Debounce TURBO Button Time
uint32_t debChargeState; // Debounce Charge Button State
Expand Down
22 changes: 11 additions & 11 deletions headers/storagemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,22 @@ class Storage {
static Storage instance;
return instance;
}

void setBoardOptions(BoardOptions); // Board Options
void setDefaultBoardOptions();
BoardOptions getBoardOptions();

const BoardOptions& getBoardOptions() { return boardOptions; }

void setPreviewBoardOptions(const BoardOptions&); // Preview Board Options
BoardOptions getPreviewBoardOptions();
const BoardOptions& getPreviewBoardOptions() { return previewBoardOptions; }

void setAddonOptions(AddonOptions); // Add-On Options
void setDefaultAddonOptions();
AddonOptions getAddonOptions();
const AddonOptions& getAddonOptions() { return addonOptions; }

void setSplashImage(SplashImage);
void setDefaultSplashImage();
SplashImage getSplashImage();
const SplashImage& getSplashImage() { return splashImage; }

void setLEDOptions(LEDOptions); // LED Options
void setDefaultLEDOptions();
LEDOptions getLEDOptions();
const LEDOptions& getLEDOptions() { return ledOptions; }

void savePS4Options(); // PS4 Options
void setDefaultPS4Options();
Expand Down Expand Up @@ -275,6 +272,9 @@ class Storage {
void initAddonOptions();
void initLEDOptions();
void initSplashImage();
void setDefaultBoardOptions();
void setDefaultAddonOptions();
void setDefaultSplashImage();
void initPS4Options();
bool CONFIG_MODE; // Config mode (boot)
Gamepad * gamepad; // Gamepad data
Expand Down
2 changes: 1 addition & 1 deletion src/addons/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define ANALOG_DEADZONE 0.05f // move to config (future release)

bool AnalogInput::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
analogAdcPinX = Storage::getInstance().getAddonOptions().analogAdcPinX;
analogAdcPinY = Storage::getInstance().getAddonOptions().analogAdcPinY;
return options.AnalogInputEnabled;
Expand Down
2 changes: 1 addition & 1 deletion src/addons/board_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "usb_driver.h" // Required to check USB state

bool BoardLedAddon::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
onBoardLedMode = options.onBoardLedMode;
return options.BoardLedAddonEnabled &&
onBoardLedMode != OnBoardLedMode::BOARD_LED_OFF; // Available only when it's not set to off
Expand Down
2 changes: 1 addition & 1 deletion src/addons/bootsel_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool __no_inline_not_in_flash_func(BootselButtonAddon::isBootselPressed)() {
}

bool BootselButtonAddon::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
bootselButtonMap = options.bootselButtonMap;
return options.BootselButtonAddonEnabled &&
bootselButtonMap != 0;
Expand Down
10 changes: 5 additions & 5 deletions src/addons/buzzerspeaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
#include "usb_driver.h"

bool BuzzerSpeakerAddon::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
buzzerPin = options.buzzerPin;
return options.BuzzerSpeakerAddonEnabled &&
buzzerPin != (uint8_t)-1;
}

void BuzzerSpeakerAddon::setup() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();

gpio_set_function(buzzerPin, GPIO_FUNC_PWM);
buzzerPinSlice = pwm_gpio_to_slice_num (buzzerPin);
buzzerPinSlice = pwm_gpio_to_slice_num (buzzerPin);
buzzerPinChannel = pwm_gpio_to_channel (buzzerPin);

buzzerVolume = options.buzzerVolume;
Expand All @@ -37,7 +37,7 @@ void BuzzerSpeakerAddon::playIntro() {
}

bool isConfigMode = Storage::getInstance().GetConfigMode();

if (!get_usb_mounted() || isConfigMode) {
play(&configModeSong);
} else {
Expand Down Expand Up @@ -82,7 +82,7 @@ void BuzzerSpeakerAddon::stop() {

uint32_t BuzzerSpeakerAddon::pwmSetFreqDuty(uint slice, uint channel, uint32_t frequency, float duty) {
uint32_t clock = 125000000;
uint32_t divider16 = clock / frequency / 4096 +
uint32_t divider16 = clock / frequency / 4096 +
(clock % (frequency * 4096) != 0);
if (divider16 / 16 == 0)
divider16 = 16;
Expand Down
14 changes: 7 additions & 7 deletions src/addons/dualdirectional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "storagemanager.h"

bool DualDirectionalInput::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
pinDualDirDown = options.pinDualDirDown;
pinDualDirUp = options.pinDualDirUp;
pinDualDirLeft = options.pinDualDirLeft;
Expand All @@ -12,7 +12,7 @@ bool DualDirectionalInput::available() {
}

void DualDirectionalInput::setup() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
combineMode = options.dualDirCombineMode;

dpadMode = options.dualDirDpadMode;
Expand Down Expand Up @@ -109,7 +109,7 @@ void DualDirectionalInput::preprocess()
gamepadState = dualState;
}
}

gamepad->state.dpad = gamepadState;
}

Expand All @@ -124,10 +124,10 @@ void DualDirectionalInput::process()
// Up-Win or Neutral Modify AFTER SOCD(gamepad), Last-Win Modifies BEFORE SOCD(gamepad)
if ( gamepad->options.socdMode == SOCD_MODE_UP_PRIORITY ||
gamepad->options.socdMode == SOCD_MODE_NEUTRAL ) {

// Up-Win or Neutral: SOCD(gamepad) *already done* | SOCD(dual) *done in preprocess()*
dualOut = SOCDCombine(gamepad->options.socdMode, gamepadDpad);

// Modify Gamepad if we're in mixed Up-Win or Neutral and dual != gamepad
if ( dualOut != gamepadDpad ) {
OverrideGamepad(gamepad, gamepad->options.dpadMode, dualOut);
Expand Down Expand Up @@ -155,7 +155,7 @@ void DualDirectionalInput::OverrideGamepad(Gamepad * gamepad, DpadMode mode, uin
break;
case DPAD_MODE_DIGITAL:
gamepad->state.dpad = dpad;
break;
break;
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ void DualDirectionalInput::SOCDDualClean(SOCDMode socdMode) {
if (socdMode == SOCD_MODE_SECOND_INPUT_PRIORITY) dualState ^= (lastDualLR == DIRECTION_LEFT) ? GAMEPAD_MASK_LEFT : GAMEPAD_MASK_RIGHT; // Last Win
else dualState ^= (lastDualLR == DIRECTION_LEFT) ? GAMEPAD_MASK_RIGHT : GAMEPAD_MASK_LEFT; // First Win
else
lastDualLR = DIRECTION_NONE;
lastDualLR = DIRECTION_NONE;
}
break;
case GAMEPAD_MASK_LEFT:
Expand Down
2 changes: 1 addition & 1 deletion src/addons/extra_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "hardware/gpio.h"

bool ExtraButtonAddon::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
extraButtonMap = options.extraButtonMap;
extraButtonPin = options.extraButtonPin;
return options.ExtraButtonAddonEnabled &&
Expand Down
4 changes: 2 additions & 2 deletions src/addons/i2canalog1219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#define VREF_VOLTAGE 2.048f

bool I2CAnalog1219Input::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
return (options.I2CAnalog1219InputEnabled &&
options.i2cAnalog1219SDAPin != (uint8_t)-1 &&
options.i2cAnalog1219SCLPin != (uint8_t)-1);
}

void I2CAnalog1219Input::setup() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();

memset(&pins, 0, sizeof(ADS_PINS));
channelHop = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/addons/i2cdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "ps4_driver.h"

bool I2CDisplayAddon::available() {
BoardOptions boardOptions = getBoardOptions();
const BoardOptions& boardOptions = getBoardOptions();
return boardOptions.hasI2CDisplay &&
boardOptions.i2cSDAPin != (uint8_t)-1 &&
boardOptions.i2cSCLPin != (uint8_t)-1;
}

void I2CDisplayAddon::setup() {
BoardOptions boardOptions = getBoardOptions();
const BoardOptions& boardOptions = getBoardOptions();

obdI2CInit(&obd,
boardOptions.displaySize,
Expand Down Expand Up @@ -104,7 +104,7 @@ void I2CDisplayAddon::process() {
break;
case I2CDisplayAddon::DisplayMode::BUTTONS:
drawStatusBar(gamepad);
BoardOptions boardOptions = getBoardOptions();
const BoardOptions& boardOptions = getBoardOptions();
ButtonLayoutCustomOptions buttonLayoutCustomOptions = boardOptions.buttonLayoutCustomOptions;

switch (boardOptions.buttonLayout) {
Expand Down Expand Up @@ -242,13 +242,13 @@ I2CDisplayAddon::DisplayMode I2CDisplayAddon::getDisplayMode() {
return I2CDisplayAddon::DisplayMode::BUTTONS;
}

BoardOptions I2CDisplayAddon::getBoardOptions() {
const BoardOptions& I2CDisplayAddon::getBoardOptions() {
bool configMode = Storage::getInstance().GetConfigMode();
return configMode ? Storage::getInstance().getPreviewBoardOptions() : Storage::getInstance().getBoardOptions();
}

int I2CDisplayAddon::initDisplay(int typeOverride) {
BoardOptions boardOptions = Storage::getInstance().getBoardOptions();
const BoardOptions& boardOptions = Storage::getInstance().getBoardOptions();
return obdI2CInit(&obd,
typeOverride > 0 ? typeOverride : boardOptions.displaySize,
boardOptions.displayI2CAddress,
Expand Down Expand Up @@ -907,8 +907,8 @@ void I2CDisplayAddon::drawText(int x, int y, std::string text) {

void I2CDisplayAddon::drawStatusBar(Gamepad * gamepad)
{
BoardOptions boardOptions = getBoardOptions();
AddonOptions addonOptions = Storage::getInstance().getAddonOptions();
const BoardOptions& boardOptions = getBoardOptions();
const AddonOptions& addonOptions = Storage::getInstance().getAddonOptions();

// Limit to 21 chars with 6x8 font for now
statusBar.clear();
Expand Down
4 changes: 2 additions & 2 deletions src/addons/jslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define DPAD_MODE_MASK (DPAD_MODE_LEFT_ANALOG & DPAD_MODE_RIGHT_ANALOG & DPAD_MODE_DIGITAL)

bool JSliderInput::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
pinSliderLS = options.pinSliderLS;
pinSliderRS = options.pinSliderRS;
return ( options.JSliderInputEnabled &&
Expand All @@ -33,7 +33,7 @@ DpadMode JSliderInput::read() {
return DPAD_MODE_LEFT_ANALOG;
} else if ( !gpio_get(pinSliderRS)) {
return DPAD_MODE_RIGHT_ANALOG;
}
}
}
return DPAD_MODE_DIGITAL;
}
Expand Down
8 changes: 4 additions & 4 deletions src/addons/neopicoleds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ PLEDAnimationState getXInputAnimationNEOPICO(uint8_t *data)
}

bool NeoPicoLEDAddon::available() {
LEDOptions ledOptions = Storage::getInstance().getLEDOptions();
const LEDOptions& ledOptions = Storage::getInstance().getLEDOptions();
return ledOptions.dataPin != -1;
}

void NeoPicoLEDAddon::setup()
{
// Set Default LED Options
LEDOptions ledOptions = Storage::getInstance().getLEDOptions();
const LEDOptions& ledOptions = Storage::getInstance().getLEDOptions();
if (!ledOptions.useUserDefinedLEDs) {
Storage::getInstance().setDefaultLEDOptions();
}
Expand All @@ -110,7 +110,7 @@ void NeoPicoLEDAddon::setup()

void NeoPicoLEDAddon::process()
{
LEDOptions ledOptions = Storage::getInstance().getLEDOptions();
const LEDOptions& ledOptions = Storage::getInstance().getLEDOptions();
if (ledOptions.dataPin < 0 || !time_reached(this->nextRunTime))
return;

Expand Down Expand Up @@ -466,7 +466,7 @@ uint8_t NeoPicoLEDAddon::setupButtonPositions()

void NeoPicoLEDAddon::configureLEDs()
{
LEDOptions ledOptions = Storage::getInstance().getLEDOptions();
const LEDOptions& ledOptions = Storage::getInstance().getLEDOptions();
uint8_t buttonCount = setupButtonPositions();
vector<vector<Pixel>> pixels = createLEDLayout(ledOptions.ledLayout, ledOptions.ledsPerButton, buttonCount);
matrix.setup(pixels, ledOptions.ledsPerButton);
Expand Down
4 changes: 2 additions & 2 deletions src/addons/playernum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include "system.h"

bool PlayerNumAddon::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
return options.PlayerNumAddonEnabled;
}

void PlayerNumAddon::setup() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
xinputIDs[0] = XINPUT_PLED_ON1;
xinputIDs[1] = XINPUT_PLED_ON2;
xinputIDs[2] = XINPUT_PLED_ON3;
Expand Down
8 changes: 4 additions & 4 deletions src/addons/reverse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "GamepadEnums.h"

bool ReverseInput::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
pinButtonReverse = options.pinButtonReverse;
return (options.ReverseInputEnabled &&
pinButtonReverse != (uint8_t)-1);
Expand All @@ -15,9 +15,9 @@ void ReverseInput::setup()
gpio_init(pinButtonReverse); // Initialize pin
gpio_set_dir(pinButtonReverse, GPIO_IN); // Set as INPUT
gpio_pull_up(pinButtonReverse); // Set as PULLUP

// Setup Reverse LED if available
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
pinLED = options.pinReverseLED;
if (pinLED != (uint8_t)-1) {
gpio_init(options.pinReverseLED);
Expand Down Expand Up @@ -68,7 +68,7 @@ void ReverseInput::process()
| input(values & mapDpadLeft->pinMask, mapDpadLeft->buttonMask, mapDpadRight->buttonMask, actionLeft, invertXAxis)
| input(values & mapDpadRight->pinMask, mapDpadRight->buttonMask, mapDpadLeft->buttonMask, actionRight, invertXAxis)
;

if (pinLED != (uint8_t)-1) {
gpio_put(pinLED, !state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/addons/slider_socd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define SOCD_MODE_MASK (SOCD_MODE_UP_PRIORITY & SOCD_MODE_SECOND_INPUT_PRIORITY & SOCD_MODE_FIRST_INPUT_PRIORITY & SOCD_MODE_NEUTRAL)

bool SliderSOCDInput::available() {
AddonOptions options = Storage::getInstance().getAddonOptions();
const AddonOptions& options = Storage::getInstance().getAddonOptions();
sliderSOCDModeOne = options.sliderSOCDModeOne;
sliderSOCDModeTwo = options.sliderSOCDModeTwo;
sliderSOCDModeDefault = options.sliderSOCDModeDefault;
Expand Down
Loading

0 comments on commit 66568a8

Please sign in to comment.