Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions HAL/pico/include/input/DebouncedGpioButtonInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ template <size_t button_count> class DebouncedGpioButtonInput : public GpioButto
uint32_t _debounce_period_ms;

void UpdateButtonState(InputState &inputs, size_t button_mapping_index, bool pressed) {
bool state_changed = update_debounce_state(
_debounce_state[button_mapping_index],
pressed,
_debounce_period_ms
);
if (state_changed) {
set_button(inputs.buttons, _button_mappings[button_mapping_index].button, pressed);
update_debounce_state(_debounce_state[button_mapping_index], pressed, _debounce_period_ms);
if (_debounce_state[button_mapping_index].pressed) {
set_button(inputs.buttons, _button_mappings[button_mapping_index].button, true);
}
}
};
Expand Down
11 changes: 3 additions & 8 deletions HAL/pico/include/input/DebouncedSwitchMatrixInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ class DebouncedSwitchMatrixInput : public SwitchMatrixInput<num_rows, num_cols>
uint32_t _debounce_period_ms;

void UpdateButtonState(InputState &inputs, size_t col_index, size_t row_index, bool pressed) {
bool state_changed = update_debounce_state(
_debounce_state[col_index][row_index],
pressed,
_debounce_period_ms
);
if (state_changed) {
Button button = this->_matrix[col_index][row_index];
set_button(inputs.buttons, button, pressed);
update_debounce_state(_debounce_state[col_index][row_index], pressed, _debounce_period_ms);
if (_debounce_state[col_index][row_index].pressed) {
set_button(inputs.buttons, this->_matrix[col_index][row_index], true);
}
};
};
Expand Down
8 changes: 7 additions & 1 deletion HAL/pico/src/input/Pca9671Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ InputScanSpeed Pca9671Input::ScanSpeed() {
}

void Pca9671Input::UpdateInputs(InputState &inputs) {
for (size_t i = 0; i < _button_count; i++) {
set_button(inputs.buttons, _button_mappings[i].button, false);
}

uint16_t pin_values = _pcf.read16();

for (size_t i = 0; i < _button_count; i++) {
Expand All @@ -43,5 +47,7 @@ void Pca9671Input::UpdateButtonState(
size_t button_mapping_index,
bool pressed
) {
set_button(inputs.buttons, _button_mappings[button_mapping_index].button, pressed);
if (pressed) {
set_button(inputs.buttons, _button_mappings[button_mapping_index].button, true);
}
}
20 changes: 20 additions & 0 deletions HAL/stm32/include/comms/XInputBackend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _COMMS_XINPUTBACKEND_HPP
#define _COMMS_XINPUTBACKEND_HPP

#include "core/CommunicationBackend.hpp"
#include "core/InputSource.hpp"
#include "stdlib.hpp"

#include <USBComposite.h>

class XInputBackend : public CommunicationBackend {
public:
XInputBackend(InputState &inputs, InputSource **input_sources, size_t input_source_count);
CommunicationBackendId BackendId();
void SendReport();

private:
USBXBox360 _xbox360;
};

#endif
121 changes: 121 additions & 0 deletions HAL/stm32/include/config_defaults.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#ifndef _CONFIG_DEFAULTS_HPP
#define _CONFIG_DEFAULTS_HPP

#include <config.pb.h>

// clang-format off

const Config default_config = {
.game_mode_configs_count = 4,
.game_mode_configs = new GameModeConfig[4] {
GameModeConfig {
.mode_id = MODE_MELEE,
.name = {},
.socd_pairs_count = 4,
.socd_pairs = new SocdPair[4] {
SocdPair { .button_dir1 = BTN_LF3, .button_dir2 = BTN_LF1, .socd_type = SOCD_2IP_NO_REAC },
SocdPair { .button_dir1 = BTN_LF2, .button_dir2 = BTN_RF4, .socd_type = SOCD_2IP_NO_REAC },
SocdPair { .button_dir1 = BTN_RT3, .button_dir2 = BTN_RT5, .socd_type = SOCD_2IP_NO_REAC },
SocdPair { .button_dir1 = BTN_RT2, .button_dir2 = BTN_RT4, .socd_type = SOCD_2IP_NO_REAC },
},
.button_remapping_count = 0,
.button_remapping = {},
.activation_binding_count = 3,
.activation_binding = new Button[3] { BTN_LT1, BTN_MB1, BTN_LF4 },
.custom_mode_config = 0,
.keyboard_mode_config = 0,
.rgb_config = 0,
},
GameModeConfig {
.mode_id = MODE_PROJECT_M,
.name = {},
.socd_pairs_count = 4,
.socd_pairs = new SocdPair[4] {
SocdPair { .button_dir1 = BTN_LF3, .button_dir2 = BTN_LF1, .socd_type = SOCD_2IP_NO_REAC },
SocdPair { .button_dir1 = BTN_LF2, .button_dir2 = BTN_RF4, .socd_type = SOCD_2IP_NO_REAC },
SocdPair { .button_dir1 = BTN_RT3, .button_dir2 = BTN_RT5, .socd_type = SOCD_2IP_NO_REAC },
SocdPair { .button_dir1 = BTN_RT2, .button_dir2 = BTN_RT4, .socd_type = SOCD_2IP_NO_REAC },
},
.button_remapping_count = 0,
.button_remapping = {},
.activation_binding_count = 3,
.activation_binding = new Button[3] { BTN_LT1, BTN_MB1, BTN_LF3 },
.custom_mode_config = 0,
.keyboard_mode_config = 0,
.rgb_config = 0,
},
GameModeConfig {
.mode_id = MODE_ULTIMATE,
.name = {},
.socd_pairs_count = 4,
.socd_pairs = new SocdPair[4] {
SocdPair { .button_dir1 = BTN_LF3, .button_dir2 = BTN_LF1, .socd_type = SOCD_2IP },
SocdPair { .button_dir1 = BTN_LF2, .button_dir2 = BTN_RF4, .socd_type = SOCD_2IP },
SocdPair { .button_dir1 = BTN_RT3, .button_dir2 = BTN_RT5, .socd_type = SOCD_2IP },
SocdPair { .button_dir1 = BTN_RT2, .button_dir2 = BTN_RT4, .socd_type = SOCD_2IP },
},
.button_remapping_count = 0,
.button_remapping = {},
.activation_binding_count = 3,
.activation_binding = new Button[3] { BTN_LT1, BTN_MB1, BTN_LF2 },
.custom_mode_config = 0,
.keyboard_mode_config = 0,
.rgb_config = 0,
},
GameModeConfig {
.mode_id = MODE_FGC,
.name = {},
.socd_pairs_count = 2,
.socd_pairs = new SocdPair[2] {
SocdPair { .button_dir1 = BTN_LF3, .button_dir2 = BTN_LF1, .socd_type = SOCD_NEUTRAL },
SocdPair { .button_dir1 = BTN_LT1, .button_dir2 = BTN_RT4, .socd_type = SOCD_NEUTRAL },
},
.button_remapping_count = 1,
.button_remapping = new ButtonRemap[1] {
ButtonRemap { .physical_button = BTN_RT4, .activates = BTN_LT1 },
},
.activation_binding_count = 3,
.activation_binding = new Button[3] { BTN_LT1, BTN_MB1, BTN_LF1 },
.custom_mode_config = 0,
.keyboard_mode_config = 0,
.rgb_config = 0,
},
},
.communication_backend_configs_count = 1,
.communication_backend_configs = new CommunicationBackendConfig[1] {
CommunicationBackendConfig {
.backend_id = COMMS_BACKEND_XINPUT,
.default_mode_config = 4,
.activation_binding_count = 0,
.activation_binding = {},
.secondary_backends = {},
},
},
.custom_modes_count = 0,
.custom_modes = {},
.keyboard_modes_count = 0,
.keyboard_modes = {},
.rgb_configs_count = 0,
.rgb_configs = {},
.default_backend_config = 1,
.default_usb_backend_config = 1,
.rgb_brightness = 0,
.has_melee_options = true,
.melee_options = {
.crouch_walk_os = false,
.disable_ledgedash_socd_override = false,
.has_custom_airdodge = false,
.custom_airdodge = { .x = 0, .y = 0 },
},
.has_project_m_options = true,
.project_m_options = {
.true_z_press = true,
.disable_ledgedash_socd_override = false,
.has_custom_airdodge = false,
.custom_airdodge = { .x = 0, .y = 0 },
},
};

// clang-format on

#endif
25 changes: 25 additions & 0 deletions HAL/stm32/include/core/KeyboardMode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef _CORE_KEYBOARDMODE_HPP
#define _CORE_KEYBOARDMODE_HPP

#include "core/InputMode.hpp"
#include "core/socd.hpp"
#include "core/state.hpp"

#include <keycodes.h>

class KeyboardMode : public InputMode {
public:
KeyboardMode();
~KeyboardMode();
void SendReport(const InputState &inputs);

void UpdateOutputs(const InputState &inputs, OutputState &outputs) {}

protected:
void Press(uint8_t keycode, bool press);

private:
virtual void UpdateKeys(const InputState &inputs) = 0;
};

#endif
25 changes: 25 additions & 0 deletions HAL/stm32/include/gpio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef _GPIO_HPP
#define _GPIO_HPP

#include "stdlib.hpp"

namespace gpio {
enum class GpioMode {
GPIO_OUTPUT,
GPIO_INPUT,
GPIO_INPUT_PULLUP,
GPIO_INPUT_PULLDOWN,
};

void init_pin(uint pin, GpioMode mode);

inline bool read_digital(uint pin) {
return digitalRead(pin);
}

inline void write_digital(uint pin, bool value) {
digitalWrite(pin, value);
}
}

#endif
Loading