storing before actually doing interrupt LED toggle
This commit is contained in:
76
test_LED_pwm/src/bin/main.rs
Normal file
76
test_LED_pwm/src/bin/main.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
#![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."
|
||||
)]
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use esp_hal::ledc::{Ledc, LowSpeed, LSGlobalClkSource};
|
||||
use esp_hal::ledc::channel::{self, ChannelIFace};
|
||||
use esp_hal::ledc::timer::{self, TimerIFace};
|
||||
use esp_hal::time::Rate;
|
||||
use log::info;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
// 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!();
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
// generator version: 0.5.0
|
||||
esp_println::logger::init_logger_from_env();
|
||||
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
esp_alloc::heap_allocator!(size: 64 * 1024);
|
||||
|
||||
let timer0 = TimerGroup::new(peripherals.TIMG1);
|
||||
esp_hal_embassy::init(timer0.timer0);
|
||||
|
||||
info!("Embassy initialized!");
|
||||
|
||||
|
||||
// LEDC initialization
|
||||
let mut ledc = Ledc::new(peripherals.LEDC);
|
||||
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||
|
||||
let mut lstimer0 = ledc.timer::<LowSpeed>(timer::Number::Timer0);
|
||||
lstimer0.configure(timer::config::Config {
|
||||
duty: timer::config::Duty::Duty5Bit,
|
||||
clock_source: timer::LSClockSource::APBClk,
|
||||
frequency: Rate::from_khz(24),
|
||||
}).unwrap();
|
||||
|
||||
let led = peripherals.GPIO4;
|
||||
let mut channel0 = ledc.channel(channel::Number::Channel0, led);
|
||||
channel0.configure(channel::config::Config {
|
||||
timer: &lstimer0,
|
||||
duty_pct: 10,
|
||||
pin_config: channel::config::PinConfig::PushPull,
|
||||
}).unwrap();
|
||||
|
||||
loop {
|
||||
// channel0.start_duty_fade(0, 100, 1000).unwrap();
|
||||
// while channel0.is_duty_fade_running() {}
|
||||
// channel0.start_duty_fade(100, 0, 1000).unwrap();
|
||||
// while channel0.is_duty_fade_running() {}
|
||||
|
||||
channel0.set_duty(100).unwrap();
|
||||
info!("LED ON");
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
|
||||
channel0.set_duty(0).unwrap();
|
||||
info!("LED OFF");
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
|
||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||
}
|
||||
1
test_LED_pwm/src/lib.rs
Normal file
1
test_LED_pwm/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
#![no_std]
|
||||
Reference in New Issue
Block a user