stm32f3xx_ll_comp.c 62 KB

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