1 /***************************************************************************//** 2 * \file cyhal_comp_lp.h 3 * 4 * Provides an implementation of the comp HAL on top of the LP (low power) block 5 * 6 ******************************************************************************** 7 * \copyright 8 * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or 9 * an affiliate of Cypress Semiconductor Corporation 10 * 11 * SPDX-License-Identifier: Apache-2.0 12 * 13 * Licensed under the Apache License, Version 2.0 (the "License"); 14 * you may not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, software 20 * distributed under the License is distributed on an "AS IS" BASIS, 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the License for the specific language governing permissions and 23 * limitations under the License. 24 *******************************************************************************/ 25 26 #pragma once 27 28 #include "cyhal_comp.h" 29 30 #if (_CYHAL_DRIVER_AVAILABLE_COMP_LP) 31 32 /** 33 * \addtogroup group_hal_comp_lp COMP (LP Comparator block) 34 * \ingroup group_hal_impl 35 * \{ 36 * Implementation of the analog comparator (Comp) driver on top of the LP (low power) comparator. 37 * 38 */ 39 40 #if defined(__cplusplus) 41 extern "C" { 42 #endif 43 44 /** Initialize the Comparator peripheral for a LP-based comparator. 45 * 46 * @param[out] obj Pointer to a Comparator object. The caller must allocate the memory 47 * for this object but the init function will initialize its contents. 48 * @param[in] vin_p Non-inverting input pin 49 * @param[in] vin_m Inverting input pin 50 * @param[in] output Comparator output pin. May be @ref NC. 51 * @param[in] cfg Configuration structure 52 * @return The status of the init request 53 */ 54 cy_rslt_t _cyhal_comp_lp_init(cyhal_comp_t *obj, cyhal_gpio_t vin_p, cyhal_gpio_t vin_m, cyhal_gpio_t output, cyhal_comp_config_t *cfg); 55 56 /** Initialize the comparator peripheral for a LP-based comparator using a configurator generated configuration struct 57 * 58 * @param[out] obj Pointer to a comparator object. The caller must allocate the memory 59 * for this object but the init function will initialize its contents. 60 * @param[in] cfg Configuration structure generated by a configurator. 61 * @return The status of the init request 62 */ 63 cy_rslt_t _cyhal_comp_lp_init_cfg(cyhal_comp_t *obj, const cyhal_comp_configurator_t *cfg); 64 65 /** Deinitialize the Comparator peripheral for a LP-based comparator. 66 * 67 * @param[in] obj Comparator object 68 */ 69 void _cyhal_comp_lp_free(cyhal_comp_t *obj); 70 71 /** Changes the current operating power level of the comparator for a LP-based comparator. 72 * 73 * If the power level is set to @ref CYHAL_POWER_LEVEL_OFF, the comparator will be powered-off 74 * but it will retain its configuration, so it is not necessary to reconfigure it when changing 75 * the power level from @ref CYHAL_POWER_LEVEL_OFF to any other value. 76 * 77 * @param[in] obj Comparator object 78 * @param[in] power The power level to set 79 * @return The status of the set power request 80 */ 81 cy_rslt_t _cyhal_comp_lp_set_power(cyhal_comp_t *obj, cyhal_power_level_t power); 82 83 /** Reconfigure the Comparator for a LP-based comparator. 84 * 85 * This retains the powered state of the comparator. 86 * Depending on the implementation, it may be necessary to temporarily deconfigure and/or 87 * power off the comparator in order to apply the new configuration. However, if the 88 * comparator is powered-off when this function is called, it will remain powered-off after 89 * it returns. Likewise, if the comparator is powered-on when this function is called, 90 * it will remain powered-on after it returns. 91 * 92 * @param[in] obj Comparator object 93 * @param[in] cfg New configuration to apply 94 * @return The status of the configure request 95 */ 96 cy_rslt_t _cyhal_comp_lp_configure(cyhal_comp_t *obj, cyhal_comp_config_t *cfg); 97 98 /** Reads the Comparator state for a LP-based comparator. 99 * 100 * @param[in] obj Comparator object 101 * @return The Comparator state. True if the non-inverting pin voltage is greater than the 102 * inverting pin voltage, false otherwise. 103 */ 104 bool _cyhal_comp_lp_read(cyhal_comp_t *obj); 105 106 /** Enable or Disable a Comparator event for a LP-based comparator 107 * 108 * When an enabled event occurs, the function specified by \ref cyhal_comp_register_callback will be called. 109 * 110 * @param[in] obj Comparator object 111 * @param[in] event Comparator event 112 * @param[in] intr_priority Priority for NVIC interrupt events 113 * @param[in] enable True to turn on event, False to turn off 114 */ 115 void _cyhal_comp_lp_enable_event(cyhal_comp_t *obj, cyhal_comp_event_t event, uint8_t intr_priority, bool enable); 116 117 118 #if defined(__cplusplus) 119 } 120 #endif 121 122 /** \} group_hal_comp */ 123 124 #endif // _CYHAL_DRIVER_AVAILABLE_COMP_LP 125