Files
charge-controller-firmware/app/src/daq.h
T
Martin JägerandClaude Opus 5.5 55f1c86523 app: use DAQ driver
Replace the register-level ADC, DAC and DMA handling in daq_driver.c by
the new DAQ driver. The application only maps the measurements to the
power ports and DC buses and handles the alerts. The factory calibration
values are removed from mcu.h, as they are provided by the driver now.

All boards are migrated to the new libresolar,stm32-daq compatible. The
unit tests use the emulated DAQ.

The high-side overvoltage limit is now set after the DAQ setup. Before,
the limit was calculated before any reading of the internal reference
voltage was available, so that the alert never triggered on boards
without fixed reference voltage (STM32F0 and STM32L0).

Note for out-of-tree boards: The adc-inputs node must use the compatible
libresolar,stm32-daq instead of adc-inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 12:16:45 +01:00

78 lines
1.7 KiB
C

/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Data Acquisition (DAQ)
*
* Measurements are taken by the DAQ driver. This module converts them to the measurement values
* stored in the structs of the power ports and DC buses, which are afterwards used by the control
* algorithms.
*/
#ifndef DAQ_H_
#define DAQ_H_
#include <libresolar/drivers/daq.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#ifdef __cplusplus
extern "C" {
#endif
/** DAQ devicetree node */
#define DAQ_NODE DT_PATH(adc_inputs)
/** DAQ device */
#define DAQ_DEV DEVICE_DT_GET(DAQ_NODE)
/**
* Get the channel index of a DAQ input
*
* @param name Lower-case-and-underscores name of the child node of the DAQ node, e.g. v_low
*/
#define DAQ_CH(name) DAQ_CHANNEL(DAQ_NODE, name)
/**
* Set offset vs. actual measured value, i.e. sets zero current point.
*
* All input/output switches and consumers should be switched off before calling this function
*/
void calibrate_current_sensors(void);
/**
* Updates structures with data read from ADC
*/
void daq_update(void);
/**
* Waits for initial measurements and calibrates the current sensors
*/
void daq_setup(void);
/**
* Set lv side (battery) voltage limits where an alert should be triggered
*
* @param lv_overvoltage Upper voltage limit
* @param lv_undervoltage Lower voltage limit
*/
void daq_set_lv_limits(float lv_overvoltage, float lv_undervoltage);
/**
* Set hv side (grid/solar) voltage limit where an alert should be triggered
*
* @param hv_overvoltage Upper voltage limit
*/
void daq_set_hv_limit(float hv_overvoltage);
#ifdef __cplusplus
}
#endif
#endif /* DAQ_H_ */