Skip to content

Commit 8bcd455

Browse files
authored
Merge pull request #4762 from willmmiles/parallel-i2s-bus-selection
bus_wrapper: Use parallel I2S first when enabled
2 parents c0875b3 + 9569ec7 commit 8bcd455

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

wled00/bus_wrapper.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,20 @@ class PolyBus {
469469
}
470470

471471
static void* create(uint8_t busType, uint8_t* pins, uint16_t len, uint8_t channel) {
472-
#if defined(ARDUINO_ARCH_ESP32) && !(defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3))
473472
// NOTE: "channel" is only used on ESP32 (and its variants) for RMT channel allocation
473+
474+
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
475+
if (_useParallelI2S && (channel >= 8)) {
476+
// Parallel I2S channels are to be used first, so subtract 8 to get the RMT channel number
477+
channel -= 8;
478+
}
479+
#endif
480+
481+
#if defined(ARDUINO_ARCH_ESP32) && !(defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3))
474482
// since 0.15.0-b3 I2S1 is favoured for classic ESP32 and moved to position 0 (channel 0) so we need to subtract 1 for correct RMT allocation
475483
if (!_useParallelI2S && channel > 0) channel--; // accommodate I2S1 which is used as 1st bus on classic ESP32
476-
// if user selected parallel I2S, RMT is used 1st (8 channels) followed by parallel I2S (8 channels)
477484
#endif
485+
478486
void* busPtr = nullptr;
479487
switch (busType) {
480488
case I_NONE: break;
@@ -1428,7 +1436,8 @@ class PolyBus {
14281436
// ESP32-S2 only has 4 RMT channels
14291437
if (_useParallelI2S) {
14301438
if (num > 11) return I_NONE;
1431-
if (num > 3) offset = 1; // use x8 parallel I2S0 channels (use last to allow Audioreactive)
1439+
if (num < 8) offset = 1; // use x8 parallel I2S0 channels followed by RMT
1440+
// Note: conflicts with AudioReactive if enabled
14321441
} else {
14331442
if (num > 4) return I_NONE;
14341443
if (num > 3) offset = 1; // only one I2S0 (use last to allow Audioreactive)
@@ -1441,15 +1450,15 @@ class PolyBus {
14411450
// On ESP32-S3 only the first 4 RMT channels are usable for transmitting
14421451
if (_useParallelI2S) {
14431452
if (num > 11) return I_NONE;
1444-
if (num > 3) offset = 1; // use x8 parallel I2S LCD channels
1453+
if (num < 8) offset = 1; // use x8 parallel I2S LCD channels, followed by RMT
14451454
} else {
14461455
if (num > 3) return I_NONE; // do not use single I2S (as it is not supported)
14471456
}
14481457
#else
14491458
// standard ESP32 has 8 RMT and x1/x8 I2S1 channels
14501459
if (_useParallelI2S) {
14511460
if (num > 15) return I_NONE;
1452-
if (num > 7) offset = 1; // 8 RMT followed by 8 I2S
1461+
if (num < 8) offset = 1; // 8 I2S followed by 8 RMT
14531462
} else {
14541463
if (num > 9) return I_NONE;
14551464
if (num == 0) offset = 1; // prefer I2S1 for 1st bus (less flickering but more RAM needed)

0 commit comments

Comments
 (0)