fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
9ba9ca8
master
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 19GpioButtonMapping button_mappings []= { 20 {& InputState ::l ,47 }, 21 {& InputState ::left ,24 }, 22 {& InputState ::down ,23 }, 23 {& InputState ::right ,25 }, 24 25 {& InputState ::mod_x ,28 }, 26 {& InputState ::mod_y ,29 }, 27 {& InputState ::select ,30 }, 28 {& InputState ::home ,31 }, 29 30 {& InputState ::start ,50 }, 31 32 {& InputState ::c_left ,36 }, 33 {& InputState ::c_up ,34 }, 34 {& InputState ::c_down ,46 }, 35 {& InputState ::a ,35 }, 36 {& InputState ::c_right ,37 }, 37 38 {& InputState ::b ,44 }, 39 {& InputState ::x ,42 }, 40 {& InputState ::z ,7 }, 41 {& InputState ::up ,45 }, 42 43 {& InputState ::r ,41 }, 44 {& InputState ::y ,43 }, 45 {& InputState ::lightshield ,40 }, 46 {& InputState ::midshield ,12 }, 47}; 48size_t button_count = sizeof (button_mappings ) /sizeof (GpioButtonMapping ); 49 50Pinout pinout = { 51 .joybus_data = 52 , 52 .mux = -1 , 53 .nunchuk_detect = -1 , 54 .nunchuk_sda = -1 , 55 .nunchuk_scl = -1 , 56}; 57 58void setup () { 59// Create Nunchuk input source - must be done before GPIO input source otherwise it would 60// disable the pullups on the i2c pins. 61NunchukInput * nunchuk = new NunchukInput (); 62 63// Create GPIO input source and use it to read button states for checking button holds. 64GpioButtonInput * gpio_input = new GpioButtonInput (button_mappings ,button_count ); 65 66InputState button_holds ; 67gpio_input -> UpdateInputs (button_holds ); 68 69// Create array of input sources to be used. 70static InputSource * input_sources []= {gpio_input ,nunchuk }; 71size_t input_source_count = sizeof (input_sources ) /sizeof (InputSource * ); 72 73CommunicationBackend * primary_backend = nullptr ; 74if (button_holds .a ) { 75// Hold A on plugin for GameCube adapter. 76primary_backend = 77new GamecubeBackend (input_sources ,input_source_count ,0 ,pinout .joybus_data ); 78 }else { 79// Default to GameCube/Wii. 80primary_backend = 81new GamecubeBackend (input_sources ,input_source_count ,125 ,pinout .joybus_data ); 82 } 83 84backend_count = 1 ; 85backends = new CommunicationBackend * [backend_count ] {primary_backend }; 86 87// Default to Melee mode. 88primary_backend -> SetGameMode ( 89new Melee20Button (socd::SOCD_2IP_NO_REAC , { .crouch_walk_os = false }) 90 ); 91} 92 93void loop () { 94select_mode (backends [0 ]); 95 96for (size_t i = 0 ;i < backend_count ;i ++ ) { 97backends [i ]-> SendReport (); 98 } 99}