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

73 lines
2.3 KiB
Plaintext

# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
menuconfig POWER_SWITCH
bool "Power switch drivers"
default y if DT_HAS_LIBRESOLAR_GPIO_POWER_SWITCH_ENABLED
default y if DT_HAS_LIBRESOLAR_STM32_LPTIM_POWER_SWITCH_ENABLED
default y if DT_HAS_LIBRESOLAR_STM32_PWM_POWER_SWITCH_ENABLED
default y if DT_HAS_LIBRESOLAR_POWER_SWITCH_EMUL_ENABLED
help
Enable drivers for power switches, e.g. used for load or USB outputs.
if POWER_SWITCH
config POWER_SWITCH_INIT_PRIORITY
int "Power switch init priority"
default 70
help
Power switch driver device initialization priority. Must be lower than the priority
of the GPIO and PWM drivers.
module = POWER_SWITCH
module-str = power_switch
source "subsys/logging/Kconfig.template.log_config"
config POWER_SWITCH_GPIO
bool "GPIO power switch driver"
default y
depends on DT_HAS_LIBRESOLAR_GPIO_POWER_SWITCH_ENABLED
select GPIO
help
Enable driver for power switches driven by a GPIO.
DT_COMPAT_LIBRESOLAR_GPIO_POWER_SWITCH := libresolar,gpio-power-switch
config POWER_SWITCH_GPIO_CHARGE_PUMP
bool
default y
depends on POWER_SWITCH_GPIO
depends on $(dt_compat_any_has_prop,$(DT_COMPAT_LIBRESOLAR_GPIO_POWER_SWITCH),charge-pump-pwms)
select PWM
help
Support for charge pump PWM signals of GPIO power switches.
config POWER_SWITCH_STM32_LPTIM
bool "STM32 LPTIM power switch driver with short-circuit protection"
default y
depends on DT_HAS_LIBRESOLAR_STM32_LPTIM_POWER_SWITCH_ENABLED
depends on SOC_SERIES_STM32L0X
select GPIO
select PINCTRL
help
Enable power switch driver using LPTIM1 and COMP2 of STM32L0 for hardware short-circuit
protection.
config POWER_SWITCH_STM32_PWM
bool "STM32 timer PWM power switch driver"
default y
depends on DT_HAS_LIBRESOLAR_STM32_PWM_POWER_SWITCH_ENABLED
select LIBRESOLAR_STM32_TIM
help
Enable power switch driver using a PWM signal of an STM32 timer, e.g. for PWM solar
charge controllers.
config POWER_SWITCH_EMUL
bool "Emulated power switch driver"
default y
depends on DT_HAS_LIBRESOLAR_POWER_SWITCH_EMUL_ENABLED
help
Enable emulated power switch driver for tests on native_sim.
endif # POWER_SWITCH