#esp32 #embedded-graphics #ws2812 #rgb-led #smart-leds #neopixel

no-std ws2812-esp32-rmt-driver

使用ESP32 RMT的WS2812驱动程序

15个版本 (9个重大变更)

新版本 0.10.0-alpha.1 2024年8月17日
0.9.0 2024年7月6日
0.8.0 2024年6月8日
0.7.1 2024年2月3日
0.2.2 2022年3月21日

#69嵌入式开发

Download history 15/week @ 2024-05-04 13/week @ 2024-05-11 8/week @ 2024-05-18 11/week @ 2024-05-25 13/week @ 2024-06-01 226/week @ 2024-06-08 19/week @ 2024-06-15 27/week @ 2024-06-22 16/week @ 2024-06-29 170/week @ 2024-07-06 24/week @ 2024-07-13 9/week @ 2024-07-20 43/week @ 2024-07-27 17/week @ 2024-08-03 28/week @ 2024-08-10 108/week @ 2024-08-17

每月下载 197次
用于 2 crate

MIT许可证

48KB
914

ws2812-esp32-rmt-driver

一个使用ESP32 RMT(远程控制)模块控制WS2812B(NeoPixel)RGB LED像素/灯带的Rust驱动库。

Rust ws2812-esp32-rmt-driver at crates.io API

通过禁用RMT的发射器的载波发生器,它可以作为一个PWM信号发生器用于WS2812B数据信号。这种控制方式与主要的Arduino/C++库(如FastLEDAdafruit_NeoPixel)相同。

RMT(远程控制)模块是针对ESP32的,因此它只能用于ESP32 SoC。

此库还支持SK6812-RGBW 4色LED像素/灯带(仅适用于smart-leds API)。

使用方法

安装支持Xtensa的rust。有关设置说明,请参阅esp-rs/rust-build

将以下依赖项添加到您的Cargo.toml中。注意,在此示例中省略了版本号,但建议在项目中明确指定版本。

[dependencies]
esp-idf-sys = { version = "*", features = ["binstart"] }
esp-idf-hal = "*"
smart-leds = "*"

ws2812-esp32-rmt-driver = { version = "*", features = ["smart-leds-trait"] }

[build-dependencies]
embuild = "*"
anyhow = "1"

有关源代码,请参阅examples/目录。

确保esp工具链可用,并且xtensa-esp32-elf-clang已添加到您的$PATH。然后,按照以下方式运行

$ cargo build
$ cargo espflash

功能

功能 默认 描述
embedded_graphics_core 嵌入式图形API ws2812_esp32_rmt_driver::lib_embedded_graphics
smart-leds-trait smart-leds API ws2812_esp32_rmt_driver::lib_smart_leds
std x 使用标准库 std
alloc x 使用内存分配器(堆)

一些示例

  • features = ["embedded-graphics-core"]以启用嵌入式图形API ws2812_esp32_rmt_driver::lib_embedded_graphics
  • features = ["smart-leds-trait"] 添加到代码中,以启用 smart-leds API ws2812_esp32_rmt_driver::lib_smart_leds
  • 默认情况下,仅启用驱动程序 API。

no_std

要使用 no_std,请禁用 default 功能。然后,std 功能将被禁用,并且此库将与 no_std 兼容。

一些示例

  • default-feature = false, features = ["alloc", "embedded-graphics-core"] 以启用具有内存分配器的 no_std 环境下的 embedded-graphics API ws2812_esp32_rmt_driver::lib_embedded_graphics
  • default-feature = false, features = ["alloc", "smart-leds-trait"] 以启用具有内存分配器的 no_std 环境下的 smart-leds API ws2812_esp32_rmt_driver::lib_smart_leds
  • default-feature = false, features = ["embedded-graphics-core"] 以启用无内存分配器的 no_std 环境下的 embedded-graphics API ws2812_esp32_rmt_driver::lib_embedded_graphics
  • default-feature = false, features = ["smart-leds-trait"] 以启用无内存分配器的 no_std 环境下的 smart-leds API ws2812_esp32_rmt_driver::lib_smart_leds

当使用内存分配器(堆)时,启用 alloc 功能。在这种情况下,大多数处理与 std 相同。当不使用内存分配器(堆)时,禁用 alloc 功能。在这种情况下,某些 API 无法使用,并且必须更改处理方式。例如,在 embedded-graphics API 中,必须由程序员使用 heapless Vec-like 结构(如 heapless::Vec<u8, X>)准备像素数据存储。

此库旨在与 espidf 一起使用。对于裸机环境(即与 esp-hal 一起使用),请使用 Espressif 官方 crate esp-hal-smartled

开发

在本地运行测试时,请指定本地工具链(如 stablenightly 等...)和目标,并明确禁用示例构建(指定 --lib)。

$ cargo +stable test --target x86_64-unknown-linux-gnu --lib

依赖项

~0.7-8MB
~58K SLoC