From c248d5dd7862ae64584f7b7a9ac683b9166e4d47 Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 25 Aug 2025 23:57:04 +0200 Subject: [PATCH] add switch for input --- src/common.h | 9 ++++++--- src/input.cpp | 19 ++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/common.h b/src/common.h index 195e5e6..4866d6c 100644 --- a/src/common.h +++ b/src/common.h @@ -7,9 +7,12 @@ #include #include "gb.h" +#define INPUT_GPIO 1 +#define INPUT_PCF8574 2 + /* Joypad Pins. */ -#define USE_JOYPAD_I2C_IO_EXPANDER -#ifdef USE_JOYPAD_I2C_IO_EXPANDER +//#define USE_JOYPAD_I2C_IO_EXPANDER +#if ENABLE_INPUT == INPUT_PCF8574 // Use PCF8574 for Joypad. Only required if an LCD with 16-bit parallel bus is used, // as Pico does not have enough pins for all peripherals. With 8-bit parallel or SPI LCDs this should not be necessary. #define PCF8574_ADDR 0x20 @@ -24,7 +27,7 @@ #define PIN_B 4 #define PIN_SELECT 6 #define PIN_START 7 -#else +#elif ENABLE_INPUT == INPUT_GPIO // Use GPIOs directly on Pico for Joypad #define PIN_UP 2 #define PIN_DOWN 3 diff --git a/src/input.cpp b/src/input.cpp index 72524a1..5681943 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -42,7 +42,7 @@ static struct unsigned down : 1; } prev_joypad_bits; -#ifdef USE_JOYPAD_I2C_IO_EXPANDER +#if ENABLE_INPUT == INPUT_PCF8574 static PCF8574 pcf8574(PCF8574_ADDR, PCF8574_SDA, PCF8574_SCL); @@ -63,7 +63,7 @@ bool readJoypad(uint8_t pin) { return pcf8574.digitalRead(pin); } -#else +#elif ENABLE_INPUT == INPUT_GPIO static void initJoypadGpios() { gpio_set_function(PIN_UP, GPIO_FUNC_SIO); @@ -102,9 +102,9 @@ bool readJoypad(uint8_t pin) { void initJoypad() { Serial.println("Init Joypad IOs ..."); -#ifdef USE_JOYPAD_I2C_IO_EXPANDER +#if ENABLE_INPUT == INPUT_PCF8574 initJoypadI2CIoExpander(); -#else +#elif ENABLE_INPUT == INPUT_GPIO initJoypadGpios(); #endif Serial.println("Joypad IOs initialized"); @@ -231,15 +231,7 @@ void handleJoypad() { prev_joypad_bits.select = gb.direct.joypad_bits.select; prev_joypad_bits.start = gb.direct.joypad_bits.start; - #if 0 - Serial.printf("pins:\n"); - for (int i = 0; i < 8; ++i) { - int in = pcf8574.digitalRead(i); - Serial.printf(" %d", in); - } - Serial.printf("\n"); - #endif - +#if ENABLE_INPUT != 0 gb.direct.joypad_bits.up = readJoypad(PIN_UP); gb.direct.joypad_bits.down = readJoypad(PIN_DOWN); gb.direct.joypad_bits.left = readJoypad(PIN_LEFT); @@ -248,6 +240,7 @@ void handleJoypad() { gb.direct.joypad_bits.b = readJoypad(PIN_B); gb.direct.joypad_bits.select = readJoypad(PIN_SELECT); gb.direct.joypad_bits.start = readJoypad(PIN_START); +#endif #if 0 if (!gb.direct.joypad_bits.up) {