HAL_comp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /**
  2. ******************************************************************************
  3. * @file HAL_comp.h
  4. * @author AE Team
  5. * @version V2.0.0
  6. * @date 22/08/2017
  7. * @brief This file contains all the functions prototypes for the COMP firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; 2017 MindMotion</center></h2>
  13. ******************************************************************************
  14. */
  15. /* Define to prevent recursive inclusion -------------------------------------*/
  16. #ifndef __HAL_COMP_H
  17. #define __HAL_COMP_H
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "HAL_device.h"
  23. /** @addtogroup
  24. * @{
  25. */
  26. /** @addtogroup COMP
  27. * @{
  28. */
  29. /* Exported types ------------------------------------------------------------*/
  30. /**
  31. * @brief COMP Init structure definition
  32. */
  33. typedef struct
  34. {
  35. uint32_t COMP_InvertingInput; /*!< Selects the inverting input of the comparator.
  36. This parameter can be a value of @ref COMP_InvertingInput */
  37. uint32_t COMP_NonInvertingInput; /*!< Selects the non inverting input of the comparator.
  38. This parameter can be a value of @ref COMP_NonInvertingInput */
  39. uint32_t COMP_Output; /*!< Selects the output redirection of the comparator.
  40. This parameter can be a value of @ref COMP_Output */
  41. uint32_t COMP_BlankingSrce; /*!< Selects the output blanking source of the comparator.
  42. This parameter can be a value of @ref COMP_BlankingSrce */
  43. uint32_t COMP_OutputPol; /*!< Selects the output polarity of the comparator.
  44. This parameter can be a value of @ref COMP_OutputPoloarity */
  45. uint32_t COMP_Hysteresis; /*!< Selects the hysteresis voltage of the comparator.
  46. This parameter can be a value of @ref COMP_Hysteresis */
  47. uint32_t COMP_Mode; /*!< Selects the operating mode of the comparator
  48. and allows to adjust the speed/consumption.
  49. This parameter can be a value of @ref COMP_Mode */
  50. }COMP_InitTypeDef;
  51. /* Exported constants --------------------------------------------------------*/
  52. /** @defgroup COMP_Exported_Constants
  53. * @{
  54. */
  55. /** @defgroup COMP_Selection
  56. * @{
  57. */
  58. #define COMP_Selection_COMP1 ((uint32_t)0x00000000) /*!< COMP1 Selection */
  59. #define COMP_Selection_COMP2 ((uint32_t)0x00000004) /*!< COMP2 Selection */
  60. #define IS_COMP_ALL_PERIPH(PERIPH) (((PERIPH) == COMP_Selection_COMP1) || \
  61. ((PERIPH) == COMP_Selection_COMP2))
  62. /**
  63. * @}
  64. */
  65. /** @defgroup COMP_InvertingInput
  66. * @{
  67. */
  68. #define COMP_InvertingInput_1_4VREFINT ((uint32_t)0x00000000) /*!< 1/4 VREFINT connected to comparator inverting input */
  69. #define COMP_InvertingInput_1_2VREFINT ((uint32_t)0x00000010) /*!< 1/2 VREFINT connected to comparator inverting input */
  70. #define COMP_InvertingInput_3_4VREFINT ((uint32_t)0x00000020) /*!< 3/4 VREFINT connected to comparator inverting input */
  71. #define COMP_InvertingInput_VREFINT ((uint32_t)0x00000030) /*!< VREFINT connected to comparator inverting input */
  72. #define COMP_InvertingInput_DAC1 ((uint32_t)0x00000040) /*!< DAC1_OUT (PA4) connected to comparator inverting input */
  73. #define COMP_InvertingInput_DAC2 ((uint32_t)0x00000050) /*!< DAC2_OUT (PA5) connected to comparator inverting input */
  74. #define COMP_InvertingInput_IO1 ((uint32_t)0x00000060) /*!< I/O1 (PA0 for COMP1, PA2 for COMP2) connected to comparator inverting input */
  75. #define COMP_InvertingInput_IO2 ((uint32_t)0x00000070) /*!< I/O2 (PA6 for COMP1, PA6 for COMP2) connected to comparator inverting input */
  76. #define IS_COMP_INVERTING_INPUT(INPUT) (((INPUT) == COMP_InvertingInput_1_4VREFINT) || \
  77. ((INPUT) == COMP_InvertingInput_1_2VREFINT) || \
  78. ((INPUT) == COMP_InvertingInput_3_4VREFINT) || \
  79. ((INPUT) == COMP_InvertingInput_VREFINT) || \
  80. ((INPUT) == COMP_InvertingInput_DAC1) || \
  81. ((INPUT) == COMP_InvertingInput_DAC2) || \
  82. ((INPUT) == COMP_InvertingInput_IO1) || \
  83. ((INPUT) == COMP_InvertingInput_IO2))
  84. /**
  85. * @}
  86. */
  87. /** @defgroup COMP_NonInvertingInput
  88. * @{
  89. */
  90. #define COMP_NonInvertingInput_IO1 ((uint32_t)0x00000000) /*!< I/O1 (PA0 for COMP1, PA0 for COMP2) connected to comparator non inverting input */
  91. #define COMP_NonInvertingInput_IO2 ((uint32_t)0x00000080) /*!< I/O2 (PA1 for COMP1, PA1 for COMP2) connected to comparator non inverting input */
  92. #define COMP_NonInvertingInput_IO3 ((uint32_t)0x00000100) /*!< I/O2 (PA2 for COMP1, PA2 for COMP2) connected to comparator non inverting input */
  93. #define COMP_NonInvertingInput_IO4 ((uint32_t)0x00000180) /*!< I/O2 (PA3 for COMP1, PA3 for COMP2) connected to comparator non inverting input */
  94. #define COMP_NonInvertingInput_IO5 ((uint32_t)0x00000200) /*!< I/O2 (PA4 for COMP1, PA4 for COMP2) connected to comparator non inverting input */
  95. #define COMP_NonInvertingInput_IO6 ((uint32_t)0x00000280) /*!< I/O2 (PA5 for COMP1, PA5 for COMP2) connected to comparator non inverting input */
  96. #define COMP_NonInvertingInput_IO7 ((uint32_t)0x00000300) /*!< I/O2 (PA6 for COMP1, PA6 for COMP2) connected to comparator non inverting input */
  97. #define COMP_NonInvertingInput_IO8 ((uint32_t)0x00000380) /*!< I/O2 (PA7 for COMP1, PA7 for COMP2) connected to comparator non inverting input */
  98. #define IS_COMP_NONINVERTING_INPUT(INPUT) (((INPUT) == COMP_NonInvertingInput_IO1) || \
  99. ((INPUT) == COMP_NonInvertingInput_IO1) || \
  100. ((INPUT) == COMP_NonInvertingInput_IO2) || \
  101. ((INPUT) == COMP_NonInvertingInput_IO3) || \
  102. ((INPUT) == COMP_NonInvertingInput_IO4) || \
  103. ((INPUT) == COMP_NonInvertingInput_IO5) || \
  104. ((INPUT) == COMP_NonInvertingInput_IO6) || \
  105. ((INPUT) == COMP_NonInvertingInput_IO7) || \
  106. ((INPUT) == COMP_NonInvertingInput_IO8))
  107. /**
  108. * @}
  109. */
  110. /** @defgroup COMP_Output
  111. * @{
  112. */
  113. #define COMP_Output_None ((uint32_t)0x00000000) /*!< COMP output isn't connected to other peripherals */
  114. /* Output Redirection common for all comparators COMP1...COMP2 */
  115. #define COMP_Output_TIM1BKIN ((uint32_t)0x00000800) /*!< COMP output connected to TIM1 Break Input (BKIN) */
  116. /* Output Redirection common for COMP1 and COMP2 */
  117. #define COMP_Output_TIM1OCREFCLR ((uint32_t)0x00001800) /*!< COMP output connected to TIM1 OCREF Clear */
  118. #define COMP_Output_TIM1IC1 ((uint32_t)0x00001C00) /*!< COMP output connected to TIM1 Input Capture 1 */
  119. #define COMP_Output_TIM2IC4 ((uint32_t)0x00002000) /*!< COMP output connected to TIM2 Input Capture 4 */
  120. #define COMP_Output_TIM2OCREFCLR ((uint32_t)0x00002400) /*!< COMP output connected to TIM2 OCREF Clear */
  121. #define COMP_Output_TIM3IC1 ((uint32_t)0x00002800) /*!< COMP output connected to TIM3 Input Capture 1 */
  122. #define COMP_Output_TIM3OCREFCLR ((uint32_t)0x00002C00) /*!< COMP output connected to TIM3 OCREF Clear */
  123. #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_Output_None) || \
  124. ((OUTPUT) == COMP_Output_TIM1BKIN) || \
  125. ((OUTPUT) == COMP_Output_TIM1IC1) || \
  126. ((OUTPUT) == COMP_Output_TIM1OCREFCLR) || \
  127. ((OUTPUT) == COMP_Output_TIM2IC4) || \
  128. ((OUTPUT) == COMP_Output_TIM2OCREFCLR) || \
  129. ((OUTPUT) == COMP_Output_TIM3IC1) || \
  130. ((OUTPUT) == COMP_Output_TIM3OCREFCLR))
  131. /**
  132. * @}
  133. */
  134. /** @defgroup COMP_BlankingSrce
  135. * @{
  136. */
  137. /* No blanking source can be selected for all comparators */
  138. #define COMP_BlankingSrce_None ((uint32_t)0x00000000) /*!< No blanking source */
  139. #define IS_COMP_BLANKING_SOURCE(SOURCE) (((SOURCE) == COMP_BlankingSrce_None))
  140. /**
  141. * @}
  142. */
  143. /** @defgroup COMP_OutputPoloarity
  144. * @{
  145. */
  146. #define COMP_OutputPol_NonInverted ((uint32_t)0x00000000) /*!< COMP output on GPIO isn't inverted */
  147. #define COMP_OutputPol_Inverted ((uint32_t)0x00008000) /*!< COMP output on GPIO is inverted */
  148. #define IS_COMP_OUTPUT_POL(POL) (((POL) == COMP_OutputPol_NonInverted) || \
  149. ((POL) == COMP_OutputPol_Inverted))
  150. /**
  151. * @}
  152. */
  153. /** @defgroup COMP_Hysteresis
  154. * @{
  155. */
  156. /* Please refer to the electrical characteristics in the device datasheet for
  157. the hysteresis level */
  158. #define COMP_Hysteresis_No 0x00000000 /*!< No hysteresis */
  159. #define COMP_Hysteresis_Low ((uint32_t)0x00010000) /*!< Hysteresis level low */
  160. #define COMP_Hysteresis_Medium ((uint32_t)0x00020000) /*!< Hysteresis level medium */
  161. #define COMP_Hysteresis_High ((uint32_t)0x00030000) /*!< Hysteresis level high */
  162. #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_Hysteresis_No) || \
  163. ((HYSTERESIS) == COMP_Hysteresis_Low) || \
  164. ((HYSTERESIS) == COMP_Hysteresis_Medium) || \
  165. ((HYSTERESIS) == COMP_Hysteresis_High))
  166. /**
  167. * @}
  168. */
  169. /** @defgroup COMP_Mode
  170. * @{
  171. */
  172. /* Please refer to the electrical characteristics in the device datasheet for
  173. the power consumption values */
  174. #define COMP_Mode_HighSpeed ((uint32_t)0x0000000C) /*!< High Speed */
  175. #define COMP_Mode_MediumSpeed ((uint32_t)0x00000008) /*!< Medium Speed */
  176. #define COMP_Mode_LowPower ((uint32_t)0x00000004) /*!< Low power mode */
  177. #define COMP_Mode_UltraLowPower 0x00000000 /*!< Ultra-low power mode */
  178. #define IS_COMP_MODE(MODE) (((MODE) == COMP_Mode_UltraLowPower) || \
  179. ((MODE) == COMP_Mode_LowPower) || \
  180. ((MODE) == COMP_Mode_MediumSpeed) || \
  181. ((MODE) == COMP_Mode_HighSpeed))
  182. /**
  183. * @}
  184. */
  185. /** @defgroup COMP_OutputLevel
  186. * @{
  187. */
  188. /* When output polarity is not inverted, comparator output is high when
  189. the non-inverting input is at a higher voltage than the inverting input */
  190. #define COMP_OutputLevel_High ((uint32_t)0x40000000)
  191. /* When output polarity is not inverted, comparator output is low when
  192. the non-inverting input is at a lower voltage than the inverting input*/
  193. #define COMP_OutputLevel_Low ((uint32_t)0x00000000)
  194. /**
  195. * @}
  196. */
  197. /** @defgroup COMP_WindowMode
  198. * @{
  199. */
  200. #define IS_COMP_WINDOW(WINDOW) (((WINDOW) == COMP_Selection_COMP2) || \
  201. ((WINDOW) == COMP_Selection_COMP4) || \
  202. ((WINDOW) == COMP_Selection_COMP6))
  203. /**
  204. * @}
  205. */
  206. /**
  207. * @}
  208. */
  209. /* Exported macro ------------------------------------------------------------*/
  210. /* Exported functions ------------------------------------------------------- */
  211. /* Function used to set the COMP configuration to the default reset state ****/
  212. void COMP_DeInit(uint32_t COMP_Selection);
  213. /* Initialization and Configuration functions *********************************/
  214. void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct);
  215. void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct);
  216. void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState);
  217. void COMP_SwitchCmd(uint32_t COMP_Selection, FunctionalState NewState);
  218. uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection);
  219. /* COMP configuration locking function ****************************************/
  220. void COMP_LockConfig(uint32_t COMP_Selection);
  221. #ifdef __cplusplus
  222. }
  223. #endif
  224. #endif /*__HAL_COMP_H */
  225. /**
  226. * @}
  227. */
  228. /**
  229. * @}
  230. */
  231. /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/