Skip to content

Commit

Permalink
feat: use 2 tasks, increase arena size
Browse files Browse the repository at this point in the history
  • Loading branch information
DavSanchez committed Jun 12, 2024
1 parent 220cd15 commit 7d5b88d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ smoltcp = { version = "0.11.0", default-features = false, features = [
] }
esp-hal-smartled = { version = "0.11.0", features = ["esp32s3"] }
smart-leds = "0.4.0"
embassy-executor = { version = "0.5.0", features = ["integrated-timers"] }
embassy-executor = { version = "0.5.0", features = [
"integrated-timers",
"task-arena-size-40960",
] }
embassy-time = "0.3.1"
esp-hal-embassy = { version = "0.1.0", features = ["esp32s3", "time-timg0"] }

Expand Down
62 changes: 37 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ use esp_hal::{
gpio::{Gpio8, Gpio9, Io, Level, Output},
peripherals::Peripherals,
prelude::*,
rmt::Rmt,
rmt::{Channel, Rmt},
system::SystemControl,
timer::timg::TimerGroup,
Blocking,
};
use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter};
use esp_println::logger::init_logger;
Expand All @@ -32,7 +33,7 @@ mod front_leds;
// mod pixel_click; // A sort of framework for the board, not yet ready

#[embassy_executor::task]
async fn run(mut red: Output<'static, Gpio8>, mut blue: Output<'static, Gpio9>) {
async fn front_leds(mut red: Output<'static, Gpio8>, mut blue: Output<'static, Gpio9>) {
loop {
info!("Playing with the leds concurrently!");
red.toggle();
Expand All @@ -41,6 +42,35 @@ async fn run(mut red: Output<'static, Gpio8>, mut blue: Output<'static, Gpio9>)
}
}

#[embassy_executor::task]
async fn led_panel(mut a_led: SmartLedsAdapter<Channel<Blocking, 0>, 865>) {
let mut color = Hsv {
hue: 0,
sat: 255,
val: 255,
};
let mut data;

loop {
info!("Iterating over the rainbow!");
// Iterate over the rainbow!
for hue in 0..=255 {
color.hue = hue;
// Convert from the HSV color space (where we can easily transition from one
// color to the other) to the RGB color space that we can then send to the LED
data = [hsv2rgb(color); 36];
// When sending to the LED, we do a gamma correction first (see smart_leds
// documentation for details) and then limit the brightness to 10 out of 255 so
// that the output it's not too bright.
a_led
.write(brightness(gamma(data.iter().cloned()), 15))
.unwrap();

Timer::after(Duration::from_millis(15)).await;
}
}
}

#[main]
async fn main(spawner: Spawner) -> ! {
init_logger(log::LevelFilter::Info);
Expand All @@ -58,38 +88,20 @@ async fn main(spawner: Spawner) -> ! {
// Init the front board LEDs
let front_red = Output::new(io.pins.gpio8, Level::High);
let front_blue = Output::new(io.pins.gpio9, Level::Low);
spawner.spawn(run(front_red, front_blue)).ok();

// For the LED panel, initialize the RMT (Remote Control Transceiver)
let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks, None).unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations
// Our PixelClick has 36 LEDs
let rmt_buffer = smartLedBuffer!(36);
let mut a_led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio5, rmt_buffer, &clocks);
let a_led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio5, rmt_buffer, &clocks);

let mut color = Hsv {
hue: 0,
sat: 255,
val: 255,
};
let mut data;
// Spawn the two tasks!
spawner.spawn(front_leds(front_red, front_blue)).ok();
spawner.spawn(led_panel(a_led)).ok();

loop {
// Iterate over the rainbow!
for hue in 0..=255 {
color.hue = hue;
// Convert from the HSV color space (where we can easily transition from one
// color to the other) to the RGB color space that we can then send to the LED
data = [hsv2rgb(color); 36];
// When sending to the LED, we do a gamma correction first (see smart_leds
// documentation for details) and then limit the brightness to 10 out of 255 so
// that the output it's not too bright.
a_led
.write(brightness(gamma(data.iter().cloned()), 15))
.unwrap();

Timer::after(Duration::from_millis(15)).await;
}
Timer::after(Duration::from_secs(1)).await;
}
}

0 comments on commit 7d5b88d

Please sign in to comment.