fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
1#include "comms/console_detection.hpp" 2 3#include "core/pinout.hpp" 4 5#include <GamecubeConsole.hpp> 6#include <N64Console.hpp> 7#include <config.pb.h> 8#include <hardware/structs/usb.h> 9 10uint latch_pulses = 0 ; 11uint clock_pulses = 0 ; 12 13void latch_irq_handler () { 14latch_pulses ++ ; 15} 16 17void clock_irq_handler () { 18clock_pulses ++ ; 19} 20 21CommunicationBackendId detect_console (const Pinout & pinout ) { 22if (pinout .nes_latch > -1 && pinout .nes_clock > -1 ) { 23attachInterrupt (pinout .nes_latch ,& latch_irq_handler ,PinStatus ::RISING ); 24attachInterrupt (pinout .nes_clock ,& clock_irq_handler ,PinStatus ::FALLING ); 25 } 26 27delay (500 ); 28bool usb_connected = usb_hw -> sie_status & USB_SIE_STATUS_CONNECTED_BITS ; 29 30if (pinout .nes_latch > -1 && pinout .nes_clock > -1 ) { 31detachInterrupt (pinout .nes_latch ); 32detachInterrupt (pinout .nes_clock ); 33 } 34 35CommunicationBackendId result = COMMS_BACKEND_UNSPECIFIED ; 36 37if (usb_connected ) { 38result = COMMS_BACKEND_XINPUT ; 39 }else if (latch_pulses && (clock_pulses /latch_pulses )> 8 ) { 40result = COMMS_BACKEND_SNES ; 41 }else if (latch_pulses && (clock_pulses /latch_pulses )> 1 ) { 42result = COMMS_BACKEND_NES ; 43 }else if (GamecubeConsole (pinout .joybus_data ).Detect ()) { 44result = COMMS_BACKEND_GAMECUBE ; 45 }else if (N64Console (pinout .joybus_data ).Detect ()) { 46result = COMMS_BACKEND_N64 ; 47 } 48 49return result ; 50}