phip1611 / ws2818-rgb-led-spi-driver

Simple, educational driver for WS28xx RGB LED (chains) written in Rust. It uses SPI device for timing. Needs Linux and works definitely on Raspberry Pi.
MIT License
19 stars 6 forks source link

no-std support #3

Closed mexus closed 3 years ago

mexus commented 3 years ago

Hi @phip1611 and thanks for your superb library!

Are you interested in adding a no-std support to the crate? Or maybe splitting into a no-std crate + linux spidev adapter?

While using linux is good for prototyping, sometimes it's better to wire everything up into a microcontroller. As far as I can tell, only minor tweaks are required to make the encoding/timings part platform-agnostic, and I guess I can make an attempt to separate the stuff.

So, what do you say?

phip1611 commented 3 years ago

Hi @mexus first of all, thanks for your interest in my library :)

Having a platform-agnostic version is a great idea. I tried to make my first attempt to make it #[no-std] but there are several problems:

What are your additional ideas on that?

Please keep in mind: My main goal of this crate is to offer a very simple, stripped down, educational version of a driver so that everyone can understand it easily.

PS: In case you tried to make some changes by yourself. Please be aware of https://github.com/phip1611/ws2818-rgb-led-spi-driver/issues/4 - so don't wonder if the master branch is called main now :)

chinoto commented 3 years ago

I came up with a way to do dynamic timings a few months ago just for fun. I just rebased the branch to include a refactoring that makes the rest of it a bit easier to understand. https://github.com/chinoto/rainbow_emanator/blob/bool2byte/examples/rpi_ws2812/src/bin/rainbow.rs#L57

Edit: I think I decided to do the dynamic timings after learning that the timings have a fairly wide tolerance range and so you can aim for the lower bound to send RGB data faster. https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/

phip1611 commented 3 years ago

@chinoto Thanks for the interesting links! I hope I can try to fix this issue soon! In a few days my big uni project is done and afterwards I have time.

Idea for the timing part:

Idea for the no_std problem:

phip1611 commented 3 years ago

By default, this crate has now the adapter_spidev-feature enabled which requires std. This can be deactivated and then this crate is really no_std. Current limitations: encoding.rs and timings.rs are still bound to the 15.6Mhz from the Raspberry Pi. As long as there are no dynamic versions of these modules it still should be really simple for everyone to adjust these values inside their project for the frequency they use by reading the code comments.