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:
+55
-1
@@ -27,6 +27,52 @@ void midi_task(void* parameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_serial_command(const String& cmd) {
|
||||||
|
if (cmd == "dump" || cmd == "d") {
|
||||||
|
mux.dump();
|
||||||
|
} else if (cmd == "ledon") {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
mux.set_led(i, true);
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
Serial.println("[CMD] All LEDs ON");
|
||||||
|
} else if (cmd == "ledoff") {
|
||||||
|
mux.clear_all();
|
||||||
|
} else if (cmd == "ledtest") {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
mux.set_led(i, true);
|
||||||
|
delay(200);
|
||||||
|
mux.set_led(i, false);
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
Serial.println("[CMD] LED test complete");
|
||||||
|
} else if (cmd == "read") {
|
||||||
|
uint16_t raw = mux.read_buttons();
|
||||||
|
Serial.printf("[CMD] Raw button state: 0x%03X (binary: ", raw);
|
||||||
|
for (int i = 9; i >= 0; i--) {
|
||||||
|
Serial.print((raw >> i) & 1);
|
||||||
|
}
|
||||||
|
Serial.println(")");
|
||||||
|
} else if (cmd == "probe") {
|
||||||
|
Serial.println("[CMD] Probing MUX pins...");
|
||||||
|
Serial.printf(" DAT (GPIO %d) = %d\n", 9, digitalRead(9));
|
||||||
|
Serial.printf(" LD (GPIO %d) = %d\n", 10, digitalRead(10));
|
||||||
|
Serial.printf(" CLK (GPIO %d) = %d\n", 11, digitalRead(11));
|
||||||
|
Serial.printf(" DI (GPIO %d) = %d\n", 12, digitalRead(12));
|
||||||
|
|
||||||
|
Serial.println(" Toggling LD pin...");
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
digitalWrite(10, HIGH);
|
||||||
|
delayMicroseconds(100);
|
||||||
|
digitalWrite(10, LOW);
|
||||||
|
delayMicroseconds(100);
|
||||||
|
}
|
||||||
|
Serial.printf(" DI after LD toggle: %d\n", digitalRead(12));
|
||||||
|
} else {
|
||||||
|
Serial.println("[CMD] Commands: dump, ledon, ledoff, ledtest, read, probe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
@@ -66,12 +112,20 @@ void setup() {
|
|||||||
|
|
||||||
Serial.println("=================================");
|
Serial.println("=================================");
|
||||||
Serial.println(" All systems ready");
|
Serial.println(" All systems ready");
|
||||||
Serial.println(" Waiting for USB MIDI host...");
|
Serial.println(" Type 'help' for diagnostics");
|
||||||
Serial.println("=================================");
|
Serial.println("=================================");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
controller.update();
|
controller.update();
|
||||||
|
|
||||||
|
if (Serial.available()) {
|
||||||
|
String cmd = Serial.readStringUntil('\n');
|
||||||
|
cmd.trim();
|
||||||
|
cmd.toLowerCase();
|
||||||
|
handle_serial_command(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-11
@@ -1,8 +1,6 @@
|
|||||||
#include "pixel_stomp_mux.h"
|
#include "pixel_stomp_mux.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
static const char* TAG = "MUX";
|
|
||||||
|
|
||||||
PixelStompMux::PixelStompMux(uint8_t dat, uint8_t ld, uint8_t clk, uint8_t di)
|
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),
|
: pin_dat(dat), pin_ld(ld), pin_clk(clk), pin_di(di),
|
||||||
last_button_state(0), current_led_state(0) {
|
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",
|
Serial.printf("[MUX] Init DAT=%d LD=%d CLK=%d DI=%d\n",
|
||||||
pin_dat, pin_ld, pin_clk, pin_di);
|
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() {
|
uint16_t PixelStompMux::read_buttons() {
|
||||||
pulse_pin(pin_ld, HIGH);
|
pulse_pin(pin_ld, HIGH);
|
||||||
delayMicroseconds(5);
|
delayMicroseconds(10);
|
||||||
pulse_pin(pin_ld, LOW);
|
pulse_pin(pin_ld, LOW);
|
||||||
delayMicroseconds(5);
|
delayMicroseconds(10);
|
||||||
|
|
||||||
uint16_t state = shift_in(NUM_INPUTS);
|
uint16_t state = shift_in(NUM_INPUTS);
|
||||||
last_button_state = state;
|
last_button_state = state;
|
||||||
@@ -44,8 +60,9 @@ bool PixelStompMux::is_button_pressed(uint8_t index) {
|
|||||||
void PixelStompMux::write_leds(uint16_t led_state) {
|
void PixelStompMux::write_leds(uint16_t led_state) {
|
||||||
current_led_state = led_state;
|
current_led_state = led_state;
|
||||||
shift_out(led_state, NUM_OUTPUTS);
|
shift_out(led_state, NUM_OUTPUTS);
|
||||||
|
|
||||||
pulse_pin(pin_ld, HIGH);
|
pulse_pin(pin_ld, HIGH);
|
||||||
delayMicroseconds(5);
|
delayMicroseconds(10);
|
||||||
pulse_pin(pin_ld, LOW);
|
pulse_pin(pin_ld, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,19 +90,20 @@ void PixelStompMux::dump() {
|
|||||||
for (int i = 0; i < NUM_INPUTS; i++) {
|
for (int i = 0; i < NUM_INPUTS; i++) {
|
||||||
bool pressed = !(buttons & (1 << i));
|
bool pressed = !(buttons & (1 << i));
|
||||||
bool led_on = current_led_state & (1 << i);
|
bool led_on = current_led_state & (1 << i);
|
||||||
if (pressed || led_on) {
|
|
||||||
Serial.printf(" [%d] Button:%s LED:%s\n", i,
|
Serial.printf(" [%d] Button:%s LED:%s\n", i,
|
||||||
pressed ? "PRESS" : "off",
|
pressed ? "PRESS" : "off",
|
||||||
led_on ? "ON" : "off");
|
led_on ? "ON" : "off");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelStompMux::shift_out(uint16_t data, uint8_t bits) {
|
void PixelStompMux::shift_out(uint16_t data, uint8_t bits) {
|
||||||
for (int i = bits - 1; i >= 0; i--) {
|
for (int i = bits - 1; i >= 0; i--) {
|
||||||
digitalWrite(pin_dat, (data >> i) & 1);
|
digitalWrite(pin_dat, (data >> i) & 1);
|
||||||
pulse_pin(pin_clk, HIGH);
|
delayMicroseconds(1);
|
||||||
pulse_pin(pin_clk, LOW);
|
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) {
|
if (bit) {
|
||||||
data |= (1 << i);
|
data |= (1 << i);
|
||||||
}
|
}
|
||||||
pulse_pin(pin_clk, HIGH);
|
digitalWrite(pin_clk, HIGH);
|
||||||
pulse_pin(pin_clk, LOW);
|
delayMicroseconds(1);
|
||||||
|
digitalWrite(pin_clk, LOW);
|
||||||
|
delayMicroseconds(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
Reference in New Issue
Block a user