Browse Source

Implement perfectly working micro-n64 support, esp32-n64 is still less than stellar

master
Travis Burtrum 7 months ago
parent
commit
a3a4e9d873
5 changed files with 222 additions and 52 deletions
  1. +29
    -25
      platformio.ini
  2. +26
    -22
      src/N64Esp32.cpp
  3. +166
    -0
      src/N64Micro.cpp
  4. +0
    -4
      src/gamepad/Switch-USB-Gamepad/SwitchUsbGamepad.h
  5. +1
    -1
      src/gamepad/common.h

+ 29
- 25
platformio.ini View File

@ -153,45 +153,49 @@ build_flags = ${in-snes.build_flags} ${out-switchusb.build_flags}
# n64 input
[in-n64]
src_filter = -<*> +<N64.cpp>
build_flags = ${common.build_flags} -DGAMEPAD_INPUT=3 -O0
#lib_deps = pothos/N64Controller@^0.1.1
[in-n64-esp32]
src_filter = -<*> +<N64Esp32.cpp>
build_flags = ${common.build_flags} -DGAMEPAD_INPUT=3 -DGAMEPAD_COUNT=1 -O0
[in-n64-micro]
src_filter = -<*> +<N64Micro.cpp>
build_flags = ${common.build_flags} -DGAMEPAD_INPUT=3 -DGAMEPAD_COUNT=1
lib_deps = https://github.com/OpenRetroPad/Nintendo
[env:esp32-n64-bt]
extends = esp32, in-n64, out-bt
src_filter = ${in-n64.src_filter} ${out-bt.src_filter}
build_flags = ${in-n64.build_flags} ${out-bt.build_flags}
extends = esp32, in-n64-esp32, out-bt
src_filter = ${in-n64-esp32.src_filter} ${out-bt.src_filter}
build_flags = ${in-n64-esp32.build_flags} ${out-bt.build_flags}
[env:esp32-n64-debug]
extends = esp32, in-n64, out-debug
src_filter = ${in-n64.src_filter} ${out-debug.src_filter}
build_flags = ${in-n64.build_flags} ${out-debug.build_flags}
extends = esp32, in-n64-esp32, out-debug
src_filter = ${in-n64-esp32.src_filter} ${out-debug.src_filter}
build_flags = ${in-n64-esp32.build_flags} ${out-debug.build_flags}
[env:micro-n64-usb]
extends = micro, in-n64, out-usb
src_filter = ${in-n64.src_filter} ${out-usb.src_filter}
build_flags = ${in-n64.build_flags} ${out-usb.build_flags}
extends = micro, in-n64-micro, out-usb
src_filter = ${in-n64-micro.src_filter} ${out-usb.src_filter}
build_flags = ${in-n64-micro.build_flags} ${out-usb.build_flags}
[env:micro-n64-debug]
extends = micro, in-n64, out-debug
src_filter = ${in-n64.src_filter} ${out-debug.src_filter}
build_flags = ${in-n64.build_flags} ${out-debug.build_flags}
extends = micro, in-n64-micro, out-debug
src_filter = ${in-n64-micro.src_filter} ${out-debug.src_filter}
build_flags = ${in-n64-micro.build_flags} ${out-debug.build_flags}
[env:micro-n64-radio]
extends = micro, in-n64, out-radio
src_filter = ${in-n64.src_filter} ${out-radio.src_filter}
build_flags = ${in-n64.build_flags} ${out-radio.build_flags}
extends = micro, in-n64-micro, out-radio
src_filter = ${in-n64-micro.src_filter} ${out-radio.src_filter}
build_flags = ${in-n64-micro.build_flags} ${out-radio.build_flags}
[env:micro-n64-usbradio]
extends = micro, in-n64, out-usbradio
src_filter = ${in-n64.src_filter} ${out-usbradio.src_filter}
build_flags = ${in-n64.build_flags} ${out-usbradio.build_flags}
extends = micro, in-n64-micro, out-usbradio
src_filter = ${in-n64-micro.src_filter} ${out-usbradio.src_filter}
build_flags = ${in-n64-micro.build_flags} ${out-usbradio.build_flags}
[env:micro-n64-switchusb]
extends = micro, in-n64, out-switchusb
src_filter = ${in-n64.src_filter} ${out-switchusb.src_filter}
build_flags = ${in-n64.build_flags} ${out-switchusb.build_flags}
extends = micro, in-n64-micro, out-switchusb
src_filter = ${in-n64-micro.src_filter} ${out-switchusb.src_filter}
build_flags = ${in-n64-micro.build_flags} ${out-switchusb.build_flags}
# genesis input


src/N64.cpp → src/N64Esp32.cpp View File


+ 166
- 0
src/N64Micro.cpp View File

@ -0,0 +1,166 @@
/*
LOOKING AT THE PLUG FROM CONTROLLER
/---------\
PIN 1-> / o o o \
/-------------\
PIN # USAGE
GND
DATA
VCC +3.3V ONLY
*/
#define DATA_PIN 2
// how often to poll, 100? 14? polling must not occur faster than every 20 ms
#define POLL_DELAY 14
#include "Arduino.h"
#include "Nintendo.h"
//#define DEBUG
#define AXIS_CENTER_IN 0
#define AXIS_MAX_IN 100
#define AXIS_MIN_IN -100
#include "gamepad/Gamepad.h"
#include "util.cpp"
// Define a N64 Controller
CN64Controller N64Controller(DATA_PIN);
#define REPORT_SIZE 4
uint8_t oldReport[REPORT_SIZE];
GAMEPAD_CLASS gamepad;
#ifdef DEBUG
void print_n64_report(N64_Report_t &controller, N64_Status_t &n64_status) {
Serial.print("buttons: ");
Serial.print(controller.a ? "A" : "-");
Serial.print(controller.b ? "B" : "-");
Serial.print(controller.z ? "Z" : "-");
Serial.print(controller.l ? "L" : "-");
Serial.print(controller.r ? "R" : "-");
Serial.print(controller.start ? "S" : "-");
Serial.print(" DPAD: ");
Serial.print(controller.dup ? "U" : "-");
Serial.print(controller.ddown ? "D" : "-");
Serial.print(controller.dleft ? "L" : "-");
Serial.print(controller.dright ? "R" : "-");
Serial.print(" C: ");
Serial.print(controller.cup ? "U" : "-");
Serial.print(controller.cdown ? "D" : "-");
Serial.print(controller.cleft ? "L" : "-");
Serial.print(controller.cright ? "R" : "-");
Serial.print(" Y: ");
Serial.print(controller.yAxis);
Serial.print(" YT: ");
Serial.print(translateAxis(-controller.yAxis));
Serial.print(" X: ");
Serial.print(controller.xAxis);
Serial.print(" XT: ");
Serial.print(translateAxis(controller.xAxis));
Serial.println();
/*
// Print device information
Serial.print(F("Device: "));
switch (n64_status.device) {
case NINTENDO_DEVICE_N64_NONE:
Serial.println(F("No N64 Controller found!"));
return;
break;
case NINTENDO_DEVICE_N64_WIRED:
Serial.println(F("Original Nintendo N64 Controller"));
break;
default:
Serial.print(F("Unknown "));
Serial.println(n64_status.device, HEX);
break;
}
*/
}
#endif
void setup() {
#ifdef DEBUG
Serial.begin(115200);
if (N64Controller.begin()) {
Serial.println(F("N64 begin() success."));
} else {
Serial.println(F("N64 begin() fail."));
}
#else
N64Controller.begin();
#endif
gamepad.begin();
}
void loop() {
delay(POLL_DELAY);
// Try to read the controller data
if (N64Controller.read()) {
// Print Controller information
auto controller = N64Controller.getReport();
if (memcmp(oldReport, controller.raw8, REPORT_SIZE)) {
memcpy(oldReport, controller.raw8, REPORT_SIZE);
} else {
// nothing changed
return;
}
#ifdef DEBUG
auto status = N64Controller.getStatus();
print_n64_report(controller, status);
#endif
uint8_t c = 0; // for now just do 1 pad
gamepad.buttons(c, 0);
if (controller.start) {
if (controller.ddown) {
// then only send menu, nothing else
gamepad.press(c, BUTTON_MENU);
gamepad.setHatSync(c, DPAD_CENTER);
return;
}
gamepad.press(c, BUTTON_START);
}
if (controller.a) {
gamepad.press(c, BUTTON_A);
}
if (controller.b) {
gamepad.press(c, BUTTON_B);
}
if (controller.z) {
gamepad.press(c, BUTTON_TR);
}
if (controller.l) {
gamepad.press(c, BUTTON_L);
}
if (controller.r) {
gamepad.press(c, BUTTON_R);
}
auto hat = calculateDpadDirection(controller.dup, controller.ddown, controller.dleft, controller.dright);
auto cHat = dpadToAxis(calculateDpadDirection(controller.cup, controller.cdown, controller.cleft, controller.cright));
gamepad.setAxis(c, translateAxis(controller.xAxis), translateAxis(-controller.yAxis), cHat.x, cHat.y, 0, 0, hat);
} else {
// Add debounce if reading failed
delay(5000);
#ifdef DEBUG
Serial.println(F("Error reading N64 controller."));
if (N64Controller.begin()) {
Serial.println(F("N64 begin() success."));
} else {
Serial.println(F("N64 begin() fail."));
}
#else
N64Controller.begin();
#endif
}
}

+ 0
- 4
src/gamepad/Switch-USB-Gamepad/SwitchUsbGamepad.h View File

@ -33,10 +33,6 @@ class SwitchUsbGamepad : public AbstractGamepad {
this->sync(cIdx);
}
virtual void setHatSync(const uint8_t cIdx, signed char hat) {
setAxis(cIdx, 0, 0, 0, 0, 0, 0, hat);
}
virtual void buttons(const uint8_t cIdx, uint32_t b) {
NSGamepad.buttons(b);
}


+ 1
- 1
src/gamepad/common.h View File

@ -286,7 +286,7 @@ class AbstractGamepad {
}
virtual void setHatSync(const uint8_t cIdx, signed char hat) {
setAxis(cIdx, 0, 0, 0, 0, 0, 0, hat);
setAxis(cIdx, AXIS_CENTER, AXIS_CENTER, AXIS_CENTER, AXIS_CENTER, 0, 0, hat);
}
virtual void buttons(const uint8_t cIdx, uint32_t b) {


Loading…
Cancel
Save