Files
Linus Torvalds 6e13afbfd6 Name the switches and the rotary for what they do
The pedal has one rotary encoder - and most boards do not even populate
that - one stomp switch, and one LED.  The code still described a board
with two of each, in a numbering that had never survived a generation:
GPIO_SW1 was the first rotary's shaft, GPIO_SW3 was the first stomp,
and SW2 and SW4 were a second rotary and second stomp that no longer
exist.  Nothing in those names said so, which is how a pile of bare
numbers ended up spread across three files with nobody able to check
them.

So name pins for their job - LED_GPIO, ROTARY_A/B/SW_GPIO, STOMP_GPIO -
and give the switches an enum instead of an index.  The switch id is
both the bit in 'switch_val' and the PIO state machine number, and
switch_gpio[] is now the one place that ties an id to a pin, walked in
order by init_sw_pins(), so a switch cannot quietly end up reading
somebody else's pin.  switch_pressed(2) becomes
switch_pressed(STOMP_SWITCH), which can be read and, more to the point,
can be got wrong visibly.

That accounts for four bindings that turn out to have been aimed at
hardware that is not there:

 - "hold both switches" tested SW1 and SW2 with gpio_get().  SW2 is
   unpopulated and pulled up, so it read high and the condition was
   never true.  Nothing could reach the reset-everything path behind
   it, including the one that left the settings pseudo-effect unable
   to reinitialise itself.

 - switch_pressed(4) tested a bit that no state machine ever set.  Bits
   are named now, so there is no fifth switch to name.

 - "save effect state to EEPROM" on a long press, and "enable/disable
   the current effect" on a press, were both bound to SW2/SW4.  Neither
   has been reachable since those switches went.  save_effect_state()
   and find_effect_slot() had no other callers and go too; saving a
   scene over SysEx uses save_scene(), which never touched them.

 - the second encoder picked which effect was being edited.  That is
   done over MIDI now, so switch_effect() goes and update_ui() reads
   current_midi_effect_idx directly.

What is left is what the hardware can actually do: turn the encoder to
change a value, hold it and turn to pick a different pot, press it to
step to the next pot, tap the stomp to bypass, hold the stomp for the
tuner.

The rotary loses its two-element arrays and its second state machine
along the way, and gains an assert that the quadrature pair stays
adjacent, which the PIO program has always required and nothing said.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-07-28 15:46:23 -07:00

69 lines
1.9 KiB
C

//
// Board GPIO pin definitions
//
// Named for what the pin does, not for the order someone happened to
// wire it up in. The board has been through several generations and
// the old numbering survived none of them: "SW1" was the first rotary's
// shaft switch, "SW3" was the first stomp, and SW2/SW4 were a second
// rotary and a second stomp that no longer exist. None of that was
// visible in the names.
//
// The pedal as it stands has one rotary encoder - and most boards do
// not even populate that - one stomp switch, and one LED.
//
// The one LED. Plain PWM brightness; see set_led().
#define LED_GPIO 0
//
// The one rotary encoder: A and B are the quadrature pair, SW is the
// shaft pressing down.
//
#define ROTARY_A_GPIO 6
#define ROTARY_B_GPIO 7
#define ROTARY_SW_GPIO 12
// The one stomp switch. Internal pull-up, closing to GND.
#define STOMP_GPIO 13
#define I2S_BCLK 8
#define I2S_FSYNC 9
#define I2S_DIN 10
#define I2S_DOUT 11
// Hardware MIDI TRS, on the pins the second rotary encoder used to have
#if MIDI_HW
#define MIDI_OUT 26
#define MIDI_IN 27
#define MIDI_UART uart1
#endif
#define I2C0_SDA 4
#define I2C0_SCL 5
#define I2C1_SDA 2
#define I2C1_SCL 3
#define MC24Cxx_I2C i2c0, 0x50
#define TAC5112_I2C i2c0, 0x51
#define SH1106_I2C i2c1, 0x3c
//
// Not all boards have this. It is the next generation's LED - a smart
// one where there is currently a plain one - and it wants GPIO1, which
// is free precisely because the second LED that used to be there is
// gone.
//
#if 0
#define WS2812_GPIO 1
#endif
//
// Pins that used to be something and no longer are, recorded so nobody
// has to go through the git history to find out why there are gaps:
//
// GPIO 1 second LED (now WS2812_GPIO, above)
// GPIO 26/27 second rotary's quadrature pair (now hardware MIDI)
// GPIO 28 second rotary's shaft switch
// GPIO 29 second stomp switch
//