Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
relay.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Siemens AG
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DRIVERS_RELAY_RELAY_H_
8#define ZEPHYR_INCLUDE_DRIVERS_RELAY_RELAY_H_
9
14
27
28#include <errno.h>
29#include <stdbool.h>
30
31#include <zephyr/device.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38typedef int (*relay_set_state_t)(const struct device *dev, bool on);
39
41typedef int (*relay_get_state_t)(const struct device *dev, bool *on);
42
50
59__syscall int relay_set_state(const struct device *dev, bool on);
60
61static inline int z_impl_relay_set_state(const struct device *dev, bool on)
62{
63 const struct relay_driver_api *api = DEVICE_API_GET(relay, dev);
64
65 return api->set_state(dev, on);
66}
67
77__syscall int relay_get_state(const struct device *dev, bool *on);
78
79static inline int z_impl_relay_get_state(const struct device *dev, bool *on)
80{
81 const struct relay_driver_api *api = DEVICE_API_GET(relay, dev);
82
83 if (api->get_state == NULL) {
84 return -ENOSYS;
85 }
86
87 return api->get_state(dev, on);
88}
89
90#ifdef __cplusplus
91}
92#endif
93
95
96#include <zephyr/syscalls/relay.h>
97
98#endif /* ZEPHYR_INCLUDE_DRIVERS_RELAY_RELAY_H_ */
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1505
System error numbers.
int relay_set_state(const struct device *dev, bool on)
Set the on/off state of the relay.
int(* relay_get_state_t)(const struct device *dev, bool *on)
Read back the on/off state of the relay.
Definition relay.h:41
int(* relay_set_state_t)(const struct device *dev, bool on)
Set the on/off state of the relay.
Definition relay.h:38
int relay_get_state(const struct device *dev, bool *on)
Read back the last requested on/off state of the relay.
#define ENOSYS
Function not implemented.
Definition errno.h:83
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
Relay driver class API.
Definition relay.h:44
relay_set_state_t set_state
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition relay.h:46
relay_get_state_t get_state
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition relay.h:48