summaryrefslogtreecommitdiff
path: root/include/aio_comparator.h
blob: 753cc05f38c06c346e395e57ed04fdebfd0c9250 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (c) 2015 Intel Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _AIO_COMPARATOR_H_
#define _AIO_COMPARATOR_H_

#ifdef __cplusplus
extern "C" {
#endif

enum aio_cmp_ref {
	AIO_CMP_REF_A,		/**< Use reference A. */
	AIO_CMP_REF_B,		/**< Use reference B. */
};

enum aio_cmp_polarity {
	AIO_CMP_POL_RISE,	/**< Match on rising edge. */
	AIO_CMP_POL_FALL,	/**< Match on falling edge. */
};

typedef void (*aio_cmp_cb)(void *);

typedef int (*aio_cmp_api_disable)(struct device *dev, uint8_t index);

typedef int (*aio_cmp_api_configure)(struct device *dev, uint8_t index,
    enum aio_cmp_polarity polarity, enum aio_cmp_ref refsel,
    aio_cmp_cb cb, void *param);

struct aio_cmp_driver_api {
	aio_cmp_api_disable disable;
	aio_cmp_api_configure configure;
};

/**
 * @brief Disable a particular comparator.
 *
 * This disables a comparator so that it no longer triggers interrupts.
 *
 * @param dev Device struct
 * @param index The index of the comparator to disable
 *
 * @return 0 if successful, otherwise failed.
 */
static inline int aio_cmp_disable(struct device *dev, uint8_t index)
{
	const struct aio_cmp_driver_api *api = dev->driver_api;

	return api->disable(dev, index);
}

/**
 * @brief Configure and enable a particular comparator.
 *
 * This performs configuration and enable a comparator, so that it will
 * generate interrupts when conditions are met.
 *
 * @param dev Device struct
 * @param index The index of the comparator to disable
 * @param polarity Match polarity (e.g. rising or falling)
 * @param refsel Reference for trigger
 * @param cb Function callback (aio_cmp_cb)
 * @param param Parameters to be passed to callback
 *
 * @return 0 if successful, otherwise failed.
 */
static inline int aio_cmp_configure(struct device *dev, uint8_t index,
				    enum aio_cmp_polarity polarity,
				    enum aio_cmp_ref refsel,
				    aio_cmp_cb cb, void *param)
{
	const struct aio_cmp_driver_api *api = dev->driver_api;

	return api->configure(dev, index, polarity, refsel, cb, param);
}

#ifdef __cplusplus
}
#endif

#endif /* _AIO_COMPARATOR_H_ */