use rom linked functions for pin keeping
This commit is contained in:
@@ -62,7 +62,8 @@ pub struct NoBatteryMonitor {}
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl BatteryInteraction for NoBatteryMonitor {
|
impl BatteryInteraction for NoBatteryMonitor {
|
||||||
async fn state_charge_percent(&mut self) -> FatResult<f32> {
|
async fn state_charge_percent(&mut self) -> FatResult<f32> {
|
||||||
Err(FatError::NoBatteryMonitor)
|
// No monitor configured: assume full battery for lightstate logic
|
||||||
|
Ok(100.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn remaining_milli_ampere_hour(&mut self) -> FatResult<u16> {
|
async fn remaining_milli_ampere_hour(&mut self) -> FatResult<u16> {
|
||||||
|
@@ -336,7 +336,7 @@ impl Esp<'_> {
|
|||||||
}
|
}
|
||||||
pub(crate) fn clear_low_voltage_in_cycle(&mut self) {
|
pub(crate) fn clear_low_voltage_in_cycle(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
LOW_VOLTAGE_DETECTED = 1;
|
LOW_VOLTAGE_DETECTED = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,7 +547,8 @@ impl Esp<'_> {
|
|||||||
if duration_in_ms == 0 {
|
if duration_in_ms == 0 {
|
||||||
software_reset();
|
software_reset();
|
||||||
} else {
|
} else {
|
||||||
let timer = TimerWakeupSource::new(core::time::Duration::from_millis(duration_in_ms));
|
///let timer = TimerWakeupSource::new(core::time::Duration::from_millis(duration_in_ms));
|
||||||
|
let timer = TimerWakeupSource::new(core::time::Duration::from_millis(5000));
|
||||||
let mut wake_pins: [(&mut dyn RtcPinWithResistors, WakeupLevel); 1] = [(&mut self.wake_gpio1, WakeupLevel::Low)];
|
let mut wake_pins: [(&mut dyn RtcPinWithResistors, WakeupLevel); 1] = [(&mut self.wake_gpio1, WakeupLevel::Low)];
|
||||||
let ext1 = esp_hal::rtc_cntl::sleep::Ext1WakeupSource::new(&mut wake_pins);
|
let ext1 = esp_hal::rtc_cntl::sleep::Ext1WakeupSource::new(&mut wake_pins);
|
||||||
rtc.sleep_deep(&[&timer, &ext1]);
|
rtc.sleep_deep(&[&timer, &ext1]);
|
||||||
|
@@ -422,7 +422,9 @@ impl PlantHal {
|
|||||||
SocResetReason::CoreEfuseCrc => "core efuse crc",
|
SocResetReason::CoreEfuseCrc => "core efuse crc",
|
||||||
SocResetReason::CoreUsbUart => {
|
SocResetReason::CoreUsbUart => {
|
||||||
//TODO still required? or via button ignore? to_config_mode = true;
|
//TODO still required? or via button ignore? to_config_mode = true;
|
||||||
|
to_config_mode = true;
|
||||||
"core usb uart"
|
"core usb uart"
|
||||||
|
|
||||||
}
|
}
|
||||||
SocResetReason::CoreUsbJtag => "core usb jtag",
|
SocResetReason::CoreUsbJtag => "core usb jtag",
|
||||||
SocResetReason::Cpu0JtagCpu => "cpu0 jtag cpu",
|
SocResetReason::Cpu0JtagCpu => "cpu0 jtag cpu",
|
||||||
|
@@ -30,6 +30,22 @@ use measurements::{Current, Voltage};
|
|||||||
use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};
|
use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};
|
||||||
use crate::log::{LogMessage, LOG_ACCESS};
|
use crate::log::{LogMessage, LOG_ACCESS};
|
||||||
|
|
||||||
|
// Minimal esp-idf equivalent for gpio_hold on esp32c6 via ROM functions
|
||||||
|
extern "C" {
|
||||||
|
fn gpio_pad_hold(gpio_num: u32);
|
||||||
|
fn gpio_pad_unhold(gpio_num: u32);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn hold_enable(gpio_num: u8) {
|
||||||
|
unsafe { gpio_pad_hold(gpio_num as u32) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn hold_disable(gpio_num: u8) {
|
||||||
|
unsafe { gpio_pad_unhold(gpio_num as u32) }
|
||||||
|
}
|
||||||
|
|
||||||
const MPPT_CURRENT_SHUNT_OHMS: f64 = 0.05_f64;
|
const MPPT_CURRENT_SHUNT_OHMS: f64 = 0.05_f64;
|
||||||
const TWAI_BAUDRATE: twai::BaudRate = twai::BaudRate::B125K;
|
const TWAI_BAUDRATE: twai::BaudRate = twai::BaudRate::B125K;
|
||||||
|
|
||||||
@@ -356,10 +372,10 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn light(&mut self, enable: bool) -> Result<(), FatError> {
|
async fn light(&mut self, enable: bool) -> Result<(), FatError> {
|
||||||
// unsafe { gpio_hold_dis(self.light.pin()) };
|
hold_disable(10);
|
||||||
self.light.set_level(enable.into());
|
self.light.set_level(enable.into());
|
||||||
// unsafe { gpio_hold_en(self.light.pin()) };
|
hold_enable(10);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn pump(&mut self, plant: usize, enable: bool) -> FatResult<()> {
|
async fn pump(&mut self, plant: usize, enable: bool) -> FatResult<()> {
|
||||||
@@ -413,9 +429,9 @@ impl<'a> BoardInteraction<'a> for V4<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn general_fault(&mut self, enable: bool) {
|
async fn general_fault(&mut self, enable: bool) {
|
||||||
//FIXME unsafe { gpio_hold_dis(self.general_fault.pin()) };
|
hold_disable(23);
|
||||||
self.general_fault.set_level(enable.into());
|
self.general_fault.set_level(enable.into());
|
||||||
//FIXME unsafe { gpio_hold_en(self.general_fault.pin()) };
|
hold_enable(23);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn test(&mut self) -> Result<(), FatError> {
|
async fn test(&mut self) -> Result<(), FatError> {
|
||||||
|
@@ -500,12 +500,12 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or(BatteryState::Unknown);
|
.unwrap_or(BatteryState::Unknown);
|
||||||
|
|
||||||
|
|
||||||
info!("Battery state is {:?}", battery_state);
|
info!("Battery state is {:?}", battery_state);
|
||||||
let mut light_state = LightState {
|
let mut light_state = LightState {
|
||||||
enabled: board.board_hal.get_config().night_lamp.enabled,
|
enabled: board.board_hal.get_config().night_lamp.enabled,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
info!("Light state is {:?}", light_state);
|
|
||||||
if light_state.enabled {
|
if light_state.enabled {
|
||||||
light_state.is_day = is_day;
|
light_state.is_day = is_day;
|
||||||
light_state.out_of_work_hour = !in_time_range(
|
light_state.out_of_work_hour = !in_time_range(
|
||||||
@@ -527,6 +527,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
.into()
|
.into()
|
||||||
{
|
{
|
||||||
board.board_hal.get_esp().set_low_voltage_in_cycle();
|
board.board_hal.get_esp().set_low_voltage_in_cycle();
|
||||||
|
info!("Set low voltage in cycle");
|
||||||
} else if state_of_charge
|
} else if state_of_charge
|
||||||
> board
|
> board
|
||||||
.board_hal
|
.board_hal
|
||||||
@@ -536,6 +537,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
|
|||||||
.into()
|
.into()
|
||||||
{
|
{
|
||||||
board.board_hal.get_esp().clear_low_voltage_in_cycle();
|
board.board_hal.get_esp().clear_low_voltage_in_cycle();
|
||||||
|
info!("Clear low voltage in cycle");
|
||||||
}
|
}
|
||||||
light_state.battery_low = board.board_hal.get_esp().low_voltage_in_cycle();
|
light_state.battery_low = board.board_hal.get_esp().low_voltage_in_cycle();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user