From 27d032dcc6353f5aa99bf79999af04a02a37a4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 12 Mar 2024 18:17:50 +0100 Subject: [PATCH 01/29] Update esp-hal to 0.16 --- Cargo.toml | 60 +++++++------------ .../drivers/battery_monitor/battery_fg.rs | 3 - src/board/drivers/bitbang_spi.rs | 1 - src/board/hardware/v4.rs | 1 - src/board/hardware/v6c6.rs | 1 - src/board/hardware/v6s3.rs | 1 - src/board/initialized.rs | 1 - src/board/mod.rs | 9 --- src/board/startup.rs | 1 - src/board/wifi/ap.rs | 5 +- src/board/wifi/ap_sta.rs | 15 ++--- src/board/wifi/mod.rs | 11 ++-- src/board/wifi/sta.rs | 5 +- src/main.rs | 1 - src/stack_protection.rs | 1 - src/states/measure.rs | 2 +- 16 files changed, 34 insertions(+), 84 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b1f0ada2..66072201 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ norfs-esp32s3 = { git = "https://github.com/card-io-ecg/norfs.git", rev = "19e14 norfs-esp32c6 = { git = "https://github.com/card-io-ecg/norfs.git", rev = "19e14b5" } object-chain = "0.1.3" bad-server = { path = "bad-server" } -defmt = { version = "=0.3.5" } +defmt = { version = "=0.3.6" } ufmt = "0.2.0" smoltcp = { version = "0.11.0", default-features = false, features = [ @@ -51,35 +51,23 @@ embassy-time = { version = "0.3.0" } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } -# esp32s2-hal = { version = "0.10.0", optional = true, features = ["rt", "async", "embassy", "embassy-time-systick", "eh1"] } -esp32s3-hal = { version = "0.15.0", optional = true, features = [ +esp-hal = { version = "0.16.1", features = [ "rt", "async", "embassy", "embassy-executor-thread", "embassy-executor-interrupt", - "embassy-time-systick", "eh1", ] } -esp32c6-hal = { version = "0.8.0", optional = true, default-features = false, features = [ - "rt", - "vectored", - "zero-rtc-bss", - "async", - "embassy", - "embassy-executor-thread", - "embassy-executor-interrupt", - "eh1", -] } -esp-backtrace = { version = "0.10.0", features = [ +esp-backtrace = { version = "0.11.1", features = [ "panic-handler", "exception-handler", ] } -esp-println = { version = "0.8.0", default-features = false, features = [ +esp-println = { version = "0.9.1", default-features = false, features = [ "critical-section", ] } esp-alloc = "0.3.0" -esp-wifi = { version = "0.3.0", default-features = false, features = [ +esp-wifi = { version = "0.4.0", default-features = false, features = [ "phy-enable-usb", "ps-max-modem", "wifi", @@ -97,7 +85,7 @@ ssd1306 = { git = "https://github.com/bugadani/ssd1306.git", branch = "ehal1", f "graphics", ] } -atomic_enum = "0.2.0" +portable_atomic_enum = "0.3.1" config-site = { path = "config-site", default-features = false, features = [ "embedded", ] } @@ -150,17 +138,10 @@ smoltcp = { workspace = true } crc = "3.0.1" enumset = "1.1.3" -[patch.crates-io] -esp32-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp32s2-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp32s3-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp32c2-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp32c3-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp32c6-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp32h2-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp-hal-procmacros = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -esp-wifi = { git = "https://github.com/esp-rs/esp-wifi", rev = "d200a167237f03cf63edce721a5f85fd65d2db84" } +# [patch.crates-io] +# esp-hal-procmacros = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } +# esp-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } +# esp-wifi = { git = "https://github.com/esp-rs/esp-wifi", rev = "d200a167237f03cf63edce721a5f85fd65d2db84" } [features] default = ["defmt"] @@ -173,8 +154,9 @@ hw_v6 = ["battery_max17055"] # skipped v5, v6 has S3 and C6 options # MCU options # esp32s2 = ["dep:esp32s2", "dep:esp32s2-hal", "esp-backtrace/esp32s2", "esp-println/esp32s2", "rtt"] esp32s3 = [ - "dep:esp32s3-hal", - "esp32s3-hal/embassy-time-systick", + "esp-hal/esp32s3", + "esp-hal/embassy-time-systick-16mhz", + "embassy-executor/integrated-timers", "dep:norfs-esp32s3", "esp-backtrace/esp32s3", "esp-println/esp32s3", @@ -182,8 +164,8 @@ esp32s3 = [ "esp-wifi/esp32s3", ] esp32c6 = [ - "dep:esp32c6-hal", - "esp32c6-hal/embassy-time-timg0", + "esp-hal/esp32c6", + "esp-hal/embassy-time-timg0", "embassy-time/generic-queue-8", "dep:norfs-esp32c6", "esp-backtrace/esp32c6", @@ -196,8 +178,8 @@ esp32c6 = [ downsampler-light = [] # uses IIR-based filtering and less memory # Print options -uart = ["esp-backtrace/print-uart", "esp-println/uart"] -jtag-serial = ["esp-backtrace/print-jtag-serial", "esp-println/jtag-serial"] +uart = ["esp-println/uart"] +jtag-serial = ["esp-println/jtag-serial"] log = [ "dep:log", @@ -205,8 +187,8 @@ log = [ "esp-println/log", "esp-println/colors", "esp-wifi/log", - "esp32s3-hal?/log", - "esp32c6-hal?/log", + "esp-hal/log", + "esp-backtrace/println", "logger/log", "config-site/log", @@ -227,8 +209,8 @@ defmt = [ "embedded-graphics/defmt", "esp-println/defmt-espflash", "esp-wifi/defmt", - "esp32s3-hal?/defmt", - "esp32c6-hal?/defmt", + "esp-hal/defmt", + "esp-backtrace/defmt", "logger/defmt", "config-site/defmt", diff --git a/src/board/drivers/battery_monitor/battery_fg.rs b/src/board/drivers/battery_monitor/battery_fg.rs index ef1088fc..2c817f23 100644 --- a/src/board/drivers/battery_monitor/battery_fg.rs +++ b/src/board/drivers/battery_monitor/battery_fg.rs @@ -3,9 +3,6 @@ use embedded_hal::digital::OutputPin; use embedded_hal_async::{delay::DelayNs, i2c::I2c}; use max17055::Max17055; -#[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))] -use crate::board::hal as esp_hal; - use crate::{task_control::TaskControlToken, Shared}; #[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))] use esp_hal::gpio::RTCPinWithResistors; diff --git a/src/board/drivers/bitbang_spi.rs b/src/board/drivers/bitbang_spi.rs index c310d5e2..e78197a3 100644 --- a/src/board/drivers/bitbang_spi.rs +++ b/src/board/drivers/bitbang_spi.rs @@ -1,6 +1,5 @@ use core::convert::Infallible; -use crate::board::hal as esp_hal; use embassy_time::{Duration, Ticker}; use embedded_hal::{ digital::{InputPin, OutputPin, PinState}, diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 4c590073..57492c2a 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -4,7 +4,6 @@ use crate::board::{ display::Display as DisplayType, frontend::{Frontend, PoweredFrontend}, }, - hal as esp_hal, utils::DummyOutputPin, wifi::WifiDriver, }; diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index a95b6b43..0d286384 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -4,7 +4,6 @@ use crate::board::{ display::Display as DisplayType, frontend::{Frontend, PoweredFrontend}, }, - hal as esp_hal, utils::DummyOutputPin, wifi::WifiDriver, }; diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index f9c6c402..fac44623 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -4,7 +4,6 @@ use crate::board::{ display::Display as DisplayType, frontend::{Frontend, PoweredFrontend}, }, - hal as esp_hal, utils::DummyOutputPin, wifi::WifiDriver, }; diff --git a/src/board/initialized.rs b/src/board/initialized.rs index 6bd6f39a..339d70c3 100644 --- a/src/board/initialized.rs +++ b/src/board/initialized.rs @@ -4,7 +4,6 @@ use crate::{ board::{ config::Config, drivers::battery_monitor::BatteryMonitor, - hal as esp_hal, storage::FileSystem, wifi::{ap::Ap, sta::Sta, WifiDriver}, ChargerStatus, Display, EcgFrontend, VbusDetect, diff --git a/src/board/mod.rs b/src/board/mod.rs index bdeaf8e9..05dfa1cc 100644 --- a/src/board/mod.rs +++ b/src/board/mod.rs @@ -22,15 +22,6 @@ pub mod wifi; use esp_backtrace as _; -#[cfg(feature = "esp32s2")] -pub use esp32s2_hal as hal; - -#[cfg(feature = "esp32s3")] -pub use esp32s3_hal as hal; - -#[cfg(feature = "esp32c6")] -pub use esp32c6_hal as hal; - pub use hardware::*; pub const DEFAULT_BACKEND_URL: &str = "https://stingray-prime-monkey.ngrok-free.app"; diff --git a/src/board/startup.rs b/src/board/startup.rs index edcc442c..b3c4d4c9 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -6,7 +6,6 @@ use static_cell::make_static; use crate::{ board::{ drivers::{battery_monitor::BatteryMonitor, frontend::Frontend}, - hal as esp_hal, utils::DummyOutputPin, wifi::WifiDriver, AdcClockEnable, AdcDrdy, AdcReset, AdcSpi, ChargerStatus, Display, DisplayChipSelect, diff --git a/src/board/wifi/ap.rs b/src/board/wifi/ap.rs index b9891851..379bf0ab 100644 --- a/src/board/wifi/ap.rs +++ b/src/board/wifi/ap.rs @@ -4,10 +4,7 @@ use enumset::EnumSet; use gui::widgets::wifi_access_point::WifiAccessPointState; use crate::{ - board::{ - hal as esp_hal, - wifi::{ap_net_task, StackWrapper}, - }, + board::wifi::{ap_net_task, StackWrapper}, task_control::{TaskControlToken, TaskController}, }; use embassy_executor::Spawner; diff --git a/src/board/wifi/ap_sta.rs b/src/board/wifi/ap_sta.rs index 880b8da5..8a1322c7 100644 --- a/src/board/wifi/ap_sta.rs +++ b/src/board/wifi/ap_sta.rs @@ -3,16 +3,11 @@ use embassy_sync::mutex::Mutex; use embassy_time::{with_timeout, Duration}; use crate::{ - board::{ - hal as esp_hal, - wifi::{ - ap::{Ap, ApConnectionState, ApController}, - ap_net_task, - sta::{ - CommandQueue, InitialStaControllerState, Sta, StaConnectionState, StaController, - }, - sta_net_task, StackWrapper, - }, + board::wifi::{ + ap::{Ap, ApConnectionState, ApController}, + ap_net_task, + sta::{CommandQueue, InitialStaControllerState, Sta, StaConnectionState, StaController}, + sta_net_task, StackWrapper, }, task_control::{TaskControlToken, TaskController}, }; diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index ac029e1e..839ffb69 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -6,13 +6,10 @@ type WifiTimer = esp_hal::timer::Timer; use crate::{ - board::{ - hal as esp_hal, - wifi::{ - ap::{Ap, ApState}, - ap_sta::ApStaState, - sta::{Sta, StaState}, - }, + board::wifi::{ + ap::{Ap, ApState}, + ap_sta::ApStaState, + sta::{Sta, StaState}, }, task_control::TaskControlToken, }; diff --git a/src/board/wifi/sta.rs b/src/board/wifi/sta.rs index 620a4201..739c8e09 100644 --- a/src/board/wifi/sta.rs +++ b/src/board/wifi/sta.rs @@ -2,7 +2,6 @@ use core::{alloc::AllocError, ptr::addr_of, sync::atomic::Ordering}; use crate::{ board::{ - hal as esp_hal, initialized::Context, wifi::{sta_net_task, StackWrapper}, }, @@ -79,9 +78,9 @@ pub type KnownNetwork = (WifiNetwork, NetworkPreference); type Command = (StaCommand, Rc>); pub type CommandQueue = Channel; -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[atomic_enum::atomic_enum] +#[portable_atomic_enum::atomic_enum] pub(super) enum InternalConnectionState { NotConnected, Connecting, diff --git a/src/main.rs b/src/main.rs index 92757b72..558fbfb1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,6 @@ pub use crate::states::menu::battery_info::battery_info_menu; use crate::{ board::{ config::{Config, ConfigFile}, - hal as esp_hal, initialized::{Context, InnerContext}, startup::StartupResources, storage::FileSystem, diff --git a/src/stack_protection.rs b/src/stack_protection.rs index 3d6c4a8b..8794aad3 100644 --- a/src/stack_protection.rs +++ b/src/stack_protection.rs @@ -1,6 +1,5 @@ use core::ops::Range; -use crate::board::hal as esp_hal; use esp_hal::{ assist_debug::DebugAssist, get_core, interrupt, diff --git a/src/states/measure.rs b/src/states/measure.rs index 5c53d7e2..f841df71 100644 --- a/src/states/measure.rs +++ b/src/states/measure.rs @@ -1,7 +1,6 @@ use crate::{ board::{ config::types::FilterStrength, - hal::prelude::*, initialized::{Context, InnerContext}, AdcSpi, EcgFrontend, PoweredEcgFrontend, }, @@ -16,6 +15,7 @@ use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channe use embassy_time::{Duration, Instant, Ticker}; use embedded_graphics::Drawable; use embedded_hal::spi::ErrorType; +use esp_hal::prelude::*; use gui::screens::{init::StartupScreen, measure::EcgScreen}; use macros as cardio; use object_chain::{chain, Chain, ChainElement, Link}; From ededb33de543cc92b49ac05a75e154963f7db041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 21 Apr 2024 20:32:35 +0200 Subject: [PATCH 02/29] Update esp-hal to 0.17 --- Cargo.toml | 7 +++---- src/board/hardware/v4.rs | 18 ++++++++++-------- src/board/hardware/v6c6.rs | 14 ++++++++------ src/board/hardware/v6s3.rs | 18 ++++++++++-------- src/board/startup.rs | 15 ++++++++------- src/board/wifi/ap.rs | 2 +- src/board/wifi/ap_sta.rs | 2 +- src/board/wifi/mod.rs | 8 +++++--- src/board/wifi/sta.rs | 2 +- src/main.rs | 21 ++++++++------------- src/stack_protection.rs | 9 +++++---- 11 files changed, 60 insertions(+), 56 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 66072201..901160c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,13 +51,12 @@ embassy-time = { version = "0.3.0" } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } -esp-hal = { version = "0.16.1", features = [ - "rt", +esp-hal = { version = "0.17.0", features = [ "async", "embassy", "embassy-executor-thread", "embassy-executor-interrupt", - "eh1", + "embedded-hal-02" ] } esp-backtrace = { version = "0.11.1", features = [ "panic-handler", @@ -67,7 +66,7 @@ esp-println = { version = "0.9.1", default-features = false, features = [ "critical-section", ] } esp-alloc = "0.3.0" -esp-wifi = { version = "0.4.0", default-features = false, features = [ +esp-wifi = { version = "0.5.0", default-features = false, features = [ "phy-enable-usb", "ps-max-modem", "wifi", diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 57492c2a..aa1e8449 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -13,14 +13,15 @@ use esp_hal::{ clock::ClockControl, dma::*, embassy, - gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown}, + gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, i2c::I2C, peripherals::{self, Peripherals}, prelude::*, + rtc_cntl::Rtc, spi::{master::dma::SpiDma, FullDuplexMode}, systimer::SystemTimer, timer::TimerGroup, - Rtc, IO, + Async, }; use display_interface_spi::SPIInterface; @@ -35,7 +36,7 @@ pub type DisplayMosi = GpioPin, 21>; pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommand>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode>, + SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -51,7 +52,7 @@ pub type AdcDrdy = GpioPin, 4>; pub type AdcReset = GpioPin, 2>; pub type TouchDetect = GpioPin, 1>; pub type AdcSpi = ExclusiveDevice< - SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode>, + SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>, AdcChipSelect, Delay, >; @@ -69,7 +70,7 @@ pub type Display = DisplayType; pub type BatteryFgI2cInstance = peripherals::I2C0; pub type I2cSda = GpioPin; pub type I2cScl = GpioPin; -pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>; +pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { @@ -81,7 +82,7 @@ impl super::startup::StartupResources { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::max(system.clock_control).freeze(); - embassy::init(&clocks, SystemTimer::new(peripherals.SYSTIMER)); + embassy::init(&clocks, SystemTimer::new_async(peripherals.SYSTIMER)); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); @@ -137,13 +138,14 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - TimerGroup::new(peripherals.TIMG1, &clocks).timer0, + TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0, peripherals.RNG, system.radio_clock_control, ) }, clocks, - rtc: Rtc::new(peripherals.LPWR), + rtc: Rtc::new(peripherals.LPWR, None), + software_interrupt1: system.software_interrupt_control.software_interrupt1, } } } diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 0d286384..ae334026 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -14,14 +14,15 @@ use esp_hal::{ clock::ClockControl, dma::*, embassy, - gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown}, + gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, i2c::I2C, peripherals::{self, Peripherals}, prelude::*, + rtc_cntl::Rtc, spi::{master::dma::SpiDma, FullDuplexMode}, systimer::SystemTimer, timer::TimerGroup, - Rtc, IO, + Async, }; pub use crate::board::drivers::bitbang_spi::BitbangSpi; @@ -36,7 +37,7 @@ pub type DisplayMosi = GpioPin, 21>; pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommand>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode>, + SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -65,7 +66,7 @@ pub type Display = DisplayType; pub type BatteryFgI2cInstance = peripherals::I2C0; pub type I2cSda = GpioPin; pub type I2cScl = GpioPin; -pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>; +pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { @@ -77,7 +78,7 @@ impl super::startup::StartupResources { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::max(system.clock_control).freeze(); - embassy::init(&clocks, TimerGroup::new(peripherals.TIMG0, &clocks)); + embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks)); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); @@ -138,7 +139,8 @@ impl super::startup::StartupResources { ) }, clocks, - rtc: Rtc::new(peripherals.LPWR), + rtc: Rtc::new(peripherals.LPWR, None), + software_interrupt1: system.software_interrupt_control.software_interrupt1, } } } diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index fac44623..5f5ac724 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -14,14 +14,15 @@ use esp_hal::{ clock::ClockControl, dma::*, embassy, - gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown}, + gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, i2c::I2C, peripherals::{self, Peripherals}, prelude::*, + rtc_cntl::Rtc, spi::{master::dma::SpiDma, FullDuplexMode}, systimer::SystemTimer, timer::TimerGroup, - Rtc, IO, + Async, }; pub type DisplaySpiInstance = peripherals::SPI2; @@ -34,7 +35,7 @@ pub type DisplayMosi = GpioPin, 38>; pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommand>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode>, + SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -49,7 +50,7 @@ pub type AdcClockEnable = GpioPin, 40>; pub type AdcDrdy = GpioPin, 4>; pub type AdcReset = GpioPin, 42>; pub type TouchDetect = GpioPin, 1>; -pub type AdcSpiBus = SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode>; +pub type AdcSpiBus = SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>; pub type AdcSpi = ExclusiveDevice; pub type BatteryAdcEnable = DummyOutputPin; @@ -65,7 +66,7 @@ pub type Display = DisplayType; pub type BatteryFgI2cInstance = peripherals::I2C0; pub type I2cSda = GpioPin; pub type I2cScl = GpioPin; -pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>; +pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { @@ -77,7 +78,7 @@ impl super::startup::StartupResources { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::max(system.clock_control).freeze(); - embassy::init(&clocks, SystemTimer::new(peripherals.SYSTIMER)); + embassy::init(&clocks, SystemTimer::new_async(peripherals.SYSTIMER)); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); @@ -133,13 +134,14 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - TimerGroup::new(peripherals.TIMG1, &clocks).timer0, + TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0, peripherals.RNG, system.radio_clock_control, ) }, clocks, - rtc: Rtc::new(peripherals.LPWR), + rtc: Rtc::new(peripherals.LPWR, None), + software_interrupt1: system.software_interrupt_control.software_interrupt1, } } } diff --git a/src/board/startup.rs b/src/board/startup.rs index b3c4d4c9..d913e78f 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -19,11 +19,12 @@ use esp_hal::{ dma::{DmaDescriptor, DmaPriority}, gpio::OutputPin as _, interrupt, peripherals, + rtc_cntl::Rtc, spi::{ master::{dma::*, Instance, Spi}, SpiMode, }, - Rtc, + system::SoftwareInterrupt, }; #[cfg(feature = "esp32s3")] @@ -50,6 +51,8 @@ pub struct StartupResources { pub wifi: &'static mut WifiDriver, pub rtc: Rtc<'static>, + + pub software_interrupt1: SoftwareInterrupt<1>, } impl StartupResources { @@ -120,7 +123,7 @@ impl StartupResources { let display_spi = Spi::new(display_spi, 40u32.MHz(), SpiMode::Mode0, clocks) .with_sck(display_sclk.into()) .with_mosi(display_mosi.into()) - .with_dma(display_dma_channel.configure( + .with_dma(display_dma_channel.configure_for_async( false, make_static!([DmaDescriptor::EMPTY; 1]), make_static!([DmaDescriptor::EMPTY; 1]), @@ -151,8 +154,6 @@ impl StartupResources { clocks: &Clocks, ) -> AdcSpi { - use embedded_hal::digital::OutputPin; - unwrap!(interrupt::enable( dma_in_interrupt, interrupt::Priority::Priority1 @@ -164,14 +165,14 @@ impl StartupResources { let mut adc_cs: AdcChipSelect = adc_cs.into(); - unwrap!(adc_cs.set_high().ok()); + adc_cs.set_high(); ExclusiveDevice::new( Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1, clocks) .with_sck(adc_sclk.into()) .with_mosi(adc_mosi.into()) .with_miso(adc_miso.into()) - .with_dma(adc_dma_channel.configure( + .with_dma(adc_dma_channel.configure_for_async( false, make_static!([DmaDescriptor::EMPTY; 1]), make_static!([DmaDescriptor::EMPTY; 1]), @@ -245,7 +246,7 @@ impl StartupResources { charger_status.into(), BatteryFg::new( Max17055::new( - I2C::new(i2c, sda.into(), scl.into(), 100u32.kHz(), clocks), + I2C::new_async(i2c, sda.into(), scl.into(), 100u32.kHz(), clocks), design, ), fg_enable.into(), diff --git a/src/board/wifi/ap.rs b/src/board/wifi/ap.rs index 379bf0ab..2e5faa99 100644 --- a/src/board/wifi/ap.rs +++ b/src/board/wifi/ap.rs @@ -10,7 +10,7 @@ use crate::{ use embassy_executor::Spawner; use embassy_futures::join::join; use embassy_net::{Config, Stack}; -use esp_hal::{peripherals::WIFI, Rng}; +use esp_hal::{peripherals::WIFI, rng::Rng}; use esp_wifi::{ wifi::{ AccessPointConfiguration, Configuration, WifiApDevice, WifiController, WifiDevice, diff --git a/src/board/wifi/ap_sta.rs b/src/board/wifi/ap_sta.rs index 8a1322c7..62a72b6b 100644 --- a/src/board/wifi/ap_sta.rs +++ b/src/board/wifi/ap_sta.rs @@ -17,7 +17,7 @@ use embassy_futures::{ select::{select, Either}, }; use embassy_net::Config; -use esp_hal::{peripherals::WIFI, Rng}; +use esp_hal::{peripherals::WIFI, rng::Rng}; use esp_wifi::{wifi::WifiController, EspWifiInitialization}; use macros as cardio; diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index 839ffb69..e6fe2e03 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -1,9 +1,10 @@ use core::{hint::unreachable_unchecked, mem, ops::Deref, ptr::NonNull}; #[cfg(feature = "esp32s3")] -type WifiTimer = esp_hal::timer::Timer>; +type WifiTimer = + esp_hal::timer::Timer, Blocking>; #[cfg(feature = "esp32c6")] -type WifiTimer = esp_hal::systimer::Alarm; +type WifiTimer = esp_hal::systimer::Alarm; use crate::{ board::wifi::{ @@ -19,8 +20,9 @@ use embassy_net::{Config, Stack, StackResources}; use esp_hal::{ clock::Clocks, peripherals::{RNG, WIFI}, + rng::Rng, system::RadioClockControl, - Rng, + Blocking, }; use esp_wifi::{ wifi::{WifiApDevice, WifiDevice, WifiDeviceMode, WifiStaDevice}, diff --git a/src/board/wifi/sta.rs b/src/board/wifi/sta.rs index 739c8e09..2ec851d3 100644 --- a/src/board/wifi/sta.rs +++ b/src/board/wifi/sta.rs @@ -24,7 +24,7 @@ use embassy_sync::{ }; use embassy_time::{with_timeout, Duration}; use enumset::EnumSet; -use esp_hal::{peripherals::WIFI, Rng}; +use esp_hal::{peripherals::WIFI, rng::Rng}; use esp_wifi::{ wifi::{ AccessPointInfo, ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, diff --git a/src/main.rs b/src/main.rs index 558fbfb1..88aff126 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use embassy_sync::{ use embassy_time::{Duration, Timer}; use norfs::{medium::StorageMedium, Storage, StorageError}; use signal_processing::compressing_buffer::CompressingBuffer; -use static_cell::StaticCell; +use static_cell::{make_static, StaticCell}; #[cfg(feature = "battery_max17055")] pub use crate::states::menu::battery_info::battery_info_menu; @@ -54,12 +54,12 @@ use crate::{ }; use esp_hal::{ - embassy::executor::{FromCpu1, InterruptExecutor}, + delay::Delay, + embassy::executor::InterruptExecutor, entry, interrupt::Priority, - prelude::{interrupt, main}, - rtc_cntl::{sleep, sleep::WakeupLevel}, - Delay, + prelude::main, + rtc_cntl::sleep::{self, WakeupLevel}, }; #[cfg(any(feature = "hw_v4", feature = "hw_v6"))] @@ -125,13 +125,6 @@ pub enum AppState { UploadOrStore(Box>), } -static INT_EXECUTOR: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR.on_interrupt() } -} - async fn load_config(storage: Option<&mut Storage>) -> &'static mut Config where [(); M::BLOCK_COUNT]:, @@ -210,6 +203,8 @@ where async fn main(_spawner: Spawner) { let resources = StartupResources::initialize().await; + let interrupt_executor = make_static!(InterruptExecutor::new(resources.software_interrupt1)); + #[cfg(feature = "hw_v4")] info!("Hardware version: v4"); @@ -229,7 +224,7 @@ async fn main(_spawner: Spawner) { inner: InnerContext { display: resources.display, clocks: resources.clocks, - high_prio_spawner: INT_EXECUTOR.start(Priority::Priority3), + high_prio_spawner: interrupt_executor.start(Priority::Priority3), battery_monitor: resources.battery_monitor, wifi: resources.wifi, config, diff --git a/src/stack_protection.rs b/src/stack_protection.rs index 8794aad3..baa3fd3f 100644 --- a/src/stack_protection.rs +++ b/src/stack_protection.rs @@ -14,7 +14,7 @@ pub struct StackMonitor { fn conjure() -> DebugAssist<'static> { let peripheral = unsafe { ASSIST_DEBUG::steal() }; - DebugAssist::new(peripheral) + DebugAssist::new(peripheral, None) } impl StackMonitor { @@ -37,7 +37,8 @@ impl StackMonitor { top as *const u32, top - bottom ); - let mut assist = conjure(); + let peripheral = unsafe { ASSIST_DEBUG::steal() }; + let mut assist = DebugAssist::new(peripheral, Some(interrupt_handler)); const CANARY_UNITS: u32 = 1; const CANARY_GRANULARITY: u32 = 16; @@ -78,8 +79,8 @@ impl Drop for StackMonitor { } } -#[interrupt] -fn ASSIST_DEBUG() { +#[handler(priority = esp_hal::interrupt::Priority::max())] +fn interrupt_handler() { let mut da = conjure(); let cpu = get_core(); From d12a1b482c8e70012657b41ed5ca576542acf069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 22 Apr 2024 20:02:38 +0200 Subject: [PATCH 03/29] Update local patch path --- Cargo.toml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 901160c7..2f86f223 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,10 +137,8 @@ smoltcp = { workspace = true } crc = "3.0.1" enumset = "1.1.3" -# [patch.crates-io] -# esp-hal-procmacros = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -# esp-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "9a95c0aa880af7271f059797339bf890d2d59c64" } -# esp-wifi = { git = "https://github.com/esp-rs/esp-wifi", rev = "d200a167237f03cf63edce721a5f85fd65d2db84" } +[patch.crates-io] +# esp-hal = { path = "../../esp-hal/esp-hal" } [features] default = ["defmt"] From 8902099878160b80ee8b6b3402a08a76c72f22d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 29 May 2024 16:28:31 +0200 Subject: [PATCH 04/29] test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ef7d3e3a..57e2d3a4 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,4 @@ Commands Use `--watch` to enable automatic reload when a file changes. - To run the config site on your PC, run `cargo example config-site simple --watch` and open `127.0.0.1:8080` in a browser. + From 8bc8049cec4e9303cb5d282b58db91102c9c5061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 12 Aug 2024 15:30:25 +0200 Subject: [PATCH 05/29] Remove S2 --- build.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/build.rs b/build.rs index 4e2ce967..6b024a54 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,5 @@ #[derive(Clone, Copy)] enum Mcu { - ESP32S2, ESP32S3, ESP32C6, } @@ -8,7 +7,6 @@ enum Mcu { impl Mcu { fn as_str(self) -> &'static str { match self { - Self::ESP32S2 => "ESP32-S2", Self::ESP32S3 => "ESP32-S3", Self::ESP32C6 => "ESP32-C6", } @@ -39,7 +37,6 @@ impl BuildConfig { fn as_str(&self) -> String { let mcu = if self.hw_version >= HwVersion::V6 { match self.mcu { - Mcu::ESP32S2 => "s2", Mcu::ESP32S3 => "s3", Mcu::ESP32C6 => "c6", } @@ -69,13 +66,12 @@ fn get_unique(values: [(bool, T); N]) -> Option { fn main() { // Ensure that only a single MCU is specified. let mcu_features = [ - (cfg!(feature = "esp32s2"), Mcu::ESP32S2), (cfg!(feature = "esp32s3"), Mcu::ESP32S3), (cfg!(feature = "esp32c6"), Mcu::ESP32C6), ]; let Some(mcu) = get_unique(mcu_features) else { - panic!("Exactly 1 MCU must be selected via its Cargo feature (esp32s2, esp32s3, esp32c6)"); + panic!("Exactly 1 MCU must be selected via its Cargo feature (esp32s3, esp32c6)"); }; // Ensure that only a single HW version From 50024e5a82a34c342fa61d231c256fb37cc14dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 12 Aug 2024 15:30:37 +0200 Subject: [PATCH 06/29] Update settings to default to v4 for now --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e77b6620..249b3085 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ "rust-analyzer.showUnlinkedFileNotification": false, "cortex-debug.variableUseNaturalFormat": false, "rust-analyzer.cargo.features": [ - "esp32c6", - "hw_v6" + "esp32s3", + "hw_v4" ] } \ No newline at end of file From 961aa9ed4da68f233c78bd56dd29e6e6d501843e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 12 Aug 2024 15:31:35 +0200 Subject: [PATCH 07/29] Update reqwless --- Cargo.toml | 2 +- src/states/firmware_update.rs | 2 +- src/states/throughput.rs | 2 +- src/states/upload_or_store_measurement.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f86f223..96c859af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,7 +104,7 @@ replace_with = { version = "0.1", default-features = false, features = [ static_cell = { version = "2.0.0", features = ["nightly"] } bad-server = { path = "bad-server", features = ["embassy"] } embedded-tls = { version = "0.17.0", default-features = false } -reqwless = "0.11.0" +reqwless = "0.12.1" embedded-graphics.workspace = true embedded-hal.workspace = true diff --git a/src/states/firmware_update.rs b/src/states/firmware_update.rs index 50b7ea21..257d2ee1 100644 --- a/src/states/firmware_update.rs +++ b/src/states/firmware_update.rs @@ -124,7 +124,7 @@ async fn do_update(context: &mut Context) -> UpdateResult { }; let response = match result { - Ok(response) => match response.status { + Ok(response) => match response.status.into() { Status::Ok => response, Status::NotModified => return UpdateResult::AlreadyUpToDate, _ => { diff --git a/src/states/throughput.rs b/src/states/throughput.rs index 19a0cfe4..6622ed32 100644 --- a/src/states/throughput.rs +++ b/src/states/throughput.rs @@ -127,7 +127,7 @@ async fn run_test(context: &mut Context) -> TestResult { }; let response = match result { - Ok(response) => match response.status { + Ok(response) => match response.status.into() { Status::Ok => response, _ => { warn!("HTTP response error: {:?}", response.status); diff --git a/src/states/upload_or_store_measurement.rs b/src/states/upload_or_store_measurement.rs index fd9e8559..5e3065b1 100644 --- a/src/states/upload_or_store_measurement.rs +++ b/src/states/upload_or_store_measurement.rs @@ -474,7 +474,7 @@ where let mut rx_buffer = [0; 512]; match with_timeout(UPLOAD_TIMEOUT, request.send(&mut rx_buffer)).await { Ok(Ok(response)) => { - if [Status::Ok, Status::Created].contains(&response.status) { + if [Status::Ok, Status::Created].contains(&response.status.into()) { return Ok(()); } From 6cf3cd3058c6641249570307de4193a3d453b9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 12 Aug 2024 16:48:06 +0200 Subject: [PATCH 08/29] Update to esp-hal 0.19, WIP --- Cargo.toml | 18 +-- .../drivers/battery_monitor/battery_fg.rs | 4 +- src/board/drivers/battery_monitor/mod.rs | 12 +- src/board/hardware/v4.rs | 93 +++++++----- src/board/hardware/v6c6.rs | 4 +- src/board/hardware/v6s3.rs | 4 +- src/board/initialized.rs | 4 +- src/board/startup.rs | 141 ++++++------------ src/board/wifi/mod.rs | 25 ++-- src/main.rs | 8 +- 10 files changed, 141 insertions(+), 172 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96c859af..2c2b2fef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ norfs-esp32s3 = { git = "https://github.com/card-io-ecg/norfs.git", rev = "19e14 norfs-esp32c6 = { git = "https://github.com/card-io-ecg/norfs.git", rev = "19e14b5" } object-chain = "0.1.3" bad-server = { path = "bad-server" } -defmt = { version = "=0.3.6" } +defmt = "0.3.8" ufmt = "0.2.0" smoltcp = { version = "0.11.0", default-features = false, features = [ @@ -51,22 +51,20 @@ embassy-time = { version = "0.3.0" } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } -esp-hal = { version = "0.17.0", features = [ +esp-hal = { version = "0.19.0", features = [ "async", - "embassy", - "embassy-executor-thread", - "embassy-executor-interrupt", "embedded-hal-02" ] } -esp-backtrace = { version = "0.11.1", features = [ +esp-hal-embassy = { version = "0.2.0" } +esp-backtrace = { version = "0.13.0", features = [ "panic-handler", "exception-handler", ] } -esp-println = { version = "0.9.1", default-features = false, features = [ +esp-println = { version = "0.10.0", default-features = false, features = [ "critical-section", ] } -esp-alloc = "0.3.0" -esp-wifi = { version = "0.5.0", default-features = false, features = [ +esp-alloc = "0.4.0" +esp-wifi = { version = "0.7.1", default-features = false, features = [ "phy-enable-usb", "ps-max-modem", "wifi", @@ -152,7 +150,6 @@ hw_v6 = ["battery_max17055"] # skipped v5, v6 has S3 and C6 options # esp32s2 = ["dep:esp32s2", "dep:esp32s2-hal", "esp-backtrace/esp32s2", "esp-println/esp32s2", "rtt"] esp32s3 = [ "esp-hal/esp32s3", - "esp-hal/embassy-time-systick-16mhz", "embassy-executor/integrated-timers", "dep:norfs-esp32s3", "esp-backtrace/esp32s3", @@ -162,7 +159,6 @@ esp32s3 = [ ] esp32c6 = [ "esp-hal/esp32c6", - "esp-hal/embassy-time-timg0", "embassy-time/generic-queue-8", "dep:norfs-esp32c6", "esp-backtrace/esp32c6", diff --git a/src/board/drivers/battery_monitor/battery_fg.rs b/src/board/drivers/battery_monitor/battery_fg.rs index 2c817f23..98c09c2b 100644 --- a/src/board/drivers/battery_monitor/battery_fg.rs +++ b/src/board/drivers/battery_monitor/battery_fg.rs @@ -5,7 +5,7 @@ use max17055::Max17055; use crate::{task_control::TaskControlToken, Shared}; #[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))] -use esp_hal::gpio::RTCPinWithResistors; +use esp_hal::gpio::RtcPinWithResistors; #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -51,7 +51,7 @@ where #[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))] pub fn disable(&mut self) where - EN: RTCPinWithResistors, + EN: RtcPinWithResistors, { // We want to keep the fuel gauge out of shutdown mode self.enable.rtcio_pad_hold(true); diff --git a/src/board/drivers/battery_monitor/mod.rs b/src/board/drivers/battery_monitor/mod.rs index 45a807bd..3edd8678 100644 --- a/src/board/drivers/battery_monitor/mod.rs +++ b/src/board/drivers/battery_monitor/mod.rs @@ -61,7 +61,11 @@ pub struct BatteryMonitor { sensor: Shared, } -impl BatteryMonitor { +impl BatteryMonitor +where + VBUS: InputPin, + CHG: InputPin, +{ pub async fn start(vbus_detect: VBUS, charger_status: CHG, sensor: BatterySensorImpl) -> Self { let this = BatteryMonitor { sensor: Rc::new(Mutex::new(BatterySensor { @@ -133,7 +137,11 @@ impl BatteryMonitor { } #[cfg(feature = "battery_max17055")] -impl BatteryMonitor { +impl BatteryMonitor +where + VBUS: InputPin, + CHG: InputPin, +{ pub fn convert_battery_data(&mut self, data: BatteryData) -> BatteryInfo { BatteryInfo { voltage: data.voltage, diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index aa1e8449..ed44a1d8 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -12,15 +12,13 @@ use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ clock::ClockControl, dma::*, - embassy, - gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, + gpio::{GpioPin, Input, Io, Output}, i2c::I2C, peripherals::{self, Peripherals}, - prelude::*, rtc_cntl::Rtc, spi::{master::dma::SpiDma, FullDuplexMode}, - systimer::SystemTimer, - timer::TimerGroup, + system::SystemControl, + timer::{OneShotTimer, PeriodicTimer}, Async, }; @@ -28,13 +26,16 @@ use display_interface_spi::SPIInterface; pub type DisplaySpiInstance = peripherals::SPI2; pub type DisplayDmaChannel = ChannelCreator0; -pub type DisplayDataCommand = GpioPin, 13>; -pub type DisplayChipSelect = GpioPin, 11>; -pub type DisplayReset = GpioPin, 12>; -pub type DisplaySclk = GpioPin, 14>; -pub type DisplayMosi = GpioPin, 21>; +pub type DisplayDataCommand = GpioPin<13>; +pub type DisplayChipSelect = GpioPin<11>; +pub type DisplayReset = GpioPin<12>; +pub type DisplaySclk = GpioPin<14>; +pub type DisplayMosi = GpioPin<21>; -pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommand>; +pub type DisplayResetPin = Output<'static, DisplayReset>; +pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; + +pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; pub type DisplaySpi<'d> = ExclusiveDevice< SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, DummyOutputPin, @@ -43,35 +44,46 @@ pub type DisplaySpi<'d> = ExclusiveDevice< pub type AdcDmaChannel = ChannelCreator1; pub type AdcSpiInstance = peripherals::SPI3; -pub type AdcSclk = GpioPin, 6>; -pub type AdcMosi = GpioPin, 7>; -pub type AdcMiso = GpioPin, 5>; -pub type AdcChipSelect = GpioPin, 18>; -pub type AdcClockEnable = GpioPin, 38>; -pub type AdcDrdy = GpioPin, 4>; -pub type AdcReset = GpioPin, 2>; -pub type TouchDetect = GpioPin, 1>; +pub type AdcSclk = GpioPin<6>; +pub type AdcMosi = GpioPin<7>; +pub type AdcMiso = GpioPin<5>; +pub type AdcChipSelect = GpioPin<18>; +pub type AdcClockEnable = GpioPin<38>; +pub type AdcDrdy = GpioPin<4>; +pub type AdcReset = GpioPin<2>; +pub type TouchDetect = GpioPin<1>; + +pub type AdcClockEnablePin = Output<'static, AdcClockEnable>; +pub type AdcDrdyPin = Input<'static, AdcDrdy>; +pub type AdcResetPin = Output<'static, AdcReset>; +pub type TouchDetectPin = Input<'static, TouchDetect>; +pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; + pub type AdcSpi = ExclusiveDevice< SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>, - AdcChipSelect, + AdcChipSelectPin, Delay, >; -pub type BatteryAdcEnable = GpioPin, 8>; -pub type VbusDetect = GpioPin, 17>; -pub type ChargerStatus = GpioPin, 47>; +pub type BatteryAdcEnable = GpioPin<8>; +pub type VbusDetect = GpioPin<17>; +pub type ChargerStatus = GpioPin<47>; + +pub type BatteryAdcEnablePin = Output<'static, BatteryAdcEnable>; +pub type VbusDetectPin = Input<'static, VbusDetect>; +pub type ChargerStatusPin = Input<'static, ChargerStatus>; -pub type EcgFrontend = Frontend; +pub type EcgFrontend = Frontend; pub type PoweredEcgFrontend = - PoweredFrontend; + PoweredFrontend; -pub type Display = DisplayType; +pub type Display = DisplayType; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type I2cSda = GpioPin; -pub type I2cScl = GpioPin; +pub type I2cSda = GpioPin<36>; +pub type I2cScl = GpioPin<35>; pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; -pub type BatteryFg = BatteryFgType; +pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { pub async fn initialize() -> Self { @@ -79,19 +91,21 @@ impl super::startup::StartupResources { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); + let system = SystemControl::new(peripherals.SYSTEM); let clocks = ClockControl::max(system.clock_control).freeze(); - embassy::init(&clocks, SystemTimer::new_async(peripherals.SYSTIMER)); + let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER); + esp_hal_embassy::init( + &clocks, + static_cell::make_static!([OneShotTimer::new(systimer.alarm0.into()); 1]), + ); - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); let display = Self::create_display_driver( dma.channel0, - peripherals::Interrupt::DMA_IN_CH0, - peripherals::Interrupt::DMA_OUT_CH0, peripherals.SPI2, io.pins.gpio12, io.pins.gpio13, @@ -104,8 +118,6 @@ impl super::startup::StartupResources { let adc = Self::create_frontend_driver( Self::create_frontend_spi( dma.channel1, - peripherals::Interrupt::DMA_IN_CH1, - peripherals::Interrupt::DMA_OUT_CH1, peripherals.SPI3, io.pins.gpio6, io.pins.gpio7, @@ -121,7 +133,6 @@ impl super::startup::StartupResources { let battery_monitor = Self::setup_battery_monitor_fg( peripherals.I2C0, - peripherals::Interrupt::I2C_EXT0, io.pins.gpio36, io.pins.gpio35, io.pins.gpio17, @@ -138,9 +149,13 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0, + PeriodicTimer::new( + esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks, None) + .timer0 + .into(), + ), peripherals.RNG, - system.radio_clock_control, + peripherals.RADIO_CLK, ) }, clocks, diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index ae334026..7fd19ee6 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -13,7 +13,6 @@ use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ clock::ClockControl, dma::*, - embassy, gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, i2c::I2C, peripherals::{self, Peripherals}, @@ -116,7 +115,6 @@ impl super::startup::StartupResources { let battery_monitor = Self::setup_battery_monitor_fg( peripherals.I2C0, - peripherals::Interrupt::I2C_EXT0, io.pins.gpio19, io.pins.gpio18, io.pins.gpio3, @@ -135,7 +133,7 @@ impl super::startup::StartupResources { peripherals.WIFI, SystemTimer::new(peripherals.SYSTIMER).alarm0, peripherals.RNG, - system.radio_clock_control, + peripherals.RADIO_CLK, ) }, clocks, diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index 5f5ac724..aa7590b2 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -13,7 +13,6 @@ use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ clock::ClockControl, dma::*, - embassy, gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, i2c::I2C, peripherals::{self, Peripherals}, @@ -117,7 +116,6 @@ impl super::startup::StartupResources { let battery_monitor = Self::setup_battery_monitor_fg( peripherals.I2C0, - peripherals::Interrupt::I2C_EXT0, io.pins.gpio36, io.pins.gpio35, io.pins.gpio2, @@ -136,7 +134,7 @@ impl super::startup::StartupResources { peripherals.WIFI, TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0, peripherals.RNG, - system.radio_clock_control, + peripherals.RADIO_CLK, ) }, clocks, diff --git a/src/board/initialized.rs b/src/board/initialized.rs index 339d70c3..e80c4b8c 100644 --- a/src/board/initialized.rs +++ b/src/board/initialized.rs @@ -16,7 +16,7 @@ use embassy_executor::SendSpawner; use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StaticConfigV4}; use embassy_time::{Duration, Instant, Timer}; use embedded_graphics::{pixelcolor::BinaryColor, prelude::DrawTarget, Drawable}; -use esp_hal::clock::Clocks; +use esp_hal::{clock::Clocks, gpio::Input}; use gui::{ screens::message::MessageScreen, widgets::{ @@ -36,7 +36,7 @@ pub struct InnerContext { pub display: Display, pub clocks: Clocks<'static>, pub high_prio_spawner: SendSpawner, - pub battery_monitor: BatteryMonitor, + pub battery_monitor: BatteryMonitor, Input<'static, ChargerStatus>>, pub wifi: &'static mut WifiDriver, pub config: &'static mut Config, pub config_changed: bool, diff --git a/src/board/startup.rs b/src/board/startup.rs index d913e78f..b3b71f28 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -8,20 +8,19 @@ use crate::{ drivers::{battery_monitor::BatteryMonitor, frontend::Frontend}, utils::DummyOutputPin, wifi::WifiDriver, - AdcClockEnable, AdcDrdy, AdcReset, AdcSpi, ChargerStatus, Display, DisplayChipSelect, - DisplayDataCommand, DisplayDmaChannel, DisplayMosi, DisplayReset, DisplaySclk, - DisplaySpiInstance, EcgFrontend, TouchDetect, VbusDetect, + AdcClockEnable, AdcDrdy, AdcReset, AdcSpi, ChargerStatus, ChargerStatusPin, Display, + DisplayChipSelect, DisplayDataCommand, DisplayDmaChannel, DisplayMosi, DisplayReset, + DisplaySclk, DisplaySpiInstance, EcgFrontend, TouchDetect, VbusDetect, VbusDetectPin, }, heap::init_heap, }; use esp_hal::{ clock::Clocks, dma::{DmaDescriptor, DmaPriority}, - gpio::OutputPin as _, - interrupt, peripherals, + gpio::{Input, Level, Output, Pull}, rtc_cntl::Rtc, spi::{ - master::{dma::*, Instance, Spi}, + master::{dma::*, Spi}, SpiMode, }, system::SoftwareInterrupt, @@ -47,7 +46,7 @@ pub struct StartupResources { pub display: Display, pub frontend: EcgFrontend, pub clocks: Clocks<'static>, - pub battery_monitor: BatteryMonitor, + pub battery_monitor: BatteryMonitor, pub wifi: &'static mut WifiDriver, pub rtc: Rtc<'static>, @@ -97,45 +96,30 @@ impl StartupResources { #[allow(clippy::too_many_arguments)] pub(crate) fn create_display_driver( display_dma_channel: DisplayDmaChannel, - dma_in_interrupt: peripherals::Interrupt, - dma_out_interrupt: peripherals::Interrupt, display_spi: DisplaySpiInstance, - display_reset: impl Into, - display_dc: impl Into, - display_cs: impl Into, - display_sclk: impl Into, - display_mosi: impl Into, + display_reset: DisplayReset, + display_dc: DisplayDataCommand, + display_cs: DisplayChipSelect, + display_sclk: DisplaySclk, + display_mosi: DisplayMosi, clocks: &Clocks, ) -> Display { - unwrap!(interrupt::enable( - dma_in_interrupt, - interrupt::Priority::Priority1 - )); - unwrap!(interrupt::enable( - dma_out_interrupt, - interrupt::Priority::Priority1 - )); - - let mut display_cs: DisplayChipSelect = display_cs.into(); - - display_cs.connect_peripheral_to_output(display_spi.cs_signal()); - let display_spi = Spi::new(display_spi, 40u32.MHz(), SpiMode::Mode0, clocks) - .with_sck(display_sclk.into()) - .with_mosi(display_mosi.into()) - .with_dma(display_dma_channel.configure_for_async( - false, + .with_sck(display_sclk) + .with_mosi(display_mosi) + .with_cs(display_cs) + .with_dma( + display_dma_channel.configure_for_async(false, DmaPriority::Priority0), make_static!([DmaDescriptor::EMPTY; 1]), make_static!([DmaDescriptor::EMPTY; 1]), - DmaPriority::Priority0, - )); + ); Display::new( SPIInterface::new( ExclusiveDevice::new(display_spi, DummyOutputPin, Delay), - display_dc.into(), + Output::new(display_dc, Level::Low), ), - display_reset.into(), + Output::new(display_reset, Level::Low), ) } @@ -144,41 +128,25 @@ impl StartupResources { #[cfg(feature = "esp32s3")] pub(crate) fn create_frontend_spi( adc_dma_channel: AdcDmaChannel, - dma_in_interrupt: peripherals::Interrupt, - dma_out_interrupt: peripherals::Interrupt, adc_spi: AdcSpiInstance, - adc_sclk: impl Into, - adc_mosi: impl Into, - adc_miso: impl Into, - adc_cs: impl Into, + adc_sclk: AdcSclk, + adc_mosi: AdcMosi, + adc_miso: AdcMiso, + adc_cs: AdcChipSelect, clocks: &Clocks, ) -> AdcSpi { - unwrap!(interrupt::enable( - dma_in_interrupt, - interrupt::Priority::Priority1 - )); - unwrap!(interrupt::enable( - dma_out_interrupt, - interrupt::Priority::Priority1 - )); - - let mut adc_cs: AdcChipSelect = adc_cs.into(); - - adc_cs.set_high(); - ExclusiveDevice::new( Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1, clocks) - .with_sck(adc_sclk.into()) - .with_mosi(adc_mosi.into()) - .with_miso(adc_miso.into()) - .with_dma(adc_dma_channel.configure_for_async( - false, + .with_sck(adc_sclk) + .with_mosi(adc_mosi) + .with_miso(adc_miso) + .with_dma( + adc_dma_channel.configure_for_async(false, DmaPriority::Priority1), make_static!([DmaDescriptor::EMPTY; 1]), make_static!([DmaDescriptor::EMPTY; 1]), - DmaPriority::Priority1, - )), - adc_cs, + ), + Output::new(adc_cs, Level::High), Delay, ) } @@ -186,23 +154,19 @@ impl StartupResources { #[inline(always)] pub(crate) fn create_frontend_driver( adc_spi: AdcSpi, - adc_drdy: impl Into, - adc_reset: impl Into, - adc_clock_enable: impl Into, - touch_detect: impl Into, + adc_drdy: AdcDrdy, + adc_reset: AdcReset, + adc_clock_enable: AdcClockEnable, + touch_detect: TouchDetect, ) -> EcgFrontend { // DRDY - unwrap!(interrupt::enable( - peripherals::Interrupt::GPIO, - interrupt::Priority::Priority3, - )); Frontend::new( adc_spi, - adc_drdy.into(), - adc_reset.into(), - adc_clock_enable.into(), - touch_detect.into(), + Input::new(adc_drdy, Pull::None), + Output::new(adc_reset, Level::Low), + Output::new(adc_clock_enable, Level::Low), + Input::new(touch_detect, Pull::None), ) } @@ -211,19 +175,13 @@ impl StartupResources { #[allow(clippy::too_many_arguments)] pub(crate) async fn setup_battery_monitor_fg( i2c: BatteryFgI2cInstance, - i2c_interrupt: peripherals::Interrupt, - sda: impl Into, - scl: impl Into, - vbus_detect: impl Into, - charger_status: impl Into, - fg_enable: impl Into, + sda: I2cSda, + scl: I2cScl, + vbus_detect: VbusDetect, + charger_status: ChargerStatus, + fg_enable: BatteryAdcEnable, clocks: &Clocks<'_>, - ) -> BatteryMonitor { - unwrap!(interrupt::enable( - i2c_interrupt, - interrupt::Priority::Priority1, - )); - + ) -> BatteryMonitor { // MCP73832T-2ACI/OT // - ITerm/Ireg = 7.5% // - Vreg = 4.2 @@ -242,14 +200,11 @@ impl StartupResources { }; BatteryMonitor::start( - vbus_detect.into(), - charger_status.into(), + Input::new(vbus_detect, Pull::None), + Input::new(charger_status, Pull::None), BatteryFg::new( - Max17055::new( - I2C::new_async(i2c, sda.into(), scl.into(), 100u32.kHz(), clocks), - design, - ), - fg_enable.into(), + Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz(), clocks), design), + Output::new(fg_enable, Level::Low), ), ) .await diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index e6fe2e03..d292ddf7 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -1,11 +1,5 @@ use core::{hint::unreachable_unchecked, mem, ops::Deref, ptr::NonNull}; -#[cfg(feature = "esp32s3")] -type WifiTimer = - esp_hal::timer::Timer, Blocking>; -#[cfg(feature = "esp32c6")] -type WifiTimer = esp_hal::systimer::Alarm; - use crate::{ board::wifi::{ ap::{Ap, ApState}, @@ -19,10 +13,9 @@ use embassy_executor::Spawner; use embassy_net::{Config, Stack, StackResources}; use esp_hal::{ clock::Clocks, - peripherals::{RNG, WIFI}, + peripherals::{RADIO_CLK, RNG, WIFI}, rng::Rng, - system::RadioClockControl, - Blocking, + timer::{ErasedTimer, PeriodicTimer}, }; use esp_wifi::{ wifi::{WifiApDevice, WifiDevice, WifiDeviceMode, WifiStaDevice}, @@ -31,6 +24,8 @@ use esp_wifi::{ use gui::widgets::{wifi_access_point::WifiAccessPointState, wifi_client::WifiClientState}; use macros as cardio; +type WifiTimer = PeriodicTimer; + pub unsafe fn as_static_mut(what: &mut T) -> &'static mut T { mem::transmute(what) } @@ -91,7 +86,7 @@ pub struct WifiDriver { struct WifiInitResources { timer: WifiTimer, rng: Rng, - rcc: RadioClockControl, + radio_clk: RADIO_CLK, } enum WifiDriverState { @@ -117,7 +112,7 @@ impl WifiDriverState { EspWifiInitFor::Wifi, resources.timer, resources.rng, - resources.rcc, + resources.radio_clk, clocks, )); info!("Wifi driver initialized"); @@ -145,12 +140,16 @@ impl WifiDriverState { } impl WifiDriver { - pub fn new(wifi: WIFI, timer: WifiTimer, rng: RNG, rcc: RadioClockControl) -> Self { + pub fn new(wifi: WIFI, timer: WifiTimer, rng: RNG, radio_clk: RADIO_CLK) -> Self { let rng = Rng::new(rng); Self { wifi, rng, - state: WifiDriverState::Uninitialized(WifiInitResources { timer, rng, rcc }), + state: WifiDriverState::Uninitialized(WifiInitResources { + timer, + rng, + radio_clk, + }), } } diff --git a/src/main.rs b/src/main.rs index 88aff126..fb4ae849 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,21 +55,21 @@ use crate::{ use esp_hal::{ delay::Delay, - embassy::executor::InterruptExecutor, entry, interrupt::Priority, prelude::main, rtc_cntl::sleep::{self, WakeupLevel}, }; +use esp_hal_embassy::InterruptExecutor; #[cfg(any(feature = "hw_v4", feature = "hw_v6"))] use crate::board::VbusDetect; #[cfg(feature = "esp32s3")] -use esp_hal::gpio::RTCPin as RtcWakeupPin; +use esp_hal::gpio::RtcPin as RtcWakeupPin; #[cfg(feature = "esp32c6")] -use esp_hal::gpio::RTCPinWithResistors as RtcWakeupPin; +use esp_hal::gpio::RtcPinWithResistors as RtcWakeupPin; mod board; mod heap; @@ -294,7 +294,7 @@ async fn main(_spawner: Spawner) { let mut wakeup_pins = heapless::Vec::<(&mut dyn RtcWakeupPin, WakeupLevel), 2>::new(); let wakeup_source = setup_wakeup_pins(&mut wakeup_pins, &mut touch, &mut charger_pin, is_charging); - rtc.sleep_deep(&[&wakeup_source], &mut delay); + rtc.sleep_deep(&[&wakeup_source]); // Shouldn't reach this. If we do, we just exit the task, which means the executor // will have nothing else to do. Not ideal, but again, we shouldn't reach this. From 046d4df8d2d5d1f54caadba6c321c93b1610595b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 13 Aug 2024 14:40:47 +0200 Subject: [PATCH 09/29] Update to main --- Cargo.toml | 7 +++++- .../drivers/battery_monitor/battery_fg.rs | 2 +- src/board/hardware/v4.rs | 23 +++++++++---------- src/board/startup.rs | 2 +- src/board/wifi/mod.rs | 2 +- src/main.rs | 9 ++++---- src/stack_protection.rs | 6 +++-- 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c2b2fef..efd4acfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,12 @@ crc = "3.0.1" enumset = "1.1.3" [patch.crates-io] -# esp-hal = { path = "../../esp-hal/esp-hal" } +esp-hal = { path = "C:/_Espressif/esp-hal/esp-hal" } +esp-hal-embassy = { path = "C:/_Espressif/esp-hal/esp-hal-embassy" } +esp-wifi = { path = "C:/_Espressif/esp-hal/esp-wifi" } +esp-backtrace = { path = "C:/_Espressif/esp-hal/esp-backtrace" } +esp-println = { path = "C:/_Espressif/esp-hal/esp-println" } +esp-alloc = { path = "C:/_Espressif/esp-hal/esp-alloc" } [features] default = ["defmt"] diff --git a/src/board/drivers/battery_monitor/battery_fg.rs b/src/board/drivers/battery_monitor/battery_fg.rs index 98c09c2b..2de08d85 100644 --- a/src/board/drivers/battery_monitor/battery_fg.rs +++ b/src/board/drivers/battery_monitor/battery_fg.rs @@ -93,6 +93,6 @@ pub async fn monitor_task_fg( }) .await; - fuel_gauge.lock().await.disable(); + //fuel_gauge.lock().await.disable(); info!("Monitor exited"); } diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index ed44a1d8..53c1df18 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -18,7 +18,7 @@ use esp_hal::{ rtc_cntl::Rtc, spi::{master::dma::SpiDma, FullDuplexMode}, system::SystemControl, - timer::{OneShotTimer, PeriodicTimer}, + timer::{ErasedTimer, OneShotTimer, PeriodicTimer}, Async, }; @@ -37,7 +37,7 @@ pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, + SpiDma<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -60,7 +60,7 @@ pub type TouchDetectPin = Input<'static, TouchDetect>; pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< - SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>, + SpiDma<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, AdcChipSelectPin, Delay, >; @@ -95,10 +95,10 @@ impl super::startup::StartupResources { let clocks = ClockControl::max(system.clock_control).freeze(); let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER); - esp_hal_embassy::init( - &clocks, - static_cell::make_static!([OneShotTimer::new(systimer.alarm0.into()); 1]), - ); + let timer = static_cell::make_static!(OneShotTimer::::new(ErasedTimer::from( + systimer.alarm0 + ))); + esp_hal_embassy::init(&clocks, core::slice::from_mut(timer)); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -150,17 +150,16 @@ impl super::startup::StartupResources { WifiDriver::new( peripherals.WIFI, PeriodicTimer::new( - esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks, None) - .timer0 - .into(), + ErasedTimer::from(esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks) + .timer0) ), peripherals.RNG, peripherals.RADIO_CLK, ) }, clocks, - rtc: Rtc::new(peripherals.LPWR, None), - software_interrupt1: system.software_interrupt_control.software_interrupt1, + rtc: Rtc::new(peripherals.LPWR), + software_interrupt1: system.software_interrupt_control.software_interrupt2, } } } diff --git a/src/board/startup.rs b/src/board/startup.rs index b3b71f28..37aad75f 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -51,7 +51,7 @@ pub struct StartupResources { pub wifi: &'static mut WifiDriver, pub rtc: Rtc<'static>, - pub software_interrupt1: SoftwareInterrupt<1>, + pub software_interrupt1: SoftwareInterrupt<2>, } impl StartupResources { diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index d292ddf7..084a79e6 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -24,7 +24,7 @@ use esp_wifi::{ use gui::widgets::{wifi_access_point::WifiAccessPointState, wifi_client::WifiClientState}; use macros as cardio; -type WifiTimer = PeriodicTimer; +type WifiTimer = PeriodicTimer<'static, ErasedTimer>; pub unsafe fn as_static_mut(what: &mut T) -> &'static mut T { mem::transmute(what) diff --git a/src/main.rs b/src/main.rs index fb4ae849..80357ca7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ use esp_hal::{ entry, interrupt::Priority, prelude::main, + reset, rtc_cntl::sleep::{self, WakeupLevel}, }; use esp_hal_embassy::InterruptExecutor; @@ -292,10 +293,10 @@ async fn main(_spawner: Spawner) { let (_, _, _, mut touch) = board.frontend.split(); let mut wakeup_pins = heapless::Vec::<(&mut dyn RtcWakeupPin, WakeupLevel), 2>::new(); - let wakeup_source = - setup_wakeup_pins(&mut wakeup_pins, &mut touch, &mut charger_pin, is_charging); - rtc.sleep_deep(&[&wakeup_source]); - + // let wakeup_source = + // setup_wakeup_pins(&mut wakeup_pins, &mut touch, &mut charger_pin, is_charging); + // rtc.sleep_deep(&[&wakeup_source]); + reset::software_reset(); // Shouldn't reach this. If we do, we just exit the task, which means the executor // will have nothing else to do. Not ideal, but again, we shouldn't reach this. } diff --git a/src/stack_protection.rs b/src/stack_protection.rs index baa3fd3f..ad4f825a 100644 --- a/src/stack_protection.rs +++ b/src/stack_protection.rs @@ -14,7 +14,7 @@ pub struct StackMonitor { fn conjure() -> DebugAssist<'static> { let peripheral = unsafe { ASSIST_DEBUG::steal() }; - DebugAssist::new(peripheral, None) + DebugAssist::new(peripheral) } impl StackMonitor { @@ -38,7 +38,9 @@ impl StackMonitor { top - bottom ); let peripheral = unsafe { ASSIST_DEBUG::steal() }; - let mut assist = DebugAssist::new(peripheral, Some(interrupt_handler)); + let mut assist = DebugAssist::new(peripheral); + + assist.set_interrupt_handler(interrupt_handler); const CANARY_UNITS: u32 = 1; const CANARY_GRANULARITY: u32 = 16; From 7c114463f5bbc72bd6c0738eda77a7fdf92ed81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 23 Aug 2024 14:04:27 +0200 Subject: [PATCH 10/29] . --- Cargo.toml | 2 +- src/board/startup.rs | 6 +++--- src/main.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index efd4acfa..f767095f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ embassy-net = { version = "0.4", features = [ "medium-ethernet", ] } embassy-sync = { version = "0.5.0" } -embassy-executor = { version = "0.5" } +embassy-executor = { version = "0.6" } heapless = "0.8" log = { version = "0.4.18", default-features = false, features = [ diff --git a/src/board/startup.rs b/src/board/startup.rs index 37aad75f..e0589702 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -102,7 +102,7 @@ impl StartupResources { display_cs: DisplayChipSelect, display_sclk: DisplaySclk, display_mosi: DisplayMosi, - clocks: &Clocks, + clocks: &Clocks<'static>, ) -> Display { let display_spi = Spi::new(display_spi, 40u32.MHz(), SpiMode::Mode0, clocks) .with_sck(display_sclk) @@ -134,7 +134,7 @@ impl StartupResources { adc_miso: AdcMiso, adc_cs: AdcChipSelect, - clocks: &Clocks, + clocks: &Clocks<'static>, ) -> AdcSpi { ExclusiveDevice::new( Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1, clocks) @@ -180,7 +180,7 @@ impl StartupResources { vbus_detect: VbusDetect, charger_status: ChargerStatus, fg_enable: BatteryAdcEnable, - clocks: &Clocks<'_>, + clocks: &Clocks<'static>, ) -> BatteryMonitor { // MCP73832T-2ACI/OT // - ITerm/Ireg = 7.5% diff --git a/src/main.rs b/src/main.rs index 80357ca7..2b4977ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,7 +225,7 @@ async fn main(_spawner: Spawner) { inner: InnerContext { display: resources.display, clocks: resources.clocks, - high_prio_spawner: interrupt_executor.start(Priority::Priority3), + high_prio_spawner: interrupt_executor.start(Priority::Priority2), battery_monitor: resources.battery_monitor, wifi: resources.wifi, config, From edec1a0109b3faab492bf522e3e5cc35b2fbd836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 23 Aug 2024 14:18:36 +0200 Subject: [PATCH 11/29] . --- Cargo.toml | 12 ++++++------ src/board/hardware/v4.rs | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f767095f..577d53f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,12 +136,12 @@ crc = "3.0.1" enumset = "1.1.3" [patch.crates-io] -esp-hal = { path = "C:/_Espressif/esp-hal/esp-hal" } -esp-hal-embassy = { path = "C:/_Espressif/esp-hal/esp-hal-embassy" } -esp-wifi = { path = "C:/_Espressif/esp-hal/esp-wifi" } -esp-backtrace = { path = "C:/_Espressif/esp-hal/esp-backtrace" } -esp-println = { path = "C:/_Espressif/esp-hal/esp-println" } -esp-alloc = { path = "C:/_Espressif/esp-hal/esp-alloc" } +esp-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } +esp-hal-embassy = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } +esp-wifi = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } +esp-backtrace = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } +esp-println = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } +esp-alloc = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } [features] default = ["defmt"] diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 53c1df18..25e44071 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -18,7 +18,7 @@ use esp_hal::{ rtc_cntl::Rtc, spi::{master::dma::SpiDma, FullDuplexMode}, system::SystemControl, - timer::{ErasedTimer, OneShotTimer, PeriodicTimer}, + timer::{systimer::Target, ErasedTimer, PeriodicTimer}, Async, }; @@ -94,11 +94,9 @@ impl super::startup::StartupResources { let system = SystemControl::new(peripherals.SYSTEM); let clocks = ClockControl::max(system.clock_control).freeze(); - let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER); - let timer = static_cell::make_static!(OneShotTimer::::new(ErasedTimer::from( - systimer.alarm0 - ))); - esp_hal_embassy::init(&clocks, core::slice::from_mut(timer)); + let systimer = + esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER).split::(); + esp_hal_embassy::init(&clocks, systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); From bc70f24b6632ab111e5c7fceac8be3755ec5fa7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 23 Aug 2024 17:38:03 +0200 Subject: [PATCH 12/29] Add release launch profile, do not remove debuginfo --- .vscode/launch.json | 11 +++++++++++ Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ef5b6b54..0207bf07 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -162,6 +162,17 @@ "programBinary": "${workspaceRoot}/target/xtensa-esp32s3-none-elf/debug/card_io_fw" } ] + }, + { + "name": "Attach to v4 release", + "type": "probe-rs-debug", + "request": "attach", + "chip": "esp32s3", + "coreConfigs": [ + { + "programBinary": "${workspaceRoot}/target/xtensa-esp32s3-none-elf/release/card_io_fw" + } + ] } ] } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 577d53f2..7d7585e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -248,7 +248,7 @@ codegen-units = 1 lto = "thin" [profile.release] -debug = false +debug = true codegen-units = 1 lto = "fat" From 80c7afd62ee4349c4df482c621ac700300037ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 28 Aug 2024 14:02:18 +0200 Subject: [PATCH 13/29] Update esp-hal --- Cargo.toml | 22 +++---- src/board/hardware/v4.rs | 44 +++++++------- src/board/hardware/v6c6.rs | 120 ++++++++++++++++++++++--------------- src/board/hardware/v6s3.rs | 114 ++++++++++++++++++++--------------- src/board/startup.rs | 39 ++++++------ src/board/wifi/mod.rs | 8 +-- src/board/wifi/sta.rs | 4 +- src/main.rs | 3 +- xtask/src/main.rs | 49 +++++++++------ 9 files changed, 230 insertions(+), 173 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d7585e1..e19efd6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,20 +51,20 @@ embassy-time = { version = "0.3.0" } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } -esp-hal = { version = "0.19.0", features = [ +esp-hal = { version = "0.20.0", features = [ "async", "embedded-hal-02" ] } -esp-hal-embassy = { version = "0.2.0" } -esp-backtrace = { version = "0.13.0", features = [ +esp-hal-embassy = { version = "0.3.0" } +esp-backtrace = { version = "0.14.0", features = [ "panic-handler", "exception-handler", ] } -esp-println = { version = "0.10.0", default-features = false, features = [ +esp-println = { version = "0.11.0", default-features = false, features = [ "critical-section", ] } esp-alloc = "0.4.0" -esp-wifi = { version = "0.7.1", default-features = false, features = [ +esp-wifi = { version = "0.9.1", default-features = false, features = [ "phy-enable-usb", "ps-max-modem", "wifi", @@ -136,12 +136,12 @@ crc = "3.0.1" enumset = "1.1.3" [patch.crates-io] -esp-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } -esp-hal-embassy = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } -esp-wifi = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } -esp-backtrace = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } -esp-println = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } -esp-alloc = { git = "https://github.com/esp-rs/esp-hal.git", rev = "05582d3ca97609e1ffb5e33ee01ecd18704bf0d7" } +esp-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } +esp-hal-embassy = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } +esp-wifi = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } +esp-backtrace = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } +esp-println = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } +esp-alloc = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } [features] default = ["defmt"] diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 25e44071..a310b0d3 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -10,15 +10,19 @@ use crate::board::{ use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ - clock::ClockControl, dma::*, - gpio::{GpioPin, Input, Io, Output}, + gpio::{GpioPin, Input, Io, Level, Output}, i2c::I2C, - peripherals::{self, Peripherals}, + interrupt::software::SoftwareInterruptControl, + peripherals, + prelude::*, rtc_cntl::Rtc, - spi::{master::dma::SpiDma, FullDuplexMode}, - system::SystemControl, - timer::{systimer::Target, ErasedTimer, PeriodicTimer}, + spi::{master::SpiDmaBus, FullDuplexMode}, + timer::{ + systimer::{SystemTimer, Target}, + timg::TimerGroup, + ErasedTimer, + }, Async, }; @@ -37,7 +41,7 @@ pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, + SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -60,7 +64,7 @@ pub type TouchDetectPin = Input<'static, TouchDetect>; pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< - SpiDma<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, + SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, AdcChipSelectPin, Delay, >; @@ -89,13 +93,13 @@ impl super::startup::StartupResources { pub async fn initialize() -> Self { Self::common_init(); - let peripherals = Peripherals::take(); - - let system = SystemControl::new(peripherals.SYSTEM); - let clocks = ClockControl::max(system.clock_control).freeze(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); - let systimer = - esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER).split::(); + let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); esp_hal_embassy::init(&clocks, systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -135,11 +139,13 @@ impl super::startup::StartupResources { io.pins.gpio35, io.pins.gpio17, io.pins.gpio47, - io.pins.gpio8, + Output::new(io.pins.gpio8, Level::Low), &clocks, ) .await; + let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); + Self { display, frontend: adc, @@ -147,17 +153,15 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - PeriodicTimer::new( - ErasedTimer::from(esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks) - .timer0) - ), + ErasedTimer::from(TimerGroup::new(peripherals.TIMG0, &clocks) + .timer0), peripherals.RNG, peripherals.RADIO_CLK, ) }, clocks, rtc: Rtc::new(peripherals.LPWR), - software_interrupt1: system.software_interrupt_control.software_interrupt2, + software_interrupt1: sw_int.software_interrupt1, } } } diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 7fd19ee6..ff698025 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -11,16 +11,19 @@ use display_interface_spi::SPIInterface; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ - clock::ClockControl, dma::*, - gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, + gpio::{GpioPin, Input, Io, Level, Output, Pull}, i2c::I2C, - peripherals::{self, Peripherals}, + interrupt::software::SoftwareInterruptControl, + peripherals, prelude::*, rtc_cntl::Rtc, - spi::{master::dma::SpiDma, FullDuplexMode}, - systimer::SystemTimer, - timer::TimerGroup, + spi::{master::SpiDmaBus, FullDuplexMode}, + timer::{ + systimer::{SystemTimer, Target}, + timg::TimerGroup, + ErasedTimer, + }, Async, }; @@ -28,65 +31,82 @@ pub use crate::board::drivers::bitbang_spi::BitbangSpi; pub type DisplaySpiInstance = peripherals::SPI2; pub type DisplayDmaChannel = ChannelCreator0; -pub type DisplayDataCommand = GpioPin, 8>; -pub type DisplayChipSelect = GpioPin, 11>; -pub type DisplayReset = GpioPin, 10>; -pub type DisplaySclk = GpioPin, 22>; -pub type DisplayMosi = GpioPin, 21>; +pub type DisplayDataCommand = GpioPin<8>; +pub type DisplayChipSelect = GpioPin<11>; +pub type DisplayReset = GpioPin<10>; +pub type DisplaySclk = GpioPin<22>; +pub type DisplayMosi = GpioPin<21>; + +pub type DisplayResetPin = Output<'static, DisplayReset>; +pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; -pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommand>; +pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, + SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; -pub type AdcSclk = GpioPin, 6>; -pub type AdcMosi = GpioPin, 7>; -pub type AdcMiso = GpioPin, 5>; -pub type AdcChipSelect = GpioPin, 9>; -pub type AdcClockEnable = GpioPin, 23>; -pub type AdcDrdy = GpioPin, 4>; -pub type AdcReset = GpioPin, 15>; -pub type TouchDetect = GpioPin, 2>; -pub type AdcSpiBus = BitbangSpi; -pub type AdcSpi = ExclusiveDevice; - -pub type BatteryAdcEnable = DummyOutputPin; -pub type VbusDetect = GpioPin, 3>; -pub type ChargerStatus = GpioPin, 20>; - -pub type EcgFrontend = Frontend; +pub type AdcSclk = GpioPin<6>; +pub type AdcMosi = GpioPin<7>; +pub type AdcMiso = GpioPin<5>; +pub type AdcChipSelect = GpioPin<9>; +pub type AdcClockEnable = GpioPin<23>; +pub type AdcDrdy = GpioPin<4>; +pub type AdcReset = GpioPin<15>; +pub type TouchDetect = GpioPin<2>; + +pub type AdcClockEnablePin = Output<'static, AdcClockEnable>; +pub type AdcDrdyPin = Input<'static, AdcDrdy>; +pub type AdcResetPin = Output<'static, AdcReset>; +pub type TouchDetectPin = Input<'static, TouchDetect>; +pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; + +pub type AdcMosiPin = Output<'static, AdcMosi>; +pub type AdcMisoPin = Input<'static, AdcMiso>; +pub type AdcSclkPin = Output<'static, AdcSclk>; + +pub type AdcSpi = + ExclusiveDevice, AdcChipSelectPin, Delay>; + +pub type VbusDetect = GpioPin<3>; +pub type ChargerStatus = GpioPin<20>; + +pub type BatteryAdcEnablePin = DummyOutputPin; +pub type VbusDetectPin = Input<'static, VbusDetect>; +pub type ChargerStatusPin = Input<'static, ChargerStatus>; + +pub type EcgFrontend = Frontend; pub type PoweredEcgFrontend = - PoweredFrontend; + PoweredFrontend; -pub type Display = DisplayType; +pub type Display = DisplayType; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type I2cSda = GpioPin; -pub type I2cScl = GpioPin; +pub type I2cSda = GpioPin<19>; +pub type I2cScl = GpioPin<18>; pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; -pub type BatteryFg = BatteryFgType; +pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { pub async fn initialize() -> Self { Self::common_init(); - let peripherals = Peripherals::take(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::max(system.clock_control).freeze(); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + esp_hal_embassy::init(&clocks, timg0.timer0); - embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks)); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); let display = Self::create_display_driver( dma.channel0, - peripherals::Interrupt::DMA_IN_CH0, - peripherals::Interrupt::DMA_OUT_CH0, peripherals.SPI2, io.pins.gpio10, io.pins.gpio8, @@ -99,12 +119,12 @@ impl super::startup::StartupResources { let adc = Self::create_frontend_driver( ExclusiveDevice::new( BitbangSpi::new( - io.pins.gpio7.into(), - io.pins.gpio5.into(), - io.pins.gpio6.into(), + Output::new(io.pins.gpio7, Level::Low), + Input::new(io.pins.gpio5, Pull::None), + Output::new(io.pins.gpio6, Level::Low), 1u32.MHz(), ), - io.pins.gpio9.into(), + Output::new(io.pins.gpio9, Level::High), Delay, ), io.pins.gpio4, @@ -124,6 +144,8 @@ impl super::startup::StartupResources { ) .await; + let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); + Self { display, frontend: adc, @@ -131,14 +153,14 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - SystemTimer::new(peripherals.SYSTIMER).alarm0, + ErasedTimer::from(SystemTimer::new(peripherals.SYSTIMER).split::().alarm0), peripherals.RNG, peripherals.RADIO_CLK, ) }, clocks, - rtc: Rtc::new(peripherals.LPWR, None), - software_interrupt1: system.software_interrupt_control.software_interrupt1, + rtc: Rtc::new(peripherals.LPWR), + software_interrupt1: sw_int.software_interrupt1, } } } diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index aa7590b2..58fa774d 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -11,82 +11,101 @@ use display_interface_spi::SPIInterface; use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ - clock::ClockControl, dma::*, - gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO}, + gpio::{GpioPin, Input, Io, Output}, i2c::I2C, - peripherals::{self, Peripherals}, + interrupt::software::SoftwareInterruptControl, + peripherals, prelude::*, rtc_cntl::Rtc, - spi::{master::dma::SpiDma, FullDuplexMode}, - systimer::SystemTimer, - timer::TimerGroup, + spi::{master::SpiDmaBus, FullDuplexMode}, + timer::{ + systimer::{SystemTimer, Target}, + timg::TimerGroup, + ErasedTimer, + }, Async, }; pub type DisplaySpiInstance = peripherals::SPI2; pub type DisplayDmaChannel = ChannelCreator0; -pub type DisplayDataCommand = GpioPin, 17>; -pub type DisplayChipSelect = GpioPin, 8>; -pub type DisplayReset = GpioPin, 18>; -pub type DisplaySclk = GpioPin, 39>; -pub type DisplayMosi = GpioPin, 38>; +pub type DisplayDataCommand = GpioPin<17>; +pub type DisplayChipSelect = GpioPin<8>; +pub type DisplayReset = GpioPin<18>; +pub type DisplaySclk = GpioPin<39>; +pub type DisplayMosi = GpioPin<38>; + +pub type DisplayResetPin = Output<'static, DisplayReset>; +pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; -pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommand>; +pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>, + SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; pub type AdcDmaChannel = ChannelCreator1; pub type AdcSpiInstance = peripherals::SPI3; -pub type AdcSclk = GpioPin, 6>; -pub type AdcMosi = GpioPin, 7>; -pub type AdcMiso = GpioPin, 5>; -pub type AdcChipSelect = GpioPin, 0>; -pub type AdcClockEnable = GpioPin, 40>; -pub type AdcDrdy = GpioPin, 4>; -pub type AdcReset = GpioPin, 42>; -pub type TouchDetect = GpioPin, 1>; -pub type AdcSpiBus = SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>; -pub type AdcSpi = ExclusiveDevice; - -pub type BatteryAdcEnable = DummyOutputPin; -pub type VbusDetect = GpioPin, 2>; -pub type ChargerStatus = GpioPin, 37>; - -pub type EcgFrontend = Frontend; +pub type AdcSclk = GpioPin<6>; +pub type AdcMosi = GpioPin<7>; +pub type AdcMiso = GpioPin<5>; +pub type AdcChipSelect = GpioPin<0>; +pub type AdcClockEnable = GpioPin<40>; +pub type AdcDrdy = GpioPin<4>; +pub type AdcReset = GpioPin<42>; +pub type TouchDetect = GpioPin<1>; + +pub type AdcClockEnablePin = Output<'static, AdcClockEnable>; +pub type AdcDrdyPin = Input<'static, AdcDrdy>; +pub type AdcResetPin = Output<'static, AdcReset>; +pub type TouchDetectPin = Input<'static, TouchDetect>; +pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; + +pub type AdcSpi = ExclusiveDevice< + SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, + AdcChipSelectPin, + Delay, +>; + +pub type VbusDetect = GpioPin<2>; +pub type ChargerStatus = GpioPin<37>; + +pub type BatteryAdcEnablePin = DummyOutputPin; +pub type VbusDetectPin = Input<'static, VbusDetect>; +pub type ChargerStatusPin = Input<'static, ChargerStatus>; + +pub type EcgFrontend = Frontend; pub type PoweredEcgFrontend = - PoweredFrontend; + PoweredFrontend; -pub type Display = DisplayType; +pub type Display = DisplayType; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type I2cSda = GpioPin; -pub type I2cScl = GpioPin; +pub type I2cSda = GpioPin<36>; +pub type I2cScl = GpioPin<35>; pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; -pub type BatteryFg = BatteryFgType; +pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { pub async fn initialize() -> Self { Self::common_init(); - let peripherals = Peripherals::take(); + let (peripherals, clocks) = esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::max(system.clock_control).freeze(); + let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); + esp_hal_embassy::init(&clocks, systimer.alarm0); - embassy::init(&clocks, SystemTimer::new_async(peripherals.SYSTIMER)); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); let display = Self::create_display_driver( dma.channel0, - peripherals::Interrupt::DMA_IN_CH0, - peripherals::Interrupt::DMA_OUT_CH0, peripherals.SPI2, io.pins.gpio18, io.pins.gpio17, @@ -99,8 +118,6 @@ impl super::startup::StartupResources { let adc = Self::create_frontend_driver( Self::create_frontend_spi( dma.channel1, - peripherals::Interrupt::DMA_IN_CH1, - peripherals::Interrupt::DMA_OUT_CH1, peripherals.SPI3, io.pins.gpio6, io.pins.gpio7, @@ -125,6 +142,8 @@ impl super::startup::StartupResources { ) .await; + let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); + Self { display, frontend: adc, @@ -132,14 +151,15 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0, + ErasedTimer::from(TimerGroup::new(peripherals.TIMG0, &clocks) + .timer0), peripherals.RNG, peripherals.RADIO_CLK, ) }, clocks, - rtc: Rtc::new(peripherals.LPWR, None), - software_interrupt1: system.software_interrupt_control.software_interrupt1, + rtc: Rtc::new(peripherals.LPWR), + software_interrupt1: sw_int.software_interrupt1, } } } diff --git a/src/board/startup.rs b/src/board/startup.rs index e0589702..8aa94906 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -16,14 +16,12 @@ use crate::{ }; use esp_hal::{ clock::Clocks, - dma::{DmaDescriptor, DmaPriority}, + dma::*, + dma_buffers, gpio::{Input, Level, Output, Pull}, + interrupt::software::SoftwareInterrupt, rtc_cntl::Rtc, - spi::{ - master::{dma::*, Spi}, - SpiMode, - }, - system::SoftwareInterrupt, + spi::{master::Spi, SpiMode}, }; #[cfg(feature = "esp32s3")] @@ -33,7 +31,7 @@ use crate::board::{AdcChipSelect, AdcDmaChannel, AdcMiso, AdcMosi, AdcSclk, AdcS use esp_hal::i2c::I2C; #[cfg(feature = "battery_max17055")] use { - crate::board::{BatteryAdcEnable, BatteryFg, BatteryFgI2cInstance, I2cScl, I2cSda}, + crate::board::{BatteryAdcEnablePin, BatteryFg, BatteryFgI2cInstance, I2cScl, I2cSda}, max17055::{DesignData, Max17055}, }; @@ -51,7 +49,7 @@ pub struct StartupResources { pub wifi: &'static mut WifiDriver, pub rtc: Rtc<'static>, - pub software_interrupt1: SoftwareInterrupt<2>, + pub software_interrupt1: SoftwareInterrupt<1>, } impl StartupResources { @@ -104,15 +102,15 @@ impl StartupResources { display_mosi: DisplayMosi, clocks: &Clocks<'static>, ) -> Display { + let (tx_buffer, tx_descriptors, rx_buffer, rx_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, clocks) .with_sck(display_sclk) .with_mosi(display_mosi) .with_cs(display_cs) - .with_dma( - display_dma_channel.configure_for_async(false, DmaPriority::Priority0), - make_static!([DmaDescriptor::EMPTY; 1]), - make_static!([DmaDescriptor::EMPTY; 1]), - ); + .with_dma(display_dma_channel.configure_for_async(false, DmaPriority::Priority0)) + .with_buffers(dma_tx_buf, dma_rx_buf); Display::new( SPIInterface::new( @@ -136,16 +134,17 @@ impl StartupResources { clocks: &Clocks<'static>, ) -> AdcSpi { + let (tx_buffer, tx_descriptors, rx_buffer, rx_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(); + ExclusiveDevice::new( Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1, clocks) .with_sck(adc_sclk) .with_mosi(adc_mosi) .with_miso(adc_miso) - .with_dma( - adc_dma_channel.configure_for_async(false, DmaPriority::Priority1), - make_static!([DmaDescriptor::EMPTY; 1]), - make_static!([DmaDescriptor::EMPTY; 1]), - ), + .with_dma(adc_dma_channel.configure_for_async(false, DmaPriority::Priority1)) + .with_buffers(dma_tx_buf, dma_rx_buf), Output::new(adc_cs, Level::High), Delay, ) @@ -179,7 +178,7 @@ impl StartupResources { scl: I2cScl, vbus_detect: VbusDetect, charger_status: ChargerStatus, - fg_enable: BatteryAdcEnable, + fg_enable: BatteryAdcEnablePin, clocks: &Clocks<'static>, ) -> BatteryMonitor { // MCP73832T-2ACI/OT @@ -204,7 +203,7 @@ impl StartupResources { Input::new(charger_status, Pull::None), BatteryFg::new( Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz(), clocks), design), - Output::new(fg_enable, Level::Low), + fg_enable, ), ) .await diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index 084a79e6..2aaf6a9a 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -15,7 +15,7 @@ use esp_hal::{ clock::Clocks, peripherals::{RADIO_CLK, RNG, WIFI}, rng::Rng, - timer::{ErasedTimer, PeriodicTimer}, + timer::ErasedTimer, }; use esp_wifi::{ wifi::{WifiApDevice, WifiDevice, WifiDeviceMode, WifiStaDevice}, @@ -24,8 +24,6 @@ use esp_wifi::{ use gui::widgets::{wifi_access_point::WifiAccessPointState, wifi_client::WifiClientState}; use macros as cardio; -type WifiTimer = PeriodicTimer<'static, ErasedTimer>; - pub unsafe fn as_static_mut(what: &mut T) -> &'static mut T { mem::transmute(what) } @@ -84,7 +82,7 @@ pub struct WifiDriver { } struct WifiInitResources { - timer: WifiTimer, + timer: ErasedTimer, rng: Rng, radio_clk: RADIO_CLK, } @@ -140,7 +138,7 @@ impl WifiDriverState { } impl WifiDriver { - pub fn new(wifi: WIFI, timer: WifiTimer, rng: RNG, radio_clk: RADIO_CLK) -> Self { + pub fn new(wifi: WIFI, timer: ErasedTimer, rng: RNG, radio_clk: RADIO_CLK) -> Self { let rng = Rng::new(rng); Self { wifi, diff --git a/src/board/wifi/sta.rs b/src/board/wifi/sta.rs index 2ec851d3..9565ff13 100644 --- a/src/board/wifi/sta.rs +++ b/src/board/wifi/sta.rs @@ -545,7 +545,9 @@ impl StaController { *preference = NetworkPreference::Deprioritized; } } - Configuration::AccessPoint(_) | Configuration::None => unreachable!(), + Configuration::EapClient(_) + | Configuration::AccessPoint(_) + | Configuration::None => unreachable!(), }, Err(_) => unreachable!(), } diff --git a/src/main.rs b/src/main.rs index 2b4977ec..7a5dbfa0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,6 @@ use crate::{ use esp_hal::{ delay::Delay, - entry, interrupt::Priority, prelude::main, reset, @@ -215,7 +214,7 @@ async fn main(_spawner: Spawner) { let mut storage = FileSystem::mount().await; let config = load_config(storage.as_deref_mut()).await; - let mut delay = Delay::new(&resources.clocks); + let delay = Delay::new(&resources.clocks); // We're boxing Context because we will need to move out of it during shutdown. let mut board = Box::new(Context { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c79efd9c..3143eacb 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -125,10 +125,13 @@ pub struct Cli { pub subcommand: Subcommands, } -fn cargo(command: &[&str]) -> Expression { - println!("🛠️ Running command: cargo +esp {}", command.join(" ")); +fn cargo(toolchain: &'static str, command: &[&str]) -> Expression { + println!( + "🛠️ Running command: cargo +{toolchain} {}", + command.join(" ") + ); - let mut args_vec = vec!["run", "esp", "cargo"]; + let mut args_vec = vec!["run", toolchain, "cargo"]; args_vec.extend(command); cmd("rustup", args_vec) @@ -143,7 +146,7 @@ fn build(config: BuildConfig, timings: bool) -> AnyResult<()> { command.extend_from_slice(&build_flags); - cargo(&command).run()?; + cargo(config.soc.toolchain(), &command).run()?; } match config.soc { @@ -162,7 +165,7 @@ fn build(config: BuildConfig, timings: bool) -> AnyResult<()> { ]; command.extend_from_slice(&build_flags); - cargo(&command).run()?; + cargo(config.soc.toolchain(), &command).run()?; Ok(()) } @@ -194,19 +197,22 @@ fn run(config: BuildConfig) -> AnyResult<()> { ]; args.extend_from_slice(&build_flags); - cargo(&args).run()?; + cargo(config.soc.toolchain(), &args).run()?; Ok(()) } fn monitor(config: BuildConfig) -> AnyResult<()> { - cargo(&[ - "espflash", - "monitor", - "-e", - &config.elf_string(), - "--log-format=defmt", - ]) + cargo( + config.soc.toolchain(), + &[ + "espflash", + "monitor", + "-e", + &config.elf_string(), + "--log-format=defmt", + ], + ) .run()?; Ok(()) @@ -219,7 +225,7 @@ fn checks(config: BuildConfig) -> AnyResult<()> { let mut args = vec!["check"]; args.extend_from_slice(&build_flags); - cargo(&args).run()?; + cargo(config.soc.toolchain(), &args).run()?; Ok(()) } @@ -235,13 +241,13 @@ fn docs(config: BuildConfig, open: bool) -> AnyResult<()> { args.push("--open"); } - cargo(&args).run()?; + cargo(config.soc.toolchain(), &args).run()?; Ok(()) } fn extra_checks(config: BuildConfig) -> AnyResult<()> { - cargo(&["fmt", "--check"]).run()?; + cargo(config.soc.toolchain(), &["fmt", "--check"]).run()?; let build_flags = config.build_flags(); let build_flags = build_flags.iter().map(|s| s.as_str()).collect::>(); @@ -249,7 +255,7 @@ fn extra_checks(config: BuildConfig) -> AnyResult<()> { let mut args = vec!["clippy"]; args.extend_from_slice(&build_flags); - cargo(&args).run()?; + cargo(config.soc.toolchain(), &args).run()?; Ok(()) } @@ -264,7 +270,7 @@ fn test() -> AnyResult<()> { args.push(p); } - cargo(&args).run()?; + cargo("esp", &args).run()?; Ok(()) } @@ -366,6 +372,13 @@ impl SocConfig { .join(self.target()) .join(profile.as_str()) } + + fn toolchain(self) -> &'static str { + match self { + SocConfig::S3 => "esp", + SocConfig::C6 => "nightly-2024-06-01-x86_64-pc-windows-msvc", + } + } } #[derive(Clone, Copy)] From 18dee4d1721b86763f4386d9befbc94a91e9114f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 5 Sep 2024 22:24:17 +0200 Subject: [PATCH 14/29] Update more, re-enable sleep --- Cargo.toml | 17 +++--- .../drivers/battery_monitor/battery_fg.rs | 15 ++--- src/board/drivers/bitbang_spi.rs | 3 +- src/board/hardware/v4.rs | 12 ++-- src/board/hardware/v6c6.rs | 17 +++--- src/board/hardware/v6s3.rs | 10 +--- src/board/initialized.rs | 7 +-- src/board/startup.rs | 30 ++++------ src/board/wifi/mod.rs | 14 ++--- src/main.rs | 60 +++++++++---------- src/states/measure.rs | 2 +- 11 files changed, 79 insertions(+), 108 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e19efd6b..607d5854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,10 +51,7 @@ embassy-time = { version = "0.3.0" } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } -esp-hal = { version = "0.20.0", features = [ - "async", - "embedded-hal-02" -] } +esp-hal = { version = "0.20.1" } esp-hal-embassy = { version = "0.3.0" } esp-backtrace = { version = "0.14.0", features = [ "panic-handler", @@ -136,12 +133,12 @@ crc = "3.0.1" enumset = "1.1.3" [patch.crates-io] -esp-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } -esp-hal-embassy = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } -esp-wifi = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } -esp-backtrace = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } -esp-println = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } -esp-alloc = { git = "https://github.com/esp-rs/esp-hal.git", rev = "49e14b7ccb10dfe5b4b6ed561759372303beddb1" } +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" } [features] default = ["defmt"] diff --git a/src/board/drivers/battery_monitor/battery_fg.rs b/src/board/drivers/battery_monitor/battery_fg.rs index 2de08d85..7ec85894 100644 --- a/src/board/drivers/battery_monitor/battery_fg.rs +++ b/src/board/drivers/battery_monitor/battery_fg.rs @@ -4,8 +4,6 @@ use embedded_hal_async::{delay::DelayNs, i2c::I2c}; use max17055::Max17055; use crate::{task_control::TaskControlToken, Shared}; -#[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))] -use esp_hal::gpio::RtcPinWithResistors; #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -49,13 +47,16 @@ where } #[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))] - pub fn disable(&mut self) + pub fn disable(&mut self) where - EN: RtcPinWithResistors, + EN: esp_hal::peripheral::Peripheral

, + R: esp_hal::gpio::RtcPinWithResistors, { + use esp_hal::peripheral::Peripheral; // We want to keep the fuel gauge out of shutdown mode - self.enable.rtcio_pad_hold(true); - self.enable.rtcio_pullup(true); + let mut enable = (&mut self.enable).into_ref(); + enable.rtcio_pad_hold(true); + enable.rtcio_pullup(true); } #[cfg(any(not(feature = "esp32s3"), feature = "hw_v6"))] @@ -93,6 +94,6 @@ pub async fn monitor_task_fg( }) .await; - //fuel_gauge.lock().await.disable(); + fuel_gauge.lock().await.disable(); info!("Monitor exited"); } diff --git a/src/board/drivers/bitbang_spi.rs b/src/board/drivers/bitbang_spi.rs index e78197a3..3367f479 100644 --- a/src/board/drivers/bitbang_spi.rs +++ b/src/board/drivers/bitbang_spi.rs @@ -6,7 +6,6 @@ use embedded_hal::{ spi::ErrorType, }; use embedded_hal_async::spi::SpiBus; -use esp_hal::clock::Clocks; use fugit::HertzU32; pub struct BitbangSpi { @@ -54,7 +53,7 @@ where } } - pub fn change_bus_frequency(&mut self, frequency: HertzU32, _clocks: &Clocks<'_>) { + pub fn change_bus_frequency(&mut self, frequency: HertzU32) { self.half_bit_delay = Self::frequency_to_duration(frequency); } } diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index a310b0d3..49d959e5 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -93,14 +93,14 @@ impl super::startup::StartupResources { pub async fn initialize() -> Self { Self::common_init(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -114,7 +114,6 @@ impl super::startup::StartupResources { io.pins.gpio11, io.pins.gpio14, io.pins.gpio21, - &clocks, ); let adc = Self::create_frontend_driver( @@ -125,7 +124,6 @@ impl super::startup::StartupResources { io.pins.gpio7, io.pins.gpio5, io.pins.gpio18, - &clocks, ), io.pins.gpio4, io.pins.gpio2, @@ -139,8 +137,7 @@ impl super::startup::StartupResources { io.pins.gpio35, io.pins.gpio17, io.pins.gpio47, - Output::new(io.pins.gpio8, Level::Low), - &clocks, + Output::new_typed(io.pins.gpio8, Level::Low), ) .await; @@ -153,13 +150,12 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - ErasedTimer::from(TimerGroup::new(peripherals.TIMG0, &clocks) + ErasedTimer::from(TimerGroup::new(peripherals.TIMG0) .timer0), peripherals.RNG, peripherals.RADIO_CLK, ) }, - clocks, rtc: Rtc::new(peripherals.LPWR), software_interrupt1: sw_int.software_interrupt1, } diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index ff698025..82703de9 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -92,14 +92,14 @@ impl super::startup::StartupResources { pub async fn initialize() -> Self { Self::common_init(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); - let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); - esp_hal_embassy::init(&clocks, timg0.timer0); + let timg0 = TimerGroup::new(peripherals.TIMG0); + esp_hal_embassy::init(timg0.timer0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -113,18 +113,17 @@ impl super::startup::StartupResources { io.pins.gpio11, io.pins.gpio22, io.pins.gpio21, - &clocks, ); let adc = Self::create_frontend_driver( ExclusiveDevice::new( BitbangSpi::new( - Output::new(io.pins.gpio7, Level::Low), - Input::new(io.pins.gpio5, Pull::None), - Output::new(io.pins.gpio6, Level::Low), + Output::new_typed(io.pins.gpio7, Level::Low), + Input::new_typed(io.pins.gpio5, Pull::None), + Output::new_typed(io.pins.gpio6, Level::Low), 1u32.MHz(), ), - Output::new(io.pins.gpio9, Level::High), + Output::new_typed(io.pins.gpio9, Level::High), Delay, ), io.pins.gpio4, @@ -140,7 +139,6 @@ impl super::startup::StartupResources { io.pins.gpio3, io.pins.gpio20, DummyOutputPin, - &clocks, ) .await; @@ -158,7 +156,6 @@ impl super::startup::StartupResources { peripherals.RADIO_CLK, ) }, - clocks, rtc: Rtc::new(peripherals.LPWR), software_interrupt1: sw_int.software_interrupt1, } diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index 58fa774d..fe17abc1 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -91,14 +91,14 @@ impl super::startup::StartupResources { pub async fn initialize() -> Self { Self::common_init(); - let (peripherals, clocks) = esp_hal::init({ + let peripherals = esp_hal::init({ let mut config = esp_hal::Config::default(); config.cpu_clock = CpuClock::max(); config }); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); - esp_hal_embassy::init(&clocks, systimer.alarm0); + esp_hal_embassy::init(systimer.alarm0); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); @@ -112,7 +112,6 @@ impl super::startup::StartupResources { io.pins.gpio8, io.pins.gpio39, io.pins.gpio38, - &clocks, ); let adc = Self::create_frontend_driver( @@ -123,7 +122,6 @@ impl super::startup::StartupResources { io.pins.gpio7, io.pins.gpio5, io.pins.gpio0, - &clocks, ), io.pins.gpio4, io.pins.gpio42, @@ -138,7 +136,6 @@ impl super::startup::StartupResources { io.pins.gpio2, io.pins.gpio37, DummyOutputPin, - &clocks, ) .await; @@ -151,13 +148,12 @@ impl super::startup::StartupResources { wifi: static_cell::make_static! { WifiDriver::new( peripherals.WIFI, - ErasedTimer::from(TimerGroup::new(peripherals.TIMG0, &clocks) + ErasedTimer::from(TimerGroup::new(peripherals.TIMG0) .timer0), peripherals.RNG, peripherals.RADIO_CLK, ) }, - clocks, rtc: Rtc::new(peripherals.LPWR), software_interrupt1: sw_int.software_interrupt1, } diff --git a/src/board/initialized.rs b/src/board/initialized.rs index e80c4b8c..c171ae12 100644 --- a/src/board/initialized.rs +++ b/src/board/initialized.rs @@ -16,7 +16,7 @@ use embassy_executor::SendSpawner; use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StaticConfigV4}; use embassy_time::{Duration, Instant, Timer}; use embedded_graphics::{pixelcolor::BinaryColor, prelude::DrawTarget, Drawable}; -use esp_hal::{clock::Clocks, gpio::Input}; +use esp_hal::gpio::Input; use gui::{ screens::message::MessageScreen, widgets::{ @@ -34,7 +34,6 @@ pub enum StaMode { pub struct InnerContext { pub display: Display, - pub clocks: Clocks<'static>, pub high_prio_spawner: SendSpawner, pub battery_monitor: BatteryMonitor, Input<'static, ChargerStatus>>, pub wifi: &'static mut WifiDriver, @@ -169,7 +168,7 @@ impl InnerContext { let sta = self .wifi - .configure_sta(NetConfig::dhcpv4(Default::default()), &self.clocks) + .configure_sta(NetConfig::dhcpv4(Default::default())) .await; sta.update_known_networks(&self.config.known_networks).await; @@ -191,7 +190,6 @@ impl InnerContext { gateway: Some(Ipv4Address::from_bytes(&[192, 168, 2, 1])), dns_servers: Default::default(), }), - &self.clocks, ) .await; @@ -213,7 +211,6 @@ impl InnerContext { dns_servers: Default::default(), }), NetConfig::dhcpv4(Default::default()), - &self.clocks, ) .await; diff --git a/src/board/startup.rs b/src/board/startup.rs index 8aa94906..96d7d819 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -15,7 +15,6 @@ use crate::{ heap::init_heap, }; use esp_hal::{ - clock::Clocks, dma::*, dma_buffers, gpio::{Input, Level, Output, Pull}, @@ -43,7 +42,6 @@ use fugit::RateExtU32; pub struct StartupResources { pub display: Display, pub frontend: EcgFrontend, - pub clocks: Clocks<'static>, pub battery_monitor: BatteryMonitor, pub wifi: &'static mut WifiDriver, @@ -100,12 +98,11 @@ impl StartupResources { display_cs: DisplayChipSelect, display_sclk: DisplaySclk, display_mosi: DisplayMosi, - clocks: &Clocks<'static>, ) -> Display { let (tx_buffer, tx_descriptors, rx_buffer, rx_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, clocks) + let display_spi = Spi::new(display_spi, 40u32.MHz(), SpiMode::Mode0) .with_sck(display_sclk) .with_mosi(display_mosi) .with_cs(display_cs) @@ -115,9 +112,9 @@ impl StartupResources { Display::new( SPIInterface::new( ExclusiveDevice::new(display_spi, DummyOutputPin, Delay), - Output::new(display_dc, Level::Low), + Output::new_typed(display_dc, Level::Low), ), - Output::new(display_reset, Level::Low), + Output::new_typed(display_reset, Level::Low), ) } @@ -131,21 +128,19 @@ impl StartupResources { adc_mosi: AdcMosi, adc_miso: AdcMiso, adc_cs: AdcChipSelect, - - clocks: &Clocks<'static>, ) -> AdcSpi { let (tx_buffer, tx_descriptors, rx_buffer, rx_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(); ExclusiveDevice::new( - Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1, clocks) + Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1) .with_sck(adc_sclk) .with_mosi(adc_mosi) .with_miso(adc_miso) .with_dma(adc_dma_channel.configure_for_async(false, DmaPriority::Priority1)) .with_buffers(dma_tx_buf, dma_rx_buf), - Output::new(adc_cs, Level::High), + Output::new_typed(adc_cs, Level::High), Delay, ) } @@ -162,10 +157,10 @@ impl StartupResources { Frontend::new( adc_spi, - Input::new(adc_drdy, Pull::None), - Output::new(adc_reset, Level::Low), - Output::new(adc_clock_enable, Level::Low), - Input::new(touch_detect, Pull::None), + Input::new_typed(adc_drdy, Pull::None), + Output::new_typed(adc_reset, Level::Low), + Output::new_typed(adc_clock_enable, Level::Low), + Input::new_typed(touch_detect, Pull::None), ) } @@ -179,7 +174,6 @@ impl StartupResources { vbus_detect: VbusDetect, charger_status: ChargerStatus, fg_enable: BatteryAdcEnablePin, - clocks: &Clocks<'static>, ) -> BatteryMonitor { // MCP73832T-2ACI/OT // - ITerm/Ireg = 7.5% @@ -199,10 +193,10 @@ impl StartupResources { }; BatteryMonitor::start( - Input::new(vbus_detect, Pull::None), - Input::new(charger_status, Pull::None), + Input::new_typed(vbus_detect, Pull::None), + Input::new_typed(charger_status, Pull::None), BatteryFg::new( - Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz(), clocks), design), + Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz()), design), fg_enable, ), ) diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index 2aaf6a9a..4f29349b 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -12,7 +12,6 @@ use alloc::{boxed::Box, rc::Rc}; use embassy_executor::Spawner; use embassy_net::{Config, Stack, StackResources}; use esp_hal::{ - clock::Clocks, peripherals::{RADIO_CLK, RNG, WIFI}, rng::Rng, timer::ErasedTimer, @@ -98,7 +97,6 @@ enum WifiDriverState { impl WifiDriverState { async fn initialize( &mut self, - clocks: &Clocks<'_>, callback: impl FnOnce(EspWifiInitialization) -> Self, ) { self.uninit().await; @@ -111,7 +109,6 @@ impl WifiDriverState { resources.timer, resources.rng, resources.radio_clk, - clocks, )); info!("Wifi driver initialized"); token @@ -151,12 +148,12 @@ impl WifiDriver { } } - pub async fn configure_ap(&mut self, ap_config: Config, clocks: &Clocks<'_>) -> Ap { + pub async fn configure_ap(&mut self, ap_config: Config) -> Ap { // Prepare, stop STA if running if !matches!(self.state, WifiDriverState::Ap(_)) { let spawner = Spawner::for_current_executor().await; self.state - .initialize(clocks, |init| { + .initialize(|init| { WifiDriverState::Ap(ApState::init( init, ap_config, @@ -179,13 +176,12 @@ impl WifiDriver { &mut self, ap_config: Config, sta_config: Config, - clocks: &Clocks<'_>, ) -> (Ap, Sta) { // Prepare, stop STA if running if !matches!(self.state, WifiDriverState::ApSta(_)) { let spawner = Spawner::for_current_executor().await; self.state - .initialize(clocks, |init| { + .initialize(|init| { WifiDriverState::ApSta(ApStaState::init( init, ap_config, @@ -206,12 +202,12 @@ impl WifiDriver { } } - pub async fn configure_sta(&mut self, sta_config: Config, clocks: &Clocks<'_>) -> Sta { + pub async fn configure_sta(&mut self, sta_config: Config) -> Sta { // Prepare, stop AP if running if !matches!(self.state, WifiDriverState::Sta(_)) { let spawner = Spawner::for_current_executor().await; self.state - .initialize(clocks, |init| { + .initialize(|init| { WifiDriverState::Sta(StaState::init( init, sta_config, diff --git a/src/main.rs b/src/main.rs index 7a5dbfa0..aea8bbf5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ use crate::{ initialized::{Context, InnerContext}, startup::StartupResources, storage::FileSystem, - TouchDetect, + TouchDetectPin, }, states::{ charging::charging, @@ -54,16 +54,15 @@ use crate::{ }; use esp_hal::{ - delay::Delay, interrupt::Priority, prelude::main, - reset, rtc_cntl::sleep::{self, WakeupLevel}, + peripheral::Peripheral }; use esp_hal_embassy::InterruptExecutor; #[cfg(any(feature = "hw_v4", feature = "hw_v6"))] -use crate::board::VbusDetect; +use crate::board::VbusDetectPin; #[cfg(feature = "esp32s3")] use esp_hal::gpio::RtcPin as RtcWakeupPin; @@ -214,8 +213,6 @@ async fn main(_spawner: Spawner) { let mut storage = FileSystem::mount().await; let config = load_config(storage.as_deref_mut()).await; - let delay = Delay::new(&resources.clocks); - // We're boxing Context because we will need to move out of it during shutdown. let mut board = Box::new(Context { // If the device is awake, the display should be enabled. @@ -223,7 +220,6 @@ async fn main(_spawner: Spawner) { storage, inner: InnerContext { display: resources.display, - clocks: resources.clocks, high_prio_spawner: interrupt_executor.start(Priority::Priority2), battery_monitor: resources.battery_monitor, wifi: resources.wifi, @@ -284,29 +280,24 @@ async fn main(_spawner: Spawner) { let mut battery_monitor = board.inner.battery_monitor; - let mut rtc = resources.rtc; let is_charging = battery_monitor.is_plugged(); - let (mut charger_pin, _) = battery_monitor.stop().await; + let (charger_pin, _) = battery_monitor.stop().await; - let (_, _, _, mut touch) = board.frontend.split(); + let (_, _, _, touch) = board.frontend.split(); - let mut wakeup_pins = heapless::Vec::<(&mut dyn RtcWakeupPin, WakeupLevel), 2>::new(); - // let wakeup_source = - // setup_wakeup_pins(&mut wakeup_pins, &mut touch, &mut charger_pin, is_charging); - // rtc.sleep_deep(&[&wakeup_source]); - reset::software_reset(); + enter_sleep(resources.rtc, touch, charger_pin, is_charging); // Shouldn't reach this. If we do, we just exit the task, which means the executor // will have nothing else to do. Not ideal, but again, we shouldn't reach this. } #[cfg(any(feature = "hw_v4", all(feature = "hw_v6", feature = "esp32s3")))] -fn setup_wakeup_pins<'a, 'b, const N: usize>( - wakeup_pins: &'a mut heapless::Vec<(&'b mut dyn RtcWakeupPin, WakeupLevel), N>, - touch: &'b mut TouchDetect, - charger_pin: &'b mut VbusDetect, +fn enter_sleep( + mut rtc: esp_hal::rtc_cntl::Rtc, + touch: TouchDetectPin, + charger_pin: VbusDetectPin, is_charging: bool, -) -> sleep::RtcioWakeupSource<'a, 'b> { +) { let charger_level = if is_charging { // Wake up momentarily when charger is disconnected WakeupLevel::Low @@ -318,19 +309,22 @@ fn setup_wakeup_pins<'a, 'b, const N: usize>( WakeupLevel::High }; - unwrap!(wakeup_pins.push((touch, WakeupLevel::Low)).ok()); - unwrap!(wakeup_pins.push((charger_pin, charger_level)).ok()); + let mut wakeup_pins: [(&mut dyn RtcWakeupPin, WakeupLevel); 2] = [ + (&mut *touch.into_ref(), WakeupLevel::Low), + (&mut *charger_pin.into_ref(), charger_level), + ]; + let wakeup_source = sleep::RtcioWakeupSource::new(&mut wakeup_pins); - sleep::RtcioWakeupSource::new(wakeup_pins) + rtc.sleep_deep(&[&wakeup_source]); } #[cfg(all(feature = "hw_v6", feature = "esp32c6"))] -fn setup_wakeup_pins<'a, 'b, const N: usize>( - wakeup_pins: &'a mut heapless::Vec<(&'b mut dyn RtcWakeupPin, WakeupLevel), N>, - touch: &'b mut TouchDetect, - charger_pin: &'b mut VbusDetect, +fn enter_sleep( + mut rtc: esp_hal::rtc_cntl::Rtc, + touch: TouchDetectPin, + charger_pin: VbusDetectPin, is_charging: bool, -) -> sleep::Ext1WakeupSource<'a, 'b> { +) { let charger_level = if is_charging { // Wake up momentarily when charger is disconnected WakeupLevel::Low @@ -342,8 +336,12 @@ fn setup_wakeup_pins<'a, 'b, const N: usize>( WakeupLevel::High }; - unwrap!(wakeup_pins.push((touch, WakeupLevel::Low)).ok()); - unwrap!(wakeup_pins.push((charger_pin, charger_level)).ok()); + let mut wakeup_pins: [(&mut dyn RtcWakeupPin, WakeupLevel); 2] = [ + (&mut *touch.into_ref(), WakeupLevel::Low), + (&mut *charger_pin.into_ref(), charger_level), + ]; + + let wakeup_source = sleep::Ext1WakeupSource::new(&mut wakeup_pins); - sleep::Ext1WakeupSource::new(wakeup_pins) + rtc.sleep_deep(&[&wakeup_source]); } diff --git a/src/states/measure.rs b/src/states/measure.rs index f841df71..04f355ed 100644 --- a/src/states/measure.rs +++ b/src/states/measure.rs @@ -197,7 +197,7 @@ async fn measure_impl( frontend .spi_mut() .bus_mut() - .change_bus_frequency(4u32.MHz(), &context.clocks); + .change_bus_frequency(4u32.MHz()); } Err(_e) => { From 3087382855742398d036109cb901612f0497c95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 5 Sep 2024 22:39:13 +0200 Subject: [PATCH 15/29] Update ssd1306 --- Cargo.toml | 4 +--- src/board/drivers/display.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 607d5854..15e2548a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,9 +75,7 @@ esp-wifi = { version = "0.9.1", default-features = false, features = [ display-interface = "0.5" display-interface-spi = "0.5" -ssd1306 = { git = "https://github.com/bugadani/ssd1306.git", branch = "ehal1", features = [ - "graphics", -] } +ssd1306 = { version = "0.9.0", features = ["async", "graphics"] } portable_atomic_enum = "0.3.1" config-site = { path = "config-site", default-features = false, features = [ diff --git a/src/board/drivers/display.rs b/src/board/drivers/display.rs index a6545844..0fad2238 100644 --- a/src/board/drivers/display.rs +++ b/src/board/drivers/display.rs @@ -8,18 +8,18 @@ use embedded_graphics::{ }; use embedded_hal::digital::OutputPin; use ssd1306::{ - command::AddrMode, mode::BufferedGraphicsMode, prelude::Brightness, rotation::DisplayRotation, - size::DisplaySize128x64, Ssd1306, + command::AddrMode, mode::BufferedGraphicsModeAsync, prelude::*, rotation::DisplayRotation, + size::DisplaySize128x64, Ssd1306Async, }; use static_cell::make_static; use crate::board::DisplayInterface; pub struct Display { - display: &'static mut Ssd1306< + display: &'static mut Ssd1306Async< DisplayInterface<'static>, DisplaySize128x64, - BufferedGraphicsMode, + BufferedGraphicsModeAsync, >, reset: RESET, } @@ -30,7 +30,7 @@ where { pub fn new(spi: DisplayInterface<'static>, reset: RESET) -> Self { let display = make_static! { - Ssd1306::new(spi, DisplaySize128x64, DisplayRotation::Rotate0) + Ssd1306Async::new(spi, DisplaySize128x64, DisplayRotation::Rotate0) .into_buffered_graphics_mode() }; @@ -40,15 +40,15 @@ where pub async fn enable(&mut self) -> Result<(), DisplayError> { unwrap!(self .display - .reset_async::<_, Delay>(&mut self.reset, &mut Delay) + .reset::<_, Delay>(&mut self.reset, &mut Delay) .await .ok()); self.display - .init_with_addr_mode_async(AddrMode::Horizontal) + .init_with_addr_mode(AddrMode::Horizontal) .await?; self.display.clear(BinaryColor::Off)?; - self.display.flush_async().await?; + self.display.flush().await?; Ok(()) } @@ -69,14 +69,14 @@ where } pub async fn flush(&mut self) -> Result<(), DisplayError> { - self.display.flush_async().await + self.display.flush().await } pub async fn update_brightness_async( &mut self, brightness: Brightness, ) -> Result<(), DisplayError> { - self.display.set_brightness_async(brightness).await + self.display.set_brightness(brightness).await } pub fn shut_down(&mut self) { From 37af86c23cb5832e368b9a07d96eebaef3bb4607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 5 Sep 2024 22:39:19 +0200 Subject: [PATCH 16/29] Fmt --- src/board/initialized.rs | 12 +++++------- src/board/wifi/mod.rs | 11 ++--------- src/main.rs | 2 +- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/board/initialized.rs b/src/board/initialized.rs index c171ae12..731782e9 100644 --- a/src/board/initialized.rs +++ b/src/board/initialized.rs @@ -184,13 +184,11 @@ impl InnerContext { let ap = self .wifi - .configure_ap( - NetConfig::ipv4_static(StaticConfigV4 { - address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 2, 1), 24), - gateway: Some(Ipv4Address::from_bytes(&[192, 168, 2, 1])), - dns_servers: Default::default(), - }), - ) + .configure_ap(NetConfig::ipv4_static(StaticConfigV4 { + address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 2, 1), 24), + gateway: Some(Ipv4Address::from_bytes(&[192, 168, 2, 1])), + dns_servers: Default::default(), + })) .await; Some(ap) diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index 4f29349b..d42f1826 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -95,10 +95,7 @@ enum WifiDriverState { } impl WifiDriverState { - async fn initialize( - &mut self, - callback: impl FnOnce(EspWifiInitialization) -> Self, - ) { + async fn initialize(&mut self, callback: impl FnOnce(EspWifiInitialization) -> Self) { self.uninit().await; replace_with::replace_with_or_abort(self, |this| { let token = match this { @@ -172,11 +169,7 @@ impl WifiDriver { } } - pub async fn configure_ap_sta( - &mut self, - ap_config: Config, - sta_config: Config, - ) -> (Ap, Sta) { + pub async fn configure_ap_sta(&mut self, ap_config: Config, sta_config: Config) -> (Ap, Sta) { // Prepare, stop STA if running if !matches!(self.state, WifiDriverState::ApSta(_)) { let spawner = Spawner::for_current_executor().await; diff --git a/src/main.rs b/src/main.rs index aea8bbf5..be5d55b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,9 +55,9 @@ use crate::{ use esp_hal::{ interrupt::Priority, + peripheral::Peripheral, prelude::main, rtc_cntl::sleep::{self, WakeupLevel}, - peripheral::Peripheral }; use esp_hal_embassy::InterruptExecutor; From 9b9af263ee629b6abf5d93272d735bc66f11f742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 5 Sep 2024 22:49:59 +0200 Subject: [PATCH 17/29] Toolchain tweak --- .github/workflows/build.yml | 5 +++++ .github/workflows/check.yml | 5 +++++ .github/workflows/merge.yml | 5 +++++ xtask/src/main.rs | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5337a288..d0946bf7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,12 @@ jobs: with: default: true buildtargets: esp32s3 + version: "1.80.0" ldproxy: false + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly-2024-06-01 + components: clippy, rustfmt, rust-src - uses: Swatinem/rust-cache@v2 - uses: cargo-bins/cargo-binstall@main diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index eb321af0..1b37d585 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -28,7 +28,12 @@ jobs: with: default: true buildtargets: esp32s3 + version: "1.80.0" ldproxy: false + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly-2024-06-01 + components: clippy, rustfmt, rust-src - uses: Swatinem/rust-cache@v2 - name: format check diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 4bd244a7..6ed57b3a 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -21,7 +21,12 @@ jobs: with: default: true buildtargets: esp32s3 + version: "1.80.0" ldproxy: false + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly-2024-06-01 + components: clippy, rustfmt, rust-src - uses: Swatinem/rust-cache@v2 - uses: cargo-bins/cargo-binstall@main diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3143eacb..07242111 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -376,7 +376,7 @@ impl SocConfig { fn toolchain(self) -> &'static str { match self { SocConfig::S3 => "esp", - SocConfig::C6 => "nightly-2024-06-01-x86_64-pc-windows-msvc", + SocConfig::C6 => "nightly-2024-06-01", } } } From 615b80ebb4c58919772e981f3a28ed2c38310d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 6 Sep 2024 09:13:38 +0200 Subject: [PATCH 18/29] Add missing pullup --- src/board/startup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/board/startup.rs b/src/board/startup.rs index 96d7d819..9478e4cb 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -194,7 +194,7 @@ impl StartupResources { BatteryMonitor::start( Input::new_typed(vbus_detect, Pull::None), - Input::new_typed(charger_status, Pull::None), + Input::new_typed(charger_status, Pull::Up), BatteryFg::new( Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz()), design), fg_enable, From 7d8d838a513b1cc3948043ab4607658c1fa84272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 6 Sep 2024 09:19:47 +0200 Subject: [PATCH 19/29] Add launch configs --- .vscode/launch.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0207bf07..d0fc64e8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -173,6 +173,28 @@ "programBinary": "${workspaceRoot}/target/xtensa-esp32s3-none-elf/release/card_io_fw" } ] + }, + { + "name": "Attach to v6c6", + "type": "probe-rs-debug", + "request": "attach", + "chip": "esp32c6", + "coreConfigs": [ + { + "programBinary": "${workspaceRoot}/target/riscv32imac-unknown-none-elf/debug/card_io_fw" + } + ] + }, + { + "name": "Attach to v6c6 release", + "type": "probe-rs-debug", + "request": "attach", + "chip": "esp32c6", + "coreConfigs": [ + { + "programBinary": "${workspaceRoot}/target/riscv32imac-unknown-none-elf/release/card_io_fw" + } + ] } ] } \ No newline at end of file From 81d26cbd13cfa387cec6830ab71ade864eca44bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 6 Sep 2024 11:50:07 +0200 Subject: [PATCH 20/29] Don't pass delay to spi drivers --- src/board/hardware/v4.rs | 7 +++---- src/board/hardware/v6c6.rs | 10 ++++------ src/board/hardware/v6s3.rs | 7 +++---- src/board/startup.rs | 6 ++---- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 49d959e5..8b9d38a3 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -7,8 +7,7 @@ use crate::board::{ utils::DummyOutputPin, wifi::WifiDriver, }; -use embassy_time::Delay; -use embedded_hal_bus::spi::ExclusiveDevice; +use embedded_hal_bus::spi::{ExclusiveDevice, NoDelay}; use esp_hal::{ dma::*, gpio::{GpioPin, Input, Io, Level, Output}, @@ -43,7 +42,7 @@ pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandP pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, - Delay, + NoDelay, >; pub type AdcDmaChannel = ChannelCreator1; @@ -66,7 +65,7 @@ pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, AdcChipSelectPin, - Delay, + NoDelay, >; pub type BatteryAdcEnable = GpioPin<8>; diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 82703de9..817f5855 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -8,8 +8,7 @@ use crate::board::{ wifi::WifiDriver, }; use display_interface_spi::SPIInterface; -use embassy_time::Delay; -use embedded_hal_bus::spi::ExclusiveDevice; +use embedded_hal_bus::spi::{ExclusiveDevice, NoDelay}; use esp_hal::{ dma::*, gpio::{GpioPin, Input, Io, Level, Output, Pull}, @@ -44,7 +43,7 @@ pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandP pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, - Delay, + NoDelay, >; pub type AdcSclk = GpioPin<6>; @@ -67,7 +66,7 @@ pub type AdcMisoPin = Input<'static, AdcMiso>; pub type AdcSclkPin = Output<'static, AdcSclk>; pub type AdcSpi = - ExclusiveDevice, AdcChipSelectPin, Delay>; + ExclusiveDevice, AdcChipSelectPin, NoDelay>; pub type VbusDetect = GpioPin<3>; pub type ChargerStatus = GpioPin<20>; @@ -116,7 +115,7 @@ impl super::startup::StartupResources { ); let adc = Self::create_frontend_driver( - ExclusiveDevice::new( + ExclusiveDevice::new_no_delay( BitbangSpi::new( Output::new_typed(io.pins.gpio7, Level::Low), Input::new_typed(io.pins.gpio5, Pull::None), @@ -124,7 +123,6 @@ impl super::startup::StartupResources { 1u32.MHz(), ), Output::new_typed(io.pins.gpio9, Level::High), - Delay, ), io.pins.gpio4, io.pins.gpio15, diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index fe17abc1..feb29e43 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -7,8 +7,7 @@ use crate::board::{ utils::DummyOutputPin, wifi::WifiDriver, }; -use display_interface_spi::SPIInterface; -use embassy_time::Delay; +use display_interface_spi::{NoDelay, SPIInterface}; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, @@ -42,7 +41,7 @@ pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandP pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, - Delay, + NoDelay, >; pub type AdcDmaChannel = ChannelCreator1; @@ -65,7 +64,7 @@ pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, AdcChipSelectPin, - Delay, + NoDelay, >; pub type VbusDetect = GpioPin<2>; diff --git a/src/board/startup.rs b/src/board/startup.rs index 9478e4cb..c5560f8c 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -1,5 +1,4 @@ use display_interface_spi::SPIInterface; -use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use static_cell::make_static; @@ -111,7 +110,7 @@ impl StartupResources { Display::new( SPIInterface::new( - ExclusiveDevice::new(display_spi, DummyOutputPin, Delay), + ExclusiveDevice::new_no_delay(display_spi, DummyOutputPin), Output::new_typed(display_dc, Level::Low), ), Output::new_typed(display_reset, Level::Low), @@ -133,7 +132,7 @@ impl StartupResources { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - ExclusiveDevice::new( + ExclusiveDevice::new_no_delay( Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1) .with_sck(adc_sclk) .with_mosi(adc_mosi) @@ -141,7 +140,6 @@ impl StartupResources { .with_dma(adc_dma_channel.configure_for_async(false, DmaPriority::Priority1)) .with_buffers(dma_tx_buf, dma_rx_buf), Output::new_typed(adc_cs, Level::High), - Delay, ) } From 46552fe7d8d32a481aca4256ce2197e9b2e0e02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 6 Sep 2024 13:00:41 +0200 Subject: [PATCH 21/29] Clean up display init --- src/board/drivers/display.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/board/drivers/display.rs b/src/board/drivers/display.rs index 0fad2238..3ce1a531 100644 --- a/src/board/drivers/display.rs +++ b/src/board/drivers/display.rs @@ -44,10 +44,7 @@ where .await .ok()); - self.display - .init_with_addr_mode(AddrMode::Horizontal) - .await?; - self.display.clear(BinaryColor::Off)?; + self.display.init().await?; self.display.flush().await?; Ok(()) From 1c50fa615b3a33965b88c8ba44501f728c7dd801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 16 Sep 2024 09:46:27 +0200 Subject: [PATCH 22/29] Revert "Don't pass delay to spi drivers" This reverts commit 511c3bd3c0a161e7be7765279f5636f65d055c34. --- src/board/hardware/v4.rs | 7 ++++--- src/board/hardware/v6c6.rs | 10 ++++++---- src/board/hardware/v6s3.rs | 7 ++++--- src/board/startup.rs | 6 ++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 8b9d38a3..49d959e5 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -7,7 +7,8 @@ use crate::board::{ utils::DummyOutputPin, wifi::WifiDriver, }; -use embedded_hal_bus::spi::{ExclusiveDevice, NoDelay}; +use embassy_time::Delay; +use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, gpio::{GpioPin, Input, Io, Level, Output}, @@ -42,7 +43,7 @@ pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandP pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, - NoDelay, + Delay, >; pub type AdcDmaChannel = ChannelCreator1; @@ -65,7 +66,7 @@ pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, AdcChipSelectPin, - NoDelay, + Delay, >; pub type BatteryAdcEnable = GpioPin<8>; diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 817f5855..82703de9 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -8,7 +8,8 @@ use crate::board::{ wifi::WifiDriver, }; use display_interface_spi::SPIInterface; -use embedded_hal_bus::spi::{ExclusiveDevice, NoDelay}; +use embassy_time::Delay; +use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, gpio::{GpioPin, Input, Io, Level, Output, Pull}, @@ -43,7 +44,7 @@ pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandP pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, - NoDelay, + Delay, >; pub type AdcSclk = GpioPin<6>; @@ -66,7 +67,7 @@ pub type AdcMisoPin = Input<'static, AdcMiso>; pub type AdcSclkPin = Output<'static, AdcSclk>; pub type AdcSpi = - ExclusiveDevice, AdcChipSelectPin, NoDelay>; + ExclusiveDevice, AdcChipSelectPin, Delay>; pub type VbusDetect = GpioPin<3>; pub type ChargerStatus = GpioPin<20>; @@ -115,7 +116,7 @@ impl super::startup::StartupResources { ); let adc = Self::create_frontend_driver( - ExclusiveDevice::new_no_delay( + ExclusiveDevice::new( BitbangSpi::new( Output::new_typed(io.pins.gpio7, Level::Low), Input::new_typed(io.pins.gpio5, Pull::None), @@ -123,6 +124,7 @@ impl super::startup::StartupResources { 1u32.MHz(), ), Output::new_typed(io.pins.gpio9, Level::High), + Delay, ), io.pins.gpio4, io.pins.gpio15, diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index feb29e43..fe17abc1 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -7,7 +7,8 @@ use crate::board::{ utils::DummyOutputPin, wifi::WifiDriver, }; -use display_interface_spi::{NoDelay, SPIInterface}; +use display_interface_spi::SPIInterface; +use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, @@ -41,7 +42,7 @@ pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandP pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, - NoDelay, + Delay, >; pub type AdcDmaChannel = ChannelCreator1; @@ -64,7 +65,7 @@ pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, AdcChipSelectPin, - NoDelay, + Delay, >; pub type VbusDetect = GpioPin<2>; diff --git a/src/board/startup.rs b/src/board/startup.rs index c5560f8c..9478e4cb 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -1,4 +1,5 @@ use display_interface_spi::SPIInterface; +use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use static_cell::make_static; @@ -110,7 +111,7 @@ impl StartupResources { Display::new( SPIInterface::new( - ExclusiveDevice::new_no_delay(display_spi, DummyOutputPin), + ExclusiveDevice::new(display_spi, DummyOutputPin, Delay), Output::new_typed(display_dc, Level::Low), ), Output::new_typed(display_reset, Level::Low), @@ -132,7 +133,7 @@ impl StartupResources { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); - ExclusiveDevice::new_no_delay( + ExclusiveDevice::new( Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1) .with_sck(adc_sclk) .with_mosi(adc_mosi) @@ -140,6 +141,7 @@ impl StartupResources { .with_dma(adc_dma_channel.configure_for_async(false, DmaPriority::Priority1)) .with_buffers(dma_tx_buf, dma_rx_buf), Output::new_typed(adc_cs, Level::High), + Delay, ) } From 6f72984cd6191e07120b579e1fe1a0b4510cb3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 16 Sep 2024 10:30:20 +0200 Subject: [PATCH 23/29] Remove unused import --- src/board/drivers/display.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/board/drivers/display.rs b/src/board/drivers/display.rs index 3ce1a531..1fc5b693 100644 --- a/src/board/drivers/display.rs +++ b/src/board/drivers/display.rs @@ -8,7 +8,7 @@ use embedded_graphics::{ }; use embedded_hal::digital::OutputPin; use ssd1306::{ - command::AddrMode, mode::BufferedGraphicsModeAsync, prelude::*, rotation::DisplayRotation, + mode::BufferedGraphicsModeAsync, prelude::*, rotation::DisplayRotation, size::DisplaySize128x64, Ssd1306Async, }; use static_cell::make_static; From e1df246c5d09d1f4a93fbfab4c9fa0bf098e8286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 16 Sep 2024 11:13:08 +0200 Subject: [PATCH 24/29] Update again --- Cargo.toml | 13 +++++++------ src/board/hardware/v4.rs | 4 ++-- src/board/hardware/v6c6.rs | 4 ++-- src/board/hardware/v6s3.rs | 4 ++-- src/board/startup.rs | 26 +++++++++++--------------- src/board/wifi/mod.rs | 6 +++--- src/heap.rs | 15 --------------- src/main.rs | 3 ++- src/states/menu/main.rs | 3 +-- 9 files changed, 30 insertions(+), 48 deletions(-) delete mode 100644 src/heap.rs 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..e2183c78 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( @@ -129,7 +125,7 @@ impl StartupResources { adc_miso: AdcMiso, adc_cs: AdcChipSelect, ) -> AdcSpi { - 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(); @@ -139,7 +135,7 @@ impl StartupResources { .with_mosi(adc_mosi) .with_miso(adc_miso) .with_dma(adc_dma_channel.configure_for_async(false, DmaPriority::Priority1)) - .with_buffers(dma_tx_buf, dma_rx_buf), + .with_buffers(dma_rx_buf, dma_tx_buf), Output::new_typed(adc_cs, Level::High), Delay, ) 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) From 20801c11e948dac4a054c1d63b38301f77ccafc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 16 Sep 2024 22:01:50 +0200 Subject: [PATCH 25/29] Erase GPIO types --- src/board/hardware/v4.rs | 56 ++++++--------------------- src/board/hardware/v6c6.rs | 68 ++++++++------------------------ src/board/hardware/v6s3.rs | 51 +++++------------------- src/board/initialized.rs | 4 +- src/board/startup.rs | 79 ++++++++++++++++++++++---------------- src/main.rs | 12 ++---- 6 files changed, 88 insertions(+), 182 deletions(-) diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 75812795..a5a139e6 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -15,7 +15,6 @@ use esp_hal::{ i2c::I2C, interrupt::software::SoftwareInterruptControl, peripherals, - prelude::*, rtc_cntl::Rtc, spi::{master::SpiDmaBus, FullDuplexMode}, timer::{ @@ -30,16 +29,8 @@ use display_interface_spi::SPIInterface; pub type DisplaySpiInstance = peripherals::SPI2; pub type DisplayDmaChannel = ChannelCreator0; -pub type DisplayDataCommand = GpioPin<13>; -pub type DisplayChipSelect = GpioPin<11>; -pub type DisplayReset = GpioPin<12>; -pub type DisplaySclk = GpioPin<14>; -pub type DisplayMosi = GpioPin<21>; -pub type DisplayResetPin = Output<'static, DisplayReset>; -pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; - -pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; +pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, @@ -48,56 +39,31 @@ pub type DisplaySpi<'d> = ExclusiveDevice< pub type AdcDmaChannel = ChannelCreator1; pub type AdcSpiInstance = peripherals::SPI3; -pub type AdcSclk = GpioPin<6>; -pub type AdcMosi = GpioPin<7>; -pub type AdcMiso = GpioPin<5>; -pub type AdcChipSelect = GpioPin<18>; -pub type AdcClockEnable = GpioPin<38>; -pub type AdcDrdy = GpioPin<4>; -pub type AdcReset = GpioPin<2>; -pub type TouchDetect = GpioPin<1>; - -pub type AdcClockEnablePin = Output<'static, AdcClockEnable>; -pub type AdcDrdyPin = Input<'static, AdcDrdy>; -pub type AdcResetPin = Output<'static, AdcReset>; -pub type TouchDetectPin = Input<'static, TouchDetect>; -pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, - AdcChipSelectPin, + Output<'static>, Delay, >; -pub type BatteryAdcEnable = GpioPin<8>; -pub type VbusDetect = GpioPin<17>; -pub type ChargerStatus = GpioPin<47>; - -pub type BatteryAdcEnablePin = Output<'static, BatteryAdcEnable>; -pub type VbusDetectPin = Input<'static, VbusDetect>; -pub type ChargerStatusPin = Input<'static, ChargerStatus>; +pub type BatteryAdcEnablePin = Output<'static>; +pub type VbusDetectPin = Input<'static>; +pub type ChargerStatusPin = Input<'static>; -pub type EcgFrontend = Frontend; +pub type EcgFrontend = + Frontend, Output<'static>, Output<'static>, Input<'static>>; pub type PoweredEcgFrontend = - PoweredFrontend; + PoweredFrontend, Output<'static>, Output<'static>, Input<'static>>; -pub type Display = DisplayType; +pub type Display = DisplayType>; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type I2cSda = GpioPin<36>; -pub type I2cScl = GpioPin<35>; pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { pub async fn initialize() -> Self { - Self::common_init(); - - let peripherals = esp_hal::init({ - let mut config = esp_hal::Config::default(); - config.cpu_clock = CpuClock::max(); - config - }); + let peripherals = Self::common_init(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); esp_hal_embassy::init(systimer.alarm0); @@ -137,7 +103,7 @@ impl super::startup::StartupResources { io.pins.gpio35, io.pins.gpio17, io.pins.gpio47, - Output::new_typed(io.pins.gpio8, Level::Low), + Output::new(io.pins.gpio8, Level::Low), ) .await; diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 65a0fe86..4dca59c5 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -31,72 +31,38 @@ pub use crate::board::drivers::bitbang_spi::BitbangSpi; pub type DisplaySpiInstance = peripherals::SPI2; pub type DisplayDmaChannel = ChannelCreator0; -pub type DisplayDataCommand = GpioPin<8>; -pub type DisplayChipSelect = GpioPin<11>; -pub type DisplayReset = GpioPin<10>; -pub type DisplaySclk = GpioPin<22>; -pub type DisplayMosi = GpioPin<21>; -pub type DisplayResetPin = Output<'static, DisplayReset>; -pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; - -pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; +pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, Delay, >; -pub type AdcSclk = GpioPin<6>; -pub type AdcMosi = GpioPin<7>; -pub type AdcMiso = GpioPin<5>; -pub type AdcChipSelect = GpioPin<9>; -pub type AdcClockEnable = GpioPin<23>; -pub type AdcDrdy = GpioPin<4>; -pub type AdcReset = GpioPin<15>; -pub type TouchDetect = GpioPin<2>; - -pub type AdcClockEnablePin = Output<'static, AdcClockEnable>; -pub type AdcDrdyPin = Input<'static, AdcDrdy>; -pub type AdcResetPin = Output<'static, AdcReset>; -pub type TouchDetectPin = Input<'static, TouchDetect>; -pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; - -pub type AdcMosiPin = Output<'static, AdcMosi>; -pub type AdcMisoPin = Input<'static, AdcMiso>; -pub type AdcSclkPin = Output<'static, AdcSclk>; - -pub type AdcSpi = - ExclusiveDevice, AdcChipSelectPin, Delay>; - -pub type VbusDetect = GpioPin<3>; -pub type ChargerStatus = GpioPin<20>; +pub type AdcSpi = ExclusiveDevice< + BitbangSpi, Input<'static>, Output<'static>>, + Output<'static>, + Delay, +>; pub type BatteryAdcEnablePin = DummyOutputPin; -pub type VbusDetectPin = Input<'static, VbusDetect>; -pub type ChargerStatusPin = Input<'static, ChargerStatus>; +pub type VbusDetectPin = Input<'static>; +pub type ChargerStatusPin = Input<'static>; -pub type EcgFrontend = Frontend; +pub type EcgFrontend = + Frontend, Output<'static>, Output<'static>, Input<'static>>; pub type PoweredEcgFrontend = - PoweredFrontend; + PoweredFrontend, Output<'static>, Output<'static>, Input<'static>>; -pub type Display = DisplayType; +pub type Display = DisplayType>; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type I2cSda = GpioPin<19>; -pub type I2cScl = GpioPin<18>; pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { pub async fn initialize() -> Self { - Self::common_init(); - - let peripherals = esp_hal::init({ - let mut config = esp_hal::Config::default(); - config.cpu_clock = CpuClock::max(); - config - }); + let peripherals = Self::common_init(); let timg0 = TimerGroup::new(peripherals.TIMG0); esp_hal_embassy::init(timg0.timer0); @@ -118,12 +84,12 @@ impl super::startup::StartupResources { let adc = Self::create_frontend_driver( ExclusiveDevice::new( BitbangSpi::new( - Output::new_typed(io.pins.gpio7, Level::Low), - Input::new_typed(io.pins.gpio5, Pull::None), - Output::new_typed(io.pins.gpio6, Level::Low), + Output::new(io.pins.gpio7, Level::Low), + Input::new(io.pins.gpio5, Pull::None), + Output::new(io.pins.gpio6, Level::Low), 1u32.MHz(), ), - Output::new_typed(io.pins.gpio9, Level::High), + Output::new(io.pins.gpio9, Level::High), Delay, ), io.pins.gpio4, diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index e459e759..4fd9fc2f 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -16,7 +16,6 @@ use esp_hal::{ i2c::I2C, interrupt::software::SoftwareInterruptControl, peripherals, - prelude::*, rtc_cntl::Rtc, spi::{master::SpiDmaBus, FullDuplexMode}, timer::{ @@ -29,16 +28,8 @@ use esp_hal::{ pub type DisplaySpiInstance = peripherals::SPI2; pub type DisplayDmaChannel = ChannelCreator0; -pub type DisplayDataCommand = GpioPin<17>; -pub type DisplayChipSelect = GpioPin<8>; -pub type DisplayReset = GpioPin<18>; -pub type DisplaySclk = GpioPin<39>; -pub type DisplayMosi = GpioPin<38>; -pub type DisplayResetPin = Output<'static, DisplayReset>; -pub type DisplayDataCommandPin = Output<'static, DisplayDataCommand>; - -pub type DisplayInterface<'a> = SPIInterface, DisplayDataCommandPin>; +pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, DummyOutputPin, @@ -47,55 +38,31 @@ pub type DisplaySpi<'d> = ExclusiveDevice< pub type AdcDmaChannel = ChannelCreator1; pub type AdcSpiInstance = peripherals::SPI3; -pub type AdcSclk = GpioPin<6>; -pub type AdcMosi = GpioPin<7>; -pub type AdcMiso = GpioPin<5>; -pub type AdcChipSelect = GpioPin<0>; -pub type AdcClockEnable = GpioPin<40>; -pub type AdcDrdy = GpioPin<4>; -pub type AdcReset = GpioPin<42>; -pub type TouchDetect = GpioPin<1>; - -pub type AdcClockEnablePin = Output<'static, AdcClockEnable>; -pub type AdcDrdyPin = Input<'static, AdcDrdy>; -pub type AdcResetPin = Output<'static, AdcReset>; -pub type TouchDetectPin = Input<'static, TouchDetect>; -pub type AdcChipSelectPin = Output<'static, AdcChipSelect>; pub type AdcSpi = ExclusiveDevice< SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, - AdcChipSelectPin, + Output<'static>, Delay, >; -pub type VbusDetect = GpioPin<2>; -pub type ChargerStatus = GpioPin<37>; - pub type BatteryAdcEnablePin = DummyOutputPin; -pub type VbusDetectPin = Input<'static, VbusDetect>; -pub type ChargerStatusPin = Input<'static, ChargerStatus>; +pub type VbusDetectPin = Input<'static>; +pub type ChargerStatusPin = Input<'static>; -pub type EcgFrontend = Frontend; +pub type EcgFrontend = + Frontend, Output<'static>, Output<'static>, Input<'static>>; pub type PoweredEcgFrontend = - PoweredFrontend; + PoweredFrontend, Output<'static>, Output<'static>, Input<'static>>; -pub type Display = DisplayType; +pub type Display = DisplayType>; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type I2cSda = GpioPin<36>; -pub type I2cScl = GpioPin<35>; pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { pub async fn initialize() -> Self { - Self::common_init(); - - let peripherals = esp_hal::init({ - let mut config = esp_hal::Config::default(); - config.cpu_clock = CpuClock::max(); - config - }); + let peripherals = Self::common_init(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::(); esp_hal_embassy::init(systimer.alarm0); diff --git a/src/board/initialized.rs b/src/board/initialized.rs index 731782e9..0c370d08 100644 --- a/src/board/initialized.rs +++ b/src/board/initialized.rs @@ -6,7 +6,7 @@ use crate::{ drivers::battery_monitor::BatteryMonitor, storage::FileSystem, wifi::{ap::Ap, sta::Sta, WifiDriver}, - ChargerStatus, Display, EcgFrontend, VbusDetect, + Display, EcgFrontend, }, saved_measurement_exists, states::MESSAGE_MIN_DURATION, @@ -35,7 +35,7 @@ pub enum StaMode { pub struct InnerContext { pub display: Display, pub high_prio_spawner: SendSpawner, - pub battery_monitor: BatteryMonitor, Input<'static, ChargerStatus>>, + pub battery_monitor: BatteryMonitor, Input<'static>>, pub wifi: &'static mut WifiDriver, pub config: &'static mut Config, pub config_changed: bool, diff --git a/src/board/startup.rs b/src/board/startup.rs index e2183c78..a1ec02e1 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -7,27 +7,29 @@ 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, + AdcSpi, ChargerStatusPin, Display, DisplayDmaChannel, DisplaySpiInstance, EcgFrontend, + VbusDetectPin, }; use esp_hal::{ + clock::CpuClock, dma::*, dma_buffers, - gpio::{Input, Level, Output, Pull}, + gpio::{Input, InputPin, Level, Output, OutputPin, Pull}, interrupt::software::SoftwareInterrupt, + peripheral::Peripheral, + peripherals::Peripherals, rtc_cntl::Rtc, spi::{master::Spi, SpiMode}, }; #[cfg(feature = "esp32s3")] -use crate::board::{AdcChipSelect, AdcDmaChannel, AdcMiso, AdcMosi, AdcSclk, AdcSpiInstance}; +use crate::board::{AdcDmaChannel, AdcSpiInstance}; #[cfg(feature = "battery_max17055")] use esp_hal::i2c::I2C; #[cfg(feature = "battery_max17055")] use { - crate::board::{BatteryAdcEnablePin, BatteryFg, BatteryFgI2cInstance, I2cScl, I2cSda}, + crate::board::{BatteryAdcEnablePin, BatteryFg, BatteryFgI2cInstance}, max17055::{DesignData, Max17055}, }; @@ -48,7 +50,7 @@ pub struct StartupResources { } impl StartupResources { - pub(super) fn common_init() { + pub(super) fn common_init() -> Peripherals { #[cfg(feature = "log")] init_logger(log::LevelFilter::Trace); // we let the compile-time log level filter do the work @@ -82,6 +84,12 @@ impl StartupResources { }; let _stack_protection = make_static!(crate::stack_protection::StackMonitor::protect(stack_range)); + + esp_hal::init({ + let mut config = esp_hal::Config::default(); + config.cpu_clock = CpuClock::max(); + config + }) } #[inline(always)] @@ -89,11 +97,11 @@ impl StartupResources { pub(crate) fn create_display_driver( display_dma_channel: DisplayDmaChannel, display_spi: DisplaySpiInstance, - display_reset: DisplayReset, - display_dc: DisplayDataCommand, - display_cs: DisplayChipSelect, - display_sclk: DisplaySclk, - display_mosi: DisplayMosi, + display_reset: impl Peripheral

+ 'static, + display_dc: impl Peripheral

+ 'static, + display_cs: impl Peripheral

+ 'static, + display_sclk: impl Peripheral

+ 'static, + display_mosi: impl Peripheral

+ 'static, ) -> Display { let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(4092); let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); @@ -108,9 +116,9 @@ impl StartupResources { Display::new( SPIInterface::new( ExclusiveDevice::new(display_spi, DummyOutputPin, Delay), - Output::new_typed(display_dc, Level::Low), + Output::new(display_dc, Level::Low), ), - Output::new_typed(display_reset, Level::Low), + Output::new(display_reset, Level::Low), ) } @@ -120,10 +128,10 @@ impl StartupResources { pub(crate) fn create_frontend_spi( adc_dma_channel: AdcDmaChannel, adc_spi: AdcSpiInstance, - adc_sclk: AdcSclk, - adc_mosi: AdcMosi, - adc_miso: AdcMiso, - adc_cs: AdcChipSelect, + adc_sclk: impl Peripheral

+ 'static, + adc_mosi: impl Peripheral

+ 'static, + adc_miso: impl Peripheral

+ 'static, + adc_cs: impl Peripheral

+ 'static, ) -> AdcSpi { let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(4092); let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); @@ -136,7 +144,7 @@ impl StartupResources { .with_miso(adc_miso) .with_dma(adc_dma_channel.configure_for_async(false, DmaPriority::Priority1)) .with_buffers(dma_rx_buf, dma_tx_buf), - Output::new_typed(adc_cs, Level::High), + Output::new(adc_cs, Level::High), Delay, ) } @@ -144,31 +152,34 @@ impl StartupResources { #[inline(always)] pub(crate) fn create_frontend_driver( adc_spi: AdcSpi, - adc_drdy: AdcDrdy, - adc_reset: AdcReset, - adc_clock_enable: AdcClockEnable, - touch_detect: TouchDetect, + adc_drdy: impl Peripheral

+ 'static, + adc_reset: impl Peripheral

+ 'static, + adc_clock_enable: impl Peripheral

+ 'static, + touch_detect: impl Peripheral

+ 'static, ) -> EcgFrontend { // DRDY Frontend::new( adc_spi, - Input::new_typed(adc_drdy, Pull::None), - Output::new_typed(adc_reset, Level::Low), - Output::new_typed(adc_clock_enable, Level::Low), - Input::new_typed(touch_detect, Pull::None), + Input::new(adc_drdy, Pull::None), + Output::new(adc_reset, Level::Low), + Output::new(adc_clock_enable, Level::Low), + Input::new(touch_detect, Pull::None), ) } #[cfg(feature = "battery_max17055")] #[inline(always)] #[allow(clippy::too_many_arguments)] - pub(crate) async fn setup_battery_monitor_fg( + pub(crate) async fn setup_battery_monitor_fg< + SDA: InputPin + OutputPin, + SCL: InputPin + OutputPin, + >( i2c: BatteryFgI2cInstance, - sda: I2cSda, - scl: I2cScl, - vbus_detect: VbusDetect, - charger_status: ChargerStatus, + sda: impl Peripheral

+ 'static, + scl: impl Peripheral

+ 'static, + vbus_detect: impl Peripheral

+ 'static, + charger_status: impl Peripheral

+ 'static, fg_enable: BatteryAdcEnablePin, ) -> BatteryMonitor { // MCP73832T-2ACI/OT @@ -189,8 +200,8 @@ impl StartupResources { }; BatteryMonitor::start( - Input::new_typed(vbus_detect, Pull::None), - Input::new_typed(charger_status, Pull::Up), + Input::new(vbus_detect, Pull::None), + Input::new(charger_status, Pull::Up), BatteryFg::new( Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz()), design), fg_enable, diff --git a/src/main.rs b/src/main.rs index 9aea49c7..ce829774 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,6 @@ use crate::{ initialized::{Context, InnerContext}, startup::StartupResources, storage::FileSystem, - TouchDetectPin, }, states::{ charging::charging, @@ -61,9 +60,6 @@ use esp_hal::{ }; use esp_hal_embassy::InterruptExecutor; -#[cfg(any(feature = "hw_v4", feature = "hw_v6"))] -use crate::board::VbusDetectPin; - #[cfg(feature = "esp32s3")] use esp_hal::gpio::RtcPin as RtcWakeupPin; @@ -295,8 +291,8 @@ async fn main(_spawner: Spawner) { #[cfg(any(feature = "hw_v4", all(feature = "hw_v6", feature = "esp32s3")))] fn enter_sleep( mut rtc: esp_hal::rtc_cntl::Rtc, - touch: TouchDetectPin, - charger_pin: VbusDetectPin, + touch: impl Peripheral

, + charger_pin: impl Peripheral

, is_charging: bool, ) { let charger_level = if is_charging { @@ -322,8 +318,8 @@ fn enter_sleep( #[cfg(all(feature = "hw_v6", feature = "esp32c6"))] fn enter_sleep( mut rtc: esp_hal::rtc_cntl::Rtc, - touch: TouchDetectPin, - charger_pin: VbusDetectPin, + touch: impl Peripheral

, + charger_pin: impl Peripheral

, is_charging: bool, ) { let charger_level = if is_charging { From 1849148b9513c35bdc875903072b82f78ddac47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 29 Sep 2024 17:13:50 +0200 Subject: [PATCH 26/29] Update to SPI driver simplification PR --- Cargo.toml | 12 ++++++------ src/board/hardware/v4.rs | 4 ++-- src/board/hardware/v6c6.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17474898..9d1da0cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,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 = "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" } +esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } +esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } +esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } +esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } +esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } +esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } [features] default = ["defmt"] diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index a5a139e6..39d54641 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -28,7 +28,7 @@ use esp_hal::{ use display_interface_spi::SPIInterface; pub type DisplaySpiInstance = peripherals::SPI2; -pub type DisplayDmaChannel = ChannelCreator0; +pub type DisplayDmaChannel = ChannelCreator<0>; pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< @@ -37,7 +37,7 @@ pub type DisplaySpi<'d> = ExclusiveDevice< Delay, >; -pub type AdcDmaChannel = ChannelCreator1; +pub type AdcDmaChannel = ChannelCreator<1>; pub type AdcSpiInstance = peripherals::SPI3; pub type AdcSpi = ExclusiveDevice< diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 4dca59c5..1837d587 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -30,7 +30,7 @@ use esp_hal::{ pub use crate::board::drivers::bitbang_spi::BitbangSpi; pub type DisplaySpiInstance = peripherals::SPI2; -pub type DisplayDmaChannel = ChannelCreator0; +pub type DisplayDmaChannel = ChannelCreator<0>; pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< From 745882207418c279b619d076894bbe55cd7bbeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 8 Oct 2024 11:40:16 +0200 Subject: [PATCH 27/29] Update to latest esp-hal --- Cargo.toml | 12 ++++++------ src/board/hardware/v4.rs | 2 +- src/board/hardware/v6c6.rs | 2 +- src/board/hardware/v6s3.rs | 6 +++--- src/board/wifi/mod.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d1da0cb..78e7ba7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,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 = "1423f84" } -esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } -esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } -esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } -esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } -esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "1423f84" } +esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } +esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } +esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } +esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } +esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } +esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } [features] default = ["defmt"] diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 39d54641..976b1207 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -11,7 +11,7 @@ use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, - gpio::{GpioPin, Input, Io, Level, Output}, + gpio::{Input, Io, Level, Output}, i2c::I2C, interrupt::software::SoftwareInterruptControl, peripherals, diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 1837d587..db87c370 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -12,7 +12,7 @@ use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, - gpio::{GpioPin, Input, Io, Level, Output, Pull}, + gpio::{Input, Io, Level, Output, Pull}, i2c::I2C, interrupt::software::SoftwareInterruptControl, peripherals, diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index 4fd9fc2f..579aa4b7 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -12,7 +12,7 @@ use embassy_time::Delay; use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, - gpio::{GpioPin, Input, Io, Output}, + gpio::{Input, Io, Output}, i2c::I2C, interrupt::software::SoftwareInterruptControl, peripherals, @@ -27,7 +27,7 @@ use esp_hal::{ }; pub type DisplaySpiInstance = peripherals::SPI2; -pub type DisplayDmaChannel = ChannelCreator0; +pub type DisplayDmaChannel = ChannelCreator<0>; pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< @@ -36,7 +36,7 @@ pub type DisplaySpi<'d> = ExclusiveDevice< Delay, >; -pub type AdcDmaChannel = ChannelCreator1; +pub type AdcDmaChannel = ChannelCreator<1>; pub type AdcSpiInstance = peripherals::SPI3; pub type AdcSpi = ExclusiveDevice< diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index 90f6f51a..1c963c5e 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -101,7 +101,7 @@ impl WifiDriverState { let token = match this { Self::Uninitialized(resources) => { info!("Initializing Wifi driver"); - let token = unwrap!(esp_wifi::initialize( + let token = unwrap!(esp_wifi::init( EspWifiInitFor::Wifi, resources.timer, resources.rng, From ed31194db2990ce872307d29bb74abb26c3cdcf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 8 Oct 2024 18:39:50 +0200 Subject: [PATCH 28/29] Update to newest esp-hal --- Cargo.toml | 14 ++++++++------ src/board/hardware/v4.rs | 4 ++-- src/board/hardware/v6c6.rs | 2 +- src/board/hardware/v6s3.rs | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 78e7ba7e..a37f9520 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,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 = "038d07f" } -esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } -esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } -esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } -esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } -esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "038d07f" } +esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } [features] default = ["defmt"] @@ -157,6 +157,7 @@ esp32s3 = [ "esp-println/esp32s3", "jtag-serial", "esp-wifi/esp32s3", + "esp-hal-embassy/esp32s3", ] esp32c6 = [ "esp-hal/esp32c6", @@ -166,6 +167,7 @@ esp32c6 = [ "esp-println/esp32c6", "jtag-serial", "esp-wifi/esp32c6", + "esp-hal-embassy/esp32c6", ] # Signal processing diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 976b1207..3010c6b1 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -32,7 +32,7 @@ pub type DisplayDmaChannel = ChannelCreator<0>; pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, + SpiDmaBus<'d, DisplaySpiInstance, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -41,7 +41,7 @@ pub type AdcDmaChannel = ChannelCreator<1>; pub type AdcSpiInstance = peripherals::SPI3; pub type AdcSpi = ExclusiveDevice< - SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, + SpiDmaBus<'static, AdcSpiInstance, FullDuplexMode, Async>, Output<'static>, Delay, >; diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index db87c370..271459f6 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -34,7 +34,7 @@ pub type DisplayDmaChannel = ChannelCreator<0>; pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, + SpiDmaBus<'d, DisplaySpiInstance, FullDuplexMode, Async>, DummyOutputPin, Delay, >; diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index 579aa4b7..d69a6f5c 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -31,7 +31,7 @@ pub type DisplayDmaChannel = ChannelCreator<0>; pub type DisplayInterface<'a> = SPIInterface, Output<'static>>; pub type DisplaySpi<'d> = ExclusiveDevice< - SpiDmaBus<'d, DisplaySpiInstance, DmaChannel0, FullDuplexMode, Async>, + SpiDmaBus<'d, DisplaySpiInstance, FullDuplexMode, Async>, DummyOutputPin, Delay, >; @@ -40,7 +40,7 @@ pub type AdcDmaChannel = ChannelCreator<1>; pub type AdcSpiInstance = peripherals::SPI3; pub type AdcSpi = ExclusiveDevice< - SpiDmaBus<'static, AdcSpiInstance, DmaChannel1, FullDuplexMode, Async>, + SpiDmaBus<'static, AdcSpiInstance, FullDuplexMode, Async>, Output<'static>, Delay, >; From 08369ef66869cdedef8564d2d071970752c1556f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Thu, 10 Oct 2024 18:02:42 +0200 Subject: [PATCH 29/29] Update to new esp-hal release --- Cargo.toml | 30 +++++++++++++++--------------- src/board/hardware/v4.rs | 4 ++-- src/board/hardware/v6c6.rs | 7 ++++--- src/board/hardware/v6s3.rs | 4 ++-- src/board/startup.rs | 7 ++++--- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a37f9520..619a7ac7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ license = "MIT" embedded-graphics = "0.8.0" embedded-hal = "1.0.0" embedded-hal-async = "1.0.0" -embedded-hal-bus = { version = "0.1.0", features = ["async"] } +embedded-hal-bus = { version = "0.2.0", features = ["async"] } embedded-nal-async = "0.7.0" embedded-io = "0.6" embedded-io-async = "0.6" @@ -21,7 +21,7 @@ embassy-net = { version = "0.4", features = [ "dns", "medium-ethernet", ] } -embassy-sync = { version = "0.5.0" } +embassy-sync = { version = "0.6.0" } embassy-executor = { version = "0.6" } heapless = "0.8" @@ -51,17 +51,17 @@ embassy-time = { version = "0.3.0" } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } -esp-hal = { version = "0.20.1" } -esp-hal-embassy = { version = "0.3.0" } -esp-backtrace = { version = "0.14.0", features = [ +esp-hal = { version = "0.21.0" } +esp-hal-embassy = { version = "0.4.0" } +esp-backtrace = { version = "0.14.2", features = [ "panic-handler", "exception-handler", ] } -esp-println = { version = "0.11.0", default-features = false, features = [ +esp-println = { version = "0.12.0", default-features = false, features = [ "critical-section", ] } -esp-alloc = "0.4.0" -esp-wifi = { version = "0.9.1", default-features = false, features = [ +esp-alloc = "0.5.0" +esp-wifi = { version = "0.10.1", default-features = false, features = [ "esp-alloc", "phy-enable-usb", "ps-max-modem", @@ -131,13 +131,13 @@ smoltcp = { workspace = true } crc = "3.0.1" enumset = "1.1.3" -[patch.crates-io] -esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } -esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } -esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } -esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } -esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } -esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +#[patch.crates-io] +#esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +#esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +#esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +#esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +#esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } +#esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" } [features] default = ["defmt"] diff --git a/src/board/hardware/v4.rs b/src/board/hardware/v4.rs index 3010c6b1..f5701809 100644 --- a/src/board/hardware/v4.rs +++ b/src/board/hardware/v4.rs @@ -12,7 +12,7 @@ use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, gpio::{Input, Io, Level, Output}, - i2c::I2C, + i2c::I2c, interrupt::software::SoftwareInterruptControl, peripherals, rtc_cntl::Rtc, @@ -58,7 +58,7 @@ pub type PoweredEcgFrontend = pub type Display = DisplayType>; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; +pub type BatteryFgI2c = I2c<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { diff --git a/src/board/hardware/v6c6.rs b/src/board/hardware/v6c6.rs index 271459f6..22f22d8d 100644 --- a/src/board/hardware/v6c6.rs +++ b/src/board/hardware/v6c6.rs @@ -13,7 +13,7 @@ use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, gpio::{Input, Io, Level, Output, Pull}, - i2c::I2C, + i2c::I2c, interrupt::software::SoftwareInterruptControl, peripherals, prelude::*, @@ -57,7 +57,7 @@ pub type PoweredEcgFrontend = pub type Display = DisplayType>; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; +pub type BatteryFgI2c = I2c<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { @@ -91,7 +91,8 @@ impl super::startup::StartupResources { ), Output::new(io.pins.gpio9, Level::High), Delay, - ), + ) + .unwrap(), io.pins.gpio4, io.pins.gpio15, io.pins.gpio23, diff --git a/src/board/hardware/v6s3.rs b/src/board/hardware/v6s3.rs index d69a6f5c..e97380c8 100644 --- a/src/board/hardware/v6s3.rs +++ b/src/board/hardware/v6s3.rs @@ -13,7 +13,7 @@ use embedded_hal_bus::spi::ExclusiveDevice; use esp_hal::{ dma::*, gpio::{Input, Io, Output}, - i2c::I2C, + i2c::I2c, interrupt::software::SoftwareInterruptControl, peripherals, rtc_cntl::Rtc, @@ -57,7 +57,7 @@ pub type PoweredEcgFrontend = pub type Display = DisplayType>; pub type BatteryFgI2cInstance = peripherals::I2C0; -pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>; +pub type BatteryFgI2c = I2c<'static, BatteryFgI2cInstance, Async>; pub type BatteryFg = BatteryFgType; impl super::startup::StartupResources { diff --git a/src/board/startup.rs b/src/board/startup.rs index a1ec02e1..08545094 100644 --- a/src/board/startup.rs +++ b/src/board/startup.rs @@ -26,7 +26,7 @@ use esp_hal::{ use crate::board::{AdcDmaChannel, AdcSpiInstance}; #[cfg(feature = "battery_max17055")] -use esp_hal::i2c::I2C; +use esp_hal::i2c::I2c; #[cfg(feature = "battery_max17055")] use { crate::board::{BatteryAdcEnablePin, BatteryFg, BatteryFgI2cInstance}, @@ -115,7 +115,7 @@ impl StartupResources { Display::new( SPIInterface::new( - ExclusiveDevice::new(display_spi, DummyOutputPin, Delay), + ExclusiveDevice::new(display_spi, DummyOutputPin, Delay).unwrap(), Output::new(display_dc, Level::Low), ), Output::new(display_reset, Level::Low), @@ -147,6 +147,7 @@ impl StartupResources { Output::new(adc_cs, Level::High), Delay, ) + .unwrap() } #[inline(always)] @@ -203,7 +204,7 @@ impl StartupResources { Input::new(vbus_detect, Pull::None), Input::new(charger_status, Pull::Up), BatteryFg::new( - Max17055::new(I2C::new_async(i2c, sda, scl, 100u32.kHz()), design), + Max17055::new(I2c::new_async(i2c, sda, scl, 100u32.kHz()), design), fg_enable, ), )