mirror of
https://github.com/speedypotato/Pico-Game-Controller.git
synced 2026-10-06 21:58:02 +03:00
Merge pull request #11 from speedypotato/feature/encoder_pio_debounce
Added clkdiv debounce to encoders.pio
This commit is contained in:
@@ -9,7 +9,7 @@ Currently working/fixed:
|
||||
- HID LEDs with Reactive LED fallback
|
||||
- sdvx/iidx spoof - Tested on EAC
|
||||
- 1000hz polling
|
||||
- Reversable Encoders
|
||||
- Reversable Encoders with debouncing
|
||||
- Switch and LED pins are now staggered for easier wiring
|
||||
- Fix 0-~71% encoder rollover in gamepad mode, uint32 max val isn't divisible evenly by ppr\*4 for joystick - thanks friends
|
||||
|
||||
@@ -39,3 +39,4 @@ Thanks to:
|
||||
- https://github.com/Drewol/rp2040-gamecon for usb gamepad descriptor info.
|
||||
- https://github.com/veroxzik/arduino-konami-spoof for konami spoof usb descriptor info.
|
||||
- https://github.com/veroxzik/roxy-firmware for nkro descriptor and logic info.
|
||||
- KyubiFox for bringing clkdiv to my attention for encoder debouncing
|
||||
Binary file not shown.
+5
-1
@@ -34,7 +34,7 @@ send:
|
||||
.wrap
|
||||
|
||||
% c-sdk {
|
||||
static inline void encoders_program_init(PIO pio, uint sm, uint offset, uint pin) {
|
||||
static inline void encoders_program_init(PIO pio, uint sm, uint offset, uint pin, bool debounce) {
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false);
|
||||
pio_gpio_init(pio, pin);
|
||||
pio_gpio_init(pio, pin+1);
|
||||
@@ -46,6 +46,10 @@ static inline void encoders_program_init(PIO pio, uint sm, uint offset, uint pin
|
||||
sm_config_set_jmp_pin(&c, pin +1);
|
||||
// Shift to left, autopull disabled
|
||||
sm_config_set_in_shift(&c, false, false, 2);
|
||||
|
||||
// Debounce via reduced clock
|
||||
if (debounce)
|
||||
sm_config_set_clkdiv(&c, 5000);
|
||||
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
pio_sm_set_enabled(pio, sm, true);
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
#include "tusb.h"
|
||||
#include "usb_descriptors.h"
|
||||
|
||||
#define SW_GPIO_SIZE 11 // Number of switches
|
||||
#define ENC_GPIO_SIZE 2 // Number of encoders
|
||||
#define ENC_PPR 600 // Encoder PPR
|
||||
#define SW_GPIO_SIZE 11 // Number of switches
|
||||
#define ENC_GPIO_SIZE 2 // Number of encoders
|
||||
#define ENC_PPR 600 // Encoder PPR
|
||||
#define ENC_DEBOUNCE true // Encoder Debouncing
|
||||
|
||||
#define ENC_PULSE (ENC_PPR * 4) // 4 pulses per PPR
|
||||
#define ENC_ROLLOVER (ENC_PULSE * 2) // Delta Rollover threshold
|
||||
#define REACTIVE_TIMEOUT_MAX 100000 // Cycles before HID falls back to reactive
|
||||
@@ -270,7 +272,7 @@ void init() {
|
||||
enc_val[i] = 0;
|
||||
prev_enc_val[i] = 0;
|
||||
cur_enc_val[i] = 0;
|
||||
encoders_program_init(pio, i, offset, ENC_GPIO[i]);
|
||||
encoders_program_init(pio, i, offset, ENC_GPIO[i], ENC_DEBOUNCE);
|
||||
|
||||
dma_channel_config c = dma_channel_get_default_config(i);
|
||||
channel_config_set_read_increment(&c, false);
|
||||
|
||||
Reference in New Issue
Block a user