This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete esp32h2 support, simplify linker args, create snippets (#141)
* Simplify linker arg specification * Default to logging * Split alloc and wifi into rhai snippets * fix ci * Add back rustfmt, with catch to print error if it fails * specify snippet deps * Rebase updates * enable proper esp-wifi feature * Update esp-hal & esp-wifi
- Loading branch information
Showing
9 changed files
with
97 additions
and
87 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
println!("cargo:rustc-link-arg-bins=-Tlinkall.x"); | ||
{% if wifi %} | ||
println!("cargo:rustc-link-arg-bins=-Trom_functions.x"); | ||
{% endif -%} | ||
} |
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
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,7 +1,14 @@ | ||
if variable::get("mcu") != "esp32h2" && variable::get("wifi"){ | ||
print("\nFor more information and examples of esp-wifi showcasing Wifi,BLE and ESP-NOW, see https://github.com/esp-rs/esp-wifi/blob/main/examples.md\n"); | ||
if variable::get("wifi"){ | ||
print("\nFor more information and examples of esp-wifi showcasing Wifi,BLE and ESP-NOW, see https://github.com/esp-rs/esp-wifi/blob/main/esp-wifi/docs/examples.md\n"); | ||
} | ||
|
||
if variable::get("ci") { | ||
file::rename(".github/rust_ci.yml", ".github/workflows/rust_ci.yml"); | ||
} | ||
|
||
|
||
try { | ||
system::command("cargo", ["fmt"]); | ||
} catch { | ||
print("Failed to run rustfmt, please ensure rustfmt is installed and in your PATH variable."); | ||
} |
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
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,74 +1,33 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
{% if alloc -%} | ||
extern crate alloc; | ||
use core::mem::MaybeUninit; | ||
{% endif -%} | ||
use esp_backtrace as _; | ||
use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay}; | ||
use esp_println::println; | ||
|
||
{% if wifi -%} | ||
use esp_wifi::{initialize, EspWifiInitFor}; | ||
|
||
{% if arch == "riscv" -%} | ||
use esp_hal::{systimer::SystemTimer, Rng}; | ||
{% else -%} | ||
use esp_hal::{timer::TimerGroup, Rng}; | ||
{% endif -%} | ||
{% endif -%} | ||
use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, delay::Delay}; | ||
|
||
{% if alloc -%} | ||
#[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); | ||
} | ||
} | ||
{{ alloc_snippet }} | ||
{% endif -%} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
{%- if alloc %} | ||
init_heap(); | ||
{%- endif %} | ||
let peripherals = Peripherals::take(); | ||
let system = peripherals.SYSTEM.split(); | ||
|
||
let clocks = ClockControl::max(system.clock_control).freeze(); | ||
let mut delay = Delay::new(&clocks); | ||
let delay = Delay::new(&clocks); | ||
|
||
{%- if alloc %} | ||
init_heap(); | ||
{%- endif %} | ||
|
||
{% if logging -%} | ||
// setup logger | ||
// To change the log_level change the env section in .cargo/config.toml | ||
// or remove it and set ESP_LOGLEVEL manually before running cargo run | ||
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358 | ||
esp_println::logger::init_logger_from_env(); | ||
log::info!("Logger is setup"); | ||
{% endif -%} | ||
println!("Hello world!"); | ||
|
||
{% if wifi -%} | ||
{% if arch == "riscv" -%} | ||
let timer = SystemTimer::new(peripherals.SYSTIMER).alarm0; | ||
{% else -%} | ||
let timer = TimerGroup::new(peripherals.TIMG1, &clocks).timer0; | ||
{% endif -%} | ||
let _init = initialize( | ||
EspWifiInitFor::Wifi, | ||
timer, | ||
Rng::new(peripherals.RNG), | ||
system.radio_clock_control, | ||
&clocks, | ||
) | ||
.unwrap(); | ||
{{ esp_wifi_snippet }} | ||
{% endif -%} | ||
|
||
loop { | ||
println!("Loop..."); | ||
delay.delay_ms(500u32); | ||
log::info!("Hello world!"); | ||
delay.delay(500.millis()); | ||
} | ||
} |