1 /* 2 * Copyright (c) 2022 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _ADC_NPCX_THRESHOLD_H_ 8 #define _ADC_NPCX_THRESHOLD_H_ 9 10 #include <zephyr/device.h> 11 12 enum adc_npcx_threshold_param_l_h { 13 ADC_NPCX_THRESHOLD_PARAM_L_H_HIGHER, 14 ADC_NPCX_THRESHOLD_PARAM_L_H_LOWER, 15 }; 16 17 enum adc_npcx_threshold_param_type { 18 /* Selects ADC channel to be used for measurement */ 19 ADC_NPCX_THRESHOLD_PARAM_CHNSEL, 20 /* Sets relation between measured value and assetion threshold value.*/ 21 ADC_NPCX_THRESHOLD_PARAM_L_H, 22 /* Sets the threshol value to which measured data is compared. */ 23 ADC_NPCX_THRESHOLD_PARAM_THVAL, 24 /* Sets worker queue thread to be notified */ 25 ADC_NPCX_THRESHOLD_PARAM_WORK, 26 27 ADC_NPCX_THRESHOLD_PARAM_MAX, 28 }; 29 30 struct adc_npcx_threshold_param { 31 /* Threshold ocntrol parameter */ 32 enum adc_npcx_threshold_param_type type; 33 /* Parameter value */ 34 uint32_t val; 35 }; 36 37 /** 38 * @brief Convert input value in millivolts to corresponding threshold register 39 * value. 40 * 41 * @note This function is available only if @kconfig{CONFIG_ADC_CMP_NPCX} 42 * is selected. 43 * 44 * @param dev Pointer to the device structure for the driver instance. 45 * @param val_mv Input value in millivolts to be converted. 46 * @param thrval Pointer of variable to hold the result of conversion. 47 * 48 * @returns 0 on success, negative result if input cannot be converted due to 49 * overflow. 50 */ 51 int adc_npcx_threshold_mv_to_thrval(const struct device *dev, uint32_t val_mv, 52 uint32_t *thrval); 53 54 /** 55 * @brief Set ADC threshold parameter. 56 * 57 * @note This function is available only if @kconfig{CONFIG_ADC_CMP_NPCX} 58 * is selected. 59 * 60 * @param dev Pointer to the device structure for the driver instance. 61 * @param th_sel Threshold selected. 62 * @param param Pointer of parameter structure. 63 * See struct adc_npcx_threshold_param for supported 64 * parameters. 65 * 66 * @returns 0 on success, negative error code otherwise. 67 */ 68 int adc_npcx_threshold_ctrl_set_param(const struct device *dev, 69 const uint8_t th_sel, 70 const struct adc_npcx_threshold_param 71 *param); 72 73 /** 74 * @brief Enables/Disables ADC threshold interruption. 75 * 76 * @note This function is available only if @kconfig{CONFIG_ADC_CMP_NPCX} 77 * is selected. 78 * 79 * @param dev Pointer to the device structure for the driver instance. 80 * @param th_sel Threshold selected. 81 * @param enable Enable or disables threshold interruption. 82 * 83 * @returns 0 on success, negative error code otherwise. 84 * all parameters must be configure prior enabling threshold 85 * interruption, otherwhise error will be returned. 86 */ 87 int adc_npcx_threshold_ctrl_enable(const struct device *dev, uint8_t th_sel, 88 const bool enable); 89 90 #endif /*_ADC_NPCX_THRESHOLD_H_ */ 91