#![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 defmt::{info, println};
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_hal::clock::CpuClock;
use esp_hal::gpio::Level;
use esp_hal::rmt::{PulseCode, Rmt, TxChannelAsync, TxChannelConfig, TxChannelCreatorAsync};
use esp_hal::time::Rate;
use esp_hal::timer::systimer::SystemTimer;
use panic_rtt_target as _;
extern crate alloc;
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
// generator version: 0.3.1
rtt_target::rtt_init_defmt!();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 72 * 1024);
let timer0 = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(timer0.alarm0);
info!("Embassy initialized!");
let output = peripherals.GPIO4;
let rate = Rate::from_mhz(80);
let carrier = Rate::from_hz(32768);
let rmt = Rmt::new(peripherals.RMT, rate)
.expect("RMT Failed to new")
.into_async();
println!("Carrier: {}", (rate / carrier));
let mut channel = rmt
.channel0
.configure(
output,
TxChannelConfig::default()
.with_carrier_high((rate / carrier / 2).try_into().unwrap()) // half the duty cycle high
.with_carrier_low((rate / carrier / 2).try_into().unwrap()) // and the other half to low
.with_carrier_modulation(true) // and enable carrier
.into(),
)
.unwrap();
// setup a test dataset
let mut data = [<u32 as PulseCode>::new(Level::High, 3000, Level::Low, 1000); 20];
// TODO: Spawn some tasks
let _ = spawner;
loop {
info!("Hello world!");
channel.transmit(&data).await.unwrap();
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-beta.0/examples/src/bin
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1