am_hal_vcomp.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. // Copyright (c) 2017, Ambiq Micro
  16. // All rights reserved.
  17. //
  18. // Redistribution and use in source and binary forms, with or without
  19. // modification, are permitted provided that the following conditions are met:
  20. //
  21. // 1. Redistributions of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // 2. Redistributions in binary form must reproduce the above copyright
  25. // notice, this list of conditions and the following disclaimer in the
  26. // documentation and/or other materials provided with the distribution.
  27. //
  28. // 3. Neither the name of the copyright holder nor the names of its
  29. // contributors may be used to endorse or promote products derived from this
  30. // software without specific prior written permission.
  31. //
  32. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  36. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. // POSSIBILITY OF SUCH DAMAGE.
  43. //
  44. // This is part of revision 1.2.9 of the AmbiqSuite Development Package.
  45. //
  46. //*****************************************************************************
  47. #ifndef AM_HAL_VCOMP_H
  48. #define AM_HAL_VCOMP_H
  49. #ifdef __cplusplus
  50. extern "C"
  51. {
  52. #endif
  53. //*****************************************************************************
  54. //
  55. //! @name Positive Input Selection
  56. //! @brief Use these macros to determine the positive input to the comparator.
  57. //! @{
  58. //
  59. //*****************************************************************************
  60. #define AM_HAL_VCOMP_PSEL_VDDADJ AM_REG_VCOMP_CFG_PSEL_VDDADJ
  61. #define AM_HAL_VCOMP_PSEL_VTEMP AM_REG_VCOMP_CFG_PSEL_VTEMP
  62. #define AM_HAL_VCOMP_PSEL_VEXT1 AM_REG_VCOMP_CFG_PSEL_VEXT1
  63. #define AM_HAL_VCOMP_PSEL_VEXT2 AM_REG_VCOMP_CFG_PSEL_VEXT2
  64. //! @}
  65. //*****************************************************************************
  66. //
  67. //! @name Negative Input Selection
  68. //! @brief Use these macros to determine the negative input to the comparator.
  69. //! @{
  70. //
  71. //*****************************************************************************
  72. #define AM_HAL_VCOMP_NSEL_VREFEXT1 AM_REG_VCOMP_CFG_NSEL_VREFEXT1
  73. #define AM_HAL_VCOMP_NSEL_VREFEXT2 AM_REG_VCOMP_CFG_NSEL_VREFEXT2
  74. #define AM_HAL_VCOMP_NSEL_VREFEXT3 AM_REG_VCOMP_CFG_NSEL_VREFEXT3
  75. #define AM_HAL_VCOMP_NSEL_DAC_LEVEL AM_REG_VCOMP_CFG_NSEL_DAC
  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. //! @name Interrupt Status Bits
  104. //! @brief Interrupt Status Bits for enable/disble use
  105. //!
  106. //! These macros may be used to set and clear interrupt bits
  107. //! @{
  108. //
  109. //*****************************************************************************
  110. #define AM_HAL_VCOMP_INT_OUTHI AM_REG_VCOMP_INTEN_OUTHI_M
  111. #define AM_HAL_VCOMP_INT_OUTLO AM_REG_VCOMP_INTEN_OUTLOW_M
  112. //! @}
  113. //*****************************************************************************
  114. //
  115. //! @brief Configuration struct
  116. //
  117. //*****************************************************************************
  118. typedef struct
  119. {
  120. //
  121. //! The DAC level setting
  122. //
  123. uint32_t ui32LevelSelect;
  124. //
  125. //! The "positive" comparator input channel
  126. //!
  127. //! This channel is usually used as the signal to be monitored.
  128. //
  129. uint32_t ui32PosInput;
  130. //
  131. //! The "negative" comparator input channel
  132. //!
  133. //! This channel is usually used as the reference signal.
  134. //
  135. uint32_t ui32NegInput;
  136. }
  137. am_hal_vcomp_config_t;
  138. //*****************************************************************************
  139. //
  140. // External function definitions
  141. //
  142. //*****************************************************************************
  143. extern void am_hal_vcomp_config(const am_hal_vcomp_config_t *psConfig);
  144. extern void am_hal_vcomp_dac_level_set(uint32_t ui3Level);
  145. extern bool am_hal_vcomp_read(void);
  146. extern void am_hal_vcomp_enable(void);
  147. extern void am_hal_vcomp_disable(void);
  148. extern void am_hal_vcomp_int_enable(uint32_t ui32Interrupt);
  149. extern uint32_t am_hal_vcomp_int_enable_get(void);
  150. extern void am_hal_vcomp_int_disable(uint32_t ui32Interrupt);
  151. extern void am_hal_vcomp_int_clear(uint32_t ui32Interrupt);
  152. extern void am_hal_vcomp_int_set(uint32_t ui32Interrupt);
  153. extern uint32_t am_hal_vcomp_int_status_get(bool bEnabledOnly);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif // AM_HAL_VCOMP_H
  158. //*****************************************************************************
  159. //
  160. // End Doxygen group.
  161. //! @}
  162. //
  163. //*****************************************************************************