feat: 实现流光效果。
This commit is contained in:
commit
f96c825034
35
.cargo/config.toml
Normal file
35
.cargo/config.toml
Normal file
@ -0,0 +1,35 @@
|
||||
[build]
|
||||
# Uncomment the relevant target for your chip here (ESP32, ESP32-S2, ESP32-S3 or ESP32-C3)
|
||||
#target = "xtensa-esp32-espidf"
|
||||
#target = "xtensa-esp32s2-espidf"
|
||||
#target = "xtensa-esp32s3-espidf"
|
||||
target = "riscv32imc-esp-espidf"
|
||||
|
||||
[target.xtensa-esp32-espidf]
|
||||
linker = "ldproxy"
|
||||
|
||||
[target.xtensa-esp32s2-espidf]
|
||||
linker = "ldproxy"
|
||||
|
||||
[target.xtensa-esp32s3-espidf]
|
||||
linker = "ldproxy"
|
||||
|
||||
[target.riscv32imc-esp-espidf]
|
||||
linker = "ldproxy"
|
||||
|
||||
# Future - necessary for the experimental "native build" of esp-idf-sys with ESP32C3
|
||||
# See also https://github.com/ivmarkov/embuild/issues/16
|
||||
rustflags = ["-C", "default-linker-libraries"]
|
||||
|
||||
[unstable]
|
||||
|
||||
build-std = ["std", "panic_abort"]
|
||||
#build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF versions without a realpath implementation
|
||||
|
||||
[env]
|
||||
# Note: these variables are not used when using pio builder
|
||||
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4)
|
||||
#ESP_IDF_VERSION = { value = "branch:release/v4.4" }
|
||||
# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline)
|
||||
ESP_IDF_VERSION = { value = "master" }
|
||||
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/.vscode
|
||||
/.embuild
|
||||
/target
|
||||
/Cargo.lock
|
34
Cargo.toml
Normal file
34
Cargo.toml
Normal file
@ -0,0 +1,34 @@
|
||||
[package]
|
||||
authors = ["Ivan Li <ivanli2048@gmail.com>"]
|
||||
edition = "2018"
|
||||
name = "esp32-c3-ws2812-leds"
|
||||
resolver = "2"
|
||||
version = "0.0.1"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
|
||||
[profile.dev]
|
||||
debug = true # Symbols are nice and they don't increase the size on Flash
|
||||
opt-level = "z"
|
||||
|
||||
[features]
|
||||
pio = ["esp-idf-sys/pio"]
|
||||
|
||||
[dependencies]
|
||||
# anyhow = {version = "1.0.57", features = ["backtrace"]}
|
||||
# embedded-graphics = "0.7.1"
|
||||
embedded-hal = "1.0.0-alpha.8"
|
||||
# embedded-hal-0-2 = {package = "embedded-hal", version = "0.2.7", features = ["unproven"]}
|
||||
embedded-svc = "0.21.3"
|
||||
# env_logger = "0.9.0"
|
||||
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal", branch="master" }
|
||||
esp-idf-svc = { git = "https://github.com/IvanLi-CN/esp-idf-svc", branch="master" }
|
||||
esp-idf-sys = {version = "0.31.5", features = ["binstart"]}
|
||||
# log = "0.4.17"
|
||||
# retry = "1.3.1"
|
||||
smart-leds = "0.3.0"
|
||||
ws2812-esp32-rmt-driver = "0.3.1"
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.57"
|
||||
embuild = "0.29.1"
|
5
build.rs
Normal file
5
build.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641
|
||||
fn main() -> anyhow::Result<()> {
|
||||
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
|
||||
embuild::build::LinkArgs::output_propagated("ESP_IDF")
|
||||
}
|
3
rust-toolchain.toml
Normal file
3
rust-toolchain.toml
Normal file
@ -0,0 +1,3 @@
|
||||
[toolchain]
|
||||
|
||||
channel = "nightly-2022-06-03"
|
10
sdkconfig.defaults
Normal file
10
sdkconfig.defaults
Normal file
@ -0,0 +1,10 @@
|
||||
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=7000
|
||||
|
||||
# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).
|
||||
# This allows to use 1 ms granuality for thread sleeps (10 ms by default).
|
||||
#CONFIG_FREERTOS_HZ=1000
|
||||
|
||||
# Workaround for https://github.com/espressif/esp-idf/issues/7631
|
||||
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n
|
||||
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n
|
36
src/main.rs
Normal file
36
src/main.rs
Normal file
@ -0,0 +1,36 @@
|
||||
#![feature(is_some_with)]
|
||||
#![feature(core_intrinsics)]
|
||||
use smart_leds::hsv::{hsv2rgb, Hsv};
|
||||
use smart_leds::SmartLedsWrite;
|
||||
use std::thread::sleep;
|
||||
use std::{env,time::Duration};
|
||||
use ws2812_esp32_rmt_driver::Ws2812Esp32Rmt;
|
||||
use esp_idf_sys::*;
|
||||
fn main() {
|
||||
env::set_var("DEFMT_LOG", "trace");
|
||||
env::set_var("RUST_LOG", "trace");
|
||||
// env_logger::init();
|
||||
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
|
||||
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
|
||||
esp_idf_sys::link_patches();
|
||||
|
||||
let mut ws2812 = Ws2812Esp32Rmt::new(0, 1).unwrap();
|
||||
|
||||
println!("Start NeoPixel rainbow!");
|
||||
|
||||
let mut hue = unsafe { esp_random() } as u8;
|
||||
loop {
|
||||
let pixels = (0..60).map(|i: u8| {
|
||||
let hue = hue.wrapping_add(i.wrapping_mul(4));
|
||||
let sat = 170;
|
||||
let val = 250;
|
||||
let rgb = hsv2rgb(Hsv { hue, sat, val });
|
||||
rgb
|
||||
});
|
||||
ws2812.write(pixels).unwrap();
|
||||
|
||||
sleep(Duration::from_millis(20));
|
||||
|
||||
hue = hue.wrapping_add(1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user