add switch for input

This commit is contained in:
Tobias Gunkel
2025-08-25 23:57:04 +02:00
parent b3b74fd922
commit c248d5dd78
2 changed files with 12 additions and 16 deletions
+6 -3
View File
@@ -7,9 +7,12 @@
#include <SdFat.h>
#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
+6 -13
View File
@@ -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) {