You've already forked torvalds-GuitarPedal
mirror of
https://github.com/torvalds/GuitarPedal.git
synced 2026-06-07 04:55:36 +00:00
The important one is the i2s decoding and encoding to do the audio interfacing with the TAC5112. But I'm also doing button debouncing and the rotary encoder quadrature decoding in PIO programs. There's also a PIO program for the WS2812 smart LED that I was using at one point. The current board doesn't actually use that, because it didn't fit the form factor, but I should probably go back to it at some point when I do a separate board for the stomp switch and associated LEDs. So right now I'm just doing plain PWM on flat-top 5mm single-color LEDs, but I think the WS2812 might make a comeback some day, so the PIO program for dealing with it remains. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
75 lines
1.4 KiB
Plaintext
75 lines
1.4 KiB
Plaintext
;
|
|
; We use a PIO divisor of 15,000 which means that
|
|
; we run the PIO block at 10kHz
|
|
;
|
|
|
|
.pio_version 1
|
|
.program debounce
|
|
.clock_div 15000
|
|
|
|
.wrap_target
|
|
start:
|
|
wait 0 jmppin [10]
|
|
|
|
; Ok, we've seen the pin go low.
|
|
; Now we need to see a stable value
|
|
newzero:
|
|
set x,31
|
|
Xrepzero:
|
|
set y,31
|
|
Yrepzero:
|
|
jmp pin newone [10]
|
|
jmp y-- Yrepzero
|
|
jmp x-- Xrepzero
|
|
|
|
; We've seen only zeroes for one second: report longpress
|
|
; x is all ones, push it
|
|
mov isr, x
|
|
push block
|
|
|
|
; Now wait for it to be released, and then quietly
|
|
; wait for a new one without sending a new key event
|
|
quietzero:
|
|
wait 1 jmppin [10]
|
|
quietnewone:
|
|
set x,31
|
|
quietrepone:
|
|
jmp pin quietstillone [10]
|
|
jmp quietzero
|
|
quietstillone:
|
|
jmp x-- quietrepone
|
|
jmp start
|
|
|
|
newone:
|
|
set x,31
|
|
repone:
|
|
jmp pin stillone [10]
|
|
jmp newzero
|
|
stillone:
|
|
jmp x-- repone
|
|
|
|
; We've seen only ones for 30ms: report shortpress
|
|
; x is all ones, !x is zero
|
|
mov isr, !x
|
|
push block
|
|
.wrap
|
|
|
|
% c-sdk {
|
|
static inline void debounce_program_init(PIO pio, uint sm, uint offset, uint pin)
|
|
{
|
|
pio_sm_config c = debounce_program_get_default_config(offset);
|
|
|
|
// Initialize the pin to be the PIO jmp pin
|
|
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false);
|
|
sm_config_set_jmp_pin(&c, pin);
|
|
|
|
// Load and run the program
|
|
pio_sm_init(pio, sm, offset, &c);
|
|
pio_sm_set_enabled(pio, sm, true);
|
|
|
|
pio_set_irq0_source_enabled(pio,
|
|
pio_get_rx_fifo_not_empty_interrupt_source(sm),
|
|
true);
|
|
}
|
|
%}
|