1 /** 2 * @file lpcmp.h 3 * @brief Low Power Comparator(LPCMP) function prototypes and data types. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 /* Define to prevent redundant inclusion */ 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_LPCMP_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_LPCMP_H_ 29 30 /* **** Includes **** */ 31 #include <stdint.h> 32 #include "lpcmp_regs.h" 33 #include "mcr_regs.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * @brief Comparator polarity select 41 * 42 */ 43 typedef enum { 44 MXC_LPCMP_POL_RISE = 0, //< Comparator interrupt happens on rising edge of comparator output 45 MXC_LPCMP_POL_FALL = 1, //< Comparator interrupt occurs on falling edge of comparator output 46 } mxc_lpcmp_polarity_t; 47 48 /** 49 * @brief Comparator select 50 * 51 */ 52 typedef enum { 53 MXC_LPCMP_CMP0 = 54 0, //< Comparator output high when positive input is greater than negative input 55 MXC_LPCMP_CMP1 = 56 1, //< Comparator output high when negative input is greater than positive input 57 MXC_LPCMP_CMP2 = 58 2, //< Comparator output high when negative input is greater than positive input 59 MXC_LPCMP_CMP3 = 60 3, //< Comparator output high when negative input is greater than positive input 61 } mxc_lpcmp_cmpsel_t; 62 63 /** 64 * @brief Typedef for pointer to comparator control register(s) 65 */ 66 typedef volatile uint32_t *mxc_lpcmp_ctrl_reg_t; 67 68 /** 69 * @brief enables comparator 70 * 71 * @param cmp Selects the comparator to enable 72 * 73 * @return int \ref MXC_Error_Codes for the list of error codes 74 */ 75 int MXC_LPCMP_Init(mxc_lpcmp_cmpsel_t cmp); 76 77 /** 78 * @brief Shutdown comparator 79 * 80 * @param cmp Selects the comparator to disable 81 * 82 * @return int \ref MXC_Error_Codes for the list of error codes 83 */ 84 int MXC_LPCMP_Shutdown(mxc_lpcmp_cmpsel_t cmp); 85 86 /** 87 * @brief Enable interrupts 88 * 89 * @param cmp Selects the comparator to enable interrupt for 90 * @param pol Selects polarity of the interrupt 91 */ 92 int MXC_LPCMP_EnableInt(mxc_lpcmp_cmpsel_t cmp, mxc_lpcmp_polarity_t pol); 93 94 /** 95 * @brief Disable interrupts 96 * 97 * @param cmp Selects the comparator to disable interrupt for 98 */ 99 int MXC_LPCMP_DisableInt(mxc_lpcmp_cmpsel_t cmp); 100 101 /** 102 * @brief Returns the interrupt flags set 103 * 104 * @param cmp Selects the comparator to get interrupt falg status for 105 * 106 * @return int interrupt flag status (1 if set, 0 if cleared) 107 */ 108 int MXC_LPCMP_GetFlags(mxc_lpcmp_cmpsel_t cmp); 109 110 /** 111 * @brief Clear interrupt flags 112 * 113 * @param cmp Selects the comparator to clear interrupt flag for 114 */ 115 int MXC_LPCMP_ClearFlags(mxc_lpcmp_cmpsel_t cmp); 116 117 /** 118 * @brief Select polatity 119 * 120 * @param cmp Selects the comparator to select polarity for 121 * @param pol \ref mxc_lpcmp_polarity_t 122 */ 123 int MXC_LPCMP_SelectPolarity(mxc_lpcmp_cmpsel_t cmp, mxc_lpcmp_polarity_t pol); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_LPCMP_H_ 130