stm32g4xx_ll_comp.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_ll_comp.c
  4. * @author MCD Application Team
  5. * @brief COMP LL module driver
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32g4xx_ll_comp.h"
  21. #ifdef USE_FULL_ASSERT
  22. #include "stm32_assert.h"
  23. #else
  24. #define assert_param(expr) ((void)0U)
  25. #endif /* USE_FULL_ASSERT */
  26. /** @addtogroup STM32G4xx_LL_Driver
  27. * @{
  28. */
  29. /** @addtogroup COMP_LL COMP
  30. * @{
  31. */
  32. /* Private types -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. /* Private constants ---------------------------------------------------------*/
  35. /* Private macros ------------------------------------------------------------*/
  36. /** @addtogroup COMP_LL_Private_Macros
  37. * @{
  38. */
  39. /* Check of parameters for configuration of COMP hierarchical scope: */
  40. /* COMP instance. */
  41. /* Note: On this STM32 series, comparator input plus parameters are */
  42. /* the same on all COMP instances. */
  43. /* However, comparator instance kept as macro parameter for */
  44. /* compatibility with other STM32 series. */
  45. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  46. (((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  47. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
  48. )
  49. #if defined(STM32G414xx) || defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
  50. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  51. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) || \
  52. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) || \
  53. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) || \
  54. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) || \
  55. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) || \
  56. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) || \
  57. (((__COMP_INSTANCE__) == COMP1) && \
  58. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  59. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1)) \
  60. ) || \
  61. (((__COMP_INSTANCE__) == COMP2) && \
  62. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) || \
  63. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2)) \
  64. ) || \
  65. (((__COMP_INSTANCE__) == COMP3) && \
  66. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  67. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1)) \
  68. ) || \
  69. (((__COMP_INSTANCE__) == COMP4) && \
  70. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  71. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2)) \
  72. ) || \
  73. (((__COMP_INSTANCE__) == COMP5) && \
  74. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) || \
  75. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC4_CH1)) \
  76. ) || \
  77. (((__COMP_INSTANCE__) == COMP6) && \
  78. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) || \
  79. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC4_CH2)) \
  80. ) || \
  81. (((__COMP_INSTANCE__) == COMP7) && \
  82. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) || \
  83. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC4_CH1)) \
  84. ))
  85. #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx) || defined(STM32G491xx) || defined(STM32G4A1xx)
  86. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  87. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) || \
  88. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) || \
  89. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) || \
  90. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) || \
  91. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) || \
  92. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) || \
  93. (((__COMP_INSTANCE__) == COMP1) && \
  94. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  95. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1)) \
  96. ) || \
  97. (((__COMP_INSTANCE__) == COMP2) && \
  98. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) || \
  99. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2)) \
  100. ) || \
  101. (((__COMP_INSTANCE__) == COMP3) && \
  102. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  103. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1)) \
  104. ) || \
  105. (((__COMP_INSTANCE__) == COMP4) && \
  106. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  107. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2)) \
  108. ))
  109. #elif defined(STM32G411xB) || defined(STM32G411xC)
  110. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  111. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) || \
  112. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) || \
  113. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) || \
  114. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) || \
  115. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) || \
  116. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) || \
  117. (((__COMP_INSTANCE__) == COMP1) && \
  118. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  119. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1)) \
  120. ) || \
  121. (((__COMP_INSTANCE__) == COMP2) && \
  122. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) || \
  123. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH2)) \
  124. ) || \
  125. (((__COMP_INSTANCE__) == COMP3) && \
  126. (((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) || \
  127. ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC3_CH1)) \
  128. ))
  129. #endif
  130. #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
  131. (((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
  132. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_10MV) \
  133. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_20MV) \
  134. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_30MV) \
  135. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_40MV) \
  136. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_50MV) \
  137. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_60MV) \
  138. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_70MV) \
  139. )
  140. #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
  141. (((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
  142. || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
  143. )
  144. #if defined(STM32G414xx) || defined(STM32G474xx) || defined(STM32G484xx) || defined(STM32G473xx) || defined(STM32G483xx)
  145. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  146. ((((__INSTANCE__) == COMP1) && \
  147. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  148. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \
  149. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \
  150. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) || \
  151. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1))) \
  152. || \
  153. (((__INSTANCE__) == COMP2) && \
  154. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  155. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) || \
  156. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) || \
  157. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) || \
  158. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2))) \
  159. || \
  160. (((__INSTANCE__) == COMP3) && \
  161. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  162. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3) || \
  163. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3) || \
  164. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3) || \
  165. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3))) \
  166. || \
  167. (((__INSTANCE__) == COMP4) && \
  168. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  169. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4) || \
  170. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) || \
  171. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4) || \
  172. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4))) \
  173. || \
  174. (((__INSTANCE__) == COMP5) && \
  175. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  176. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5) || \
  177. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5) || \
  178. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5) || \
  179. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5))) \
  180. || \
  181. (((__INSTANCE__) == COMP6) && \
  182. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  183. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6) || \
  184. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) || \
  185. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6) || \
  186. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6))) \
  187. || \
  188. (((__INSTANCE__) == COMP7) && \
  189. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  190. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7) || \
  191. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7) || \
  192. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7) || \
  193. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7))) \
  194. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM20_OC5) \
  195. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1) \
  196. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM4_OC3) \
  197. )
  198. #elif defined(STM32GBK1CB) || defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx)
  199. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  200. ((((__INSTANCE__) == COMP1) && \
  201. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  202. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \
  203. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \
  204. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) || \
  205. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1))) \
  206. || \
  207. (((__INSTANCE__) == COMP2) && \
  208. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  209. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) || \
  210. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) || \
  211. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) || \
  212. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2))) \
  213. || \
  214. (((__INSTANCE__) == COMP3) && \
  215. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  216. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3) || \
  217. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3) || \
  218. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3) || \
  219. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3))) \
  220. || \
  221. (((__INSTANCE__) == COMP4) && \
  222. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  223. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4) || \
  224. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) || \
  225. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4) || \
  226. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4))) \
  227. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1) \
  228. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM4_OC3) \
  229. )
  230. #elif defined(STM32G491xx) || defined(STM32G4A1xx)
  231. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  232. ((((__INSTANCE__) == COMP1) && \
  233. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  234. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \
  235. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \
  236. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) || \
  237. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1))) \
  238. || \
  239. (((__INSTANCE__) == COMP2) && \
  240. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  241. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) || \
  242. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) || \
  243. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) || \
  244. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2))) \
  245. || \
  246. (((__INSTANCE__) == COMP3) && \
  247. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  248. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3) || \
  249. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3) || \
  250. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3) || \
  251. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3))) \
  252. || \
  253. (((__INSTANCE__) == COMP4) && \
  254. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  255. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4) || \
  256. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) || \
  257. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4) || \
  258. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4))) \
  259. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM20_OC5) \
  260. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1) \
  261. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM4_OC3) \
  262. )
  263. #elif defined(STM32G411xB) || defined(STM32G411xC)
  264. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  265. ((((__INSTANCE__) == COMP1) && \
  266. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  267. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \
  268. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \
  269. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1) || \
  270. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1))) \
  271. || \
  272. (((__INSTANCE__) == COMP2) && \
  273. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  274. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) || \
  275. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) || \
  276. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) || \
  277. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2))) \
  278. || \
  279. (((__INSTANCE__) == COMP3) && \
  280. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) || \
  281. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3) || \
  282. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3) || \
  283. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3) || \
  284. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3))) \
  285. )
  286. #endif
  287. /**
  288. * @}
  289. */
  290. /* Private function prototypes -----------------------------------------------*/
  291. /* Exported functions --------------------------------------------------------*/
  292. /** @addtogroup COMP_LL_Exported_Functions
  293. * @{
  294. */
  295. /** @addtogroup COMP_LL_EF_Init
  296. * @{
  297. */
  298. /**
  299. * @brief De-initialize registers of the selected COMP instance
  300. * to their default reset values.
  301. * @note If comparator is locked, de-initialization by software is
  302. * not possible.
  303. * The only way to unlock the comparator is a device hardware reset.
  304. * @param COMPx COMP instance
  305. * @retval An ErrorStatus enumeration value:
  306. * - SUCCESS: COMP registers are de-initialized
  307. * - ERROR: COMP registers are not de-initialized
  308. */
  309. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
  310. {
  311. ErrorStatus status = SUCCESS;
  312. /* Check the parameters */
  313. assert_param(IS_COMP_ALL_INSTANCE(COMPx));
  314. /* Note: Hardware constraint (refer to description of this function): */
  315. /* COMP instance must not be locked. */
  316. if (LL_COMP_IsLocked(COMPx) == 0UL)
  317. {
  318. LL_COMP_WriteReg(COMPx, CSR, 0x00000000UL);
  319. }
  320. else
  321. {
  322. /* Comparator instance is locked: de-initialization by software is */
  323. /* not possible. */
  324. /* The only way to unlock the comparator is a device hardware reset. */
  325. status = ERROR;
  326. }
  327. return status;
  328. }
  329. /**
  330. * @brief Initialize some features of COMP instance.
  331. * @note This function configures features of the selected COMP instance.
  332. * Some features are also available at scope COMP common instance
  333. * (common to several COMP instances).
  334. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  335. * @param COMPx COMP instance
  336. * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
  337. * @retval An ErrorStatus enumeration value:
  338. * - SUCCESS: COMP registers are initialized
  339. * - ERROR: COMP registers are not initialized
  340. */
  341. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct)
  342. {
  343. ErrorStatus status = SUCCESS;
  344. /* Check the parameters */
  345. assert_param(IS_COMP_ALL_INSTANCE(COMPx));
  346. assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
  347. assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
  348. assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
  349. assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
  350. assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMPx, COMP_InitStruct->OutputBlankingSource));
  351. /* Note: Hardware constraint (refer to description of this function) */
  352. /* COMP instance must not be locked. */
  353. if (LL_COMP_IsLocked(COMPx) == 0UL)
  354. {
  355. /* Configuration of comparator instance : */
  356. /* - InputPlus */
  357. /* - InputMinus */
  358. /* - InputHysteresis */
  359. /* - OutputPolarity */
  360. /* - OutputBlankingSource */
  361. MODIFY_REG(COMPx->CSR,
  362. COMP_CSR_INPSEL
  363. | COMP_CSR_SCALEN
  364. | COMP_CSR_BRGEN
  365. | COMP_CSR_INMSEL
  366. | COMP_CSR_HYST
  367. | COMP_CSR_POLARITY
  368. | COMP_CSR_BLANKING
  369. ,
  370. COMP_InitStruct->InputPlus
  371. | COMP_InitStruct->InputMinus
  372. | COMP_InitStruct->InputHysteresis
  373. | COMP_InitStruct->OutputPolarity
  374. | COMP_InitStruct->OutputBlankingSource
  375. );
  376. }
  377. else
  378. {
  379. /* Initialization error: COMP instance is locked. */
  380. status = ERROR;
  381. }
  382. return status;
  383. }
  384. /**
  385. * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
  386. * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
  387. * whose fields will be set to default values.
  388. * @retval None
  389. */
  390. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
  391. {
  392. /* Set COMP_InitStruct fields to default values */
  393. COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
  394. COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
  395. COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
  396. COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
  397. COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
  398. }
  399. /**
  400. * @}
  401. */
  402. /**
  403. * @}
  404. */
  405. /**
  406. * @}
  407. */
  408. /**
  409. * @}
  410. */
  411. #endif /* USE_FULL_LL_DRIVER */