mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-27 12:20:56 +00:00
Simplify initialization APIs (#1957)
* Accept more types in embassy::init * Apply the same treatment to esp-wifi * Changelog * Clean up * Add doc examples * Fix Alarm generic parameters
This commit is contained in:
parent
6e706c5f11
commit
f95ab0def5
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Changed
|
||||
|
||||
- Updated to latest release (`0.6.0`) for `embassy-executor` (#1942)
|
||||
- Changed `init` to accept timers of multiple types (#1957)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -21,6 +21,7 @@ esp-hal = { version = "0.19.0", path = "../esp-hal" }
|
||||
log = { version = "0.4.22", optional = true }
|
||||
macros = { version = "0.12.0", features = ["embassy"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
|
||||
portable-atomic = "1.6.0"
|
||||
static_cell = "2.1.0"
|
||||
|
||||
[build-dependencies]
|
||||
cfg-if = "1.0.0"
|
||||
|
@ -36,7 +36,12 @@
|
||||
// MUST be the first module
|
||||
mod fmt;
|
||||
|
||||
use esp_hal::clock::Clocks;
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
use esp_hal::timer::systimer::Alarm;
|
||||
use esp_hal::{
|
||||
clock::Clocks,
|
||||
timer::{timg::Timer as TimgTimer, ErasedTimer},
|
||||
};
|
||||
pub use macros::main;
|
||||
|
||||
#[cfg(feature = "executors")]
|
||||
@ -47,7 +52,100 @@ use self::time_driver::{EmbassyTimer, Timer};
|
||||
mod executor;
|
||||
mod time_driver;
|
||||
|
||||
/// Initialize embassy
|
||||
pub fn init(clocks: &Clocks, time_driver: &'static mut [Timer]) {
|
||||
EmbassyTimer::init(clocks, time_driver)
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
/// A trait to allow better UX for initializing the timers.
|
||||
///
|
||||
/// This trait is meant to be used only for the `init` function.
|
||||
/// Calling `timers()` multiple times may panic.
|
||||
pub trait TimerCollection {
|
||||
/// Returns the timers as a slice.
|
||||
fn timers(self) -> &'static mut [Timer];
|
||||
}
|
||||
|
||||
/// Helper trait to reduce boilerplate.
|
||||
///
|
||||
/// We can't blanket-implement for `Into<ErasedTimer>` because of possible
|
||||
/// conflicting implementations.
|
||||
trait IntoErasedTimer: Into<ErasedTimer> {}
|
||||
|
||||
impl IntoErasedTimer for ErasedTimer {}
|
||||
|
||||
impl<T, DM> IntoErasedTimer for TimgTimer<T, DM>
|
||||
where
|
||||
DM: esp_hal::Mode,
|
||||
Self: Into<ErasedTimer>,
|
||||
{
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
impl<T, DM, COMP, UNIT> IntoErasedTimer for Alarm<'_, T, DM, COMP, UNIT>
|
||||
where
|
||||
DM: esp_hal::Mode,
|
||||
Self: Into<ErasedTimer>,
|
||||
{
|
||||
}
|
||||
|
||||
impl<T> TimerCollection for T
|
||||
where
|
||||
T: IntoErasedTimer,
|
||||
{
|
||||
fn timers(self) -> &'static mut [Timer] {
|
||||
Timer::new(self.into()).timers()
|
||||
}
|
||||
}
|
||||
|
||||
impl TimerCollection for Timer {
|
||||
fn timers(self) -> &'static mut [Timer] {
|
||||
let timers = mk_static!([Timer; 1], [self]);
|
||||
timers.timers()
|
||||
}
|
||||
}
|
||||
|
||||
impl TimerCollection for &'static mut [Timer] {
|
||||
fn timers(self) -> &'static mut [Timer] {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> TimerCollection for &'static mut [Timer; N] {
|
||||
fn timers(self) -> &'static mut [Timer] {
|
||||
self.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize embassy.
|
||||
///
|
||||
/// Call this as soon as possible, before the first timer-related operation.
|
||||
///
|
||||
/// The time driver can be one of a number of different options:
|
||||
///
|
||||
/// - A timg `Timer` instance
|
||||
/// - A systimer `Alarm` instance
|
||||
/// - An `ErasedTimer` instance
|
||||
/// - A `OneShotTimer` instance
|
||||
/// - A mutable static slice of `OneShotTimer` instances
|
||||
/// - A mutable static array of `OneShotTimer` instances
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust, no_run
|
||||
#[doc = esp_hal::before_snippet!()]
|
||||
/// use esp_hal::timg::TimerGroup;
|
||||
///
|
||||
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
/// esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
///
|
||||
/// // ... now you can spawn embassy tasks or use `Timer::after` etc.
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn init(clocks: &Clocks, time_driver: impl TimerCollection) {
|
||||
EmbassyTimer::init(clocks, time_driver.timers())
|
||||
}
|
||||
|
@ -680,7 +680,10 @@ unsafe extern "C" fn stack_chk_fail() {
|
||||
#[macro_export]
|
||||
macro_rules! before_snippet {
|
||||
() => {
|
||||
core::include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/doc-helper/before"))
|
||||
core::include_str!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../esp-hal/doc-helper/before"
|
||||
))
|
||||
};
|
||||
}
|
||||
|
||||
@ -690,6 +693,9 @@ macro_rules! before_snippet {
|
||||
#[macro_export]
|
||||
macro_rules! before_snippet {
|
||||
() => {
|
||||
core::include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "\\doc-helper\\before"))
|
||||
core::include_str!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"\\..\\esp-hal\\doc-helper\\before"
|
||||
))
|
||||
};
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Block until the timer has elasped.
|
||||
/// Block until the timer has elapsed.
|
||||
pub fn wait(&mut self) {
|
||||
while !self.has_elapsed() {}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed `init` to accept timers of multiple types (#1957)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Increased NPL event queue size to prevent overflow (#1891)
|
||||
|
@ -53,8 +53,9 @@ atomic-waker = { version = "1.1.2", default-features = false, features = [
|
||||
] }
|
||||
|
||||
[build-dependencies]
|
||||
toml-cfg = "0.2.0"
|
||||
esp-build = { version = "0.1.0", path = "../esp-build" }
|
||||
toml-cfg = "0.2.0"
|
||||
esp-build = { version = "0.1.0", path = "../esp-build" }
|
||||
esp-metadata = { version = "0.2.0", path = "../esp-metadata" }
|
||||
|
||||
[features]
|
||||
default = ["log"]
|
||||
|
@ -28,7 +28,7 @@ Minimum supported Rust compiler version: 1.72.0.0
|
||||
|
||||
### Importing
|
||||
|
||||
Ensure that the right features are enabled for your chip. See [Examples] for more examples.
|
||||
Ensure that the right features are enabled for your chip. See [Examples](https://github.com/esp-rs/esp-hal/tree/main/examples#examples) for more examples.
|
||||
|
||||
```toml
|
||||
[dependencies.esp-wifi]
|
||||
|
@ -1,11 +1,41 @@
|
||||
use esp_build::assert_unique_used_features;
|
||||
use std::{error::Error, str::FromStr};
|
||||
|
||||
fn main() -> Result<(), String> {
|
||||
use esp_build::assert_unique_used_features;
|
||||
use esp_metadata::{Chip, Config};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Ensure that only a single chip is specified:
|
||||
assert_unique_used_features!(
|
||||
"esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32s2", "esp32s3"
|
||||
);
|
||||
|
||||
// NOTE: update when adding new device support!
|
||||
// Determine the name of the configured device:
|
||||
let device_name = if cfg!(feature = "esp32") {
|
||||
"esp32"
|
||||
} else if cfg!(feature = "esp32c2") {
|
||||
"esp32c2"
|
||||
} else if cfg!(feature = "esp32c3") {
|
||||
"esp32c3"
|
||||
} else if cfg!(feature = "esp32c6") {
|
||||
"esp32c6"
|
||||
} else if cfg!(feature = "esp32h2") {
|
||||
"esp32h2"
|
||||
} else if cfg!(feature = "esp32s2") {
|
||||
"esp32s2"
|
||||
} else if cfg!(feature = "esp32s3") {
|
||||
"esp32s3"
|
||||
} else {
|
||||
unreachable!() // We've confirmed exactly one known device was selected
|
||||
};
|
||||
|
||||
// Load the configuration file for the configured device:
|
||||
let chip = Chip::from_str(device_name)?;
|
||||
let config = Config::for_chip(&chip);
|
||||
|
||||
// Define all necessary configuration symbols for the configured device:
|
||||
config.define_symbols();
|
||||
|
||||
#[cfg(all(feature = "ble", feature = "esp32s2"))]
|
||||
{
|
||||
panic!(
|
||||
@ -38,39 +68,17 @@ fn main() -> Result<(), String> {
|
||||
"#
|
||||
);
|
||||
}
|
||||
match std::env::var("OPT_LEVEL") {
|
||||
Ok(level) => {
|
||||
if level != "2" && level != "3" {
|
||||
let message = format!(
|
||||
"esp-wifi should be built with optimization level 2 or 3 - yours is {level}.
|
||||
See https://github.com/esp-rs/esp-wifi",
|
||||
);
|
||||
print_warning(message);
|
||||
}
|
||||
if let Ok(level) = std::env::var("OPT_LEVEL") {
|
||||
if level != "2" && level != "3" {
|
||||
let message = format!(
|
||||
"esp-wifi should be built with optimization level 2 or 3 - yours is {level}.
|
||||
See https://github.com/esp-rs/esp-wifi",
|
||||
);
|
||||
print_warning(message);
|
||||
}
|
||||
Err(_err) => (),
|
||||
}
|
||||
|
||||
#[cfg(feature = "esp32")]
|
||||
println!("cargo:rustc-cfg=esp32");
|
||||
|
||||
#[cfg(feature = "esp32c2")]
|
||||
println!("cargo:rustc-cfg=esp32c2");
|
||||
|
||||
#[cfg(feature = "esp32c3")]
|
||||
println!("cargo:rustc-cfg=esp32c3");
|
||||
|
||||
#[cfg(feature = "esp32c6")]
|
||||
println!("cargo:rustc-cfg=esp32c6");
|
||||
|
||||
#[cfg(feature = "esp32h2")]
|
||||
println!("cargo:rustc-cfg=esp32h2");
|
||||
|
||||
#[cfg(feature = "esp32s2")]
|
||||
println!("cargo:rustc-cfg=esp32s2");
|
||||
|
||||
#[cfg(feature = "esp32s3")]
|
||||
println!("cargo:rustc-cfg=esp32s3");
|
||||
println!("cargo:rustc-cfg={}", device_name);
|
||||
|
||||
#[cfg(feature = "coex")]
|
||||
{
|
||||
|
@ -17,8 +17,14 @@ use core::{cell::RefCell, mem::MaybeUninit, ptr::addr_of_mut};
|
||||
use common_adapter::{chip_specific::phy_mem_init, init_radio_clock_control, RADIO_CLOCKS};
|
||||
use critical_section::Mutex;
|
||||
use esp_hal as hal;
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
use esp_hal::timer::systimer::Alarm;
|
||||
use fugit::MegahertzU32;
|
||||
use hal::{clock::Clocks, system::RadioClockController};
|
||||
use hal::{
|
||||
clock::Clocks,
|
||||
system::RadioClockController,
|
||||
timer::{timg::Timer as TimgTimer, ErasedTimer, PeriodicTimer},
|
||||
};
|
||||
use linked_list_allocator::Heap;
|
||||
#[cfg(feature = "wifi")]
|
||||
use wifi::WifiError;
|
||||
@ -142,7 +148,7 @@ fn init_heap() {
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) type EspWifiTimer = crate::timer::TimeBase;
|
||||
type TimeBase = PeriodicTimer<'static, ErasedTimer>;
|
||||
|
||||
#[derive(Debug, PartialEq, PartialOrd)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
@ -215,10 +221,86 @@ impl EspWifiInitFor {
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize for using WiFi and or BLE
|
||||
/// A trait to allow better UX for initializing esp-wifi.
|
||||
///
|
||||
/// This trait is meant to be used only for the `init` function.
|
||||
/// Calling `timers()` multiple times may panic.
|
||||
pub trait EspWifiTimerSource {
|
||||
/// Returns the timer source.
|
||||
fn timer(self) -> TimeBase;
|
||||
}
|
||||
|
||||
/// Helper trait to reduce boilerplate.
|
||||
///
|
||||
/// We can't blanket-implement for `Into<ErasedTimer>` because of possible
|
||||
/// conflicting implementations.
|
||||
trait IntoErasedTimer: Into<ErasedTimer> {}
|
||||
|
||||
impl<T, DM> IntoErasedTimer for TimgTimer<T, DM>
|
||||
where
|
||||
DM: esp_hal::Mode,
|
||||
Self: Into<ErasedTimer>,
|
||||
{
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
impl<T, DM, COMP, UNIT> IntoErasedTimer for Alarm<'_, T, DM, COMP, UNIT>
|
||||
where
|
||||
DM: esp_hal::Mode,
|
||||
Self: Into<ErasedTimer>,
|
||||
{
|
||||
}
|
||||
|
||||
impl IntoErasedTimer for ErasedTimer {}
|
||||
|
||||
impl<T> EspWifiTimerSource for T
|
||||
where
|
||||
T: IntoErasedTimer,
|
||||
{
|
||||
fn timer(self) -> TimeBase {
|
||||
TimeBase::new(self.into()).timer()
|
||||
}
|
||||
}
|
||||
|
||||
impl EspWifiTimerSource for TimeBase {
|
||||
fn timer(self) -> TimeBase {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize for using WiFi and or BLE.
|
||||
///
|
||||
/// # The `timer` argument
|
||||
///
|
||||
/// The `timer` argument is a timer source that is used by the WiFi driver to
|
||||
/// schedule internal tasks. The timer source can be any of the following:
|
||||
///
|
||||
/// - A timg `Timer` instance
|
||||
/// - A systimer `Alarm` instance
|
||||
/// - An `ErasedTimer` instance
|
||||
/// - A `OneShotTimer` instance
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust, no_run
|
||||
#[doc = esp_hal::before_snippet!()]
|
||||
/// use esp_hal::{rng::Rng, timg::TimerGroup};
|
||||
/// use esp_wifi::EspWifiInitFor;
|
||||
///
|
||||
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
/// let init = esp_wifi::initialize(
|
||||
/// EspWifiInitFor::Wifi,
|
||||
/// timg0.timer0,
|
||||
/// Rng::new(peripherals.RNG),
|
||||
/// peripherals.RADIO_CLK,
|
||||
/// &clocks,
|
||||
/// )
|
||||
/// .unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn initialize(
|
||||
init_for: EspWifiInitFor,
|
||||
timer: EspWifiTimer,
|
||||
timer: impl EspWifiTimerSource,
|
||||
rng: hal::rng::Rng,
|
||||
radio_clocks: hal::peripherals::RADIO_CLK,
|
||||
clocks: &Clocks,
|
||||
@ -238,7 +320,7 @@ pub fn initialize(
|
||||
init_radio_clock_control(radio_clocks);
|
||||
init_rng(rng);
|
||||
init_tasks();
|
||||
setup_timer_isr(timer)?;
|
||||
setup_timer_isr(timer.timer())?;
|
||||
wifi_set_log_verbose();
|
||||
init_clocks();
|
||||
|
||||
|
@ -14,6 +14,8 @@ mod arch_specific;
|
||||
pub use arch_specific::*;
|
||||
pub use chip_specific::*;
|
||||
|
||||
use crate::TimeBase;
|
||||
|
||||
pub fn setup_timer_isr(timebase: TimeBase) -> Result<(), esp_hal::timer::Error> {
|
||||
setup_radio_isr();
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
use core::cell::RefCell;
|
||||
|
||||
use critical_section::Mutex;
|
||||
use esp_hal::{
|
||||
interrupt::InterruptHandler,
|
||||
timer::{ErasedTimer, PeriodicTimer},
|
||||
};
|
||||
use esp_hal::interrupt::InterruptHandler;
|
||||
#[cfg(any(feature = "esp32c6", feature = "esp32h2"))]
|
||||
use peripherals::INTPRI as SystemPeripheral;
|
||||
#[cfg(not(any(feature = "esp32c6", feature = "esp32h2")))]
|
||||
@ -17,10 +14,10 @@ use crate::{
|
||||
riscv,
|
||||
},
|
||||
preempt::preempt::task_switch,
|
||||
TimeBase,
|
||||
};
|
||||
|
||||
/// The timer responsible for time slicing.
|
||||
pub type TimeBase = PeriodicTimer<'static, ErasedTimer>;
|
||||
static ALARM0: Mutex<RefCell<Option<TimeBase>>> = Mutex::new(RefCell::new(None));
|
||||
const TIMESLICE_FREQUENCY: fugit::HertzU64 =
|
||||
fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64);
|
||||
|
@ -1,18 +1,15 @@
|
||||
use core::cell::RefCell;
|
||||
|
||||
use critical_section::Mutex;
|
||||
use esp_hal::{
|
||||
interrupt::InterruptHandler,
|
||||
timer::{ErasedTimer, PeriodicTimer},
|
||||
};
|
||||
use esp_hal::interrupt::InterruptHandler;
|
||||
|
||||
use crate::{
|
||||
hal::{interrupt, trapframe::TrapFrame, xtensa_lx, xtensa_lx_rt},
|
||||
preempt::preempt::task_switch,
|
||||
TimeBase,
|
||||
};
|
||||
|
||||
/// The timer responsible for time slicing.
|
||||
pub type TimeBase = PeriodicTimer<'static, ErasedTimer>;
|
||||
static TIMER1: Mutex<RefCell<Option<TimeBase>>> = Mutex::new(RefCell::new(None));
|
||||
const TIMESLICE_FREQUENCY: fugit::HertzU64 =
|
||||
fugit::HertzU64::from_raw(crate::CONFIG.tick_rate_hz as u64);
|
||||
|
@ -16,19 +16,9 @@ use esp_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn run() {
|
||||
loop {
|
||||
@ -47,10 +37,7 @@ async fn main(spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
spawner.spawn(run()).ok();
|
||||
|
||||
|
@ -26,20 +26,10 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use lis3dh_async::{Lis3dh, Range, SlaveAddr};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let peripherals = Peripherals::take();
|
||||
@ -47,10 +37,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -27,19 +27,9 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let peripherals = Peripherals::take();
|
||||
@ -47,10 +37,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -28,20 +28,10 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
println!("Init!");
|
||||
@ -50,10 +40,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -42,7 +42,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
@ -54,16 +54,6 @@ const SINE: [i16; 64] = [
|
||||
-28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211,
|
||||
];
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
println!("Init!");
|
||||
@ -72,10 +62,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -105,8 +105,7 @@ async fn main(low_prio_spawner: Spawner) {
|
||||
OneShotTimer::new(alarm0)
|
||||
};
|
||||
|
||||
let timers = [timer0, timer1];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], timers);
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], [timer0, timer1]);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
|
||||
static EXECUTOR: StaticCell<InterruptExecutor<2>> = StaticCell::new();
|
||||
|
@ -22,24 +22,10 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{
|
||||
systimer::{SystemTimer, Target},
|
||||
ErasedTimer,
|
||||
OneShotTimer,
|
||||
},
|
||||
timer::systimer::{SystemTimer, Target},
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
esp_println::println!("Init!");
|
||||
@ -48,10 +34,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -33,24 +33,10 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
prelude::*,
|
||||
system::SystemControl,
|
||||
timer::{
|
||||
systimer::{SystemTimer, Target},
|
||||
ErasedTimer,
|
||||
OneShotTimer,
|
||||
},
|
||||
timer::systimer::{SystemTimer, Target},
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
esp_println::println!("Init!");
|
||||
@ -59,10 +45,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync},
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
|
||||
@ -28,16 +28,6 @@ const WIDTH: usize = 80;
|
||||
#[cfg(debug_assertions)]
|
||||
compile_error!("Run this example in release mode");
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn signal_task(mut pin: Output<'static, Gpio5>) {
|
||||
loop {
|
||||
@ -57,10 +47,7 @@ async fn main(spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -21,20 +21,10 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rmt::{asynch::TxChannelAsync, PulseCode, Rmt, TxChannelConfig, TxChannelCreatorAsync},
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
println!("Init!");
|
||||
@ -43,10 +33,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -17,7 +17,7 @@ use esp_hal::{
|
||||
gpio::Io,
|
||||
peripherals::{Peripherals, UART0},
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
uart::{
|
||||
config::{AtCmdConfig, Config},
|
||||
Uart,
|
||||
@ -33,16 +33,6 @@ const READ_BUF_SIZE: usize = 64;
|
||||
// EOT (CTRL-D)
|
||||
const AT_CMD: u8 = 0x04;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn writer(
|
||||
mut tx: UartTx<'static, UART0, Async>,
|
||||
@ -95,10 +85,7 @@ async fn main(spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -33,19 +33,9 @@ use esp_hal::{
|
||||
SpiMode,
|
||||
},
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
esp_println::println!("Init!");
|
||||
@ -54,10 +44,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let sclk = io.pins.gpio0;
|
||||
|
@ -22,21 +22,11 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rtc_cntl::Rtc,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
touch::{Touch, TouchConfig, TouchPad},
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
@ -46,10 +36,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut rtc = Rtc::new(peripherals.LPWR);
|
||||
|
@ -30,7 +30,7 @@ use esp_hal::{
|
||||
interrupt,
|
||||
peripherals::{self, Peripherals, TWAI0},
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
twai::{self, EspTwaiFrame, TwaiMode, TwaiRx, TwaiTx},
|
||||
};
|
||||
use esp_println::println;
|
||||
@ -38,16 +38,6 @@ use static_cell::StaticCell;
|
||||
|
||||
type TwaiOutbox = Channel<NoopRawMutex, EspTwaiFrame, 16>;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn receiver(
|
||||
mut rx: TwaiRx<'static, TWAI0, esp_hal::Async>,
|
||||
@ -99,10 +89,7 @@ async fn main(spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -29,19 +29,9 @@ use esp_hal::{
|
||||
},
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) -> () {
|
||||
esp_println::println!("Init!");
|
||||
@ -50,10 +40,7 @@ async fn main(_spawner: Spawner) -> () {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -15,7 +15,7 @@ use esp_hal::{
|
||||
clock::ClockControl,
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx},
|
||||
Async,
|
||||
};
|
||||
@ -23,16 +23,6 @@ use static_cell::StaticCell;
|
||||
|
||||
const MAX_BUFFER_SIZE: usize = 512;
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn writer(
|
||||
mut tx: UsbSerialJtagTx<'static, Async>,
|
||||
@ -80,10 +70,7 @@ async fn main(spawner: Spawner) -> () {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split();
|
||||
|
||||
|
@ -16,19 +16,9 @@ use esp_hal::{
|
||||
gpio::{Input, Io, Pull},
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
esp_println::println!("Init!");
|
||||
@ -37,10 +27,7 @@ async fn main(_spawner: Spawner) {
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]
|
||||
|
@ -21,7 +21,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -48,12 +48,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -22,7 +22,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -55,12 +55,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -22,7 +22,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
@ -68,12 +68,10 @@ fn main() -> ! {
|
||||
let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address");
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -30,7 +30,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor};
|
||||
@ -45,12 +45,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Ble,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -32,7 +32,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -61,12 +61,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::WifiBle,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -54,12 +54,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -32,7 +32,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -69,12 +69,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -88,20 +86,14 @@ async fn main(spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let config = Config::ipv4_static(StaticConfigV4 {
|
||||
|
@ -35,7 +35,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -77,12 +77,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -96,20 +94,14 @@ async fn main(spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let ap_config = Config::ipv4_static(StaticConfigV4 {
|
||||
|
@ -26,7 +26,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
@ -81,12 +81,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let server_address: Ipv4Address = HOST_IP.parse().expect("Invalid HOST_IP address");
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -100,20 +98,14 @@ async fn main(spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let config = Config::dhcpv4(Default::default());
|
||||
|
@ -32,21 +32,11 @@ use esp_hal::{
|
||||
peripherals::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{ble::controller::asynch::BleConnector, initialize, EspWifiInitFor};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
@ -57,12 +47,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Ble,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -83,20 +71,14 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let mut bluetooth = peripherals.BT;
|
||||
|
@ -22,7 +22,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
@ -62,12 +62,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -81,20 +79,14 @@ async fn main(spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let config = Config::dhcpv4(Default::default());
|
||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
@ -28,16 +28,6 @@ use esp_wifi::{
|
||||
EspWifiInitFor,
|
||||
};
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
@ -48,12 +38,10 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -67,20 +55,14 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let mut ticker = Ticker::every(Duration::from_secs(5));
|
||||
|
@ -19,7 +19,7 @@ use esp_hal::{
|
||||
peripherals::Peripherals,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
@ -48,12 +48,10 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
@ -67,20 +65,14 @@ async fn main(spawner: Spawner) -> ! {
|
||||
#[cfg(feature = "esp32")]
|
||||
{
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timer0: ErasedTimer = timg1.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg1.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
{
|
||||
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER)
|
||||
.split::<esp_hal::timer::systimer::Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = [OneShotTimer::new(alarm0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
}
|
||||
|
||||
let (manager, sender, receiver) = esp_now.split();
|
||||
|
@ -15,7 +15,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
@ -35,12 +35,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -20,7 +20,7 @@ use esp_hal::{
|
||||
prelude::*,
|
||||
rng::Rng,
|
||||
system::SystemControl,
|
||||
timer::{timg::TimerGroup, ErasedTimer, PeriodicTimer},
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
@ -54,12 +54,10 @@ fn main() -> ! {
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timer = PeriodicTimer::new(timer0);
|
||||
|
||||
let init = initialize(
|
||||
EspWifiInitFor::Wifi,
|
||||
timer,
|
||||
timg0.timer0,
|
||||
Rng::new(peripherals.RNG),
|
||||
peripherals.RADIO_CLK,
|
||||
&clocks,
|
||||
|
@ -120,17 +120,13 @@ struct Resources {
|
||||
impl Resources {
|
||||
fn set_up_embassy_with_timg0(self) {
|
||||
let timg0 = TimerGroup::new(self.timg0, &self.clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = mk_static!(OneShotTimer<ErasedTimer>, OneShotTimer::new(timer0));
|
||||
esp_hal_embassy::init(&self.clocks, core::slice::from_mut(timers));
|
||||
esp_hal_embassy::init(&self.clocks, timg0.timer0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
fn set_up_embassy_with_systimer(self) {
|
||||
let systimer = SystemTimer::new(self.systimer).split::<Target>();
|
||||
let alarm0: ErasedTimer = systimer.alarm0.into();
|
||||
let timers = mk_static!(OneShotTimer<ErasedTimer>, OneShotTimer::new(alarm0));
|
||||
esp_hal_embassy::init(&self.clocks, core::slice::from_mut(timers));
|
||||
esp_hal_embassy::init(&self.clocks, systimer.alarm0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,10 +55,7 @@ impl<'d> Context<'d> {
|
||||
let delay = Delay::new(&clocks);
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
let timers = [OneShotTimer::new(timer0)];
|
||||
let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);
|
||||
esp_hal_embassy::init(&clocks, timers);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
|
||||
Context {
|
||||
io2: Input::new(io.pins.gpio2, Pull::Down),
|
||||
|
Loading…
x
Reference in New Issue
Block a user