Extend the power switch API for switches driven by a PWM signal, as used
in PWM solar charge controllers:
- Set and get the duty cycle
- Check if the switch is currently conducting (momentary PWM state)
- Generic event callback replacing the fault callback, which also
reports the rising edges of the PWM signal
New backends:
- libresolar,stm32-pwm-power-switch: PWM signal generated by a channel
of an STM32 timer. The output is driven inactive while switched off
instead of disabling the channel, which left the pin floating.
- libresolar,power-switch-emul: Emulated switch for tests on native_sim
supporting all features of the API. Power-good failures and events
can be injected by the test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a driver class for power switches, e.g. used for load and USB
outputs. Besides switching on and off, drivers may provide a power-good
feedback and report faults that were already handled in hardware.
Two backends are available:
- libresolar,gpio-power-switch: Switch driven by a GPIO with optional
latching power-good feedback and charge pump PWM for high-side gate
drivers. The latch time is handled by delayable work instead of
blocking the caller.
- libresolar,stm32-lptim-power-switch: Switch driven by LPTIM1 of
STM32L0, which is triggered by COMP2 to switch off within a few
microseconds in case of a short circuit (PWM 2420 LUS).
The GPIO backend is tested on native_sim using the GPIO emulator and the
fake PWM driver.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>