Match BMC protocol: 5µs delays, read DI before CLK, WS2812+RGB, power limit
This commit is contained in:
+20
-21
@@ -1,7 +1,7 @@
|
||||
#include "pixel_stomp_mux.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#define ROXMUX_DELAY 2
|
||||
#define BMC_MUX_74HC165_DELAY 5
|
||||
|
||||
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),
|
||||
@@ -18,7 +18,8 @@ void PixelStompMux::begin() {
|
||||
|
||||
delay(100);
|
||||
|
||||
FastLED.addLeds<WS2812B, 9, GRB>(leds, NUM_LEDS);
|
||||
FastLED.addLeds<WS2812, 9, RGB>(leds, NUM_LEDS);
|
||||
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
|
||||
FastLED.setBrightness(128);
|
||||
fill_solid(leds, NUM_LEDS, CRGB::Black);
|
||||
FastLED.show();
|
||||
@@ -30,20 +31,20 @@ void PixelStompMux::begin() {
|
||||
|
||||
uint8_t PixelStompMux::read_buttons() {
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(ROXMUX_DELAY);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
|
||||
digitalWrite(pin_ld, LOW);
|
||||
delayMicroseconds(ROXMUX_DELAY);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
digitalWrite(pin_ld, HIGH);
|
||||
delayMicroseconds(ROXMUX_DELAY);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
|
||||
uint8_t data = 0;
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(ROXMUX_DELAY);
|
||||
bitWrite(data, i, digitalRead(pin_di));
|
||||
digitalWrite(pin_clk, HIGH);
|
||||
delayMicroseconds(ROXMUX_DELAY);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
}
|
||||
|
||||
last_button_state = data;
|
||||
@@ -90,33 +91,31 @@ void PixelStompMux::dump() {
|
||||
}
|
||||
|
||||
void PixelStompMux::probe() {
|
||||
Serial.println("[MUX] === Hardware Probe ===");
|
||||
Serial.println("[MUX] === Hardware Probe (BMC Protocol) ===");
|
||||
|
||||
for (int round = 0; round < 5; round++) {
|
||||
Serial.printf("--- Round %d ---\n", round);
|
||||
|
||||
digitalWrite(pin_clk, LOW);
|
||||
digitalWrite(pin_ld, HIGH);
|
||||
delayMicroseconds(10);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
|
||||
Serial.printf(" Before latch: DI=%d\n", digitalRead(pin_di));
|
||||
|
||||
digitalWrite(pin_ld, LOW);
|
||||
delayMicroseconds(10);
|
||||
Serial.printf(" LD=LOW: DI=%d\n", digitalRead(pin_di));
|
||||
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
digitalWrite(pin_ld, HIGH);
|
||||
delayMicroseconds(10);
|
||||
Serial.printf(" LD=HIGH: DI=%d\n", digitalRead(pin_di));
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
|
||||
Serial.printf(" After latch: DI=%d\n", digitalRead(pin_di));
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(5);
|
||||
bool bit_before = digitalRead(pin_di);
|
||||
bool bit_val = digitalRead(pin_di);
|
||||
digitalWrite(pin_clk, HIGH);
|
||||
delayMicroseconds(5);
|
||||
bool bit_after = digitalRead(pin_di);
|
||||
Serial.printf(" CLK %2d: before=%d after=%d\n", i, bit_before, bit_after);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
digitalWrite(pin_clk, LOW);
|
||||
delayMicroseconds(BMC_MUX_74HC165_DELAY);
|
||||
Serial.printf(" CLK %2d: DI=%d\n", i, bit_val);
|
||||
}
|
||||
|
||||
delay(500);
|
||||
|
||||
Reference in New Issue
Block a user