Relay
The relay subsystem exposes a hardware-agnostic on/off view of a single relay, regardless of whether the underlying part is switched by a GPIO line or driven through a PWM channel. A backend driver implements the API and hides all coil-drive details behind it.
Basic Operation
Applications obtain a relay device through devicetree and drive it through the functions in include/zephyr/drivers/relay/relay.h:
relay_set_state()energizes (true) or releases (false) the coil.relay_get_state()reads back the last requested state.
Backends
Two devicetree-discoverable backends are provided:
zephyr,gpio-relayfor a relay switched by a single GPIO. The coil’s active level comes from the flags in thegpiosspecifier.zephyr,pwm-relayfor a relay driven from a PWM channel. The driver owns an optional pull-in/hold current profile: it can drive a stronger pull-in pulse forpull-in-time-msbefore dropping tohold-duty-percentto reduce holding current, and periodically re-pulse the coil everyrefresh-interval-ms. Each stage is opt-in and skipped when set to 0.
Shell
When CONFIG_RELAY_SHELL is enabled, the relay shell
command turns relays on and off, reads back their state, and lists the relay
devices in the system.