Commit Graph
7 Commits
Author SHA1 Message Date
Martin JägerandClaude Opus 5.5 bef0ed576c app: convert DC/DC control to C
The Dcdc class becomes struct dcdc with prefixed functions. Private
member functions become static functions. dcdc_check_start_conditions()
and dcdc_control() are still weak, so they can be overridden by custom
implementations.

The constructor is replaced by dcdc_init(), which is called from a
SYS_INIT hook at application level in setup.cpp. This corresponds to the
time the global C++ objects were constructed before, so the unit tests
(which don't run main()) still get initialized objects. The remaining
objects will be moved to this hook when they are converted.

The global device status is declared in device_status.h instead of
setup.h, so that C modules don't need to include the C++ setup header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 15:33:37 +01:00
Martin JägerandClaude Opus 5.5 a428892916 app: convert device status to C struct
DeviceStatus becomes struct device_status with prefixed functions. The
error flag helpers are static inline functions in the header.

The implementation stays in C++ for now, as it reads data from objects
which are not converted yet. The header doesn't include the headers of
these objects anymore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 15:21:57 +01:00
Martin JägerandClaude Opus 5.5 3cc24411b5 app: convert power port to C
DcBus and PowerPort become struct dc_bus and struct power_port with
prefixed functions instead of member functions.

The default member initializers are replaced by dc_bus_init() and
power_port_init(). The only non-zero default value is the series
multiplier of the bus, which is set to 1 by dc_bus_init() and in the
static initializers of the global buses.

The optional voltage parameter of the control voltage functions has to
be passed explicitly now, 0 still selects the voltage intercept of the
bus.

LoadOutput and PwmSwitch still inherit from the C struct until they are
converted, and initialize it with power_port_init().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 15:12:51 +01:00
Martin JägerandClaude Opus 5.5 dc0356b41a app: use power switch driver for load and USB outputs
Replace the function pointers for the load and USB switches by power
switch devices. The register-level code for the short-circuit comparator
of the PWM 2420 LUS moved to the STM32 LPTIM power switch driver, which
reports short circuits via the fault callback. load_driver.c is removed.

The load and USB switches are now standalone devicetree nodes with the
labels load_switch and usb_switch instead of children of the outputs
node. The separate charge_pump node is replaced by the charge-pump-pwms
property of the load switch.

The comparator interrupt now only clears its own EXTI pending flag
instead of all pending flags.

Note for out-of-tree boards and overlays: The load and usb-pwr children
of the outputs node must be converted to nodes with the compatible
libresolar,gpio-power-switch and the labels load_switch and usb_switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 13:43:57 +01:00
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
Martin JägerandClaude Opus 5.5 a1fff4ee6f tests: app: migrate unit tests from Unity to ztest
Convert the application unit tests to ztest, so that all tests can be
run with twister and the Unity module is not required anymore.

Each test file becomes a ztest suite. The test names got the prefix
test_ as required by twister. Unity assertions were converted as
follows:

- TEST_ASSERT_EQUAL_FLOAT is replaced by assert_float_equal, which uses
  the same relative precision of 1e-5 as Unity.
- TEST_ASSERT_EQUAL and other integer assertions are replaced by their
  ztest equivalents. Unity compared these as integers, so float values
  were truncated before. All tests still pass with exact comparison.

In contrast to Unity, ztest runs the tests of a suite in alphabetical
order. The setup code for the DAQ tests is moved into a before function
and the half bridge is stopped before each buck converter test (same as
for the boost converter tests), as the buck tests previously relied on
running before the boost tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 13:40:14 +02:00
Martin JägerandClaude Opus 5.5 a3f888fd79 tests: move application unit tests to tests/app
Move the unit tests of the application next to the driver tests in
tests/drivers, so that the tests directory only contains test suites in
subdirectories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 13:22:26 +02:00