Implement perfectly working micro-n64 support, esp32-n64 is still less than stellar
This commit is contained in:
parent
eaf0c1bd41
commit
a3a4e9d873
|
@ -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
|
||||
|
||||
|
|
|
@ -1,4 +1,18 @@
|
|||
/*
|
||||
LOOKING AT THE PLUG FROM CONTROLLER
|
||||
/---------\
|
||||
PIN 1-> / o o o \
|
||||
/-------------\
|
||||
|
||||
|
||||
PIN # USAGE
|
||||
|
||||
GND
|
||||
DATA
|
||||
VCC +3.3V ONLY
|
||||
*/
|
||||
|
||||
#define DATA_PIN 13
|
||||
#include "Arduino.h"
|
||||
|
||||
//#define PRINT_Y_AXIS_VALUES 1
|
||||
|
@ -17,22 +31,6 @@
|
|||
#include "gamepad/Gamepad.h"
|
||||
#include "util.cpp"
|
||||
|
||||
/*
|
||||
LOOKING AT THE PLUG
|
||||
/---------\
|
||||
PIN 1-> / o o o \
|
||||
/-------------\
|
||||
|
||||
|
||||
PIN # USAGE
|
||||
|
||||
GND
|
||||
DATA
|
||||
VCC +3.3V ONLY
|
||||
*/
|
||||
|
||||
#define DATA_PIN 13
|
||||
|
||||
#define LINE_WRITE_HIGH pinMode(DATA_PIN, INPUT_PULLUP)
|
||||
#define LINE_WRITE_LOW pinMode(DATA_PIN, OUTPUT)
|
||||
|
||||
|
@ -307,6 +305,9 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
// polling must not occur faster than every 20 ms
|
||||
delay(14);
|
||||
|
||||
//Serial.println("sending command to n64");
|
||||
// send command 0x01 to n64 controller
|
||||
sendCommand(0x01);
|
||||
|
@ -318,6 +319,15 @@ void loop() {
|
|||
//outputToiQue(&controller);
|
||||
uint8_t c = 0; // for now just do 1 pad
|
||||
gamepad.buttons(c, 0);
|
||||
if (controller.buttonStart) {
|
||||
if (controller.DPadDown) {
|
||||
// then only send menu, nothing else
|
||||
gamepad.press(c, BUTTON_MENU);
|
||||
gamepad.setHatSync(c, DPAD_CENTER);
|
||||
return;
|
||||
}
|
||||
gamepad.press(c, BUTTON_START);
|
||||
}
|
||||
if (controller.buttonA) {
|
||||
gamepad.press(c, BUTTON_A);
|
||||
}
|
||||
|
@ -333,16 +343,10 @@ void loop() {
|
|||
if (controller.buttonR) {
|
||||
gamepad.press(c, BUTTON_R);
|
||||
}
|
||||
if (controller.buttonStart) {
|
||||
gamepad.press(c, BUTTON_START);
|
||||
}
|
||||
auto hat = calculateDpadDirection(controller.DPadUp, controller.DPadDown, controller.DPadLeft, controller.DPadRight);
|
||||
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);
|
||||
|
||||
// polling must not occur faster than every 20 ms
|
||||
delay(14);
|
||||
|
||||
//checkUpdateCombo(&controller);
|
||||
|
||||
#ifdef DEBUG
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue