Line data Source code
1 0 : /*
2 : * Copyright (c) 2024 Nordic Semiconductor ASA
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_
8 : #define ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_
9 :
10 : #include <zephyr/dt-bindings/comparator/nrf-comp.h>
11 : #include <zephyr/drivers/comparator.h>
12 :
13 : #ifdef __cplusplus
14 : extern "C" {
15 : #endif
16 :
17 : /** Reference selection */
18 1 : enum comp_nrf_lpcomp_refsel {
19 : /** Use (VDD * (1/8)) as reference */
20 : COMP_NRF_LPCOMP_REFSEL_VDD_1_8,
21 : /** Use (VDD * (2/8)) as reference */
22 : COMP_NRF_LPCOMP_REFSEL_VDD_2_8,
23 : /** Use (VDD * (3/8)) as reference */
24 : COMP_NRF_LPCOMP_REFSEL_VDD_3_8,
25 : /** Use (VDD * (4/8)) as reference */
26 : COMP_NRF_LPCOMP_REFSEL_VDD_4_8,
27 : /** Use (VDD * (5/8)) as reference */
28 : COMP_NRF_LPCOMP_REFSEL_VDD_5_8,
29 : /** Use (VDD * (6/8)) as reference */
30 : COMP_NRF_LPCOMP_REFSEL_VDD_6_8,
31 : /** Use (VDD * (7/8)) as reference */
32 : COMP_NRF_LPCOMP_REFSEL_VDD_7_8,
33 : /** Use (VDD * (1/16)) as reference */
34 : COMP_NRF_LPCOMP_REFSEL_VDD_1_16,
35 : /** Use (VDD * (3/16)) as reference */
36 : COMP_NRF_LPCOMP_REFSEL_VDD_3_16,
37 : /** Use (VDD * (5/16)) as reference */
38 : COMP_NRF_LPCOMP_REFSEL_VDD_5_16,
39 : /** Use (VDD * (7/16)) as reference */
40 : COMP_NRF_LPCOMP_REFSEL_VDD_7_16,
41 : /** Use (VDD * (9/16)) as reference */
42 : COMP_NRF_LPCOMP_REFSEL_VDD_9_16,
43 : /** Use (VDD * (11/16)) as reference */
44 : COMP_NRF_LPCOMP_REFSEL_VDD_11_16,
45 : /** Use (VDD * (13/16)) as reference */
46 : COMP_NRF_LPCOMP_REFSEL_VDD_13_16,
47 : /** Use (VDD * (15/16)) as reference */
48 : COMP_NRF_LPCOMP_REFSEL_VDD_15_16,
49 : /** Use external analog reference */
50 : COMP_NRF_LPCOMP_REFSEL_AREF,
51 : };
52 :
53 : /**
54 : * @brief Configuration structure
55 : *
56 : * @note extrefsel is only used if refsel == COMP_NRF_LPCOMP_REFSEL_AREF
57 : */
58 1 : struct comp_nrf_lpcomp_config {
59 : /** Positive input selection defined by the NRF_COMP_AIN defines */
60 1 : uint8_t psel;
61 : /** External reference input selection defined by the NRF_COMP_AIN defines */
62 1 : uint8_t extrefsel;
63 : /** Reference selection */
64 1 : enum comp_nrf_lpcomp_refsel refsel;
65 : /** Hysteresis configuration */
66 1 : bool enable_hyst;
67 : };
68 :
69 : /**
70 : * @brief Configure comparator
71 : *
72 : * @param dev Comparator device instance
73 : * @param config Configuration
74 : *
75 : * @retval 0 if successful
76 : * @retval negative errno-code otherwise
77 : */
78 1 : int comp_nrf_lpcomp_configure(const struct device *dev,
79 : const struct comp_nrf_lpcomp_config *config);
80 :
81 : #ifdef __cplusplus
82 : }
83 : #endif
84 :
85 : #endif /* ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ */
|