You've already forked ivan-torvalds-GuitarPedal
forked from AllSpiceMirrors/torvalds-GuitarPedal
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>