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