This commit is contained in:
2025-09-28 13:42:30 +02:00
parent f0bda32d7a
commit 7ebc147f51
12 changed files with 590 additions and 536 deletions

View File

@@ -3,6 +3,7 @@ pub mod esp;
mod initial_hal;
mod little_fs2storage_adapter;
pub(crate) mod rtc;
mod v3_hal;
mod v4_hal;
mod v4_sensor;
mod water;
@@ -79,11 +80,11 @@ use esp_hal::clock::CpuClock;
use esp_hal::gpio::{Input, InputConfig, Pull};
use measurements::{Current, Voltage};
use crate::fat_error::{FatError, FatResult};
use crate::hal::battery::{print_battery_bq34z100, BQ34Z100G1};
use crate::hal::little_fs2storage_adapter::LittleFs2Filesystem;
use crate::hal::water::TankSensor;
use crate::log::LOG_ACCESS;
use crate::fat_error::FatError;
use embassy_sync::mutex::Mutex;
use embassy_sync::once_lock::OnceLock;
use esp_alloc as _;
@@ -134,7 +135,7 @@ pub trait BoardInteraction<'a> {
fn get_config(&mut self) -> &PlantControllerConfig;
fn get_battery_monitor(&mut self) -> &mut Box<dyn BatteryInteraction + Send>;
fn get_rtc_module(&mut self) -> &mut Box<dyn RTCModuleInteraction + Send>;
fn set_charge_indicator(&mut self, charging: bool) -> Result<(), FatError>;
async fn set_charge_indicator(&mut self, charging: bool) -> Result<(), FatError>;
async fn deep_sleep(&mut self, duration_in_ms: u64) -> !;
fn is_day(&self) -> bool;
@@ -230,9 +231,11 @@ impl PlantHal {
esp_alloc::heap_allocator!(#[link_section = ".dram2_uninit"] size: 64000);
let rtc: Rtc = Rtc::new(peripherals.LPWR);
TIME_ACCESS.init(Mutex::new(rtc)).map_err(|_| FatError::String {
error: "Init error rct".to_string(),
})?;
TIME_ACCESS
.init(Mutex::new(rtc))
.map_err(|_| FatError::String {
error: "Init error rct".to_string(),
})?;
let systimer = SystemTimer::new(peripherals.SYSTIMER);
@@ -387,8 +390,8 @@ impl PlantHal {
fs,
rng,
controller: Arc::new(Mutex::new(controller)),
interface_sta : Some(sta),
interface_ap : Some(ap),
interface_sta: Some(sta),
interface_ap: Some(ap),
boot_button,
wake_gpio1,
mqtt_client: None,
@@ -424,7 +427,6 @@ impl PlantHal {
//TODO still required? or via button ignore? to_config_mode = true;
to_config_mode = true;
"core usb uart"
}
SocResetReason::CoreUsbJtag => "core usb jtag",
SocResetReason::Cpu0JtagCpu => "cpu0 jtag cpu",
@@ -539,9 +541,9 @@ impl PlantHal {
BoardVersion::INITIAL => {
initial_hal::create_initial_board(free_pins, config, esp)?
}
// BoardVersion::V3 => {
// v3_hal::create_v3(free_pins, esp, config, battery_interaction, rtc_module)?
// }
BoardVersion::V3 => {
v3_hal::create_v3(free_pins, esp, config, battery_interaction, rtc_module)?
}
BoardVersion::V4 => {
v4_hal::create_v4(free_pins, esp, config, battery_interaction, rtc_module)
.await?
@@ -584,9 +586,9 @@ pub async fn esp_time() -> DateTime<Utc> {
DateTime::from_timestamp_micros(guard.current_time_us() as i64).unwrap()
}
pub async fn esp_set_time(time: DateTime<FixedOffset>) {
pub async fn esp_set_time(time: DateTime<FixedOffset>) -> FatResult<()> {
{
let mut guard = TIME_ACCESS.get().await.lock().await;
let guard = TIME_ACCESS.get().await.lock().await;
guard.set_current_time_us(time.timestamp_micros() as u64);
}
BOARD_ACCESS
@@ -597,5 +599,5 @@ pub async fn esp_set_time(time: DateTime<FixedOffset>) {
.board_hal
.get_rtc_module()
.set_rtc_time(&time.to_utc())
.await;
.await
}