Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debouncing #171

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions components/retro-go/rg_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions components/retro-go/targets/byteboi-rev1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions components/retro-go/targets/byteboi-rev1/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)