stm32f3xx_ll_comp.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_ll_comp.c
  4. * @author MCD Application Team
  5. * @brief COMP LL module driver
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. #if defined(USE_FULL_LL_DRIVER)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32f3xx_ll_comp.h"
  38. #ifdef USE_FULL_ASSERT
  39. #include "stm32_assert.h"
  40. #else
  41. #define assert_param(expr) ((void)0U)
  42. #endif
  43. /** @addtogroup STM32F3xx_LL_Driver
  44. * @{
  45. */
  46. /* Note: Devices of STM32F3 serie embed 1 out of 2 different comparator IP. */
  47. /* - STM32F30x, STM32F31x, STM32F32x, STM32F33x, STM32F35x, STM32F39x: */
  48. /* COMP IP from 3 to 7 instances and other specific features */
  49. /* (comparator output blanking, ...) (refer to reference manual). */
  50. /* - STM32F37x: */
  51. /* COMP IP with 2 instances */
  52. /* This file contains the drivers of these COMP IP, located in 2 area */
  53. /* delimited by compilation switches. */
  54. #if defined(COMP_V1_3_0_0)
  55. #if defined (COMP1) || defined (COMP2) || defined (COMP3) || defined (COMP4) || defined (COMP5) || defined (COMP6) || defined (COMP7)
  56. /** @addtogroup COMP_LL COMP
  57. * @{
  58. */
  59. /* Private types -------------------------------------------------------------*/
  60. /* Private variables ---------------------------------------------------------*/
  61. /* Private constants ---------------------------------------------------------*/
  62. /* Private macros ------------------------------------------------------------*/
  63. /** @addtogroup COMP_LL_Private_Macros
  64. * @{
  65. */
  66. /* Check of parameters for configuration of COMP hierarchical scope: */
  67. /* COMP instance. */
  68. #if defined(COMP_CSR_COMPxMODE)
  69. #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
  70. ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
  71. || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
  72. || ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
  73. || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
  74. )
  75. #else
  76. #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
  77. ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED)
  78. #endif
  79. /* Note: On this STM32 serie, comparator input plus parameters are */
  80. /* the same on all COMP instances. */
  81. /* However, comparator instance kept as macro parameter for */
  82. /* compatibility with other STM32 families. */
  83. #if defined(COMP_CSR_COMPxNONINSEL) && defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1)
  84. /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
  85. /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
  86. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  87. ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  88. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
  89. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1) \
  90. )
  91. #elif defined(COMP_CSR_COMPxNONINSEL) && defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2)
  92. /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
  93. /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
  94. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  95. ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  96. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
  97. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2) \
  98. )
  99. #elif defined(COMP_CSR_COMPxNONINSEL)
  100. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  101. ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  102. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO2) \
  103. )
  104. #elif defined(LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2)
  105. /* Note: On devices where bit COMP_CSR_COMPxNONINSEL is available, */
  106. /* feature LL_COMP_INPUT_PLUS_DAC1_CH1_COMP1 is also available. */
  107. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  108. ( ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  109. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1_COMP2) \
  110. )
  111. #else
  112. /* Note: Device without comparator input plus configurable: corresponds to */
  113. /* setting "LL_COMP_INPUT_PLUS_IO1" or "LL_COMP_INPUT_PLUS_IO2" */
  114. /* compared to other STM32F3 devices, depending on comparator instance */
  115. /* (refer to reference manual). */
  116. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  117. ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1)
  118. #endif
  119. #if defined(STM32F303xC) || defined(STM32F358xx) || defined(STM32F303xE) || defined(STM32F398xx)
  120. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  121. ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
  122. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
  123. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
  124. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
  125. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
  126. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
  127. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
  128. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
  129. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
  130. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
  131. )
  132. #elif defined(STM32F303x8) || defined(STM32F328xx) || defined(STM32F334x8)
  133. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  134. ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
  135. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
  136. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
  137. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
  138. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
  139. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
  140. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
  141. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
  142. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
  143. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) \
  144. )
  145. #elif defined(STM32F302xC) || defined(STM32F302xE)
  146. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  147. ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
  148. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
  149. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
  150. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
  151. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
  152. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
  153. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
  154. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
  155. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
  156. )
  157. #else /* STM32F301x8 || STM32F318xx || STM32F302x8 */
  158. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  159. ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
  160. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
  161. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
  162. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
  163. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
  164. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
  165. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
  166. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
  167. )
  168. #endif
  169. #if defined(COMP_CSR_COMPxHYST)
  170. #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
  171. ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
  172. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
  173. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
  174. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
  175. )
  176. #else
  177. #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
  178. ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE)
  179. #endif
  180. #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  181. #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
  182. (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
  183. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
  184. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
  185. ) \
  186. ? ( \
  187. (1U) \
  188. ) \
  189. : \
  190. (((__COMP_INSTANCE__) == COMP2) \
  191. ? ( \
  192. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP2) \
  193. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP2) \
  194. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP2) \
  195. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP2) \
  196. ) \
  197. : \
  198. (((__COMP_INSTANCE__) == COMP4) \
  199. ? ( \
  200. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
  201. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
  202. ) \
  203. : \
  204. ( \
  205. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
  206. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
  207. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
  208. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
  209. ) \
  210. ) \
  211. ) \
  212. )
  213. #elif defined(STM32F303x8) || defined(STM32F328xx) || defined(STM32F334x8)
  214. #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
  215. (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
  216. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
  217. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
  218. ) \
  219. ? ( \
  220. (1U) \
  221. ) \
  222. : \
  223. (((__COMP_INSTANCE__) == COMP2) \
  224. ? ( \
  225. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2_4) \
  226. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP2) \
  227. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP2) \
  228. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP2) \
  229. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP2) \
  230. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP2) \
  231. ) \
  232. : \
  233. (((__COMP_INSTANCE__) == COMP4) \
  234. ? ( \
  235. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2_4)\
  236. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
  237. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
  238. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
  239. ) \
  240. : \
  241. ( \
  242. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
  243. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
  244. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
  245. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
  246. ) \
  247. ) \
  248. ) \
  249. )
  250. #elif defined(STM32F302xC) || defined(STM32F302xE)
  251. #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
  252. (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
  253. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
  254. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
  255. ) \
  256. ? ( \
  257. (1U) \
  258. ) \
  259. : \
  260. ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
  261. ? ( \
  262. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
  263. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
  264. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
  265. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2) \
  266. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2) \
  267. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
  268. ) \
  269. : \
  270. (((__COMP_INSTANCE__) == COMP4) \
  271. ? ( \
  272. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
  273. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
  274. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
  275. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
  276. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
  277. ) \
  278. : \
  279. ( \
  280. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4) \
  281. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
  282. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
  283. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
  284. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
  285. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
  286. ) \
  287. ) \
  288. ) \
  289. )
  290. #elif defined(STM32F303xC) || defined(STM32F358xx)
  291. #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
  292. (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
  293. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
  294. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
  295. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_BKIN2) \
  296. ) \
  297. ? ( \
  298. (1U) \
  299. ) \
  300. : \
  301. ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
  302. ? ( \
  303. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
  304. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
  305. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
  306. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
  307. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
  308. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
  309. ) \
  310. : \
  311. (((__COMP_INSTANCE__) == COMP3) \
  312. ? ( \
  313. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
  314. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
  315. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC2_COMP3) \
  316. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1_COMP3) \
  317. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC1_COMP3) \
  318. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_BKIN) \
  319. ) \
  320. : \
  321. (((__COMP_INSTANCE__) == COMP4) \
  322. ? ( \
  323. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
  324. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
  325. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
  326. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
  327. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
  328. ) \
  329. : \
  330. (((__COMP_INSTANCE__) == COMP5) \
  331. ? ( \
  332. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
  333. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
  334. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC1_COMP5) \
  335. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC3_COMP5) \
  336. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_IC1_COMP5) \
  337. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
  338. ) \
  339. : \
  340. (((__COMP_INSTANCE__) == COMP6) \
  341. ? ( \
  342. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
  343. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
  344. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
  345. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
  346. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
  347. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
  348. ) \
  349. : \
  350. ( \
  351. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
  352. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
  353. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC2_COMP7) \
  354. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC3_COMP7) \
  355. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_OCCLR_COMP7) \
  356. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_BKIN) \
  357. ) \
  358. ) \
  359. ) \
  360. ) \
  361. ) \
  362. ) \
  363. )
  364. #elif defined(STM32F303xE) || defined(STM32F398xx)
  365. #define IS_LL_COMP_OUTPUT_SELECTION(__COMP_INSTANCE__, __OUTPUT_SELECTION__) \
  366. (( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
  367. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN) \
  368. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_BKIN2) \
  369. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_BKIN2) \
  370. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_BKIN) \
  371. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_BKIN2) \
  372. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_TIM8_TIM20_BKIN2) \
  373. ) \
  374. ? ( \
  375. (1U) \
  376. ) \
  377. : \
  378. ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
  379. ? ( \
  380. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
  381. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
  382. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
  383. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC1_COMP1_2) \
  384. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4_COMP1_2) \
  385. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP1_2) \
  386. || (((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM20_OCCLR_COMP2) \
  387. && ((__COMP_INSTANCE__) == COMP2) ) \
  388. ) \
  389. : \
  390. (((__COMP_INSTANCE__) == COMP3) \
  391. ? ( \
  392. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
  393. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP1_2_3) \
  394. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC2_COMP3) \
  395. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1_COMP3) \
  396. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC1_COMP3) \
  397. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_BKIN) \
  398. ) \
  399. : \
  400. (((__COMP_INSTANCE__) == COMP4) \
  401. ? ( \
  402. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
  403. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC3_COMP4) \
  404. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC2_COMP4) \
  405. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_IC2_COMP4) \
  406. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM15_OCCLR_COMP4) \
  407. ) \
  408. : \
  409. (((__COMP_INSTANCE__) == COMP5) \
  410. ? ( \
  411. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP1_2_4_5) \
  412. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
  413. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC1_COMP5) \
  414. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC3_COMP5) \
  415. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_IC1_COMP5) \
  416. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
  417. ) \
  418. : \
  419. (((__COMP_INSTANCE__) == COMP6) \
  420. ? ( \
  421. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
  422. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC2_COMP6) \
  423. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR_COMP6) \
  424. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC4_COMP6) \
  425. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_IC1_COMP6) \
  426. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_OCCLR_COMP6) \
  427. ) \
  428. : \
  429. ( \
  430. ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_OCCLR_COMP1_2_3_7) \
  431. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM8_OCCLR_COMP4_5_6_7) \
  432. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM1_IC2_COMP7) \
  433. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC3_COMP7) \
  434. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_OCCLR_COMP7) \
  435. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM17_BKIN) \
  436. ) \
  437. ) \
  438. ) \
  439. ) \
  440. ) \
  441. ) \
  442. )
  443. #endif
  444. #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
  445. ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
  446. || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
  447. )
  448. #if defined(COMP_CSR_COMPxBLANKING)
  449. #if defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
  450. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  451. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
  452. ? ( \
  453. (1U) \
  454. ) \
  455. : \
  456. (((__COMP_INSTANCE__) == COMP2) \
  457. ? ( \
  458. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2) \
  459. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2) \
  460. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2) \
  461. ) \
  462. : \
  463. (((__COMP_INSTANCE__) == COMP4) \
  464. ? ( \
  465. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
  466. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
  467. ) \
  468. : \
  469. ( \
  470. (((__COMP_INSTANCE__) == COMP6) \
  471. ? ( \
  472. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) \
  473. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6) \
  474. ) \
  475. : \
  476. ( \
  477. (0U) \
  478. ) \
  479. ) \
  480. ) \
  481. ) \
  482. ) \
  483. )
  484. #elif defined(STM32F302xE) || defined(STM32F302xC)
  485. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  486. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
  487. ? ( \
  488. (1U) \
  489. ) \
  490. : \
  491. ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
  492. ? ( \
  493. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2) \
  494. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1_2) \
  495. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1_2) \
  496. ) \
  497. : \
  498. (((__COMP_INSTANCE__) == COMP4) \
  499. ? ( \
  500. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
  501. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
  502. ) \
  503. : \
  504. ( \
  505. (((__COMP_INSTANCE__) == COMP6) \
  506. ? ( \
  507. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6) \
  508. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6) \
  509. ) \
  510. : \
  511. ( \
  512. (0U) \
  513. ) \
  514. ) \
  515. ) \
  516. ) \
  517. ) \
  518. )
  519. #elif defined(STM32F303xE) || defined(STM32F398xx) || defined(STM32F303xC) || defined(STM32F358xx)
  520. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  521. (((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE) \
  522. ? ( \
  523. (1U) \
  524. ) \
  525. : \
  526. ((((__COMP_INSTANCE__) == COMP1) || ((__COMP_INSTANCE__) == COMP2)) \
  527. ? ( \
  528. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2_7) \
  529. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1_2) \
  530. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1_2) \
  531. ) \
  532. : \
  533. (((__COMP_INSTANCE__) == COMP3) \
  534. ? ( \
  535. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3_6) \
  536. ) \
  537. : \
  538. (((__COMP_INSTANCE__) == COMP4) \
  539. ? ( \
  540. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
  541. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4) \
  542. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4) \
  543. ) \
  544. : \
  545. (((__COMP_INSTANCE__) == COMP5) \
  546. ? ( \
  547. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
  548. ) \
  549. : \
  550. (((__COMP_INSTANCE__) == COMP6) \
  551. ? ( \
  552. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
  553. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3_6) \
  554. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6_7) \
  555. ) \
  556. : \
  557. ( \
  558. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4_5_6_7) \
  559. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1_2_7) \
  560. || ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6_7) \
  561. ) \
  562. ) \
  563. ) \
  564. ) \
  565. ) \
  566. ) \
  567. )
  568. #endif
  569. #else
  570. #define IS_LL_COMP_OUTPUT_BLANKING_SOURCE(__COMP_INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  571. ((__OUTPUT_BLANKING_SOURCE__) == LL_COMP_BLANKINGSRC_NONE)
  572. #endif
  573. /**
  574. * @}
  575. */
  576. /* Private function prototypes -----------------------------------------------*/
  577. /* Exported functions --------------------------------------------------------*/
  578. /** @addtogroup COMP_LL_Exported_Functions
  579. * @{
  580. */
  581. /** @addtogroup COMP_LL_EF_Init
  582. * @{
  583. */
  584. /**
  585. * @brief De-initialize registers of the selected COMP instance
  586. * to their default reset values.
  587. * @note If comparator is locked, de-initialization by software is
  588. * not possible.
  589. * The only way to unlock the comparator is a device hardware reset.
  590. * @param COMPx COMP instance
  591. * @retval An ErrorStatus enumeration value:
  592. * - SUCCESS: COMP registers are de-initialized
  593. * - ERROR: COMP registers are not de-initialized
  594. */
  595. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
  596. {
  597. ErrorStatus status = SUCCESS;
  598. /* Check the parameters */
  599. assert_param(IS_COMP_ALL_INSTANCE(COMPx));
  600. /* Note: Hardware constraint (refer to description of this function): */
  601. /* COMP instance must not be locked. */
  602. if(LL_COMP_IsLocked(COMPx) == 0U)
  603. {
  604. LL_COMP_WriteReg(COMPx, CSR, 0x00000000U);
  605. }
  606. else
  607. {
  608. /* Comparator instance is locked: de-initialization by software is */
  609. /* not possible. */
  610. /* The only way to unlock the comparator is a device hardware reset. */
  611. status = ERROR;
  612. }
  613. return status;
  614. }
  615. /**
  616. * @brief Initialize some features of COMP instance.
  617. * @note This function configures features of the selected COMP instance.
  618. * Some features are also available at scope COMP common instance
  619. * (common to several COMP instances).
  620. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  621. * @param COMPx COMP instance
  622. * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
  623. * @retval An ErrorStatus enumeration value:
  624. * - SUCCESS: COMP registers are initialized
  625. * - ERROR: COMP registers are not initialized
  626. */
  627. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
  628. {
  629. ErrorStatus status = SUCCESS;
  630. /* Check the parameters */
  631. assert_param(IS_COMP_ALL_INSTANCE(COMPx));
  632. assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
  633. assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
  634. assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
  635. assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
  636. assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMPx, COMP_InitStruct->OutputSelection));
  637. assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
  638. assert_param(IS_LL_COMP_OUTPUT_BLANKING_SOURCE(COMPx, COMP_InitStruct->OutputBlankingSource));
  639. /* Note: Hardware constraint (refer to description of this function) */
  640. /* COMP instance must not be locked. */
  641. if(LL_COMP_IsLocked(COMPx) == 0U)
  642. {
  643. /* Configuration of comparator instance : */
  644. /* - PowerMode */
  645. /* - InputPlus */
  646. /* - InputMinus */
  647. /* - InputHysteresis */
  648. /* - OutputSelection */
  649. /* - OutputPolarity */
  650. /* - OutputBlankingSource */
  651. MODIFY_REG(COMPx->CSR,
  652. ((uint32_t)0x00000000U)
  653. #if defined(COMP_CSR_COMPxMODE)
  654. | COMP_CSR_COMPxMODE
  655. #endif
  656. #if defined(COMP_CSR_COMPxNONINSEL)
  657. | COMP_CSR_COMPxNONINSEL
  658. #endif
  659. | COMP_CSR_COMPxINSEL
  660. #if defined(COMP_CSR_COMPxHYST)
  661. | COMP_CSR_COMPxHYST
  662. #endif
  663. | COMP_CSR_COMPxOUTSEL
  664. | COMP_CSR_COMPxPOL
  665. | COMP_CSR_COMPxBLANKING
  666. ,
  667. ((uint32_t)0x00000000U)
  668. #if defined(COMP_CSR_COMPxMODE)
  669. | COMP_InitStruct->PowerMode
  670. #endif
  671. #if defined(COMP_CSR_COMPxNONINSEL)
  672. | COMP_InitStruct->InputPlus
  673. #endif
  674. | COMP_InitStruct->InputMinus
  675. #if defined(COMP_CSR_COMPxHYST)
  676. | COMP_InitStruct->InputHysteresis
  677. #endif
  678. | COMP_InitStruct->OutputSelection
  679. | COMP_InitStruct->OutputPolarity
  680. | COMP_InitStruct->OutputBlankingSource
  681. );
  682. }
  683. else
  684. {
  685. /* Initialization error: COMP instance is locked. */
  686. status = ERROR;
  687. }
  688. return status;
  689. }
  690. /**
  691. * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
  692. * @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
  693. * whose fields will be set to default values.
  694. * @retval None
  695. */
  696. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
  697. {
  698. /* Set COMP_InitStruct fields to default values */
  699. /* Note: Comparator power mode "high speed" is the only mode */
  700. /* available on all STMF3 devices. */
  701. COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_HIGHSPEED;
  702. COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
  703. COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
  704. COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
  705. COMP_InitStruct->OutputSelection = LL_COMP_OUTPUT_NONE;
  706. COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
  707. COMP_InitStruct->OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
  708. }
  709. /**
  710. * @}
  711. */
  712. /**
  713. * @}
  714. */
  715. /**
  716. * @}
  717. */
  718. #endif /* COMP1 || COMP2 || COMP3 || COMP4 || COMP5 || COMP6 || COMP7 */
  719. #endif /* STM32F301x8 || STM32F302x8 || STM32F302xC || STM32F302xE || STM32F303x8 || STM32F303xC || STM32F303xE || STM32F318xx || STM32F328xx || STM32F334x8 || STM32F358xx || STM32F398xx */
  720. #if defined (COMP_V1_1_0_0)
  721. #if defined (COMP1) || defined (COMP2)
  722. /** @addtogroup COMP_LL COMP
  723. * @{
  724. */
  725. /* Private types -------------------------------------------------------------*/
  726. /* Private variables ---------------------------------------------------------*/
  727. /* Private constants ---------------------------------------------------------*/
  728. /* Private macros ------------------------------------------------------------*/
  729. /** @addtogroup COMP_LL_Private_Macros
  730. * @{
  731. */
  732. /* Check of parameters for configuration of COMP hierarchical scope: */
  733. /* COMP instance. */
  734. #define IS_LL_COMP_POWER_MODE(__POWER_MODE__) \
  735. ( ((__POWER_MODE__) == LL_COMP_POWERMODE_HIGHSPEED) \
  736. || ((__POWER_MODE__) == LL_COMP_POWERMODE_MEDIUMSPEED) \
  737. || ((__POWER_MODE__) == LL_COMP_POWERMODE_LOWPOWER) \
  738. || ((__POWER_MODE__) == LL_COMP_POWERMODE_ULTRALOWPOWER) \
  739. )
  740. /* Note: On this STM32 serie, comparator input plus parameters are */
  741. /* the different depending on COMP instances. */
  742. #define IS_LL_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  743. (((__COMP_INSTANCE__) == COMP1) \
  744. ? ( \
  745. ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  746. || ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_DAC1_CH1) \
  747. ) \
  748. : \
  749. ( \
  750. ((__INPUT_PLUS__) == LL_COMP_INPUT_PLUS_IO1) \
  751. ) \
  752. )
  753. /* Note: On this STM32 serie, comparator input minus parameters are */
  754. /* the same on all COMP instances. */
  755. /* However, comparator instance kept as macro parameter for */
  756. /* compatibility with other STM32 families. */
  757. #define IS_LL_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  758. ( ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_4VREFINT) \
  759. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_1_2VREFINT) \
  760. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_3_4VREFINT) \
  761. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_VREFINT) \
  762. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH1) \
  763. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC1_CH2) \
  764. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO1) \
  765. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO2) \
  766. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO3) \
  767. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_IO4) \
  768. || ((__INPUT_MINUS__) == LL_COMP_INPUT_MINUS_DAC2_CH1) \
  769. )
  770. #define IS_LL_COMP_INPUT_HYSTERESIS(__INPUT_HYSTERESIS__) \
  771. ( ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_NONE) \
  772. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_LOW) \
  773. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_MEDIUM) \
  774. || ((__INPUT_HYSTERESIS__) == LL_COMP_HYSTERESIS_HIGH) \
  775. )
  776. /* Note: Output redirection is specific to COMP instances but is checked */
  777. /* with literals of instance COMP2 (no differentiation possible since */
  778. /* literals of COMP1 and COMP2 share the same values range). */
  779. #define IS_LL_COMP_OUTPUT_SELECTION(__OUTPUT_SELECTION__) \
  780. ( ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_NONE) \
  781. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM16_BKIN) \
  782. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_IC1) \
  783. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM4_OCCLR) \
  784. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_IC4) \
  785. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM2_OCCLR) \
  786. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_IC1_COMP2) \
  787. || ((__OUTPUT_SELECTION__) == LL_COMP_OUTPUT_TIM3_OCCLR_COMP2) \
  788. )
  789. #define IS_LL_COMP_OUTPUT_POLARITY(__POLARITY__) \
  790. ( ((__POLARITY__) == LL_COMP_OUTPUTPOL_NONINVERTED) \
  791. || ((__POLARITY__) == LL_COMP_OUTPUTPOL_INVERTED) \
  792. )
  793. /**
  794. * @}
  795. */
  796. /* Private function prototypes -----------------------------------------------*/
  797. /* Exported functions --------------------------------------------------------*/
  798. /** @addtogroup COMP_LL_Exported_Functions
  799. * @{
  800. */
  801. /** @addtogroup COMP_LL_EF_Init
  802. * @{
  803. */
  804. /**
  805. * @brief De-initialize registers of the selected COMP instance
  806. * to their default reset values.
  807. * @note If comparator is locked, de-initialization by software is
  808. * not possible.
  809. * The only way to unlock the comparator is a device hardware reset.
  810. * @param COMPx COMP instance
  811. * @retval An ErrorStatus enumeration value:
  812. * - SUCCESS: COMP registers are de-initialized
  813. * - ERROR: COMP registers are not de-initialized
  814. */
  815. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx)
  816. {
  817. ErrorStatus status = SUCCESS;
  818. /* Check the parameters */
  819. assert_param(IS_COMP_ALL_INSTANCE(COMPx));
  820. /* Note: Hardware constraint (refer to description of this function): */
  821. /* COMP instance must not be locked. */
  822. if(LL_COMP_IsLocked(COMPx) == 0U)
  823. {
  824. /* Note: Connection switch is applicable only to COMP instance COMP1, */
  825. /* therefore is COMP2 is selected the equivalent bit is */
  826. /* kept unmodified. */
  827. if(COMPx == COMP1)
  828. {
  829. CLEAR_BIT(COMP->CSR,
  830. ( COMP_CSR_COMP1MODE
  831. | COMP_CSR_COMP1INSEL
  832. | COMP_CSR_COMP1SW1
  833. | COMP_CSR_COMP1OUTSEL
  834. | COMP_CSR_COMP1HYST
  835. | COMP_CSR_COMP1POL
  836. | COMP_CSR_COMP1EN
  837. ) << __COMP_BITOFFSET_INSTANCE(COMPx)
  838. );
  839. }
  840. else
  841. {
  842. CLEAR_BIT(COMP->CSR,
  843. ( COMP_CSR_COMP1MODE
  844. | COMP_CSR_COMP1INSEL
  845. | COMP_CSR_COMP1OUTSEL
  846. | COMP_CSR_COMP1HYST
  847. | COMP_CSR_COMP1POL
  848. | COMP_CSR_COMP1EN
  849. ) << __COMP_BITOFFSET_INSTANCE(COMPx)
  850. );
  851. }
  852. }
  853. else
  854. {
  855. /* Comparator instance is locked: de-initialization by software is */
  856. /* not possible. */
  857. /* The only way to unlock the comparator is a device hardware reset. */
  858. status = ERROR;
  859. }
  860. return status;
  861. }
  862. /**
  863. * @brief Initialize some features of COMP instance.
  864. * @note This function configures features of the selected COMP instance.
  865. * Some features are also available at scope COMP common instance
  866. * (common to several COMP instances).
  867. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  868. * @param COMPx COMP instance
  869. * @param COMP_InitStruct Pointer to a @ref LL_COMP_InitTypeDef structure
  870. * @retval An ErrorStatus enumeration value:
  871. * - SUCCESS: COMP registers are initialized
  872. * - ERROR: COMP registers are not initialized
  873. */
  874. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct)
  875. {
  876. ErrorStatus status = SUCCESS;
  877. /* Check the parameters */
  878. assert_param(IS_COMP_ALL_INSTANCE(COMPx));
  879. assert_param(IS_LL_COMP_POWER_MODE(COMP_InitStruct->PowerMode));
  880. assert_param(IS_LL_COMP_INPUT_PLUS(COMPx, COMP_InitStruct->InputPlus));
  881. assert_param(IS_LL_COMP_INPUT_MINUS(COMPx, COMP_InitStruct->InputMinus));
  882. assert_param(IS_LL_COMP_INPUT_HYSTERESIS(COMP_InitStruct->InputHysteresis));
  883. assert_param(IS_LL_COMP_OUTPUT_SELECTION(COMP_InitStruct->OutputSelection));
  884. assert_param(IS_LL_COMP_OUTPUT_POLARITY(COMP_InitStruct->OutputPolarity));
  885. /* Note: Hardware constraint (refer to description of this function) */
  886. /* COMP instance must not be locked. */
  887. if(LL_COMP_IsLocked(COMPx) == 0U)
  888. {
  889. /* Configuration of comparator instance : */
  890. /* - PowerMode */
  891. /* - InputPlus */
  892. /* - InputMinus */
  893. /* - InputHysteresis */
  894. /* - OutputSelection */
  895. /* - OutputPolarity */
  896. /* Note: Connection switch is applicable only to COMP instance COMP1, */
  897. /* therefore is COMP2 is selected the equivalent bit is */
  898. /* kept unmodified. */
  899. if(COMPx == COMP1)
  900. {
  901. MODIFY_REG(COMP->CSR,
  902. ( COMP_CSR_COMP1MODE
  903. | COMP_CSR_COMP1INSEL
  904. | COMP_CSR_COMP1SW1
  905. | COMP_CSR_COMP1OUTSEL
  906. | COMP_CSR_COMP1HYST
  907. | COMP_CSR_COMP1POL
  908. ) << __COMP_BITOFFSET_INSTANCE(COMPx)
  909. ,
  910. ( COMP_InitStruct->PowerMode
  911. | COMP_InitStruct->InputPlus
  912. | COMP_InitStruct->InputMinus
  913. | COMP_InitStruct->InputHysteresis
  914. | COMP_InitStruct->OutputSelection
  915. | COMP_InitStruct->OutputPolarity
  916. ) << __COMP_BITOFFSET_INSTANCE(COMPx)
  917. );
  918. }
  919. else
  920. {
  921. MODIFY_REG(COMP->CSR,
  922. ( COMP_CSR_COMP1MODE
  923. | COMP_CSR_COMP1INSEL
  924. | COMP_CSR_COMP1OUTSEL
  925. | COMP_CSR_COMP1HYST
  926. | COMP_CSR_COMP1POL
  927. ) << __COMP_BITOFFSET_INSTANCE(COMPx)
  928. ,
  929. ( COMP_InitStruct->PowerMode
  930. | COMP_InitStruct->InputPlus
  931. | COMP_InitStruct->InputMinus
  932. | COMP_InitStruct->InputHysteresis
  933. | COMP_InitStruct->OutputSelection
  934. | COMP_InitStruct->OutputPolarity
  935. ) << __COMP_BITOFFSET_INSTANCE(COMPx)
  936. );
  937. }
  938. }
  939. else
  940. {
  941. /* Initialization error: COMP instance is locked. */
  942. status = ERROR;
  943. }
  944. return status;
  945. }
  946. /**
  947. * @brief Set each @ref LL_COMP_InitTypeDef field to default value.
  948. * @param COMP_InitStruct pointer to a @ref LL_COMP_InitTypeDef structure
  949. * whose fields will be set to default values.
  950. * @retval None
  951. */
  952. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct)
  953. {
  954. /* Set COMP_InitStruct fields to default values */
  955. COMP_InitStruct->PowerMode = LL_COMP_POWERMODE_ULTRALOWPOWER;
  956. COMP_InitStruct->InputPlus = LL_COMP_INPUT_PLUS_IO1;
  957. COMP_InitStruct->InputMinus = LL_COMP_INPUT_MINUS_VREFINT;
  958. COMP_InitStruct->InputHysteresis = LL_COMP_HYSTERESIS_NONE;
  959. COMP_InitStruct->OutputSelection = LL_COMP_OUTPUT_NONE;
  960. COMP_InitStruct->OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
  961. }
  962. /**
  963. * @}
  964. */
  965. /**
  966. * @}
  967. */
  968. /**
  969. * @}
  970. */
  971. #endif /* COMP1 || COMP2 */
  972. #endif /* STM32F373xC || STM32F378xx */
  973. /**
  974. * @}
  975. */
  976. #endif /* USE_FULL_LL_DRIVER */
  977. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/