Simplify pin definitions

This commit is contained in:
Travis Burtrum 2020-12-29 10:58:38 -05:00
parent 58a4b7ff79
commit 06b907c776
8 changed files with 107 additions and 97 deletions

View File

@ -42,7 +42,9 @@ GAMECUBE:
I tie all 3 grounds together
*/
#define DATA_PIN 2
#include "pins.h"
#define DATA_PIN OR_PIN_2
// how often to poll, 100? 14? polling must not occur faster than every 20 ms
#define POLL_DELAY 14

View File

@ -11,15 +11,13 @@ micro values:
#if defined(ARDUINO_ARCH_ESP32)
int analogPin = 35;
int Vin = 3.3;
auto steps = 4095.0;
float Vin = 3.3;
float steps = 4095.0;
#else
int analogPin = 9;
int Vin = 5;
auto steps = 1024.0;
float Vin = 5;
float steps = 1024.0;
#endif // ARDUINO_ARCH_ESP32
@ -28,6 +26,8 @@ float R1 = 1000;
#include "Arduino.h"
#include "pins.h"
int raw = 0;
float Vout = 0;
float R2 = 0;
@ -38,7 +38,7 @@ void setup() {
}
void loop() {
raw = analogRead(analogPin);
raw = analogRead(OR_PIN_9);
if (raw) {
buffer = raw * Vin;
Vout = (buffer) / steps;

View File

@ -1,6 +1,3 @@
#include "Arduino.h"
/*
LOOKING AT THE PLUG
-------------------------------
@ -22,25 +19,24 @@ PIN # USAGE (colors from my extension cable, check your own)
*/
#if defined(ARDUINO_ARCH_ESP32)
#include "Arduino.h"
#define DATA1 2
#define CMD1 4
#define ATT1 16
#define CLK1 17
#include "pins.h"
#define DATA1 OR_PIN_2
#define CMD1 OR_PIN_3
#define ATT1 OR_PIN_4
#define CLK1 OR_PIN_5
#if defined(ARDUINO_ARCH_ESP32)
#define CTRL_BYTE_DELAY 18
#else
#define DATA1 2
#define CMD1 3
#define ATT1 4
#define CLK1 5
#define CTRL_BYTE_DELAY 6
#endif // esp32 vs generic pins
#endif // esp32 vs micro delay
#ifndef GAMEPAD_COUNT
#define GAMEPAD_COUNT 4

View File

@ -9,17 +9,9 @@
#include "gamepad/Gamepad.h"
#if defined(ARDUINO_ARCH_ESP32)
// esp32
#define CE_PIN 18
#define CSN_PIN 19
#else
// micro
#define CE_PIN 7
#define CSN_PIN 8
#endif // ARDUINO_ARCH_ESP32
#include "pins.h"
RF24 radio(CE_PIN, CSN_PIN);
RF24 radio(OR_PIN_7, OR_PIN_8); // CE, CSN
const byte address[13] = "OpenRetroPad";

View File

@ -43,18 +43,20 @@ enum
SC_BTN_RIGHT = 8,
};
#include "pins.h"
static const int DATA_PIN_SELECT[GAMEPAD_COUNT] = {
OR_PIN_5,
#if GAMEPAD_COUNT > 1
OR_PIN_7,
#endif
};
#if CODE_PLATFORM == 2
#define OPT_PIN_READ1(X) (bitRead(reg1, DATA_PIN[c][X]))
#define OPT_PIN_READ2(X) (bitRead(reg2, DATA_PIN[c][X]))
static const int DATA_PIN_SELECT[GAMEPAD_COUNT] = {
5,
#if GAMEPAD_COUNT > 1
7,
#endif
};
//individual data pin BIT for each controller, they are read in bulk
static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
{3, 2, 1, 0, 4, 7},
@ -68,40 +70,14 @@ static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
#define OPT_PIN_READ1(X) (digitalRead(DATA_PIN[c][X]))
#define OPT_PIN_READ2(X) (digitalRead(DATA_PIN[c][X]))
#if defined(ARDUINO_ARCH_ESP32)
static const int DATA_PIN_SELECT[GAMEPAD_COUNT] = {
17,
#if GAMEPAD_COUNT > 1
18,
#endif
};
//individual data pin for each controller
static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
{15, 1, 2, 4, 16, 5},
{OR_PIN_1, OR_PIN_11, OR_PIN_2, OR_PIN_3, OR_PIN_4, OR_PIN_6},
#if GAMEPAD_COUNT > 1
{26, 25, 33, 32, 12, 14},
{OR_PIN_18, OR_PIN_19, OR_PIN_20, OR_PIN_21, OR_PIN_14, OR_PIN_15},
#endif
};
#else // end esp32 pins, start generic pins
static const int DATA_PIN_SELECT[GAMEPAD_COUNT] = {
5,
#if GAMEPAD_COUNT > 1
7,
#endif
};
//individual data pin for each controller
static const int DATA_PIN[GAMEPAD_COUNT][PIN_COUNT] = {
{1, 0, 2, 3, 4, 6},
#if GAMEPAD_COUNT > 1
{18, 19, 20, 21, 14, 15},
#endif
};
#endif // esp32 vs generic pins
#endif // CODE_PLATFORM
const byte SC_CYCLE_DELAY = 10; // Delay (µs) between setting the select pin and reading the button pins

View File

@ -6,46 +6,25 @@
#endif
#define BUTTON_COUNT 12 // SNES has 12, NES only has 8
#include "pins.h"
//shared pins between all controllers
#if defined(ARDUINO_ARCH_ESP32)
// ESP32
static const int LATCH_PIN = 2; // brown
static const int CLOCK_PIN = 4; // white
static const int LATCH_PIN = OR_PIN_2; // brown
static const int CLOCK_PIN = OR_PIN_3; // white
//individual data pin for each controller
static const int DATA_PIN[GAMEPAD_COUNT] = {
26,
OR_PIN_18,
#if GAMEPAD_COUNT > 1
25,
OR_PIN_19,
#endif
#if GAMEPAD_COUNT > 2
33,
OR_PIN_20,
#endif
#if GAMEPAD_COUNT > 3
32,
OR_PIN_21,
#endif
};
#else
// micro
static const int LATCH_PIN = 2; // brown
static const int CLOCK_PIN = 3; // white
//individual data pin for each controller
static const int DATA_PIN[GAMEPAD_COUNT] = {
18,
#if GAMEPAD_COUNT > 1
19,
#endif
#if GAMEPAD_COUNT > 2
20,
#endif
#if GAMEPAD_COUNT > 3
21,
#endif
};
#endif
// power red, ground black
//#define DEBUG

View File

@ -13,7 +13,9 @@
#include "../common.h"
RF24 radio(7, 8); // CE, CSN
#include "../../pins.h"
RF24 radio(OR_PIN_7, OR_PIN_8); // CE, CSN
const byte address[13] = "OpenRetroPad";
class RadioGamepad : public AbstractGamepad {

63
src/pins.h Normal file
View File

@ -0,0 +1,63 @@
// this let's me keep the db-25 pin mapping naming the same across all inputs/outputs
#ifndef OR_PINS_H
#define OR_PINS_H
#if defined(ARDUINO_ARCH_ESP32)
// esp32
#define OR_PIN_1 15
#define OR_PIN_2 2
#define OR_PIN_3 4
#define OR_PIN_4 16
#define OR_PIN_5 17
#define OR_PIN_6 5
#define OR_PIN_7 18
#define OR_PIN_8 19
#define OR_PIN_9 35
#define OR_PIN_10 3
#define OR_PIN_11 1
//#define OR_PIN_12 22
//#define OR_PIN_13 23
#define OR_PIN_14 12
#define OR_PIN_15 14
#define OR_PIN_16 13
//#define OR_PIN_17 27
#define OR_PIN_18 26
#define OR_PIN_19 25
#define OR_PIN_20 33
#define OR_PIN_21 32
//#define OR_PIN_22 22
//#define OR_PIN_23 23
//#define OR_PIN_24 24
//#define OR_PIN_25 25
#else
// micro
#define OR_PIN_1 1
#define OR_PIN_2 2
#define OR_PIN_3 3
#define OR_PIN_4 4
#define OR_PIN_5 5
#define OR_PIN_6 6
#define OR_PIN_7 7
#define OR_PIN_8 8
#define OR_PIN_9 9
#define OR_PIN_10 10
#define OR_PIN_11 0
//#define OR_PIN_12 12
//#define OR_PIN_13 13
#define OR_PIN_14 14
#define OR_PIN_15 15
#define OR_PIN_16 16
//#define OR_PIN_17 17
#define OR_PIN_18 18
#define OR_PIN_19 19
#define OR_PIN_20 20
#define OR_PIN_21 21
//#define OR_PIN_22 22
//#define OR_PIN_23 23
//#define OR_PIN_24 24
//#define OR_PIN_25 25
#endif // ARDUINO_ARCH_ESP32
#endif // OR_PINS_H