Add MUX diagnostic commands and GPIO probe
Serial commands: - dump: show button and LED state - ledon/ledoff: toggle all LEDs - ledtest: sequential LED test - read: raw button read - probe: check pin states and test LD toggle
This commit is contained in:
+34
-14
@@ -1,8 +1,6 @@
|
||||
#include "pixel_stomp_mux.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
static const char* TAG = "MUX";
|
||||
|
||||
PixelStompMux::PixelStompMux(uint8_t dat, uint8_t ld, uint8_t clk, uint8_t di)
|
||||
: pin_dat(dat), pin_ld(ld), pin_clk(clk), pin_di(di),
|
||||
last_button_state(0), current_led_state(0) {
|
||||
@@ -20,13 +18,31 @@ void PixelStompMux::begin() {
|
||||
|
||||
Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n",
|
||||
pin_dat, pin_ld, pin_clk, pin_di);
|
||||
|
||||
Serial.println("[MUX] GPIO probe:");
|
||||
Serial.printf(" DI (GPIO %d) reads: %d (should be 1 with pullup)\n",
|
||||
pin_di, digitalRead(pin_di));
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
digitalWrite(pin_clk, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(10);
|
||||
}
|
||||
Serial.printf(" DI after 3 CLK pulses: %d\n", digitalRead(pin_di));
|
||||
|
||||
digitalWrite(pin_ld, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(pin_ld, LOW);
|
||||
delayMicroseconds(10);
|
||||
Serial.printf(" DI after LD pulse: %d\n", digitalRead(pin_di));
|
||||
}
|
||||
|
||||
uint16_t PixelStompMux::read_buttons() {
|
||||
pulse_pin(pin_ld, HIGH);
|
||||
delayMicroseconds(5);
|
||||
delayMicroseconds(10);
|
||||
pulse_pin(pin_ld, LOW);
|
||||
delayMicroseconds(5);
|
||||
delayMicroseconds(10);
|
||||
|
||||
uint16_t state = shift_in(NUM_INPUTS);
|
||||
last_button_state = state;
|
||||
@@ -44,8 +60,9 @@ bool PixelStompMux::is_button_pressed(uint8_t index) {
|
||||
void PixelStompMux::write_leds(uint16_t led_state) {
|
||||
current_led_state = led_state;
|
||||
shift_out(led_state, NUM_OUTPUTS);
|
||||
|
||||
pulse_pin(pin_ld, HIGH);
|
||||
delayMicroseconds(5);
|
||||
delayMicroseconds(10);
|
||||
pulse_pin(pin_ld, LOW);
|
||||
}
|
||||
|
||||
@@ -73,19 +90,20 @@ void PixelStompMux::dump() {
|
||||
for (int i = 0; i < NUM_INPUTS; i++) {
|
||||
bool pressed = !(buttons & (1 << i));
|
||||
bool led_on = current_led_state & (1 << i);
|
||||
if (pressed || led_on) {
|
||||
Serial.printf(" [%d] Button:%s LED:%s\n", i,
|
||||
pressed ? "PRESS" : "off",
|
||||
led_on ? "ON" : "off");
|
||||
}
|
||||
Serial.printf(" [%d] Button:%s LED:%s\n", i,
|
||||
pressed ? "PRESS" : "off",
|
||||
led_on ? "ON" : "off");
|
||||
}
|
||||
}
|
||||
|
||||
void PixelStompMux::shift_out(uint16_t data, uint8_t bits) {
|
||||
for (int i = bits - 1; i >= 0; i--) {
|
||||
digitalWrite(pin_dat, (data >> i) & 1);
|
||||
pulse_pin(pin_clk, HIGH);
|
||||
pulse_pin(pin_clk, LOW);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(pin_clk, HIGH);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +115,10 @@ uint16_t PixelStompMux::shift_in(uint8_t bits) {
|
||||
if (bit) {
|
||||
data |= (1 << i);
|
||||
}
|
||||
pulse_pin(pin_clk, HIGH);
|
||||
pulse_pin(pin_clk, LOW);
|
||||
digitalWrite(pin_clk, HIGH);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user