opened
dpgeorge
username_0
This PR adds a "general" `machine.pixelbitstream(pin, timing, buf)` function which can be used to drive neopixels/ws2812/etc LEDs, using a software bit-banging approach.  Arguments are:
- pin -- the pin to output on (can be any pin)
- timing -- tuple of 4 values for T0H, T0L, T1H, T1L in nanoseconds
- buf -- buffer of bytes to output on the pin

The bytes are output according to the "ws2812 scheme", where each bit is encoded by a high pulse then a low pulse of a certain duration, specified by the timing tuple.

This should be general enough to support all variants of these kinds of LEDs, and tune the timing values in Python for any particular application.

Note that this uses a software implementation and IRQs are disabled during the output of the bits.  So long streams of bits will pause IRQs for a long time.  But it's still useful for the cases where hardware (eg SPI) can't be used.

This function should be able to be used without much effort on all ports, but it's only tested and tuned so far on stm32 (PYBv1.0, also tested on an F0 to show that it can work at low CPU freq).

See also #5117
stm32/machine_pixelbitstream: Add machine.pixelbitstream function.
issue
created
maludwig
username_1
There's a few things I would personally change here. You should include docs for how to use it. The "Example usage:" section in python should just be the NeoPixel class itself, as in the ESP8266/32 implementation. Make life easy for people. Have things be more similar across ports. I also feel like pixelbitstream should be exposed under the NeoPixel class, since it seems more related to neopixels as a concept, rather than to the machine. I'll make other, more minor suggestions with comments directly on the code.
comment
created
maludwig
username_1
After a conversation with @jimmo on IRC, I think it would be better to move this from the STM32 implementation, into a more generic place for all ports. I'm happy to test it on ESP8266/ESP32 and make the code work there, if you're happy to test the stm32 implementation. Let me know if I can help.
comment
created
dpgeorge
username_0
Ok, I'll move it so it can be reused by all ports.  Then we can try to make it work well on stm32/esp8266/esp32.
comment
created
dpgeorge
username_0
See #5318 for a version of this which is usable by all ports.  That PR would supersede this one.
comment
created
mcauser
username_2
This is mostly about driving NeoPixels, but it would be cool to use something like this to drive simple ASK/OOK 433MHz transmitters too. I was experimenting with the [ESP32 RTM implementation #5184](https://github.com/micropython/micropython/pull/5184) and the signals are pretty consistent and easy to generate.
comment
created
dpgeorge
username_0
The RMT is a much more general purpose bit stream generator.  It's very esp32 specific but we could in principle implement a software version of it (bit banging) for other ports...
comment
created
dpgeorge
username_0
Closed in favour of #7637.
comment