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