Files
Martin JägerandClaude Opus 5.5 da59ab8276 drivers: power_switch: add PWM support
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>
2026-11-01 14:20:21 +01:00

47 lines
1.0 KiB
C

/*
* Copyright (c) The Libre Solar Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef LIBRESOLAR_DRIVERS_POWER_SWITCH_EMUL_H_
#define LIBRESOLAR_DRIVERS_POWER_SWITCH_EMUL_H_
/**
* @file
* @brief Backend API of the emulated power switch for tests
*/
#include <zephyr/device.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Set the power-good feedback reported while the switch is on
*
* @param dev Emulated power switch device
* @param power_good Power-good state
*/
void power_switch_emul_set_power_good(const struct device *dev, bool power_good);
/**
* Trigger events as if they were detected by the hardware
*
* A fault event switches off the output before the callback is called.
*
* @param dev Emulated power switch device
* @param events Bitmask of events according to enum power_switch_event
*/
void power_switch_emul_trigger_events(const struct device *dev, uint32_t events);
#ifdef __cplusplus
}
#endif
#endif /* LIBRESOLAR_DRIVERS_POWER_SWITCH_EMUL_H_ */