Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menuconfig option to choose between rmt and i2s. #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions components/FastLED-idf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ set(srcs
"wiring.cpp"
"hal/esp32-hal-misc.c"
"hal/esp32-hal-gpio.c"
# remove the following if you want I2S instead of RMT hardware, just put a pound in front
# "platforms/esp/32/clockless_rmt_esp32.cpp"
"platforms/esp/32/clockless_rmt_esp32.cpp"
)

# everything needs the ESP32 flag, not sure why this won't work
# going to hack by adding the ESP32 define in the h file
#`target_compile_options(${COMPONENT_LIB} PRIVATE "-DESP32")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "." "./hal" )

# target_compile_options(${COMPONENT_LIB} PRIVATE "-DESP32") won't work because the esp-idf uses a custom component system
idf_build_set_property(COMPILE_OPTIONS -DESP32 APPEND)
idf_build_set_property(COMPILE_OPTIONS -DFASTLED_NO_PINMAP APPEND)
if (CONFIG_FASTLED_ESP32_I2S)
idf_build_set_property(COMPILE_OPTIONS "-DFASTLED_ESP32_I2S" APPEND)
endif()
8 changes: 0 additions & 8 deletions components/FastLED-idf/FastLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
///@file FastLED.h
/// central include file for FastLED, defines the CFastLED class/object

// BB hack
#define ESP32
#define FASTLED_NO_PINMAP

// prefer I2S? Comment this in.
// Not the default because haven't tried it as much, does work
#define FASTLED_ESP32_I2S

#include "esp32-hal.h"

#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
Expand Down
10 changes: 0 additions & 10 deletions components/FastLED-idf/Kconfig

This file was deleted.

9 changes: 9 additions & 0 deletions components/FastLED-idf/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
menu "FastLED"

config FASTLED_ESP32_I2S
bool "Use I2S instead of RMT"
default y
help
Removes the RMT sources and uses RMT instead of I2S.

endmenu
35 changes: 17 additions & 18 deletions components/FastLED-idf/platforms/esp/32/clockless_rmt_esp32.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


#ifndef FASTLED_ESP32_I2S
#define FASTLED_INTERNAL
#include "FastLED.h"

Expand All @@ -11,7 +10,7 @@
class ESP32RMTController;

// -- Array of all controllers
// This array is filled at the time controllers are registered
// This array is filled at the time controllers are registered
// (Usually when the sketch calls addLeds)
static ESP32RMTController * gControllers[FASTLED_RMT_MAX_CONTROLLERS];

Expand Down Expand Up @@ -89,7 +88,7 @@ void IRAM_ATTR memorybuf_int( int i, char sep) {
if ( maxbuf == 0 ) return;

// for speed, just make sure I have 12 bytes, even though maybe I need fewer
// 12 is the number because I need a null which I will fill with sep, and
// 12 is the number because I need a null which I will fill with sep, and
// there's always the chance of a minus
if (maxbuf <= 12) return;

Expand Down Expand Up @@ -204,9 +203,9 @@ static inline void fastled_set_mem_owner(rmt_channel_t channel, uint8_t owner)


ESP32RMTController::ESP32RMTController(int DATA_PIN, int T1, int T2, int T3)
: mPixelData(0),
mSize(0),
mCur(0),
: mPixelData(0),
mSize(0),
mCur(0),
mWhichHalf(0),
mBuffer(0),
mBufferSize(0),
Expand Down Expand Up @@ -285,7 +284,7 @@ void ESP32RMTController::init()
rmt_tx.gpio_num = gpio_num_t(0); // The particular pin will be assigned later
#endif

rmt_tx.mem_block_num = MEM_BLOCK_NUM;
rmt_tx.mem_block_num = MEM_BLOCK_NUM;
rmt_tx.clk_div = DIVIDER;
rmt_tx.tx_config.loop_en = false;
rmt_tx.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
Expand All @@ -298,7 +297,7 @@ void ESP32RMTController::init()

if (FASTLED_RMT_BUILTIN_DRIVER) {
ESP_ERROR_CHECK( rmt_driver_install(rmt_channel, 0, 0) );
}
}
else {

// -- Set up the RMT to send 32 bits of the pulse buffer and then
Expand Down Expand Up @@ -390,7 +389,7 @@ void ESP32RMTController::showPixels()

#if FASTLED_ESP32_SHOWTIMING == 1
// the interrupts may have dumped things to the buffer. Print it.
// warning: this does a fairly large stack allocation.
// warning: this does a fairly large stack allocation.
char mb[MEMORYBUF_SIZE+1];
int mb_len = MEMORYBUF_SIZE;
memorybuf_get(mb, &mb_len);
Expand Down Expand Up @@ -479,12 +478,12 @@ void ESP32RMTController::tx_start()

// In the case of the build-in driver, they specify the RMT channel
// so we use the arg instead
void ESP32RMTController::doneOnRMTChannel(rmt_channel_t channel, void * arg)
void ESP32RMTController::doneOnRMTChannel(rmt_channel_t channel, void * arg)
{
doneOnChannel((int) arg, (void *) 0);
}

// -- A controller is done
// -- A controller is done
// This function is called when a controller finishes writing
// its data. It is called either by the custom interrupt
// handler (below), or as a callback from the built-in
Expand Down Expand Up @@ -518,7 +517,7 @@ void ESP32RMTController::doneOnChannel(int channel, void * arg)
}
}
}

// -- Custom interrupt handler
// This interrupt handler handles two cases: a controller is
// done writing its data, or a controller needs to fill the
Expand Down Expand Up @@ -588,7 +587,7 @@ bool IRAM_ATTR ESP32RMTController::timingOk() {
memorybuf_add( g_bail_str );
#endif /* FASTLED_ESP32_SHOWTIMING == 1 */

// how do we bail out? It seems if we simply call rmt_tx_stop,
// how do we bail out? It seems if we simply call rmt_tx_stop,
// we'll still flicker on the end. Setting mCur to mSize has the side effect
// of triggering the other code that says "we're finished"

Expand Down Expand Up @@ -633,8 +632,8 @@ void IRAM_ATTR ESP32RMTController::fillNext()

// set the owner to SW --- current driver does this but its not clear it matters
fastled_set_mem_owner(mRMT_channel, RMT_MEM_OWNER_SW);
// Shift bits out, MSB first, setting RMTMEM.chan[n].data32[x] to the

// Shift bits out, MSB first, setting RMTMEM.chan[n].data32[x] to the
// rmt_item32_t value corresponding to the buffered bit value

for (int i=0; i < PULSES_PER_FILL / 32; i++) {
Expand Down Expand Up @@ -682,7 +681,7 @@ void IRAM_ATTR ESP32RMTController::fillNext()

// -- Init pulse buffer
// Set up the buffer that will hold all of the pulse items for this
// controller.
// controller.
// This function is only used when the built-in RMT driver is chosen
void ESP32RMTController::initPulseBuffer(int size_in_bytes)
{
Expand Down Expand Up @@ -714,4 +713,4 @@ void ESP32RMTController::convertByte(uint32_t byteval)
mCurPulse++;
}
}

#endif // FASTLED_ESP32_I2S