1 /* 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/drivers/comparator.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** Positive input selection */ 17 enum comp_nrf_lpcomp_psel { 18 /** AIN0 external input */ 19 COMP_NRF_LPCOMP_PSEL_AIN0, 20 /** AIN1 external input */ 21 COMP_NRF_LPCOMP_PSEL_AIN1, 22 /** AIN2 external input */ 23 COMP_NRF_LPCOMP_PSEL_AIN2, 24 /** AIN3 external input */ 25 COMP_NRF_LPCOMP_PSEL_AIN3, 26 /** AIN4 external input */ 27 COMP_NRF_LPCOMP_PSEL_AIN4, 28 /** AIN5 external input */ 29 COMP_NRF_LPCOMP_PSEL_AIN5, 30 /** AIN6 external input */ 31 COMP_NRF_LPCOMP_PSEL_AIN6, 32 /** AIN7 external input */ 33 COMP_NRF_LPCOMP_PSEL_AIN7, 34 }; 35 36 /** External reference selection */ 37 enum comp_nrf_lpcomp_extrefsel { 38 /** AIN0 external input */ 39 COMP_NRF_LPCOMP_EXTREFSEL_AIN0, 40 /** AIN1 external input */ 41 COMP_NRF_LPCOMP_EXTREFSEL_AIN1, 42 }; 43 44 /** Reference selection */ 45 enum comp_nrf_lpcomp_refsel { 46 /** Use (VDD * (1/8)) as reference */ 47 COMP_NRF_LPCOMP_REFSEL_VDD_1_8, 48 /** Use (VDD * (2/8)) as reference */ 49 COMP_NRF_LPCOMP_REFSEL_VDD_2_8, 50 /** Use (VDD * (3/8)) as reference */ 51 COMP_NRF_LPCOMP_REFSEL_VDD_3_8, 52 /** Use (VDD * (4/8)) as reference */ 53 COMP_NRF_LPCOMP_REFSEL_VDD_4_8, 54 /** Use (VDD * (5/8)) as reference */ 55 COMP_NRF_LPCOMP_REFSEL_VDD_5_8, 56 /** Use (VDD * (6/8)) as reference */ 57 COMP_NRF_LPCOMP_REFSEL_VDD_6_8, 58 /** Use (VDD * (7/8)) as reference */ 59 COMP_NRF_LPCOMP_REFSEL_VDD_7_8, 60 /** Use (VDD * (1/16)) as reference */ 61 COMP_NRF_LPCOMP_REFSEL_VDD_1_16, 62 /** Use (VDD * (3/16)) as reference */ 63 COMP_NRF_LPCOMP_REFSEL_VDD_3_16, 64 /** Use (VDD * (5/16)) as reference */ 65 COMP_NRF_LPCOMP_REFSEL_VDD_5_16, 66 /** Use (VDD * (7/16)) as reference */ 67 COMP_NRF_LPCOMP_REFSEL_VDD_7_16, 68 /** Use (VDD * (9/16)) as reference */ 69 COMP_NRF_LPCOMP_REFSEL_VDD_9_16, 70 /** Use (VDD * (11/16)) as reference */ 71 COMP_NRF_LPCOMP_REFSEL_VDD_11_16, 72 /** Use (VDD * (13/16)) as reference */ 73 COMP_NRF_LPCOMP_REFSEL_VDD_13_16, 74 /** Use (VDD * (15/16)) as reference */ 75 COMP_NRF_LPCOMP_REFSEL_VDD_15_16, 76 /** Use external analog reference */ 77 COMP_NRF_LPCOMP_REFSEL_AREF, 78 }; 79 80 /** 81 * @brief Configuration structure 82 * 83 * @note extrefsel is only used if refsel == COMP_NRF_LPCOMP_REFSEL_AREF 84 */ 85 struct comp_nrf_lpcomp_config { 86 /** Positive input selection */ 87 enum comp_nrf_lpcomp_psel psel; 88 /** External reference selection */ 89 enum comp_nrf_lpcomp_extrefsel extrefsel; 90 /** Reference selection */ 91 enum comp_nrf_lpcomp_refsel refsel; 92 /** Hysteresis configuration */ 93 bool enable_hyst; 94 }; 95 96 /** 97 * @brief Configure comparator 98 * 99 * @param dev Comparator device instance 100 * @param config Configuration 101 * 102 * @retval 0 if successful 103 * @retval negative errno-code otherwise 104 */ 105 int comp_nrf_lpcomp_configure(const struct device *dev, 106 const struct comp_nrf_lpcomp_config *config); 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #endif /* ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ */ 113