fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
9ba9ca8
WASD_NeutralSOCD
1#include "comms/B0XXInputViewer.hpp" 2#include "comms/DInputBackend.hpp" 3#include "comms/GamecubeBackend.hpp" 4#include "comms/N64Backend.hpp" 5#include "config/mode_selection.hpp" 6#include "core/CommunicationBackend.hpp" 7#include "core/InputMode.hpp" 8#include "core/pinout.hpp" 9#include "core/socd.hpp" 10#include "core/state.hpp" 11#include "input/GpioButtonInput.hpp" 12#include "input/NunchukInput.hpp" 13#include "modes/Melee20Button.hpp" 14#include "stdlib.hpp" 15 16CommunicationBackend ** backends = nullptr ; 17size_t backend_count ; 18KeyboardMode * current_kb_mode = nullptr ; 19 20GpioButtonMapping button_mappings []= { 21 {& InputState ::l ,9 }, 22 {& InputState ::left ,15 }, 23 {& InputState ::down ,16 }, 24 {& InputState ::right ,14 }, 25 26 {& InputState ::mod_x ,8 }, 27 {& InputState ::mod_y ,6 }, 28 29 {& InputState ::start ,12 }, 30 31 {& InputState ::c_left ,A1 }, 32 {& InputState ::c_up ,A2 }, 33 {& InputState ::c_down ,5 }, 34 {& InputState ::a ,13 }, 35 {& InputState ::c_right ,A0 }, 36 37 {& InputState ::b ,4 }, 38 {& InputState ::x ,A5 }, 39 {& InputState ::z ,A4 }, 40 {& InputState ::up ,A3 }, 41 42 {& InputState ::r ,0 }, 43 {& InputState ::y ,1 }, 44 {& InputState ::lightshield ,10 }, 45 {& InputState ::midshield ,11 }, 46}; 47size_t button_count = sizeof (button_mappings ) /sizeof (GpioButtonMapping ); 48 49Pinout pinout = { 50 .joybus_data = 17 , 51 .mux = 7 , 52 .nunchuk_detect = -1 , 53 .nunchuk_sda = -1 , 54 .nunchuk_scl = -1 , 55}; 56 57void setup () { 58// Create Nunchuk input source - must be done before GPIO input source otherwise it would 59// disable the pullups on the i2c pins. 60NunchukInput * nunchuk = new NunchukInput (); 61 62// Create GPIO input source and use it to read button states for checking button holds. 63GpioButtonInput * gpio_input = new GpioButtonInput (button_mappings ,button_count ); 64 65InputState button_holds ; 66gpio_input -> UpdateInputs (button_holds ); 67 68// Create array of input sources to be used. 69static InputSource * input_sources []= {gpio_input ,nunchuk }; 70size_t input_source_count = sizeof (input_sources ) /sizeof (InputSource * ); 71 72// Hold B on plugin for Brook board mode. 73pinMode (pinout .mux ,OUTPUT ); 74if (button_holds .b ) 75digitalWrite (pinout .mux ,LOW ); 76else 77digitalWrite (pinout .mux ,HIGH ); 78 79CommunicationBackend * primary_backend = new DInputBackend (input_sources ,input_source_count ); 80delay (500 ); 81bool usb_connected = UDADDR & _BV (ADDEN ); 82 83/* Select communication backend. */ 84if (usb_connected ) { 85// Default to DInput mode if USB is connected. 86// Input viewer only used when connected to PC i.e. when using DInput mode. 87backend_count = 2 ; 88backends = new CommunicationBackend * [backend_count ] { 89primary_backend ,new B0XXInputViewer (input_sources ,input_source_count ) 90 }; 91 }else { 92delete primary_backend ; 93if (button_holds .c_left ) { 94// Hold C-Left on plugin for N64. 95primary_backend = 96new N64Backend (input_sources ,input_source_count ,60 ,pinout .joybus_data ); 97 }else if (button_holds .a ) { 98// Hold A on plugin for GameCube adapter. 99primary_backend = 100new GamecubeBackend (input_sources ,input_source_count ,0 ,pinout .joybus_data ); 101 }else { 102// Default to GameCube/Wii. 103primary_backend = 104new GamecubeBackend (input_sources ,input_source_count ,125 ,pinout .joybus_data ); 105 } 106 107// If not DInput then only using 1 backend (no input viewer). 108backend_count = 1 ; 109backends = new CommunicationBackend * [backend_count ] {primary_backend }; 110 } 111 112// Default to Melee mode. 113primary_backend -> SetGameMode ( 114new Melee20Button (socd::SOCD_2IP_NO_REAC , { .crouch_walk_os = false }) 115 ); 116} 117 118void loop () { 119select_mode (backends [0 ]); 120 121for (size_t i = 0 ;i < backend_count ;i ++ ) { 122backends [i ]-> SendReport (); 123 } 124 125if (current_kb_mode != nullptr ) { 126current_kb_mode -> SendReport (backends [0 ]-> GetInputs ()); 127 } 128}