diff --git a/components/retro-go/rg_input.c b/components/retro-go/rg_input.c index d247d1552..7f93acbd1 100644 --- a/components/retro-go/rg_input.c +++ b/components/retro-go/rg_input.c @@ -196,7 +196,11 @@ bool rg_input_read_gamepad_raw(uint32_t *out) static void input_task(void *arg) { +#ifdef RG_GAMEPAD_DEBOUNCE_LEVEL + const uint8_t debounce_level = RG_GAMEPAD_DEBOUNCE_LEVEL; +#else const uint8_t debounce_level = 0x03; +#endif uint8_t debounce[RG_KEY_COUNT]; uint32_t local_gamepad_state = 0; uint32_t state; @@ -211,17 +215,17 @@ static void input_task(void *arg) { for (int i = 0; i < RG_KEY_COUNT; ++i) { + if (((local_gamepad_state >> i) & 1) == 1) { + if ((debounce[i] == debounce_level && ((state >> i) & 1) == 0) || debounce[i] == 0) { + local_gamepad_state &= ~(1 << i); // Released + } + } else { + if ((debounce[i] == 0 && ((state >> i) & 1) == 1) || debounce[i] == debounce_level) { + local_gamepad_state |= (1 << i); // Pressed + } + } debounce[i] = ((debounce[i] << 1) | ((state >> i) & 1)); debounce[i] &= debounce_level; - - if (debounce[i] == debounce_level) // Pressed - { - local_gamepad_state |= (1 << i); - } - else if (debounce[i] == 0x00) // Released - { - local_gamepad_state &= ~(1 << i); - } } gamepad_state = local_gamepad_state; } diff --git a/components/retro-go/targets/byteboi-rev1/config.h b/components/retro-go/targets/byteboi-rev1/config.h index 966dd9cc7..12a731e7b 100644 --- a/components/retro-go/targets/byteboi-rev1/config.h +++ b/components/retro-go/targets/byteboi-rev1/config.h @@ -65,6 +65,9 @@ {RG_KEY_OPTION, RG_KEY_UP| RG_KEY_SELECT},\ } +//Try 0x0F or 0x3F with the original switches +#define RG_GAMEPAD_DEBOUNCE_LEVEL 0x03 + // Battery #define RG_BATTERY_DRIVER 1 #define RG_BATTERY_ADC_UNIT ADC_UNIT_1 diff --git a/components/retro-go/targets/byteboi-rev1/docs/README.md b/components/retro-go/targets/byteboi-rev1/docs/README.md index d48c1075e..1f7a72adc 100644 --- a/components/retro-go/targets/byteboi-rev1/docs/README.md +++ b/components/retro-go/targets/byteboi-rev1/docs/README.md @@ -23,6 +23,7 @@ Button mapping: - Really only supports the first hardware revision. The second revision has a different display and the buttons are connected differently, so it will definitely not work at all with this configuration! - No display brightness support (the backlight is connected to the GPIO extender with no PWM support). - Low sound quality due to use of internal 8-bit DAC (especially at low volumes). +- The switches are rather bouncy and somewhat unreliable. I recommend replacing them (e.g. Omron B3F-4050 works very well). Alternatively, you can try to increase the RG_GAMEPAD_DEBOUNCE_LEVEL to 0x0F or 0x3F. # Images ![device.jpg](device.jpg)