use rom linked functions for pin keeping

This commit is contained in:
2025-09-26 23:32:41 +02:00
parent 76f59b093d
commit f0bda32d7a
5 changed files with 32 additions and 10 deletions

View File

@@ -30,6 +30,22 @@ use measurements::{Current, Voltage};
use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};
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 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> {
// unsafe { gpio_hold_dis(self.light.pin()) };
self.light.set_level(enable.into());
// unsafe { gpio_hold_en(self.light.pin()) };
Ok(())
hold_disable(10);
self.light.set_level(enable.into());
hold_enable(10);
Ok(())
}
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) {
//FIXME unsafe { gpio_hold_dis(self.general_fault.pin()) };
hold_disable(23);
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> {