NeoPixelBus icon indicating copy to clipboard operation
NeoPixelBus copied to clipboard

Support for ESP32-S3 peripherals

Open shlomozippel opened this issue 2 years ago • 12 comments

There is already support for RMT and SPI on ESP32-S3 and it would be great to take it a few steps further:

  1. There are 2 GP-SPI peripherals, SPI2 has support for 8 bit transfer and SPI3 has support for 4 bit. Currently DotStarEsp32DmaSpiMethod ESP32-S3 support includes SPI2 with up to 4 bit transfers, and doesn't support SPI3
  2. The new LCD peripheral supports 8-16 bit transfers. It seems like the I2S peripheral isn't used for this scenario anymore like it was in previous ESP32 chips and now only supports 1 data line. Example of using this new peripheral: https://blog.adafruit.com/2022/06/14/esp32uesday-hacking-the-esp32-s3-lcd-peripheral/

Related to #598 and #559

shlomozippel avatar Jan 03 '23 18:01 shlomozippel

Thanks for suggestion and pointers.

Makuna avatar Jan 03 '23 19:01 Makuna

If I understand the adafruit infos correctly, the LCD driver unit is basically an evolution of the esp32 "secret I2S feature" to drive 8x/16x parallel outputs? So it might be possible to get up to 16 parallel led outputs on -S3 from the lcd unit?

softhack007 avatar Jun 29 '23 16:06 softhack007

@softhack007 Yes, this is my understanding. BUT it seems they wrapped the details into a driver model that only exposes LCD API rather than a data API. When I get bits of time I am still investigating, and it is helpful if others come upon details to link them here for me to review. Searching seems to be like finding a needle in a haystack.

Makuna avatar Jun 29 '23 17:06 Makuna

@Makuna I'd like to dig into this, based on the parallel LCD support for FastLED here https://github.com/hpwit/I2SClockLessLedDriveresp32s3

Do you have any advice on how you would approach this?

coliniuliano avatar May 08 '24 18:05 coliniuliano

@Makuna I'd like to dig into this, based on the parallel LCD support for FastLED here https://github.com/hpwit/I2SClockLessLedDriveresp32s3

Do you have any advice on how you would approach this?

That example implementation is a good reference, and I found the adafruit one to be a bit more readable: https://github.com/adafruit/Adafruit_NeoPXL8/blob/master/Adafruit_NeoPXL8.cpp (Note that there are multiple implementations there for multiple microcontrollers).

I wrote a driver using the adafruit code as reference for the LCD peripheral, FastLED code for the transpose logic, and custom color order and gamma tables: https://github.com/chroma-tech/micropython/blob/fern/ports/esp32/usermodules/modcanopy/driver.h

(You wouldn't need to deal with the color order and gamma stuff if porting to NPB)

shlomozippel avatar May 08 '24 19:05 shlomozippel

@Makuna I'd like to dig into this, based on the parallel LCD support for FastLED here https://github.com/hpwit/I2SClockLessLedDriveresp32s3

Do you have any advice on how you would approach this?

Review the CoreShaderBeta or work within that branch, as that is going to be next major release and some of this has changed. Copy this file, https://github.com/Makuna/NeoPixelBus/blob/master/src/internal/methods/NeoEsp32I2sXMethod.h into a NeoEsp32LcdXMethod.h. Remove I2S low level code calls and Replace with LCD calls. Change any !defined(CONFIG_IDF_TARGET_ESP32S3) or C3 and remove the not (!) so it's only for those two. Rename all i2s to lcd keeping the capitalization present. Not sure there is more than one LCD peripheral, so may need to remove the i2s0 and i2s1 support if there is only one. Make sure to support x8 and x16 if possible if it uses less DMA memory. Expand to x24 if needed as the memory consumption is ridiculous and it rarely is needed, while x8 is the greatest priority, then x16.

NPB does color order, luminance, and gamma at a higher level, so the methods are just about getting the bits out.

Makuna avatar May 08 '24 20:05 Makuna

I've managed to implement code for my specific use-case: S3 using the LCD peripheral to drive 8 parallel WS2812x strips with WLED. PR is here in case it's useful to anyone: https://github.com/Makuna/NeoPixelBus/pull/808

coliniuliano avatar May 28 '24 21:05 coliniuliano

@coliniuliano Thanks! I will take a look at the PR as soon as I can, but don't expect it this week.

Makuna avatar Jun 04 '24 14:06 Makuna

@coliniuliano Good work on the PR. Let me know if you can (willing) to apply the requested changes. Alternately I can provide a branch (for the changes to master) that you can provide the pull to, and I will merge and fixup before merging into main.
I will already have to do some work as you stated you were only doing the WS2812x and the others will be needed.

Makuna avatar Jun 22 '24 12:06 Makuna

Just an update. There is a branch that takes Colin changes but there are some things that still need to be cleaned up.

  • There are some optimizations I already have made but not checked in yet. After a few tests this will get merged into that branch (Esp32S3Led)
  • It needs to support more than just WS2812x chip speeds and reset. This will require some investigation into the LCD speed properties, but they seem similar to the i2s.
  • Testing, lots of testing. Once these are done, the branch will get merged into master.

Makuna avatar Aug 04 '24 22:08 Makuna