diff options
| author | andromeda <andromeda@lenovo> | 2026-04-06 13:18:41 +0200 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-04-06 13:18:41 +0200 |
| commit | 8942975bc4ba972d67b7cd3e86dbb3ece5612816 (patch) | |
| tree | f4725fe8ccd27b588c861182c27415c118fe0574 /src | |
| parent | 399d59d5e7a01d6d6bd5f8321450f666dc841bef (diff) | |
hello world RGB blinky
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/main.rs | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 7ead6f2..3567fbb 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,26 +1,22 @@ #![no_std] #![no_main] -#![deny( - clippy::mem_forget, - reason = "mem::forget is generally not safe to do with esp_hal types, especially those \ - holding buffers for the duration of a data transfer." -)] -#![deny(clippy::large_stack_frames)] use esp_backtrace as _; use esp_hal::clock::CpuClock; use esp_hal::main; -use esp_hal::time::{Duration, Instant}; +use esp_hal::rmt::Rmt; +use esp_hal::time::{Duration, Instant, Rate}; +use esp_hal_smartled::{SmartLedsAdapter, smart_led_buffer}; use log::info; +use smart_leds::{ + SmartLedsWrite as _, brightness, + colors::{BLUE, GREEN, RED}, +}; // This creates a default app-descriptor required by the esp-idf bootloader. // For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description> esp_bootloader_esp_idf::esp_app_desc!(); -#[allow( - clippy::large_stack_frames, - reason = "it's not unusual to allocate larger buffers etc. in main" -)] #[main] fn main() -> ! { // generator version: 1.2.0 @@ -28,13 +24,24 @@ fn main() -> ! { esp_println::logger::init_logger_from_env(); let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); - let _peripherals = esp_hal::init(config); + let peripherals = esp_hal::init(config); + + let mut buffer = smart_led_buffer!(1); + let mut led = { + let frequency = Rate::from_mhz(80); + let rmt = Rmt::new(peripherals.RMT, frequency).expect("failed to initialize RMT0"); + SmartLedsAdapter::new(rmt.channel0, peripherals.GPIO8, &mut buffer) + }; + let level = 10; loop { info!("Hello world!"); let delay_start = Instant::now(); + led.write(brightness([RED].into_iter(), level)).unwrap(); while delay_start.elapsed() < Duration::from_millis(500) {} + led.write(brightness([GREEN].into_iter(), level)).unwrap(); + while delay_start.elapsed() < Duration::from_millis(1000) {} + led.write(brightness([BLUE].into_iter(), level)).unwrap(); + while delay_start.elapsed() < Duration::from_millis(1500) {} } - - // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0/examples } |
