From 966f1c7e36f0e6c1260f27d61e89225e367cf934 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Wed, 30 Dec 2020 01:34:03 -0500 Subject: [PATCH] Change ESP32 pin layout once again, tweak N64Esp32.cpp, still doesn't work quite right --- readme.md | 4 ++-- src/N64Esp32.cpp | 57 ++++++++++++++++++++++++++---------------------- src/pins.h | 13 ++++++----- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/readme.md b/readme.md index d3670d3..77e5c88 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,7 @@ Wiring | DB-25 Pins | Arduino Pro Micro GPIO | ESP32 GPIO | Radio | SNES | PSX | N64 | Gamecube | Genesis | |---------------|------------------------|------------|----------|--------|--------|----------|----------|-------------| -| 1 TX | 1 | 1 | - | LATCH | - | - | - | P1-1 | +| 1 TX | 1 | 19 | - | LATCH | - | - | - | P1-1 | | 2 SDA | 2 | 21 | - | CLOCK | DATA | DATA1 | DATA1 | P1-3 | | 3 SCL | 3 | 22 | - | DATA1 | CMD | - | - | P1-4 | | 4 Analog | 4 | 15 | - | DATA2 | ATT | - | - | P1-6 | @@ -35,7 +35,7 @@ Wiring | 8 Analog | 8 | 4 | CSN | - | - | - | - | - | | 9 Analog | 9 > 1k Ω | 35 > 1k Ω | - | 330 Ω | 100 Ω | 220 Ω | 680 Ω | 470 Ω | | 10 Analog | 10 | 32 | - | - | - | - | - | - | -| 11 RX | 0 | 3 | - | - | - | - | - | P1-2 | +| 11 RX | 0 | 18 | - | - | - | - | - | P1-2 | | 12 - | - | - | - | - | - | - | - | - | | 13 - | - | - | - | - | - | - | - | - | | 14 MISO | 14 | 12 | MISO | - | - | - | - | P2-6* | diff --git a/src/N64Esp32.cpp b/src/N64Esp32.cpp index 6903c05..1d0b9ea 100644 --- a/src/N64Esp32.cpp +++ b/src/N64Esp32.cpp @@ -12,11 +12,14 @@ PIN # USAGE VCC +3.3V ONLY */ -#define DATA_PIN 13 #include "Arduino.h" -//#define PRINT_Y_AXIS_VALUES 1 -//#define PRINT_X_AXIS_VALUES 1 +#include "pins.h" + +#define DATA_PIN OR_PIN_2 + +#define PRINT_Y_AXIS_VALUES 1 +#define PRINT_X_AXIS_VALUES 1 //#define PLOT_CONSOLE_POLLING 1 #define DEBUG @@ -80,14 +83,7 @@ int bitResolution; * Must be run from RAM to defy timing differences introduced from * reading Code from ESP32's SPI Flash Chip. */ -//#ifdef ARDUINO_ARCH_ESP32 -#if defined(CONFIG_BT_ENABLED) -void IRAM_ATTR sendCommand(byte command) -#else -// todo: what should be done here?? -void sendCommand(byte command) -#endif -{ +void IRAM_ATTR sendCommand(byte command) { // the current bit to write bool bit; @@ -200,22 +196,31 @@ void populateControllerStruct(ControllerData *data) { for (int i = 0; i < 8; i++) { data->xAxis += (data->xAxisRaw[i] * (0x80 >> (i))); data->yAxis += (data->yAxisRaw[i] * (0x80 >> (i))); - -// print y axis values -#ifdef PRINT_Y_AXIS_VALUES - Serial.printf( - "yRaw: %i %i %i %i %i %i %i %i\n", data->yAxisRaw[0], data->yAxisRaw[1], data->yAxisRaw[2], data->yAxisRaw[3], data->yAxisRaw[4], data->yAxisRaw[5], data->yAxisRaw[6], data->yAxisRaw[7]); - Serial.printf("yAxis: %i \n", data->yAxis); -#endif - -// print x axis values -#ifdef PRINT_X_AXIS_VALUES - Serial.printf( - "xRaw: %i %i %i %i %i %i %i %i\n", data->xAxisRaw[0], data->xAxisRaw[1], data->xAxisRaw[2], data->xAxisRaw[3], data->xAxisRaw[4], data->xAxisRaw[5], data->xAxisRaw[6], data->xAxisRaw[7]); - Serial.printf("xAxis: %i \n", data->xAxis); -#endif } +// print axis values +#ifdef DEBUG + Serial.printf("yRaw: %i %i %i %i %i %i %i %i xRaw: %i %i %i %i %i %i %i %i yAxis: %03i xAxis: %03i", + data->yAxisRaw[0], + data->yAxisRaw[1], + data->yAxisRaw[2], + data->yAxisRaw[3], + data->yAxisRaw[4], + data->yAxisRaw[5], + data->yAxisRaw[6], + data->yAxisRaw[7], + data->xAxisRaw[0], + data->xAxisRaw[1], + data->xAxisRaw[2], + data->xAxisRaw[3], + data->xAxisRaw[4], + data->xAxisRaw[5], + data->xAxisRaw[6], + data->xAxisRaw[7], + data->yAxis, + data->xAxis); +#endif + // decode xAxis two's complement if (data->xAxis & 0x80) { data->xAxis = -1 * (0xff - data->xAxis); @@ -350,7 +355,7 @@ void loop() { //checkUpdateCombo(&controller); #ifdef DEBUG - Serial.print("buttons: "); + Serial.print(" buttons: "); Serial.print(controller.buttonA ? "A" : "-"); Serial.print(controller.buttonB ? "B" : "-"); Serial.print(controller.buttonZ ? "Z" : "-"); diff --git a/src/pins.h b/src/pins.h index 6463279..1978b66 100644 --- a/src/pins.h +++ b/src/pins.h @@ -6,24 +6,25 @@ #if defined(ARDUINO_ARCH_ESP32) // esp32 -#define OR_PIN_1 1 +#define OR_PIN_1 19 #define OR_PIN_2 21 #define OR_PIN_3 22 -#define OR_PIN_4 15 +#define OR_PIN_4 15 // pwm at boot #define OR_PIN_5 16 -#define OR_PIN_6 2 +#define OR_PIN_6 2 // connected to led #define OR_PIN_7 17 #define OR_PIN_8 4 #define OR_PIN_9 35 #define OR_PIN_10 32 -#define OR_PIN_11 3 -#define OR_PIN_14 12 -#define OR_PIN_15 14 +#define OR_PIN_11 18 +#define OR_PIN_14 12 // boot fail if pulled high +#define OR_PIN_15 14 // pwm at boot #define OR_PIN_16 13 #define OR_PIN_18 27 #define OR_PIN_19 26 #define OR_PIN_20 25 #define OR_PIN_21 33 +// 23 #else // micro #define OR_PIN_1 1