From e5616d71606eeaad74191c5318d41240a37a5860 Mon Sep 17 00:00:00 2001 From: Ferdinand Silva Date: Thu, 27 Jan 2022 19:08:51 +0800 Subject: [PATCH 1/3] added GPIO input support --- components/nofrendo-esp32/Kconfig.projbuild | 53 ++++++++- components/nofrendo-esp32/psxcontroller.c | 120 +++++++++++++++++++- components/nofrendo-esp32/psxcontroller.h | 1 + sdkconfig | 15 +++ sdkconfig.old | 16 ++- 5 files changed, 199 insertions(+), 6 deletions(-) diff --git a/components/nofrendo-esp32/Kconfig.projbuild b/components/nofrendo-esp32/Kconfig.projbuild index 743a74b..fb3fed0 100644 --- a/components/nofrendo-esp32/Kconfig.projbuild +++ b/components/nofrendo-esp32/Kconfig.projbuild @@ -141,10 +141,61 @@ config SOUND_ENA config HW_PSX_ENA bool "Enable PSX controller input" - default y + default n help If you connect a PSX/PS2 controller to the following GPIOs, you can control the NES. +config HW_GPIO_ENA + bool "Enable GPIO controller input" + default n + +config HW_GPIO_UP + int "Up Control" + depends on HW_GPIO_ENA + range 1 39 + default 3 + +config HW_GPIO_DOWN + int "Down Control" + depends on HW_GPIO_ENA + range 1 39 + default 1 + +config HW_GPIO_RIGHT + int "Right Control" + depends on HW_GPIO_ENA + range 1 39 + default 16 + +config HW_GPIO_LEFT + int "Left Control" + depends on HW_GPIO_ENA + range 1 39 + default 17 + +config HW_GPIO_A + int "A Control" + depends on HW_GPIO_ENA + range 1 39 + default 5 + +config HW_GPIO_B + int "B Control" + depends on HW_GPIO_ENA + range 1 39 + default 2 + +config HW_GPIO_SELECT + int "Select Control" + depends on HW_GPIO_ENA + range 1 39 + default 37 + +config HW_GPIO_START + int "Start Control" + depends on HW_GPIO_ENA + range 1 39 + default 38 config HW_PSX_CLK int "PSX controller CLK GPIO pin" diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c index 457aea4..7aabc27 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -25,15 +25,30 @@ #include "sdkconfig.h" #include "i2c_keyboard.h" +#define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") + +void initGPIO(int gpioNo){ + gpio_set_direction(gpioNo, GPIO_MODE_INPUT); + gpio_pulldown_en(gpioNo); +} + +#if CONFIG_HW_PSX_ENA || CONFIG_HW_GPIO_ENA + +#ifndef CONFIG_HW_GPIO_ENA + #define PSX_CLK CONFIG_HW_PSX_CLK #define PSX_DAT CONFIG_HW_PSX_DAT #define PSX_ATT CONFIG_HW_PSX_ATT #define PSX_CMD CONFIG_HW_PSX_CMD -#define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") +#else +#define PSX_CLK 14 +#define PSX_DAT 27 +#define PSX_ATT 16 +#define PSX_CMD 2 -#if CONFIG_HW_PSX_ENA +#endif /* Sends and receives a byte from/to the PSX controller using SPI */ static int psxSendRecv(int send) { @@ -75,22 +90,117 @@ static void psxDone() { GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, (1< Date: Fri, 28 Jan 2022 15:17:15 +0800 Subject: [PATCH 2/3] code cleanup --- components/nofrendo-esp32/psxcontroller.c | 55 +++++------------------ 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c index 7aabc27..77bcc6d 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -26,6 +26,16 @@ #include "i2c_keyboard.h" #define DELAY() asm("nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;nop; nop; nop; nop;") +#define bit_joypad1_select 0 +#define bit_joypad1_start 3 +#define bit_joypad1_up 4 +#define bit_joypad1_right 5 +#define bit_joypad1_down 6 +#define bit_joypad1_left 7 +#define bit_soft_reset 12 +#define bit_joypad1_a 13 +#define bit_joypad1_b 14 +#define bit_hard_reset 15 void initGPIO(int gpioNo){ gpio_set_direction(gpioNo, GPIO_MODE_INPUT); @@ -90,38 +100,6 @@ static void psxDone() { GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, (1< Date: Mon, 7 Feb 2022 13:46:12 +0800 Subject: [PATCH 3/3] fix bug --- components/nofrendo-esp32/psxcontroller.c | 59 ++++++----------------- sdkconfig | 16 +++--- sdkconfig.old | 16 +++--- 3 files changed, 32 insertions(+), 59 deletions(-) diff --git a/components/nofrendo-esp32/psxcontroller.c b/components/nofrendo-esp32/psxcontroller.c index 77bcc6d..97d9dfe 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -112,56 +112,29 @@ int psxReadInput() { psxDone(); b2b1 = (b2<<8)|b1; #else - uint16_t retval = 0; - if (gpio_get_level(CONFIG_HW_GPIO_UP) == 1) { - retval |= 1<