py32f002b_ll_comp.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_ll_comp.h
  4. * @author MCU Application Team
  5. * @brief Header file of COMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F002B_LL_COMP_H
  32. #define __PY32F002B_LL_COMP_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F002B_LL_Driver
  39. * @{
  40. */
  41. #if defined (COMP1) || defined (COMP2)
  42. /** @defgroup COMP_LL COMP
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private constants ---------------------------------------------------------*/
  48. /** @defgroup COMP_LL_Private_Constants COMP Private Constants
  49. * @{
  50. */
  51. /* Internal mask for pair of comparators instances window mode: */
  52. /* To select into literals LL_COMP_WINDOWMODE_COMPx_INPUT_PLUS_COMMON */
  53. /* the relevant bits for: */
  54. /* (concatenation of multiple bits used in different registers) */
  55. /* - Comparator instance selected as master for window mode : register offset */
  56. /* - Window mode enable or disable: bit value */
  57. #define LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK (0x00000000U) /* Register of COMP instance odd (COMP1_CSR, ...) defined as reference register */
  58. #define LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK (0x00000004U) /* Register of COMP instance even (COMP2_CSR, ...) offset vs register of COMP instance odd */
  59. #define LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK (LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
  60. #define LL_COMP_WINDOWMODE_COMPX_SETTING_MASK (COMP_CSR_WINMODE)
  61. #define LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW (1U)
  62. /* COMP registers bits positions */
  63. #define LL_COMP_WINDOWMODE_BITOFFSET_POS (11U) /* Value equivalent to POSITION_VAL(COMP_CSR_WINMODE) */
  64. #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_COMP_OUT) */
  65. /**
  66. * @}
  67. */
  68. /* Private macros ------------------------------------------------------------*/
  69. /** @defgroup COMP_LL_Private_Macros COMP Private Macros
  70. * @{
  71. */
  72. /**
  73. * @brief Driver macro reserved for internal use: set a pointer to
  74. * a register from a register basis from which an offset
  75. * is applied.
  76. * @param __REG__ Register basis from which the offset is applied.
  77. * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
  78. * @retval Pointer to register address
  79. */
  80. #define __COMP_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
  81. ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2U))))
  82. /**
  83. * @}
  84. */
  85. /* Exported types ------------------------------------------------------------*/
  86. #if defined(USE_FULL_LL_DRIVER)
  87. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  88. * @{
  89. */
  90. /**
  91. * @brief Structure definition of some features of COMP instance.
  92. */
  93. typedef struct
  94. {
  95. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  96. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  97. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  98. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  99. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  100. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  101. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  102. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  103. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
  104. uint32_t DigitalFilter; /*!< Specifies the digital filter.
  105. This parameter must be a number between 0 and 0xFFFF
  106. The filter is prohibited,when the value is zero.
  107. This feature can be modified afterwards using unitary function @ref LL_COMP_SetDigitalFilter(). */
  108. } LL_COMP_InitTypeDef;
  109. /**
  110. * @}
  111. */
  112. #endif /* USE_FULL_LL_DRIVER */
  113. /* Exported constants --------------------------------------------------------*/
  114. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  115. * @{
  116. */
  117. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  118. * @{
  119. */
  120. #define LL_COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
  121. #define LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window mode enable: if used from COMP1 or COMP2 instance, comparators instances pair COMP1 and COMP2 have their input plus connected together, the common input is COMP2 input plus (COMP1 input plus is no more accessible). */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  126. * @{
  127. */
  128. #define LL_COMP_INPUT_PLUS_IO1 (0x00000000U) /*!< Comparator input plus connected to IO1 (Reserved for COMP1, pin PA3 for COMP2) */
  129. #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL) /*!< Comparator input plus connected to IO2 (Reserved for COMP1, VREFCMP for COMP2) */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  134. * @{
  135. */
  136. #define LL_COMP_INPUT_MINUS_IO1 (0x00000000U) /*!< Comparator input minus connected to IO1 (pin PB0 for COMP1, pin PA4 for COMP2) */
  137. #define LL_COMP_INPUT_MINUS_IO2 (COMP_CSR_INNSEL) /*!< Comparator input minus connected to IO2 (pin PB1 for COMP1, pin PA3 for COMP2) */
  138. /**
  139. * @}
  140. */
  141. /** @defgroup COMP_LL_EC_VREFCMP_DIV Comparator Vrefcmp div
  142. * @{
  143. */
  144. #define LL_COMP_VREFCMP_DIV_1_16VREFCMP (0x00000000U)
  145. #define LL_COMP_VREFCMP_DIV_2_16VREFCMP ( COMP_CSR_COMP_VCDIV_0)
  146. #define LL_COMP_VREFCMP_DIV_3_16VREFCMP ( COMP_CSR_COMP_VCDIV_1 )
  147. #define LL_COMP_VREFCMP_DIV_4_16VREFCMP ( COMP_CSR_COMP_VCDIV_1 | COMP_CSR_COMP_VCDIV_0)
  148. #define LL_COMP_VREFCMP_DIV_5_16VREFCMP ( COMP_CSR_COMP_VCDIV_2 )
  149. #define LL_COMP_VREFCMP_DIV_6_16VREFCMP ( COMP_CSR_COMP_VCDIV_2 | COMP_CSR_COMP_VCDIV_0)
  150. #define LL_COMP_VREFCMP_DIV_7_16VREFCMP ( COMP_CSR_COMP_VCDIV_2 | COMP_CSR_COMP_VCDIV_1 )
  151. #define LL_COMP_VREFCMP_DIV_8_16VREFCMP ( COMP_CSR_COMP_VCDIV_2 | COMP_CSR_COMP_VCDIV_1 | COMP_CSR_COMP_VCDIV_0)
  152. #define LL_COMP_VREFCMP_DIV_9_16VREFCMP (COMP_CSR_COMP_VCDIV_3 )
  153. #define LL_COMP_VREFCMP_DIV_10_16VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_0)
  154. #define LL_COMP_VREFCMP_DIV_11_16VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_1 )
  155. #define LL_COMP_VREFCMP_DIV_12_16VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_1 | COMP_CSR_COMP_VCDIV_0)
  156. #define LL_COMP_VREFCMP_DIV_13_16VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_2 )
  157. #define LL_COMP_VREFCMP_DIV_14_16VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_2 | COMP_CSR_COMP_VCDIV_0)
  158. #define LL_COMP_VREFCMP_DIV_15_16VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_2 | COMP_CSR_COMP_VCDIV_1 )
  159. #define LL_COMP_VREFCMP_DIV_VREFCMP (COMP_CSR_COMP_VCDIV_3 | COMP_CSR_COMP_VCDIV_2 | COMP_CSR_COMP_VCDIV_1 | COMP_CSR_COMP_VCDIV_0)
  160. /**
  161. * @}
  162. */
  163. /** @defgroup COMP_LL_EC_VREFCMP_SRC Comparator Vrefcmp source
  164. * @{
  165. */
  166. #define LL_COMP_VREFCMP_SOURCE_VREFBUF (0x00000000U)
  167. #define LL_COMP_VREFCMP_SOURCE_VCC (COMP_CSR_COMP_VCSEL)
  168. /**
  169. * @}
  170. */
  171. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  172. * @{
  173. */
  174. #define LL_COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< COMP output polarity is not inverted: comparator output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */
  175. #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY) /*!< COMP output polarity is inverted: comparator output is low when the plus (non-inverting) input is at a lower voltage than the minus (inverting) input */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  180. * @{
  181. */
  182. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  183. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  184. /**
  185. * @}
  186. */
  187. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  188. * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
  189. * not timeout values.
  190. * For details on delays values, refer to descriptions in source code
  191. * above each literal definition.
  192. * @{
  193. */
  194. /* Delay for comparator startup time. */
  195. /* Note: Delay required to reach propagation delay specification. */
  196. /* Literal set to maximum value (refer to device datasheet, */
  197. /* parameter "tSTART"). */
  198. /* Unit: us */
  199. #define LL_COMP_DELAY_STARTUP_US ( 80U) /*!< Delay for COMP startup time */
  200. /* Delay for comparator voltage scaler stabilization time. */
  201. /* Note: Voltage scaler is used when selecting comparator input */
  202. /* based on VrefInt: VrefInt or subdivision of VrefInt. */
  203. /* Literal set to maximum value (refer to device datasheet, */
  204. /* parameter "tSTART_SCALER"). */
  205. /* Unit: us */
  206. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200U) /*!< Delay for COMP voltage scaler stabilization time */
  207. /**
  208. * @}
  209. */
  210. /**
  211. * @}
  212. */
  213. /* Exported macro ------------------------------------------------------------*/
  214. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  215. * @{
  216. */
  217. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  218. * @{
  219. */
  220. /**
  221. * @brief Write a value in COMP register
  222. * @param __INSTANCE__ comparator instance
  223. * @param __REG__ Register to be written
  224. * @param __VALUE__ Value to be written in the register
  225. * @retval None
  226. */
  227. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  228. /**
  229. * @brief Read a value in COMP register
  230. * @param __INSTANCE__ comparator instance
  231. * @param __REG__ Register to be read
  232. * @retval Register value
  233. */
  234. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  235. /**
  236. * @}
  237. */
  238. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  239. * @{
  240. */
  241. /**
  242. * @brief Helper macro to select the COMP common instance
  243. * to which is belonging the selected COMP instance.
  244. * @note COMP common register instance can be used to
  245. * set parameters common to several COMP instances.
  246. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  247. * @param __COMPx__ COMP instance
  248. * @retval COMP common instance or value "0" if there is no COMP common instance.
  249. */
  250. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) (COMP12_COMMON)
  251. /**
  252. * @}
  253. */
  254. /**
  255. * @}
  256. */
  257. /* Exported functions --------------------------------------------------------*/
  258. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  259. * @{
  260. */
  261. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  262. * @{
  263. */
  264. /**
  265. * @brief Set window mode of a pair of comparators instances
  266. * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
  267. * @param COMPxy_COMMON Comparator common instance
  268. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  269. * @param WindowMode This parameter can be one of the following values:
  270. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  271. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  272. * @retval None
  273. */
  274. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  275. {
  276. uint32_t window_mode_tmp = WindowMode;
  277. __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
  278. /* Clear the potential previous setting of window mode */
  279. __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (~(window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK));
  280. CLEAR_BIT(*preg_clear,COMP_CSR_WINMODE);
  281. /* Set window mode */
  282. MODIFY_REG(*preg, COMP_CSR_WINMODE,(window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_SETTING_MASK));
  283. }
  284. /**
  285. * @brief Get window mode of a pair of comparators instances
  286. * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
  287. * @param COMPxy_COMMON Comparator common instance
  288. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  289. * @retval Returned value can be one of the following values:
  290. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  291. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  292. *
  293. */
  294. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  295. {
  296. const uint32_t window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
  297. const uint32_t window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
  298. return (uint32_t)(window_mode_comp_odd | window_mode_comp_even
  299. | ((window_mode_comp_even >> LL_COMP_WINDOWMODE_BITOFFSET_POS) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK));
  300. }
  301. /**
  302. * @}
  303. */
  304. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  305. * @{
  306. */
  307. /**
  308. * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
  309. * @note In case of comparator input selected to be connected to IO:
  310. * GPIO pins are specific to each comparator instance.
  311. * Refer to description of parameters or to reference manual.
  312. * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
  313. * CSR INPSEL LL_COMP_ConfigInputs
  314. * @param COMPx Comparator instance
  315. * @param InputMinus This parameter can be one of the following values:
  316. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  317. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  318. * @param InputPlus This parameter can be one of the following values:
  319. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  320. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  321. * @retval None
  322. */
  323. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  324. {
  325. MODIFY_REG(COMPx->CSR,COMP_CSR_INNSEL | COMP_CSR_INPSEL,InputMinus | InputPlus);
  326. }
  327. /**
  328. * @brief Set comparator input plus (non-inverting).
  329. * @note In case of comparator input selected to be connected to IO:
  330. * GPIO pins are specific to each comparator instance.
  331. * Refer to description of parameters or to reference manual.
  332. * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
  333. * @param COMPx Comparator instance
  334. * @param InputPlus This parameter can be one of the following values:
  335. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  336. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  337. * @retval None
  338. */
  339. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  340. {
  341. MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
  342. }
  343. /**
  344. * @brief Get comparator input plus (non-inverting).
  345. * @note In case of comparator input selected to be connected to IO:
  346. * GPIO pins are specific to each comparator instance.
  347. * Refer to description of parameters or to reference manual.
  348. * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
  349. * @param COMPx Comparator instance
  350. * @retval Returned value can be one of the following values:
  351. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  352. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  353. */
  354. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  355. {
  356. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
  357. }
  358. /**
  359. * @brief Set comparator input minus (inverting).
  360. * @note In case of comparator input selected to be connected to IO:
  361. * GPIO pins are specific to each comparator instance.
  362. * Refer to description of parameters or to reference manual.
  363. * @rmtoll CSR INMSEL LL_COMP_SetInputMinus
  364. * @param COMPx Comparator instance
  365. * @param InputMinus This parameter can be one of the following values:
  366. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  367. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  368. * @retval None
  369. */
  370. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  371. {
  372. MODIFY_REG(COMPx->CSR, COMP_CSR_INNSEL, InputMinus);
  373. }
  374. /**
  375. * @brief Get comparator input minus (inverting).
  376. * @note In case of comparator input selected to be connected to IO:
  377. * GPIO pins are specific to each comparator instance.
  378. * Refer to description of parameters or to reference manual.
  379. * @rmtoll CSR INMSEL LL_COMP_GetInputMinus
  380. * @param COMPx Comparator instance
  381. * @retval Returned value can be one of the following values:
  382. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  383. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  384. */
  385. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  386. {
  387. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INNSEL));
  388. }
  389. /**
  390. * @brief Enable comparator VrefCmp Divider
  391. * @rmtoll CSR COMP_CSR_VCDIV_EN LL_COMP_EnableVrefCmpDivider
  392. * @param COMPx Comparator instance
  393. * @retval None
  394. */
  395. __STATIC_INLINE void LL_COMP_EnableVrefCmpDivider(COMP_TypeDef *COMPx)
  396. {
  397. SET_BIT(COMP1->CSR, COMP_CSR_COMP_VCDIV_EN);
  398. }
  399. /**
  400. * @brief Disable comparator VrefCmp Divider
  401. * @rmtoll CSR COMP_CSR_COMP_VCDIV_EN LL_COMP_DisableVrefCmpDivider
  402. * @param COMPx Comparator instance
  403. * @retval None
  404. */
  405. __STATIC_INLINE void LL_COMP_DisableVrefCmpDivider(COMP_TypeDef *COMPx)
  406. {
  407. CLEAR_BIT(COMP1->CSR, COMP_CSR_COMP_VCDIV_EN);
  408. }
  409. /**
  410. * @brief Get comparator VrefCmp Divider enable state
  411. * (0: VrefCmp Divider is disabled, 1: VrefCmp Divider is enabled)
  412. * @rmtoll CSR COMP_CSR_COMP_VCDIV_EN LL_COMP_IsEnabledVrefCmpDivider
  413. * @param COMPx Comparator instance
  414. * @retval State of bit (1 or 0).
  415. */
  416. __STATIC_INLINE uint32_t LL_COMP_IsEnabledVrefCmpDivider(COMP_TypeDef *COMPx)
  417. {
  418. return ((READ_BIT(COMP1->CSR, COMP_CSR_COMP_VCDIV_EN) == (COMP_CSR_COMP_VCDIV_EN)) ? 1U : 0U);
  419. }
  420. /**
  421. * @brief Set comparator VrefCmp voltage divider configuration.
  422. * @rmtoll CSR COMP_CSR_COMP_VCDIV LL_COMP_SetVrefCmpDivider
  423. * @param COMPx Comparator instance
  424. * @param VrefCmpDiv can be one of the following values:
  425. * @arg @ref LL_COMP_VREFCMP_DIV_1_16VREFCMP
  426. * @arg @ref LL_COMP_VREFCMP_DIV_2_16VREFCMP
  427. * @arg @ref LL_COMP_VREFCMP_DIV_3_16VREFCMP
  428. * @arg @ref LL_COMP_VREFCMP_DIV_4_16VREFCMP
  429. * @arg @ref LL_COMP_VREFCMP_DIV_5_16VREFCMP
  430. * @arg @ref LL_COMP_VREFCMP_DIV_6_16VREFCMP
  431. * @arg @ref LL_COMP_VREFCMP_DIV_7_16VREFCMP
  432. * @arg @ref LL_COMP_VREFCMP_DIV_8_16VREFCMP
  433. * @arg @ref LL_COMP_VREFCMP_DIV_9_16VREFCMP
  434. * @arg @ref LL_COMP_VREFCMP_DIV_10_16VREFCMP
  435. * @arg @ref LL_COMP_VREFCMP_DIV_11_16VREFCMP
  436. * @arg @ref LL_COMP_VREFCMP_DIV_12_16VREFCMP
  437. * @arg @ref LL_COMP_VREFCMP_DIV_13_16VREFCMP
  438. * @arg @ref LL_COMP_VREFCMP_DIV_14_16VREFCMP
  439. * @arg @ref LL_COMP_VREFCMP_DIV_15_16VREFCMP
  440. * @arg @ref LL_COMP_VREFCMP_DIV_VREFCMP
  441. * @retval None
  442. */
  443. __STATIC_INLINE void LL_COMP_SetVrefCmpDivider(COMP_TypeDef *COMPx, uint32_t VrefCmpDiv)
  444. {
  445. MODIFY_REG(COMP1->CSR, COMP_CSR_COMP_VCDIV, VrefCmpDiv);
  446. }
  447. /**
  448. * @brief Get comparator VREFCMP voltage divider configuration.
  449. * @rmtoll CSR COMP_CSR_COMP_VCDIV LL_COMP_GetVrefCmpDivider
  450. * @param COMPx Comparator instance
  451. * @retval Returned value can be one of the following values:
  452. * @arg @ref LL_COMP_VREFCMP_DIV_1_16VREFCMP
  453. * @arg @ref LL_COMP_VREFCMP_DIV_2_16VREFCMP
  454. * @arg @ref LL_COMP_VREFCMP_DIV_3_16VREFCMP
  455. * @arg @ref LL_COMP_VREFCMP_DIV_4_16VREFCMP
  456. * @arg @ref LL_COMP_VREFCMP_DIV_5_16VREFCMP
  457. * @arg @ref LL_COMP_VREFCMP_DIV_6_16VREFCMP
  458. * @arg @ref LL_COMP_VREFCMP_DIV_7_16VREFCMP
  459. * @arg @ref LL_COMP_VREFCMP_DIV_8_16VREFCMP
  460. * @arg @ref LL_COMP_VREFCMP_DIV_9_16VREFCMP
  461. * @arg @ref LL_COMP_VREFCMP_DIV_10_16VREFCMP
  462. * @arg @ref LL_COMP_VREFCMP_DIV_11_16VREFCMP
  463. * @arg @ref LL_COMP_VREFCMP_DIV_12_16VREFCMP
  464. * @arg @ref LL_COMP_VREFCMP_DIV_13_16VREFCMP
  465. * @arg @ref LL_COMP_VREFCMP_DIV_14_16VREFCMP
  466. * @arg @ref LL_COMP_VREFCMP_DIV_15_16VREFCMP
  467. * @arg @ref LL_COMP_VREFCMP_DIV_VREFCMP
  468. */
  469. __STATIC_INLINE uint32_t LL_COMP_GetVrefCmpDivider(COMP_TypeDef *COMPx)
  470. {
  471. return (uint32_t)(READ_BIT(COMP1->CSR, COMP_CSR_COMP_VCDIV));
  472. }
  473. /**
  474. * @brief Set comparator VrefCmp reference source selection.
  475. * @rmtoll CSR COMP_CSR_COMP_VCSEL LL_COMP_SetVrefCmpSource
  476. * @param COMPx Comparator instance
  477. * @param VrefCmpSource can be one of the following values:
  478. * @arg @ref LL_COMP_VREFCMP_SOURCE_VREFBUF
  479. * @arg @ref LL_COMP_VREFCMP_SOURCE_VCC
  480. * @retval None
  481. */
  482. __STATIC_INLINE void LL_COMP_SetVrefCmpSource(COMP_TypeDef *COMPx, uint32_t VrefCmpSource)
  483. {
  484. MODIFY_REG(COMP1->CSR, COMP_CSR_COMP_VCSEL, VrefCmpSource);
  485. }
  486. /**
  487. * @brief Get comparator VrefCmp reference source selection.
  488. * @rmtoll CSR COMP_CSR_COMP_VCSEL LL_COMP_GetVrefCmpSource
  489. * @param COMPx Comparator instance
  490. * @retval Returned value can be one of the following values:
  491. * @arg @ref LL_COMP_VREFCMP_SOURCE_VREFBUF
  492. * @arg @ref LL_COMP_VREFCMP_SOURCE_VCC
  493. */
  494. __STATIC_INLINE uint32_t LL_COMP_GetVrefCmpSource(COMP_TypeDef *COMPx)
  495. {
  496. return (uint32_t)(READ_BIT(COMP1->CSR, COMP_CSR_COMP_VCSEL));
  497. }
  498. /**
  499. * @}
  500. */
  501. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  502. * @{
  503. */
  504. /**
  505. * @brief Set comparator instance output polarity.
  506. * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
  507. * @param COMPx Comparator instance
  508. * @param OutputPolarity This parameter can be one of the following values:
  509. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  510. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  511. * @retval None
  512. */
  513. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  514. {
  515. MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
  516. }
  517. /**
  518. * @brief Get comparator instance output polarity.
  519. * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
  520. * @param COMPx Comparator instance
  521. * @retval Returned value can be one of the following values:
  522. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  523. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  524. */
  525. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
  526. {
  527. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
  528. }
  529. /**
  530. * @}
  531. */
  532. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  533. * @{
  534. */
  535. /**
  536. * @brief Enable comparator instance.
  537. * @note After enable from off state, comparator requires a delay
  538. * to reach reach propagation delay specification.
  539. * Refer to device datasheet, parameter "tSTART".
  540. * @rmtoll CSR EN LL_COMP_Enable
  541. * @param COMPx Comparator instance
  542. * @retval None
  543. */
  544. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  545. {
  546. SET_BIT(COMPx->CSR, COMP_CSR_EN);
  547. }
  548. /**
  549. * @brief Disable comparator instance.
  550. * @rmtoll CSR EN LL_COMP_Disable
  551. * @param COMPx Comparator instance
  552. * @retval None
  553. */
  554. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  555. {
  556. CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
  557. }
  558. /**
  559. * @brief Get comparator enable state
  560. * (0: COMP is disabled, 1: COMP is enabled)
  561. * @rmtoll CSR EN LL_COMP_IsEnabled
  562. * @param COMPx Comparator instance
  563. * @retval State of bit (1 or 0).
  564. */
  565. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  566. {
  567. return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1U : 0U);
  568. }
  569. /**
  570. * @brief Read comparator instance output level.
  571. * @note The comparator output level depends on the selected polarity
  572. * (Refer to function @ref LL_COMP_SetOutputPolarity()).
  573. * If the comparator polarity is not inverted:
  574. * - Comparator output is low when the input plus
  575. * is at a lower voltage than the input minus
  576. * - Comparator output is high when the input plus
  577. * is at a higher voltage than the input minus
  578. * If the comparator polarity is inverted:
  579. * - Comparator output is high when the input plus
  580. * is at a lower voltage than the input minus
  581. * - Comparator output is low when the input plus
  582. * is at a higher voltage than the input minus
  583. * @rmtoll CSR COMP_CSR_COMP_OUT LL_COMP_ReadOutputLevel
  584. * @param COMPx Comparator instance
  585. * @retval Returned value can be one of the following values:
  586. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  587. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  588. */
  589. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  590. {
  591. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP_OUT)>> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
  592. }
  593. /**
  594. * @}
  595. */
  596. /** @defgroup COMP_LL_EF_DigitalFilter DigitalFilter on comparator instance
  597. * @{
  598. */
  599. /**
  600. * @brief Enable comparator DigitalFilter.
  601. * @rmtoll FR FLTEN LL_COMP_EnableDigitalFilter
  602. * @param COMPx Comparator instance
  603. * @retval None
  604. */
  605. __STATIC_INLINE void LL_COMP_EnableDigitalFilter(COMP_TypeDef *COMPx)
  606. {
  607. SET_BIT(COMPx->FR, COMP_FR_FLTEN);
  608. }
  609. /**
  610. * @brief Disable comparator DigitalFilter.
  611. * @rmtoll FR FLTEN LL_COMP_DisableDigitalFilter
  612. * @param COMPx Comparator instance
  613. * @retval None
  614. */
  615. __STATIC_INLINE void LL_COMP_DisableDigitalFilter(COMP_TypeDef *COMPx)
  616. {
  617. CLEAR_BIT(COMPx->FR, COMP_FR_FLTEN);
  618. }
  619. /**
  620. * @brief Get comparator DigitalFilter state
  621. * (0: Filter is Disabled, 1: Filter is Enabled).
  622. * @rmtoll FR FLTEN LL_COMP_IsEnabledDigitalFilter
  623. * @param COMPx Comparator instance
  624. * @retval State of bit (1 or 0).
  625. */
  626. __STATIC_INLINE uint32_t LL_COMP_IsEnabledDigitalFilter(COMP_TypeDef *COMPx)
  627. {
  628. return ((READ_BIT(COMPx->FR, COMP_FR_FLTEN) == (COMP_FR_FLTEN)) ? 1U : 0U);
  629. }
  630. /**
  631. * @brief Set comparator DigitalFilter Value.
  632. * @rmtoll FR FLTCNT LL_COMP_SetDigitalFilter
  633. * @param COMPx Comparator instance
  634. * @param FLTCNTValue DigitalFilter Value between Min_Data=0x0000 and Max_Data=0xFFFF
  635. * @retval None
  636. */
  637. __STATIC_INLINE void LL_COMP_SetDigitalFilter(COMP_TypeDef *COMPx,uint32_t FLTCNTValue)
  638. {
  639. MODIFY_REG(COMPx->FR,COMP_FR_FLTCNT,FLTCNTValue << COMP_FR_FLTCNT_Pos);
  640. }
  641. /**
  642. * @brief Get comparator DigitalFilter Value
  643. * @rmtoll FR FLTCNT LL_COMP_GetDigitalFilter
  644. * @param COMPx Comparator instance
  645. * @retval DigitalFilter Value between Min_Data=0x0000 and Max_Data=0xFFFF
  646. */
  647. __STATIC_INLINE uint32_t LL_COMP_GetDigitalFilter(COMP_TypeDef *COMPx)
  648. {
  649. return (uint32_t)(READ_REG(COMPx->FR)>>COMP_FR_FLTCNT_Pos);
  650. }
  651. /**
  652. * @}
  653. */
  654. #if defined(USE_FULL_LL_DRIVER)
  655. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  656. * @{
  657. */
  658. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  659. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  660. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  661. /**
  662. * @}
  663. */
  664. #endif /* USE_FULL_LL_DRIVER */
  665. /**
  666. * @}
  667. */
  668. /**
  669. * @}
  670. */
  671. #endif /* COMP1 || COMP2 */
  672. /**
  673. * @}
  674. */
  675. #ifdef __cplusplus
  676. }
  677. #endif
  678. #endif /* PY32F002B_LL_COMP_H */
  679. /************************ (C) COPYRIGHT Puya *****END OF FILE****/