fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
fb5ac91
v0.1.0
1#include "comms/GamecubeBackend.hpp" 2 3#include "core/InputSource.hpp" 4 5#include <GamecubeConsole.hpp> 6#include <hardware/pio.h> 7#include <hardware/timer.h> 8 9GamecubeBackend ::GamecubeBackend ( 10InputSource ** input_sources , 11size_t input_source_count , 12uint data_pin , 13PIO pio , 14int sm , 15int offset 16) 17 :CommunicationBackend (input_sources ,input_source_count ) { 18_gamecube = new GamecubeConsole (data_pin ,pio ,sm ,offset ); 19_report = default_gc_report ; 20} 21 22GamecubeBackend ::~GamecubeBackend () { 23delete _gamecube ; 24} 25 26void GamecubeBackend ::SendReport () { 27// Update slower inputs before we start waiting for poll. 28ScanInputs (InputScanSpeed ::SLOW ); 29ScanInputs (InputScanSpeed ::MEDIUM ); 30 31// Read inputs 32_gamecube -> WaitForPollStart (); 33 34// Update fast inputs in response to poll. 35// But wait 40us first so that we read inputs at the start of the 3rd byte of the poll command 36// not the second, so inputs are maximum 40us old by the time we start sending the report. 37busy_wait_us (40 ); 38ScanInputs (InputScanSpeed ::FAST ); 39 40// Run gamemode logic. 41UpdateOutputs (); 42 43// Digital outputs 44_report .a = _outputs .a ; 45_report .b = _outputs .b ; 46_report .x = _outputs .x ; 47_report .y = _outputs .y ; 48_report .z = _outputs .buttonR ; 49_report .l = _outputs .triggerLDigital ; 50_report .r = _outputs .triggerRDigital ; 51_report .start = _outputs .start ; 52_report .dpad_left = _outputs .dpadLeft |_outputs .select ; 53_report .dpad_right = _outputs .dpadRight |_outputs .home ; 54_report .dpad_down = _outputs .dpadDown ; 55_report .dpad_up = _outputs .dpadUp ; 56 57// Analog outputs 58_report .stick_x = _outputs .leftStickX ; 59_report .stick_y = _outputs .leftStickY ; 60_report .cstick_x = _outputs .rightStickX ; 61_report .cstick_y = _outputs .rightStickY ; 62_report .l_analog = _outputs .triggerLAnalog ; 63_report .r_analog = _outputs .triggerRAnalog ; 64 65// Send outputs to console unless poll command is invalid. 66if (_gamecube -> WaitForPollEnd ()!= PollStatus ::ERROR ) { 67_gamecube -> SendReport (& _report ); 68 } 69} 70 71int GamecubeBackend ::GetOffset () { 72return _gamecube -> GetOffset (); 73}