Skip to content

Commit

Permalink
Merge pull request #367 from adafruit/espidf5_rmt
Browse files Browse the repository at this point in the history
Espidf5 new RMT support
  • Loading branch information
ladyada authored Oct 30, 2023
2 parents fe882b8 + a5856b2 commit f8ec6ae
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions esp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,58 @@
#if defined(ESP32)

#include <Arduino.h>
#include "driver/rmt.h"

#if defined(ESP_IDF_VERSION)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
#define HAS_ESP_IDF_4
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#define HAS_ESP_IDF_5
#endif
#endif



#ifdef HAS_ESP_IDF_5

void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz) {
rmt_data_t led_data[numBytes * 8];

if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) {
log_e("Failed to init RMT TX mode on pin %d", pin);
return;
}

int i=0;
for (int b=0; b < numBytes; b++) {
for (int bit=0; bit<8; bit++){
if ( pixels[b] & (1<<(7-bit)) ) {
led_data[i].level0 = 1;
led_data[i].duration0 = 8;
led_data[i].level1 = 0;
led_data[i].duration1 = 4;
} else {
led_data[i].level0 = 1;
led_data[i].duration0 = 4;
led_data[i].level1 = 0;
led_data[i].duration1 = 8;
}
i++;
}
}

//pinMode(pin, OUTPUT); // don't do this, will cause the rmt to disable!
rmtWrite(pin, led_data, numBytes * 8, RMT_WAIT_FOR_EVER);
delay(10);
}



#else

#include "driver/rmt.h"


// This code is adapted from the ESP-IDF v3.4 RMT "led_strip" example, altered
// to work with the Arduino version of the ESP-IDF (3.2)

Expand Down Expand Up @@ -175,4 +219,7 @@ void espShow(uint8_t pin, uint8_t *pixels, uint32_t numBytes, boolean is800KHz)
gpio_set_direction(pin, GPIO_MODE_OUTPUT);
}

#endif
#endif // ifndef IDF5


#endif // ifdef(ESP32)

0 comments on commit f8ec6ae

Please sign in to comment.