Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
comparator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_
8#define ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_
9
19#include <zephyr/device.h>
20#include <errno.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
37
39typedef void (*comparator_callback_t)(const struct device *dev, void *user_data);
40
43typedef int (*comparator_api_get_output)(const struct device *dev);
44typedef int (*comparator_api_set_trigger)(const struct device *dev,
45 enum comparator_trigger trigger);
46typedef int (*comparator_api_set_trigger_callback)(const struct device *dev,
47 comparator_callback_t callback,
48 void *user_data);
49typedef int (*comparator_api_trigger_is_pending)(const struct device *dev);
50
51__subsystem struct comparator_driver_api {
52 comparator_api_get_output get_output;
53 comparator_api_set_trigger set_trigger;
54 comparator_api_set_trigger_callback set_trigger_callback;
55 comparator_api_trigger_is_pending trigger_is_pending;
56};
57
69__syscall int comparator_get_output(const struct device *dev);
70
71static inline int z_impl_comparator_get_output(const struct device *dev)
72{
73 return DEVICE_API_GET(comparator, dev)->get_output(dev);
74}
75
85__syscall int comparator_set_trigger(const struct device *dev,
86 enum comparator_trigger trigger);
87
88static inline int z_impl_comparator_set_trigger(const struct device *dev,
89 enum comparator_trigger trigger)
90{
91 return DEVICE_API_GET(comparator, dev)->set_trigger(dev, trigger);
92}
93
107static inline int comparator_set_trigger_callback(const struct device *dev,
108 comparator_callback_t callback,
109 void *user_data)
110{
111 return DEVICE_API_GET(comparator, dev)->set_trigger_callback(dev, callback, user_data);
112}
113
123__syscall int comparator_trigger_is_pending(const struct device *dev);
124
125static inline int z_impl_comparator_trigger_is_pending(const struct device *dev)
126{
127 return DEVICE_API_GET(comparator, dev)->trigger_is_pending(dev);
128}
129
130#ifdef __cplusplus
131}
132#endif
133
136#include <zephyr/syscalls/comparator.h>
137
138#endif /* ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1221
System error numbers.
static int comparator_set_trigger_callback(const struct device *dev, comparator_callback_t callback, void *user_data)
Set comparator's trigger callback.
Definition comparator.h:107
int comparator_trigger_is_pending(const struct device *dev)
Check if comparator's trigger is pending and clear it.
void(* comparator_callback_t)(const struct device *dev, void *user_data)
Comparator callback template.
Definition comparator.h:39
int comparator_get_output(const struct device *dev)
Get comparator's output state.
int comparator_set_trigger(const struct device *dev, enum comparator_trigger trigger)
Set comparator's trigger.
comparator_trigger
Comparator trigger enumerations.
Definition comparator.h:27
@ COMPARATOR_TRIGGER_RISING_EDGE
Trigger on rising edge of comparator output.
Definition comparator.h:31
@ COMPARATOR_TRIGGER_BOTH_EDGES
Trigger on both edges of comparator output.
Definition comparator.h:35
@ COMPARATOR_TRIGGER_FALLING_EDGE
Trigger on falling edge of comparator output.
Definition comparator.h:33
@ COMPARATOR_TRIGGER_NONE
No trigger.
Definition comparator.h:29
Runtime device structure (in ROM) per driver instance.
Definition device.h:411