Zephyr API 3.6.99
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 const struct comparator_driver_api *api =
74 (const struct comparator_driver_api *)dev->api;
75
76 return api->get_output(dev);
77}
78
88__syscall int comparator_set_trigger(const struct device *dev,
89 enum comparator_trigger trigger);
90
91static inline int z_impl_comparator_set_trigger(const struct device *dev,
92 enum comparator_trigger trigger)
93{
94 const struct comparator_driver_api *api =
95 (const struct comparator_driver_api *)dev->api;
96
97 return api->set_trigger(dev, trigger);
98}
99
113static inline int comparator_set_trigger_callback(const struct device *dev,
114 comparator_callback_t callback,
115 void *user_data)
116{
117 const struct comparator_driver_api *api =
118 (const struct comparator_driver_api *)dev->api;
119
120 return api->set_trigger_callback(dev, callback, user_data);
121}
122
132__syscall int comparator_trigger_is_pending(const struct device *dev);
133
134static inline int z_impl_comparator_trigger_is_pending(const struct device *dev)
135{
136 const struct comparator_driver_api *api =
137 (const struct comparator_driver_api *)dev->api;
138
139 return api->trigger_is_pending(dev);
140}
141
142#ifdef __cplusplus
143}
144#endif
145
148#include <zephyr/syscalls/comparator.h>
149
150#endif /* ZEPHYR_INCLUDE_DRIVERS_COMPARATOR_H_ */
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:113
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:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409