minimal startup running

This commit is contained in:
2025-09-14 13:19:30 +02:00
parent b3cc313139
commit 4aa25c687b
7 changed files with 146 additions and 119 deletions

View File

@@ -175,7 +175,7 @@ impl Esp<'_> {
}
}
pub(crate) async fn wifi_ap(&mut self) -> anyhow::Result<Stack> {
pub(crate) async fn wifi_ap(&mut self) -> anyhow::Result<Stack<'static>> {
let _ssid = match self.load_config() {
Ok(config) => config.network.ap_ssid.clone(),
Err(_) => heapless::String::from_str("PlantCtrl Emergency Mode").unwrap(),
@@ -207,7 +207,7 @@ impl Esp<'_> {
let controller = self.controller.take().unwrap();
spawner.spawn(connection(controller)).ok();
spawner.spawn(net_task(runner)).ok();
spawner.spawn(run_dhcp(stack, gw_ip_addr_str)).ok();
spawner.spawn(run_dhcp(stack.clone(), gw_ip_addr_str)).ok();
loop {
if stack.is_link_up() {
@@ -699,7 +699,7 @@ impl Esp<'_> {
}
#[embassy_executor::task]
async fn run_dhcp(stack: &'static Stack<'static>, gw_ip_addr: &'static str) {
async fn run_dhcp(stack: Stack<'static>, gw_ip_addr: &'static str) {
use core::net::{Ipv4Addr, SocketAddrV4};
use edge_dhcp::{
@@ -716,7 +716,7 @@ async fn run_dhcp(stack: &'static Stack<'static>, gw_ip_addr: &'static str) {
let mut gw_buf = [Ipv4Addr::UNSPECIFIED];
let buffers = UdpBuffers::<3, 1024, 1024, 10>::new();
let unbound_socket = Udp::new(*stack, &buffers);
let unbound_socket = Udp::new(stack, &buffers);
let mut bound_socket = unbound_socket
.bind(core::net::SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::UNSPECIFIED,

View File

@@ -11,10 +11,12 @@ use crate::{
use anyhow::{bail, Result};
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use esp_hal::gpio::{Level, Output, OutputConfig};
use log::info;
use measurements::{Current, Voltage};
pub struct Initial<'a> {
//pub(crate) general_fault: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>,
pub(crate) general_fault: Output<'a>,
pub(crate) esp: Esp<'a>,
pub(crate) config: PlantControllerConfig,
pub(crate) battery: Box<dyn BatteryInteraction + Send>,
@@ -47,21 +49,14 @@ impl RTCModuleInteraction for NoRTC {
}
pub(crate) fn create_initial_board(
//free_pins: FreePeripherals,
_fs_mount_error: bool,
free_pins: FreePeripherals<'static>,
config: PlantControllerConfig,
esp: Esp<'static>,
) -> Result<Box<dyn BoardInteraction<'static> + Send>> {
log::info!("Start initial");
// let mut general_fault = PinDriver::input_output(free_pins.gpio6.downgrade())?;
// general_fault.set_pull(Pull::Floating)?;
// general_fault.set_low()?;
//
// if fs_mount_error {
// general_fault.set_high()?
// }
let general_fault = Output::new(free_pins.gpio23, Level::Low, OutputConfig::default());
let v = Initial {
//general_fault,
general_fault,
config,
esp,
battery: Box::new(NoBatteryMonitor {}),
@@ -122,8 +117,8 @@ impl<'a> BoardInteraction<'a> for Initial<'a> {
bail!("Please configure board revision")
}
async fn general_fault(&mut self, _enable: bool) {
//let _ = self.general_fault.set_state(enable.into());
async fn general_fault(&mut self, enable: bool) {
self.general_fault.set_level(enable.into());
}
async fn test(&mut self) -> Result<()> {

View File

@@ -6,6 +6,10 @@ mod rtc;
use crate::alloc::string::ToString;
use crate::hal::rtc::RTCModuleInteraction;
use esp_hal::peripherals::Peripherals;
use esp_hal::peripherals::GPIO23;
use esp_hal::peripherals::GPIO6;
//use crate::hal::water::TankSensor;
use crate::{
config::{BatteryBoardVersion, BoardVersion, PlantControllerConfig},
@@ -33,7 +37,7 @@ use embassy_sync::once_lock::OnceLock;
use embassy_time::{Duration, Timer};
use esp_bootloader_esp_idf::partitions::DataPartitionSubType;
use esp_hal::clock::CpuClock;
use esp_hal::gpio::{Input, InputConfig, Pull};
use esp_hal::gpio::{Input, InputConfig, Io, Pull};
use esp_hal::timer::systimer::SystemTimer;
use esp_println::{print, println};
use measurements::{Current, Voltage};
@@ -41,6 +45,7 @@ use measurements::{Current, Voltage};
use embassy_sync::mutex::{Mutex, MutexGuard};
use esp_alloc as _;
use esp_backtrace as _;
use esp_hal::analog::adc::Adc;
use esp_hal::rng::Rng;
use esp_hal::timer::timg::TimerGroup;
use esp_wifi::wifi::{
@@ -125,14 +130,14 @@ impl dyn BoardInteraction<'_> {
}
#[allow(dead_code)]
pub struct FreePeripherals {
pub struct FreePeripherals<'a> {
// pub gpio0: Gpio0,
// pub gpio1: Gpio1,
// pub gpio2: Gpio2,
// pub gpio3: Gpio3,
// pub gpio4: Gpio4,
// pub gpio5: Gpio5,
// pub gpio6: Gpio6,
pub gpio6: GPIO6<'a>,
// pub gpio7: Gpio7,
// pub gpio8: Gpio8,
// //config button here
@@ -148,7 +153,7 @@ pub struct FreePeripherals {
// //i2c here
// pub gpio21: Gpio21,
// pub gpio22: Gpio22,
// pub gpio23: Gpio23,
pub gpio23: GPIO23<'a>,
// pub gpio24: Gpio24,
// pub gpio25: Gpio25,
// pub gpio26: Gpio26,
@@ -192,7 +197,7 @@ impl PlantHal {
pub async fn create(spawner: Spawner) -> Result<Mutex<CriticalSectionRawMutex, HAL<'static>>> {
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
let peripherals: Peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 64 * 1024);
let systimer = SystemTimer::new(peripherals.SYSTIMER);
@@ -215,41 +220,42 @@ impl PlantHal {
use esp_hal::timer::systimer::SystemTimer;
esp_hal_embassy::init(systimer.alarm0);
//let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
//
// let free_pins = FreePeripherals {
// can: peripherals.can,
// adc1: peripherals.adc1,
// pcnt0: peripherals.pcnt0,
// pcnt1: peripherals.pcnt1,
// gpio0: peripherals.pins.gpio0,
// gpio1: peripherals.pins.gpio1,
// gpio2: peripherals.pins.gpio2,
// gpio3: peripherals.pins.gpio3,
// gpio4: peripherals.pins.gpio4,
// gpio5: peripherals.pins.gpio5,
// gpio6: peripherals.pins.gpio6,
// gpio7: peripherals.pins.gpio7,
// gpio8: peripherals.pins.gpio8,
// gpio10: peripherals.pins.gpio10,
// gpio11: peripherals.pins.gpio11,
// gpio12: peripherals.pins.gpio12,
// gpio13: peripherals.pins.gpio13,
// gpio14: peripherals.pins.gpio14,
// gpio15: peripherals.pins.gpio15,
// gpio16: peripherals.pins.gpio16,
// gpio17: peripherals.pins.gpio17,
// gpio18: peripherals.pins.gpio18,
// gpio21: peripherals.pins.gpio21,
// gpio22: peripherals.pins.gpio22,
// gpio23: peripherals.pins.gpio23,
// gpio24: peripherals.pins.gpio24,
// gpio25: peripherals.pins.gpio25,
// gpio26: peripherals.pins.gpio26,
// gpio27: peripherals.pins.gpio27,
// gpio28: peripherals.pins.gpio28,
// gpio29: peripherals.pins.gpio29,
// gpio30: peripherals.pins.gpio30,
// };
let free_pins = FreePeripherals {
// can: peripherals.can,
// adc1: peripherals.adc1,
// pcnt0: peripherals.pcnt0,
// pcnt1: peripherals.pcnt1,
// gpio0: peripherals.pins.gpio0,
// gpio1: peripherals.pins.gpio1,
// gpio2: peripherals.pins.gpio2,
// gpio3: peripherals.pins.gpio3,
// gpio4: peripherals.pins.gpio4,
// gpio5: peripherals.pins.gpio5,
gpio6: peripherals.GPIO6,
// gpio7: peripherals.pins.gpio7,
// gpio8: peripherals.pins.gpio8,
// gpio10: peripherals.pins.gpio10,
// gpio11: peripherals.pins.gpio11,
// gpio12: peripherals.pins.gpio12,
// gpio13: peripherals.pins.gpio13,
// gpio14: peripherals.pins.gpio14,
// gpio15: peripherals.pins.gpio15,
// gpio16: peripherals.pins.gpio16,
// gpio17: peripherals.pins.gpio17,
// gpio18: peripherals.pins.gpio18,
// gpio21: peripherals.pins.gpio21,
// gpio22: peripherals.pins.gpio22,
gpio23: peripherals.GPIO23,
// gpio24: peripherals.pins.gpio24,
// gpio25: peripherals.pins.gpio25,
// gpio26: peripherals.pins.gpio26,
// gpio27: peripherals.pins.gpio27,
// gpio28: peripherals.pins.gpio28,
// gpio29: peripherals.pins.gpio29,
// gpio30: peripherals.pins.gpio30,
};
//
let mut storage = esp_storage::FlashStorage::new();
@@ -392,7 +398,7 @@ impl PlantHal {
let board_hal: Box<dyn BoardInteraction + Send> = match config.hardware.board {
BoardVersion::INITIAL => {
initial_hal::create_initial_board(fs_mount_error, config, esp)?
initial_hal::create_initial_board(free_pins, config, esp)?
}
// BoardVersion::V3 => {
// v3_hal::create_v3(free_pins, esp, config, battery_interaction, rtc_module)?
@@ -417,7 +423,7 @@ impl PlantHal {
);
HAL {
board_hal: initial_hal::create_initial_board(
fs_mount_error,
free_pins,
PlantControllerConfig::default(),
esp,
)?,