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