stm32f0xx_comp.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_comp.h
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  7. * @brief This file contains all the functions prototypes for the COMP firmware
  8. * library, applicable only for STM32F051 and STM32F072 devices.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_COMP_H
  30. #define __STM32F0XX_COMP_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup COMP
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief COMP Init structure definition
  45. */
  46. typedef struct
  47. {
  48. uint32_t COMP_InvertingInput; /*!< Selects the inverting input of the comparator.
  49. This parameter can be a value of @ref COMP_InvertingInput */
  50. uint32_t COMP_Output; /*!< Selects the output redirection of the comparator.
  51. This parameter can be a value of @ref COMP_Output */
  52. uint32_t COMP_OutputPol; /*!< Selects the output polarity of the comparator.
  53. This parameter can be a value of @ref COMP_OutputPolarity */
  54. uint32_t COMP_Hysteresis; /*!< Selects the hysteresis voltage of the comparator.
  55. This parameter can be a value of @ref COMP_Hysteresis */
  56. uint32_t COMP_Mode; /*!< Selects the operating mode of the comparator
  57. and allows to adjust the speed/consumption.
  58. This parameter can be a value of @ref COMP_Mode */
  59. }COMP_InitTypeDef;
  60. /* Exported constants --------------------------------------------------------*/
  61. /** @defgroup COMP_Exported_Constants
  62. * @{
  63. */
  64. /** @defgroup COMP_Selection
  65. * @{
  66. */
  67. #define COMP_Selection_COMP1 ((uint32_t)0x00000000) /*!< COMP1 Selection */
  68. #define COMP_Selection_COMP2 ((uint32_t)0x00000010) /*!< COMP2 Selection */
  69. #define IS_COMP_ALL_PERIPH(PERIPH) (((PERIPH) == COMP_Selection_COMP1) || \
  70. ((PERIPH) == COMP_Selection_COMP2))
  71. /**
  72. * @}
  73. */
  74. /** @defgroup COMP_InvertingInput
  75. * @{
  76. */
  77. #define COMP_InvertingInput_1_4VREFINT ((uint32_t)0x00000000) /*!< 1/4 VREFINT connected to comparator inverting input */
  78. #define COMP_InvertingInput_1_2VREFINT COMP_CSR_COMP1INSEL_0 /*!< 1/2 VREFINT connected to comparator inverting input */
  79. #define COMP_InvertingInput_3_4VREFINT COMP_CSR_COMP1INSEL_1 /*!< 3/4 VREFINT connected to comparator inverting input */
  80. #define COMP_InvertingInput_VREFINT ((uint32_t)0x00000030) /*!< VREFINT connected to comparator inverting input */
  81. #define COMP_InvertingInput_DAC1 COMP_CSR_COMP1INSEL_2 /*!< DAC1_OUT (PA4) connected to comparator inverting input */
  82. #define COMP_InvertingInput_DAC2 ((uint32_t)0x00000050) /*!< DAC2_OUT (PA5) connected to comparator inverting input, applicable only for STM32F072 devices */
  83. #define COMP_InvertingInput_IO ((uint32_t)0x00000060) /*!< I/O (PA0 for COMP1 and PA2 for COMP2) connected to comparator inverting input */
  84. #define IS_COMP_INVERTING_INPUT(INPUT) (((INPUT) == COMP_InvertingInput_1_4VREFINT) || \
  85. ((INPUT) == COMP_InvertingInput_1_2VREFINT) || \
  86. ((INPUT) == COMP_InvertingInput_3_4VREFINT) || \
  87. ((INPUT) == COMP_InvertingInput_VREFINT) || \
  88. ((INPUT) == COMP_InvertingInput_DAC1) || \
  89. ((INPUT) == COMP_InvertingInput_DAC2) || \
  90. ((INPUT) == COMP_InvertingInput_1_4VREFINT) || \
  91. ((INPUT) == COMP_InvertingInput_IO))
  92. /**
  93. * @}
  94. */
  95. /** @defgroup COMP_Output
  96. * @{
  97. */
  98. #define COMP_Output_None ((uint32_t)0x00000000) /*!< COMP output isn't connected to other peripherals */
  99. #define COMP_Output_TIM1BKIN COMP_CSR_COMP1OUTSEL_0 /*!< COMP output connected to TIM1 Break Input (BKIN) */
  100. #define COMP_Output_TIM1IC1 COMP_CSR_COMP1OUTSEL_1 /*!< COMP output connected to TIM1 Input Capture 1 */
  101. #define COMP_Output_TIM1OCREFCLR ((uint32_t)0x00000300) /*!< COMP output connected to TIM1 OCREF Clear */
  102. #define COMP_Output_TIM2IC4 COMP_CSR_COMP1OUTSEL_2 /*!< COMP output connected to TIM2 Input Capture 4 */
  103. #define COMP_Output_TIM2OCREFCLR ((uint32_t)0x00000500) /*!< COMP output connected to TIM2 OCREF Clear */
  104. #define COMP_Output_TIM3IC1 ((uint32_t)0x00000600) /*!< COMP output connected to TIM3 Input Capture 1 */
  105. #define COMP_Output_TIM3OCREFCLR COMP_CSR_COMP1OUTSEL /*!< COMP output connected to TIM3 OCREF Clear */
  106. #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_Output_None) || \
  107. ((OUTPUT) == COMP_Output_TIM1BKIN) || \
  108. ((OUTPUT) == COMP_Output_TIM1IC1) || \
  109. ((OUTPUT) == COMP_Output_TIM1OCREFCLR) || \
  110. ((OUTPUT) == COMP_Output_TIM2IC4) || \
  111. ((OUTPUT) == COMP_Output_TIM2OCREFCLR) || \
  112. ((OUTPUT) == COMP_Output_TIM3IC1) || \
  113. ((OUTPUT) == COMP_Output_TIM3OCREFCLR))
  114. /**
  115. * @}
  116. */
  117. /** @defgroup COMP_OutputPolarity
  118. * @{
  119. */
  120. #define COMP_OutputPol_NonInverted ((uint32_t)0x00000000) /*!< COMP output on GPIO isn't inverted */
  121. #define COMP_OutputPol_Inverted COMP_CSR_COMP1POL /*!< COMP output on GPIO is inverted */
  122. #define IS_COMP_OUTPUT_POL(POL) (((POL) == COMP_OutputPol_NonInverted) || \
  123. ((POL) == COMP_OutputPol_Inverted))
  124. /**
  125. * @}
  126. */
  127. /** @defgroup COMP_Hysteresis
  128. * @{
  129. */
  130. /* Please refer to the electrical characteristics in the device datasheet for
  131. the hysteresis level */
  132. #define COMP_Hysteresis_No 0x00000000 /*!< No hysteresis */
  133. #define COMP_Hysteresis_Low COMP_CSR_COMP1HYST_0 /*!< Hysteresis level low */
  134. #define COMP_Hysteresis_Medium COMP_CSR_COMP1HYST_1 /*!< Hysteresis level medium */
  135. #define COMP_Hysteresis_High COMP_CSR_COMP1HYST /*!< Hysteresis level high */
  136. #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_Hysteresis_No) || \
  137. ((HYSTERESIS) == COMP_Hysteresis_Low) || \
  138. ((HYSTERESIS) == COMP_Hysteresis_Medium) || \
  139. ((HYSTERESIS) == COMP_Hysteresis_High))
  140. /**
  141. * @}
  142. */
  143. /** @defgroup COMP_Mode
  144. * @{
  145. */
  146. /* Please refer to the electrical characteristics in the device datasheet for
  147. the power consumption values */
  148. #define COMP_Mode_HighSpeed 0x00000000 /*!< High Speed */
  149. #define COMP_Mode_MediumSpeed COMP_CSR_COMP1MODE_0 /*!< Medium Speed */
  150. #define COMP_Mode_LowPower COMP_CSR_COMP1MODE_1 /*!< Low power mode */
  151. #define COMP_Mode_UltraLowPower COMP_CSR_COMP1MODE /*!< Ultra-low power mode */
  152. #define IS_COMP_MODE(MODE) (((MODE) == COMP_Mode_UltraLowPower) || \
  153. ((MODE) == COMP_Mode_LowPower) || \
  154. ((MODE) == COMP_Mode_MediumSpeed) || \
  155. ((MODE) == COMP_Mode_HighSpeed))
  156. /**
  157. * @}
  158. */
  159. /** @defgroup COMP_OutputLevel
  160. * @{
  161. */
  162. /* When output polarity is not inverted, comparator output is high when
  163. the non-inverting input is at a higher voltage than the inverting input */
  164. #define COMP_OutputLevel_High COMP_CSR_COMP1OUT
  165. /* When output polarity is not inverted, comparator output is low when
  166. the non-inverting input is at a lower voltage than the inverting input*/
  167. #define COMP_OutputLevel_Low ((uint32_t)0x00000000)
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. /* Exported macro ------------------------------------------------------------*/
  175. /* Exported functions ------------------------------------------------------- */
  176. /* Function used to set the COMP configuration to the default reset state ****/
  177. void COMP_DeInit(void);
  178. /* Initialization and Configuration functions *********************************/
  179. void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct);
  180. void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct);
  181. void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState);
  182. void COMP_SwitchCmd(FunctionalState NewState);
  183. uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection);
  184. /* Window mode control function ***********************************************/
  185. void COMP_WindowCmd(FunctionalState NewState);
  186. /* COMP configuration locking function ****************************************/
  187. void COMP_LockConfig(uint32_t COMP_Selection);
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /*__STM32F0XX_COMP_H */
  192. /**
  193. * @}
  194. */
  195. /**
  196. * @}
  197. */
  198. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/