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.11 of the AmbiqSuite Development Package.
  45. //
  46. //*****************************************************************************
  47. #ifndef AM_HAL_VCOMP_H
  48. #define AM_HAL_VCOMP_H
  49. //*****************************************************************************
  50. //
  51. //! @name Positive Input Selection
  52. //! @brief Use these macros to determine the positive input to the comparator.
  53. //! @{
  54. //
  55. //*****************************************************************************
  56. #define AM_HAL_VCOMP_PSEL_VDDADJ AM_REG_VCOMP_CFG_PSEL_VDDADJ
  57. #define AM_HAL_VCOMP_PSEL_VTEMP AM_REG_VCOMP_CFG_PSEL_VTEMP
  58. #define AM_HAL_VCOMP_PSEL_VEXT1 AM_REG_VCOMP_CFG_PSEL_VEXT1
  59. #define AM_HAL_VCOMP_PSEL_VEXT2 AM_REG_VCOMP_CFG_PSEL_VEXT2
  60. //! @}
  61. //*****************************************************************************
  62. //
  63. //! @name Negative Input Selection
  64. //! @brief Use these macros to determine the negative input to the comparator.
  65. //! @{
  66. //
  67. //*****************************************************************************
  68. #define AM_HAL_VCOMP_NSEL_VREFEXT1 AM_REG_VCOMP_CFG_NSEL_VREFEXT1
  69. #define AM_HAL_VCOMP_NSEL_VREFEXT2 AM_REG_VCOMP_CFG_NSEL_VREFEXT2
  70. #define AM_HAL_VCOMP_NSEL_VREFEXT3 AM_REG_VCOMP_CFG_NSEL_VREFEXT3
  71. #define AM_HAL_VCOMP_NSEL_DAC_LEVEL AM_REG_VCOMP_CFG_NSEL_DAC
  72. //! @}
  73. //*****************************************************************************
  74. //
  75. //! @name Negative Input DAC Selectioin
  76. //! @brief Use these macros to determine the NSEL DAC voltage setting
  77. //! @{
  78. //
  79. //*****************************************************************************
  80. #define AM_HAL_VCOMP_DAC_LVLSEL_0_58V AM_REG_VCOMP_CFG_LVLSEL_0P58V
  81. #define AM_HAL_VCOMP_DAC_LVLSEL_0_77V AM_REG_VCOMP_CFG_LVLSEL_0P77V
  82. #define AM_HAL_VCOMP_DAC_LVLSEL_0_97V AM_REG_VCOMP_CFG_LVLSEL_0P97V
  83. #define AM_HAL_VCOMP_DAC_LVLSEL_1_16V AM_REG_VCOMP_CFG_LVLSEL_1P16V
  84. #define AM_HAL_VCOMP_DAC_LVLSEL_1_35V AM_REG_VCOMP_CFG_LVLSEL_1P35V
  85. #define AM_HAL_VCOMP_DAC_LVLSEL_1_55V AM_REG_VCOMP_CFG_LVLSEL_1P55V
  86. #define AM_HAL_VCOMP_DAC_LVLSEL_1_74V AM_REG_VCOMP_CFG_LVLSEL_1P74V
  87. #define AM_HAL_VCOMP_DAC_LVLSEL_1_93V AM_REG_VCOMP_CFG_LVLSEL_1P93V
  88. #define AM_HAL_VCOMP_DAC_LVLSEL_2_13V AM_REG_VCOMP_CFG_LVLSEL_2P13V
  89. #define AM_HAL_VCOMP_DAC_LVLSEL_2_32V AM_REG_VCOMP_CFG_LVLSEL_2P32V
  90. #define AM_HAL_VCOMP_DAC_LVLSEL_2_51V AM_REG_VCOMP_CFG_LVLSEL_2P51V
  91. #define AM_HAL_VCOMP_DAC_LVLSEL_2_71V AM_REG_VCOMP_CFG_LVLSEL_2P71V
  92. #define AM_HAL_VCOMP_DAC_LVLSEL_2_90V AM_REG_VCOMP_CFG_LVLSEL_2P90V
  93. #define AM_HAL_VCOMP_DAC_LVLSEL_3_09V AM_REG_VCOMP_CFG_LVLSEL_3P09V
  94. #define AM_HAL_VCOMP_DAC_LVLSEL_3_29V AM_REG_VCOMP_CFG_LVLSEL_3P29V
  95. #define AM_HAL_VCOMP_DAC_LVLSEL_3_48V AM_REG_VCOMP_CFG_LVLSEL_3P48V
  96. //! @}
  97. //*****************************************************************************
  98. //
  99. //! @name Interrupt Status Bits
  100. //! @brief Interrupt Status Bits for enable/disble use
  101. //!
  102. //! These macros may be used to set and clear interrupt bits
  103. //! @{
  104. //
  105. //*****************************************************************************
  106. #define AM_HAL_VCOMP_INT_OUTHI AM_REG_VCOMP_INTEN_OUTHI_M
  107. #define AM_HAL_VCOMP_INT_OUTLO AM_REG_VCOMP_INTEN_OUTLOW_M
  108. //! @}
  109. //*****************************************************************************
  110. //
  111. //! @brief Configuration struct
  112. //
  113. //*****************************************************************************
  114. typedef struct
  115. {
  116. //
  117. //! The DAC level setting
  118. //
  119. uint32_t ui32LevelSelect;
  120. //
  121. //! The "positive" comparator input channel
  122. //!
  123. //! This channel is usually used as the signal to be monitored.
  124. //
  125. uint32_t ui32PosInput;
  126. //
  127. //! The "negative" comparator input channel
  128. //!
  129. //! This channel is usually used as the reference signal.
  130. //
  131. uint32_t ui32NegInput;
  132. }
  133. am_hal_vcomp_config_t;
  134. #ifdef __cplusplus
  135. extern "C"
  136. {
  137. #endif
  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. //*****************************************************************************