-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bc2b1d
commit 8ab7393
Showing
1 changed file
with
26 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,42 @@ | ||
//! Blinks an LED | ||
//! | ||
//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO0) | ||
|
||
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use esp_backtrace as _; | ||
use esp_hal::{ | ||
clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*, system::SystemControl, | ||
clock::ClockControl, | ||
delay::Delay, | ||
gpio::{Io, Level, Output}, | ||
peripherals::Peripherals, | ||
prelude::*, | ||
system::SystemControl, | ||
}; | ||
|
||
extern crate alloc; | ||
use core::mem::MaybeUninit; | ||
|
||
#[global_allocator] | ||
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); | ||
|
||
fn init_heap() { | ||
const HEAP_SIZE: usize = 32 * 1024; | ||
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit(); | ||
|
||
unsafe { | ||
ALLOCATOR.init(HEAP.as_mut_ptr() as *mut u8, HEAP_SIZE); | ||
} | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let peripherals = Peripherals::take(); | ||
let system = SystemControl::new(peripherals.SYSTEM); | ||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); | ||
|
||
let clocks = ClockControl::max(system.clock_control).freeze(); | ||
let delay = Delay::new(&clocks); | ||
init_heap(); | ||
// Set GPIO0 as an output, and set its state high initially. | ||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); | ||
let mut led_red = Output::new(io.pins.gpio8, Level::High); | ||
let mut led_blue = Output::new(io.pins.gpio9, Level::High); | ||
|
||
esp_println::logger::init_logger_from_env(); | ||
|
||
let timer = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0; | ||
let _init = esp_wifi::initialize( | ||
esp_wifi::EspWifiInitFor::Wifi, | ||
timer, | ||
esp_hal::rng::Rng::new(peripherals.RNG), | ||
peripherals.RADIO_CLK, | ||
&clocks, | ||
) | ||
.unwrap(); | ||
let delay = Delay::new(&clocks); | ||
|
||
loop { | ||
log::info!("Hello world!"); | ||
delay.delay(500.millis()); | ||
led_red.toggle(); | ||
led_blue.toggle(); | ||
delay.delay_millis(500); | ||
led_red.toggle(); | ||
led_blue.toggle(); | ||
// or using `fugit` duration | ||
delay.delay(2.secs()); | ||
} | ||
} | ||
} |