diff --git a/Cargo.toml b/Cargo.toml index 15e2548a..17474898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ esp-println = { version = "0.11.0", default-features = false, features = [ ] } esp-alloc = "0.4.0" esp-wifi = { version = "0.9.1", default-features = false, features = [ + "esp-alloc", "phy-enable-usb", "ps-max-modem", "wifi", @@ -131,12 +132,12 @@ crc = "3.0.1" enumset = "1.1.3" [patch.crates-io] -esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "38abd6e1ab9ca621d310a198696a300db82c0ad8" } -esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "38abd6e1ab9ca621d310a198696a300db82c0ad8" } -esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "38abd6e1ab9ca621d310a198696a300db82c0ad8" } -esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "38abd6e1ab9ca621d310a198696a300db82c0ad8" } -esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "38abd6e1ab9ca621d310a198696a300db82c0ad8" } -esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "38abd6e1ab9ca621d310a198696a300db82c0ad8" } +esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "2a74addee03970f1f79522b96dea285c947ac329" } +esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "2a74addee03970f1f79522b96dea285c947ac329" } +esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "2a74addee03970f1f79522b96dea285c947ac329" } +esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "2a74addee03970f1f79522b96dea285c947ac329" } +esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "2a74addee03970f1f79522b96dea285c947ac329" } +esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "2a74addee03970f1f79522b96dea285c947ac329" } [features] default = ["defmt"] diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 49d959e5..75812795 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -21,7 +21,7 @@ use esp_hal::{ timer::{ systimer::{SystemTimer, Target}, timg::TimerGroup, - ErasedTimer, + AnyTimer, }, Async, }; @@ -150,7 +150,7 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - ErasedTimer::from(TimerGroup::new(peripherals.TIMG0) + AnyTimer::from(TimerGroup::new(peripherals.TIMG0) .timer0), peripherals.RNG, peripherals.RADIO_CLK, diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 82703de9..65a0fe86 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -22,7 +22,7 @@ use esp_hal::{ timer::{ systimer::{SystemTimer, Target}, timg::TimerGroup, - ErasedTimer, + AnyTimer, }, Async, }; @@ -151,7 +151,7 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - ErasedTimer::from(SystemTimer::new(peripherals.SYSTIMER).split::().alarm0), + AnyTimer::from(SystemTimer::new(peripherals.SYSTIMER).split::().alarm0), peripherals.RNG, peripherals.RADIO_CLK, ) diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index fe17abc1..e459e759 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -22,7 +22,7 @@ use esp_hal::{ timer::{ systimer::{SystemTimer, Target}, timg::TimerGroup, - ErasedTimer, + AnyTimer, }, Async, }; @@ -148,7 +148,7 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - ErasedTimer::from(TimerGroup::new(peripherals.TIMG0) + AnyTimer::from(TimerGroup::new(peripherals.TIMG0) .timer0), peripherals.RNG, peripherals.RADIO_CLK, diff --git a/src/board/startup.rs b/src/board/startup.rs index 9478e4cb..92f27b90 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -3,16 +3,13 @@ use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use static_cell::make_static; -use crate::{ - board::{ - drivers::{battery_monitor::BatteryMonitor, frontend::Frontend}, - utils::DummyOutputPin, - wifi::WifiDriver, - AdcClockEnable, AdcDrdy, AdcReset, AdcSpi, ChargerStatus, ChargerStatusPin, Display, - DisplayChipSelect, DisplayDataCommand, DisplayDmaChannel, DisplayMosi, DisplayReset, - DisplaySclk, DisplaySpiInstance, EcgFrontend, TouchDetect, VbusDetect, VbusDetectPin, - }, - heap::init_heap, +use crate::board::{ + drivers::{battery_monitor::BatteryMonitor, frontend::Frontend}, + utils::DummyOutputPin, + wifi::WifiDriver, + AdcClockEnable, AdcDrdy, AdcReset, AdcSpi, ChargerStatus, ChargerStatusPin, Display, + DisplayChipSelect, DisplayDataCommand, DisplayDmaChannel, DisplayMosi, DisplayReset, + DisplaySclk, DisplaySpiInstance, EcgFrontend, TouchDetect, VbusDetect, VbusDetectPin, }; use esp_hal::{ dma::*, @@ -54,7 +51,6 @@ impl StartupResources { pub(super) fn common_init() { #[cfg(feature = "log")] init_logger(log::LevelFilter::Trace); // we let the compile-time log level filter do the work - init_heap(); use core::ptr::addr_of; @@ -99,7 +95,7 @@ impl StartupResources { display_sclk: DisplaySclk, display_mosi: DisplayMosi, ) -> Display { - let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(4092); + let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(4092); let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); let display_spi = Spi::new(display_spi, 40u32.MHz(), SpiMode::Mode0) @@ -107,7 +103,7 @@ impl StartupResources { .with_mosi(display_mosi) .with_cs(display_cs) .with_dma(display_dma_channel.configure_for_async(false, DmaPriority::Priority0)) - .with_buffers(dma_tx_buf, dma_rx_buf); + .with_buffers(dma_rx_buf, dma_tx_buf); Display::new( SPIInterface::new( diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index d42f1826..90f6f51a 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -14,7 +14,7 @@ use embassy_net::{Config, Stack, StackResources}; use esp_hal::{ peripherals::{RADIO_CLK, RNG, WIFI}, rng::Rng, - timer::ErasedTimer, + timer::AnyTimer, }; use esp_wifi::{ wifi::{WifiApDevice, WifiDevice, WifiDeviceMode, WifiStaDevice}, @@ -81,7 +81,7 @@ pub struct WifiDriver { } struct WifiInitResources { - timer: ErasedTimer, + timer: AnyTimer, rng: Rng, radio_clk: RADIO_CLK, } @@ -132,7 +132,7 @@ impl WifiDriverState { } impl WifiDriver { - pub fn new(wifi: WIFI, timer: ErasedTimer, rng: RNG, radio_clk: RADIO_CLK) -> Self { + pub fn new(wifi: WIFI, timer: AnyTimer, rng: RNG, radio_clk: RADIO_CLK) -> Self { let rng = Rng::new(rng); Self { wifi, diff --git a/src/heap.rs b/src/heap.rs deleted file mode 100644 index 762472cd..00000000 --- a/src/heap.rs +++ /dev/null @@ -1,15 +0,0 @@ -use core::{mem::MaybeUninit, ptr::addr_of_mut}; - -#[global_allocator] -pub static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); - -pub fn init_heap() { - const HEAP_SIZE: usize = (48 + 96) * 1024; - static mut HEAP: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; - - unsafe { - let heap_size = HEAP.len(); - info!("Heap size: {}", heap_size); - ALLOCATOR.init(addr_of_mut!(HEAP).cast(), heap_size); - } -} diff --git a/src/main.rs b/src/main.rs index be5d55b8..9aea49c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,6 @@ use esp_hal::gpio::RtcPin as RtcWakeupPin; use esp_hal::gpio::RtcPinWithResistors as RtcWakeupPin; mod board; -mod heap; pub mod human_readable; mod stack_protection; mod states; @@ -200,6 +199,8 @@ where #[main] async fn main(_spawner: Spawner) { + esp_alloc::heap_allocator!((48 + 96) * 1024); + let resources = StartupResources::initialize().await; let interrupt_executor = make_static!(InterruptExecutor::new(resources.software_interrupt1)); diff --git a/src/states/menu/main.rs b/src/states/menu/main.rs index 872208a3..7f64446b 100644 --- a/src/states/menu/main.rs +++ b/src/states/menu/main.rs @@ -1,6 +1,5 @@ use crate::{ board::initialized::Context, - heap::ALLOCATOR, states::menu::{AppMenu, MenuScreen}, AppState, }; @@ -29,7 +28,7 @@ impl SelectValue for MainMenuEvents { } pub async fn main_menu(context: &mut Context) -> AppState { - info!("Free heap: {} bytes", ALLOCATOR.free()); + info!("Free heap: {} bytes", esp_alloc::HEAP.free()); MainMenu .display(context)