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..97d9dfe 100644 --- a/components/nofrendo-esp32/psxcontroller.c +++ b/components/nofrendo-esp32/psxcontroller.c @@ -25,15 +25,40 @@ #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;") +#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); + 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 +100,58 @@ static void psxDone() { GPIO_REG_WRITE(GPIO_OUT_W1TS_REG, (1<