Add PixelStomp MUX driver (DAT=9, LD=10, CLK=11, DI=12)

- New PixelStompMux class with shift register read/write
- Read 10 buttons via DI (active LOW)
- Drive 10 LEDs via DAT (shift out + latch)
- LED startup animation uses MUX
- Switch polling reads from MUX shift register
- MUX instance shared between switch and LED drivers
This commit is contained in:
2026-06-23 13:27:24 +00:00
parent c94be67384
commit 102cae9d91
7 changed files with 194 additions and 34 deletions
+11 -18
View File
@@ -1,14 +1,13 @@
#include "switch_stub.h"
#include "pixel_stomp_mux.h"
#include <Arduino.h>
static const uint8_t SWITCH_PINS[10] = {
2, 3, 4, 5, 6, 7, 15, 16, 17, 18
};
static PixelStompMux* mux_ptr = nullptr;
DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
for (int i = 0; i < NUM_SWITCHES; i++) {
switch_states[i].id = i;
switch_states[i].gpio_pin = SWITCH_PINS[i];
switch_states[i].gpio_pin = 0;
switch_states[i].current_state = false;
switch_states[i].previous_state = false;
switch_states[i].last_change_time = 0;
@@ -17,24 +16,21 @@ DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
}
void DefaultSwitchStub::begin() {
for (int i = 0; i < NUM_SWITCHES; i++) {
pinMode(switch_states[i].gpio_pin, INPUT_PULLUP);
}
Serial.println("[SW] Using PixelStomp MUX for button input");
initialized = true;
Serial.printf("[SW] %d switches on GPIOs: ", NUM_SWITCHES);
for (int i = 0; i < NUM_SWITCHES; i++) {
Serial.printf("%d ", switch_states[i].gpio_pin);
}
Serial.println();
}
void DefaultSwitchStub::set_mux(PixelStompMux* mux) {
mux_ptr = mux;
}
bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
if (!initialized || switch_id >= NUM_SWITCHES) {
if (!initialized || switch_id >= NUM_SWITCHES || !mux_ptr) {
return false;
}
SwitchState& sw = switch_states[switch_id];
bool raw = (digitalRead(sw.gpio_pin) == LOW);
bool raw = mux_ptr->is_button_pressed(switch_id);
uint32_t now = millis();
if (raw != sw.previous_state) {
@@ -54,10 +50,7 @@ bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
void DefaultSwitchStub::configure_switch(uint8_t switch_id, uint8_t gpio_pin) {
if (switch_id >= NUM_SWITCHES) return;
switch_states[switch_id].gpio_pin = gpio_pin;
if (initialized) {
pinMode(gpio_pin, INPUT_PULLUP);
}
Serial.printf("[SW] Switch %d -> GPIO %d\n", switch_id, gpio_pin);
Serial.printf("[SW] Switch %d remapped to GPIO %d\n", switch_id, gpio_pin);
}
void DefaultSwitchStub::set_debounce_time(uint32_t time_ms) {