fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

Jonathan Haylettfix: use C++17 for AVR to avoid compilation error9ba9ca8

v0.1.2
3.0 KiB100 linesraw
1#include "comms/GamecubeBackend.hpp"
2#include "comms/N64Backend.hpp"
3#include "config/mode_selection.hpp"
4#include "core/CommunicationBackend.hpp"
5#include "core/InputMode.hpp"
6#include "core/KeyboardMode.hpp"
7#include "core/pinout.hpp"
8#include "core/socd.hpp"
9#include "core/state.hpp"
10#include "input/GpioButtonInput.hpp"
11#include "input/NunchukInput.hpp"
12#include "modes/Melee20Button.hpp"
13#include "stdlib.hpp"
14
15CommunicationBackend **backends = nullptr;
16size_t backend_count;
17KeyboardMode *current_kb_mode = nullptr;
18
19// Customise this to match your controller's pinout.
20GpioButtonMapping button_mappings[] = {
21    {&InputState::l,            15},
22    { &InputState::left,        16},
23    { &InputState::down,        14},
24    { &InputState::right,       1 },
25
26    { &InputState::mod_x,       12},
27    { &InputState::mod_y,       0 },
28
29    { &InputState::select,      2 },
30    { &InputState::start,       4 },
31    { &InputState::home,        3 },
32
33    { &InputState::c_left,      8 },
34    { &InputState::c_up,        10},
35    { &InputState::c_down,      6 },
36    { &InputState::a,           9 },
37    { &InputState::c_right,     5 },
38
39    { &InputState::b,           A2},
40    { &InputState::x,           A1},
41    { &InputState::z,           A0},
42    { &InputState::up,          13},
43
44    { &InputState::r,           7 },
45    { &InputState::y,           A5},
46    { &InputState::lightshield, A4},
47    { &InputState::midshield,   A3},
48};
49size_t button_count = sizeof(button_mappings) / sizeof(GpioButtonMapping);
50
51Pinout pinout = {
52    .joybus_data = 13,
53    .mux = -1,
54    .nunchuk_detect = -1,
55    .nunchuk_sda = -1,
56    .nunchuk_scl = -1,
57};
58
59void setup() {
60    // Create Nunchuk input source - must be done before GPIO input source otherwise it would
61    // disable the pullups on the i2c pins.
62    NunchukInput *nunchuk = new NunchukInput();
63
64    // Create GPIO input source and use it to read button states for checking button holds.
65    GpioButtonInput *gpio_input = new GpioButtonInput(button_mappings, button_count);
66
67    InputState button_holds;
68    gpio_input->UpdateInputs(button_holds);
69
70    // Create array of input sources to be used.
71    static InputSource *input_sources[] = { gpio_input, nunchuk };
72    size_t input_source_count = sizeof(input_sources) / sizeof(InputSource *);
73
74    CommunicationBackend *primary_backend = nullptr;
75    if (button_holds.a) {
76        // Hold A on plugin for GameCube adapter.
77        primary_backend =
78            new GamecubeBackend(input_sources, input_source_count, 0, pinout.joybus_data);
79    } else {
80        // Default to GameCube/Wii.
81        primary_backend =
82            new GamecubeBackend(input_sources, input_source_count, 125, pinout.joybus_data);
83    }
84
85    backend_count = 1;
86    backends = new CommunicationBackend *[backend_count] { primary_backend };
87
88    // Default to Melee mode.
89    primary_backend->SetGameMode(
90        new Melee20Button(socd::SOCD_2IP_NO_REAC, { .crouch_walk_os = false })
91    );
92}
93
94void loop() {
95    select_mode(backends[0]);
96
97    for (size_t i = 0; i < backend_count; i++) {
98        backends[i]->SendReport();
99    }
100}