-
Notifications
You must be signed in to change notification settings - Fork 16
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
Non blocking smart led #6
base: main
Are you sure you want to change the base?
Conversation
82bcdde
to
c10d4d4
Compare
I finally got around to some testing tonight. It only seems to only work with 2 of 6 ws28xx variants. On my esp32, I measure about 25us between pixels and about 55us total. From some research like https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/amp/ and the various datasheets, depending on the chip, the last time might be ~6us, ~50us, or ~250us on the other 4, only one LED lights. So if this is accepted, it needs to be accepted with the caveat that it depends heavily on which LED are used Incidentally among those not working are what I'm pretty sure are genuine WorldSemi LEDs. But... exciting news, I am able to drive two sets of the type that work in parallel using a But... here, the time between pixels is closer to 34us I should go back to exploring double buffering in RMT async writes. Supposedly there's an ability now to force code into RAM to run faster? |
one more very odd thing with a buffer size of 65, I can only send 62 pixels of data. Otherwise I get #[main]
async fn main(spawner: Spawner) {
let peripherals = esp_hal::init(esp_hal::Config::default());
esp_println::logger::init_logger_from_env();
esp_println::println!("Init!");
let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let led_pin = io.pins.gpio18;
let l2_pin = io.pins.gpio23;
let rmt = Rmt::new_async(peripherals.RMT, 80.MHz()).unwrap();
let rmt_buffer = smartLedBuffer!(67);
let rmt2_buffer = smartLedBuffer!(67);
let mut l1 = asynch::SmartLedAdapterAsync::new(rmt.channel0, led_pin, rmt_buffer);
let mut l2 = asynch::SmartLedAdapterAsync::new(rmt.channel1, l2_pin, rmt2_buffer);
esp_println::println!("Start!");
let mut ofs = 0;
loop {
let data = {
let mut i = 0;
[(); 64].map(|_| {
i += 1;
hsv2rgb(Hsv {
hue: (((i * 4) + ofs + 60) % 255) as u8,
sat: 240,
val: 10,
})
})
};
let f1 = l1.write(data[0..64].iter().cloned());
let f2 = l2.write(data[0..64].iter().cloned());
//let (o1, o2) = embassy_futures::join::join(f1, f2).await;
let o1 = f1.await;
let o2 = f2.await;
o1.unwrap_or_else(|e| {
esp_println::println!("Error1: {:?}", e);
});
o2.unwrap_or_else(|e| {
esp_println::println!("Error2: {:?}", e);
});
ofs = (ofs + 1) % 255;
esp_println::print!(".");
Timer::after(Duration::from_millis(10)).await;
}
} changing the above to |
esp-hal-smartled/Cargo.toml
Outdated
@@ -14,18 +14,18 @@ targets = ["riscv32imac-unknown-none-elf"] | |||
[dependencies] | |||
defmt = { version = "0.3.8", optional = true } | |||
document-features = "0.2.10" | |||
esp-hal = "0.20.0" | |||
esp-hal = ">=0.20.0, <=0.21.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why to exclude esp-hal 0.21.1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, no. I just wonder whether <=0.21 or <=0.21.* would be cleaner/better (or even does the job)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.rs/semver/latest/semver/enum.Op.html The first way works :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh I see! It seems a bit misleading before a good Samaritan points you to the SemVer docs 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it seems something is missing, this bit me:
error: failed to select a version for `esp-hal`.
... required by package `esp-hal-smartled v0.13.0`
... which satisfies dependency `esp-hal-smartled = "^0.13.0"` of package `test-xtensa-nostd v0.1.0 (/home/being/code/practice/rust/test-xtensa-nostd)`
versions that meet the requirements `^0.20.0` are: 0.20.1
the package `esp-hal` links to the native library `esp-hal`, but it conflicts with a previous package which links to `esp-hal` as well:
package `esp-hal v0.21.1`
... which satisfies dependency `esp-hal = "^0.21.1"` of package
My relevant lines on Cargo.toml
are:
esp-hal = { version = "0.21.1", features = ["esp32s3"] }
esp-hal-smartled = { version = "0.13.0", features = ["esp32s3"] }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just fixed the dependency specifier to also allow higher versions.. Can you try 0.14? I also bumped the minor version of the crate itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worked fine! I had to set in Cargo.toml
:
esp-hal-smartled = { git = "https://github.com/robamu/esp-hal-community.git", rev = "3562306", features = ["esp32s3"] }
On the second problem: the async API requires a different and slightly larger buffer size because each transfer must be 0 terminated. I have not created an async macro to declare that buffer yet, but i provided a const function which calculates the required buffer size. It might be a reasonable idea to also add an async example? |
async example sounds like a great idea 👍 |
aafb0d1
to
355dd33
Compare
355dd33
to
3562306
Compare
I can try to add an example which is similar to the existing one, except it uses the async API. |
Here's mine:
|
smart-leds-trait just added an async version of the trait, though it hasn't been released yet: smart-leds-rs/smart-leds-trait#14 |
No description provided.