Add rmtled: direct RMT WS2812 driver via ESP-IDF API
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/rmt.h>
|
||||
#include <esp_rom_sys.h>
|
||||
#include "midi_transport.h"
|
||||
#include "pixel_stomp_mux.h"
|
||||
@@ -124,6 +125,7 @@ void handle_serial_command(const String& cmd) {
|
||||
Serial.println(" pixel0/pixel1 - single pixel test");
|
||||
Serial.println(" gpiotest - raw GPIO pin diagnostic");
|
||||
Serial.println(" rawled - bit-bang WS2812 (no library)");
|
||||
Serial.println(" rmtled - RMT WS2812 direct (ESP-IDF)");
|
||||
Serial.println(" anim - re-run startup animation from loop");
|
||||
} else if (cmd == "anim") {
|
||||
Serial.println("[CMD] Running animation...");
|
||||
@@ -139,6 +141,55 @@ void handle_serial_command(const String& cmd) {
|
||||
}
|
||||
mux.clear_all();
|
||||
Serial.println("[CMD] Animation done");
|
||||
} else if (cmd == "rmtled") {
|
||||
Serial.println("[CMD] RMT WS2812: pixel 0 = RED on GPIO 9");
|
||||
uint8_t pin = 9;
|
||||
uint8_t grb[] = {0x00, 0xFF, 0x00};
|
||||
rmt_channel_t ch = RMT_CHANNEL_0;
|
||||
|
||||
rmt_config_t cfg = {
|
||||
.rmt_mode = RMT_MODE_TX,
|
||||
.channel = ch,
|
||||
.gpio_num = (gpio_num_t)pin,
|
||||
.clk_div = 8,
|
||||
.mem_block_num = 1,
|
||||
.flags = 0,
|
||||
.tx_config = {
|
||||
.carrier_freq_hz = 38000,
|
||||
.carrier_level = RMT_CARRIER_LEVEL_HIGH,
|
||||
.idle_level = RMT_IDLE_LEVEL_LOW,
|
||||
.carrier_duty_percent = 33,
|
||||
.carrier_en = false,
|
||||
.loop_en = false,
|
||||
.idle_output_en = true,
|
||||
}
|
||||
};
|
||||
rmt_config(&cfg);
|
||||
rmt_driver_install(ch, 0, 0);
|
||||
|
||||
rmt_item32_t items[25];
|
||||
int idx = 0;
|
||||
for (int b = 0; b < 3; b++) {
|
||||
for (int bit = 7; bit >= 0; bit--) {
|
||||
if (grb[b] & (1 << bit)) {
|
||||
items[idx].level0 = 1; items[idx].duration0 = 10;
|
||||
items[idx].level1 = 0; items[idx].duration1 = 10;
|
||||
} else {
|
||||
items[idx].level0 = 1; items[idx].duration0 = 4;
|
||||
items[idx].level1 = 0; items[idx].duration1 = 12;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
items[idx].level0 = 0; items[idx].duration0 = 500;
|
||||
items[idx].level1 = 0; items[idx].duration1 = 0;
|
||||
idx++;
|
||||
|
||||
rmt_write_items(ch, items, idx, 1);
|
||||
rmt_driver_uninstall(ch);
|
||||
Serial.println("[CMD] RMT done. Wait 2 sec...");
|
||||
delay(2000);
|
||||
Serial.println("[CMD] Done");
|
||||
} else if (cmd == "rawled") {
|
||||
uint8_t pin = 9;
|
||||
Serial.println("[CMD] Bit-bang WS2812: pixel 0 = RED on GPIO 9");
|
||||
|
||||
Reference in New Issue
Block a user