1 //***************************************************************************** 2 // 3 // am_hal_vcomp.h 4 //! @file 5 //! 6 //! @brief Functions for operating the on-chip Voltage Comparator 7 //! 8 //! @addtogroup vcomp2 Voltage Comparator (VCOMP) 9 //! @ingroup apollo2hal 10 //! @{ 11 // 12 //***************************************************************************** 13 14 //***************************************************************************** 15 // 16 // Copyright (c) 2017, Ambiq Micro 17 // All rights reserved. 18 // 19 // Redistribution and use in source and binary forms, with or without 20 // modification, are permitted provided that the following conditions are met: 21 // 22 // 1. Redistributions of source code must retain the above copyright notice, 23 // this list of conditions and the following disclaimer. 24 // 25 // 2. Redistributions in binary form must reproduce the above copyright 26 // notice, this list of conditions and the following disclaimer in the 27 // documentation and/or other materials provided with the distribution. 28 // 29 // 3. Neither the name of the copyright holder nor the names of its 30 // contributors may be used to endorse or promote products derived from this 31 // software without specific prior written permission. 32 // 33 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 34 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 35 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 36 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 37 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 38 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 41 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 42 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 // POSSIBILITY OF SUCH DAMAGE. 44 // 45 // This is part of revision 1.2.11 of the AmbiqSuite Development Package. 46 // 47 //***************************************************************************** 48 #ifndef AM_HAL_VCOMP_H 49 #define AM_HAL_VCOMP_H 50 51 //***************************************************************************** 52 // 53 //! @name Positive Input Selection 54 //! @brief Use these macros to determine the positive input to the comparator. 55 //! @{ 56 // 57 //***************************************************************************** 58 #define AM_HAL_VCOMP_PSEL_VDDADJ AM_REG_VCOMP_CFG_PSEL_VDDADJ 59 #define AM_HAL_VCOMP_PSEL_VTEMP AM_REG_VCOMP_CFG_PSEL_VTEMP 60 #define AM_HAL_VCOMP_PSEL_VEXT1 AM_REG_VCOMP_CFG_PSEL_VEXT1 61 #define AM_HAL_VCOMP_PSEL_VEXT2 AM_REG_VCOMP_CFG_PSEL_VEXT2 62 //! @} 63 64 //***************************************************************************** 65 // 66 //! @name Negative Input Selection 67 //! @brief Use these macros to determine the negative input to the comparator. 68 //! @{ 69 // 70 //***************************************************************************** 71 #define AM_HAL_VCOMP_NSEL_VREFEXT1 AM_REG_VCOMP_CFG_NSEL_VREFEXT1 72 #define AM_HAL_VCOMP_NSEL_VREFEXT2 AM_REG_VCOMP_CFG_NSEL_VREFEXT2 73 #define AM_HAL_VCOMP_NSEL_VREFEXT3 AM_REG_VCOMP_CFG_NSEL_VREFEXT3 74 #define AM_HAL_VCOMP_NSEL_DAC_LEVEL AM_REG_VCOMP_CFG_NSEL_DAC 75 //! @} 76 77 //***************************************************************************** 78 // 79 //! @name Negative Input DAC Selectioin 80 //! @brief Use these macros to determine the NSEL DAC voltage setting 81 //! @{ 82 // 83 //***************************************************************************** 84 #define AM_HAL_VCOMP_DAC_LVLSEL_0_58V AM_REG_VCOMP_CFG_LVLSEL_0P58V 85 #define AM_HAL_VCOMP_DAC_LVLSEL_0_77V AM_REG_VCOMP_CFG_LVLSEL_0P77V 86 #define AM_HAL_VCOMP_DAC_LVLSEL_0_97V AM_REG_VCOMP_CFG_LVLSEL_0P97V 87 #define AM_HAL_VCOMP_DAC_LVLSEL_1_16V AM_REG_VCOMP_CFG_LVLSEL_1P16V 88 #define AM_HAL_VCOMP_DAC_LVLSEL_1_35V AM_REG_VCOMP_CFG_LVLSEL_1P35V 89 #define AM_HAL_VCOMP_DAC_LVLSEL_1_55V AM_REG_VCOMP_CFG_LVLSEL_1P55V 90 #define AM_HAL_VCOMP_DAC_LVLSEL_1_74V AM_REG_VCOMP_CFG_LVLSEL_1P74V 91 #define AM_HAL_VCOMP_DAC_LVLSEL_1_93V AM_REG_VCOMP_CFG_LVLSEL_1P93V 92 #define AM_HAL_VCOMP_DAC_LVLSEL_2_13V AM_REG_VCOMP_CFG_LVLSEL_2P13V 93 #define AM_HAL_VCOMP_DAC_LVLSEL_2_32V AM_REG_VCOMP_CFG_LVLSEL_2P32V 94 #define AM_HAL_VCOMP_DAC_LVLSEL_2_51V AM_REG_VCOMP_CFG_LVLSEL_2P51V 95 #define AM_HAL_VCOMP_DAC_LVLSEL_2_71V AM_REG_VCOMP_CFG_LVLSEL_2P71V 96 #define AM_HAL_VCOMP_DAC_LVLSEL_2_90V AM_REG_VCOMP_CFG_LVLSEL_2P90V 97 #define AM_HAL_VCOMP_DAC_LVLSEL_3_09V AM_REG_VCOMP_CFG_LVLSEL_3P09V 98 #define AM_HAL_VCOMP_DAC_LVLSEL_3_29V AM_REG_VCOMP_CFG_LVLSEL_3P29V 99 #define AM_HAL_VCOMP_DAC_LVLSEL_3_48V AM_REG_VCOMP_CFG_LVLSEL_3P48V 100 //! @} 101 102 //***************************************************************************** 103 // 104 //! @name Interrupt Status Bits 105 //! @brief Interrupt Status Bits for enable/disble use 106 //! 107 //! These macros may be used to set and clear interrupt bits 108 //! @{ 109 // 110 //***************************************************************************** 111 #define AM_HAL_VCOMP_INT_OUTHI AM_REG_VCOMP_INTEN_OUTHI_M 112 #define AM_HAL_VCOMP_INT_OUTLO AM_REG_VCOMP_INTEN_OUTLOW_M 113 //! @} 114 115 //***************************************************************************** 116 // 117 //! @brief Configuration struct 118 // 119 //***************************************************************************** 120 typedef struct 121 { 122 // 123 //! The DAC level setting 124 // 125 uint32_t ui32LevelSelect; 126 127 // 128 //! The "positive" comparator input channel 129 //! 130 //! This channel is usually used as the signal to be monitored. 131 // 132 uint32_t ui32PosInput; 133 134 // 135 //! The "negative" comparator input channel 136 //! 137 //! This channel is usually used as the reference signal. 138 // 139 uint32_t ui32NegInput; 140 } 141 am_hal_vcomp_config_t; 142 143 #ifdef __cplusplus 144 extern "C" 145 { 146 #endif 147 148 //***************************************************************************** 149 // 150 // External function definitions 151 // 152 //***************************************************************************** 153 extern void am_hal_vcomp_config(const am_hal_vcomp_config_t *psConfig); 154 extern void am_hal_vcomp_dac_level_set(uint32_t ui3Level); 155 extern bool am_hal_vcomp_read(void); 156 extern void am_hal_vcomp_enable(void); 157 extern void am_hal_vcomp_disable(void); 158 extern void am_hal_vcomp_int_enable(uint32_t ui32Interrupt); 159 extern uint32_t am_hal_vcomp_int_enable_get(void); 160 extern void am_hal_vcomp_int_disable(uint32_t ui32Interrupt); 161 extern void am_hal_vcomp_int_clear(uint32_t ui32Interrupt); 162 extern void am_hal_vcomp_int_set(uint32_t ui32Interrupt); 163 extern uint32_t am_hal_vcomp_int_status_get(bool bEnabledOnly); 164 165 #ifdef __cplusplus 166 } 167 #endif 168 169 #endif // AM_HAL_VCOMP_H 170 171 //***************************************************************************** 172 // 173 // End Doxygen group. 174 //! @} 175 // 176 //***************************************************************************** 177