py32f0xx_ll_comp.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_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 __PY32F0XX_LL_COMP_H
  32. #define __PY32F0XX_LL_COMP_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F0xx_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 PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  96. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  97. This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
  98. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  99. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  100. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  101. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  102. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  103. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  104. uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
  105. This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
  106. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
  107. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  108. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  109. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
  110. uint32_t DigitalFilter; /*!< Specifies the digital filter.
  111. This parameter must be a number between 0 and 0xFFFF
  112. The filter is prohibited,when the value is zero.
  113. This feature can be modified afterwards using unitary function @ref LL_COMP_SetDigitalFilter(). */
  114. } LL_COMP_InitTypeDef;
  115. /**
  116. * @}
  117. */
  118. #endif /* USE_FULL_LL_DRIVER */
  119. /* Exported constants --------------------------------------------------------*/
  120. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  121. * @{
  122. */
  123. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  124. * @{
  125. */
  126. #define LL_COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
  127. #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
  128. #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). If used from COMP3 instance (when available), comparators instances pair COMP2 and COMP3 have their input plus connected together, the common input is COMP2 input plus (COMP3 input plus is no more accessible). */
  129. /**
  130. * @}
  131. */
  132. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  133. * @{
  134. */
  135. #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000U) /*!< COMP power mode to high speed */
  136. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */
  137. /**
  138. * @}
  139. */
  140. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  141. * @{
  142. */
  143. #define LL_COMP_INPUT_PLUS_IO1 (0x00000000U) /*!< Comparator input plus connected to IO1 (pin PB8 for COMP1, pin PB4 for COMP2) */
  144. #define LL_COMP_INPUT_PLUS_IO2 ( COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
  145. #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1 ) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
  146. #define LL_COMP_INPUT_PLUS_IO4 (COMP_CSR_INPSEL_1|COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO4 (Reserved for COMP1, pin PF3 for COMP2) */
  147. /**
  148. * @}
  149. */
  150. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  151. * @{
  152. */
  153. #define LL_COMP_INPUT_MINUS_1_4VREFINT (0x00000000U) /*!< Comparator input minus connected to 1/4 VrefInt */
  154. #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */
  155. #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */
  156. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
  157. #define LL_COMP_INPUT_MINUS_VCC ( COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to VCC */
  158. #define LL_COMP_INPUT_MINUS_TS ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to TS */
  159. #define LL_COMP_INPUT_MINUS_IO1 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */
  160. #define LL_COMP_INPUT_MINUS_IO2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (Reserved for COMP1, pin PB7 for COMP2) */
  161. #define LL_COMP_INPUT_MINUS_IO3 (COMP_CSR_INMSEL_3 ) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
  162. /**
  163. * @}
  164. */
  165. /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
  166. * @{
  167. */
  168. #define LL_COMP_HYSTERESIS_DISABLE (0x00000000U) /*!< No hysteresis */
  169. #define LL_COMP_HYSTERESIS_ENABLE (COMP_CSR_HYST) /*!< Hysteresis enable */
  170. /**
  171. * @}
  172. */
  173. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  174. * @{
  175. */
  176. #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 */
  177. #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 */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  182. * @{
  183. */
  184. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  185. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  190. * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
  191. * not timeout values.
  192. * For details on delays values, refer to descriptions in source code
  193. * above each literal definition.
  194. * @{
  195. */
  196. /* Delay for comparator startup time. */
  197. /* Note: Delay required to reach propagation delay specification. */
  198. /* Literal set to maximum value (refer to device datasheet, */
  199. /* parameter "tSTART"). */
  200. /* Unit: us */
  201. #define LL_COMP_DELAY_STARTUP_US ( 80U) /*!< Delay for COMP startup time */
  202. /* Delay for comparator voltage scaler stabilization time. */
  203. /* Note: Voltage scaler is used when selecting comparator input */
  204. /* based on VrefInt: VrefInt or subdivision of VrefInt. */
  205. /* Literal set to maximum value (refer to device datasheet, */
  206. /* parameter "tSTART_SCALER"). */
  207. /* Unit: us */
  208. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200U) /*!< Delay for COMP voltage scaler stabilization time */
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */
  215. /* Exported macro ------------------------------------------------------------*/
  216. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  217. * @{
  218. */
  219. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  220. * @{
  221. */
  222. /**
  223. * @brief Write a value in COMP register
  224. * @param __INSTANCE__ comparator instance
  225. * @param __REG__ Register to be written
  226. * @param __VALUE__ Value to be written in the register
  227. * @retval None
  228. */
  229. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  230. /**
  231. * @brief Read a value in COMP register
  232. * @param __INSTANCE__ comparator instance
  233. * @param __REG__ Register to be read
  234. * @retval Register value
  235. */
  236. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  237. /**
  238. * @}
  239. */
  240. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  241. * @{
  242. */
  243. /**
  244. * @brief Helper macro to select the COMP common instance
  245. * to which is belonging the selected COMP instance.
  246. * @note COMP common register instance can be used to
  247. * set parameters common to several COMP instances.
  248. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  249. * @param __COMPx__ COMP instance
  250. * @retval COMP common instance or value "0" if there is no COMP common instance.
  251. */
  252. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) (COMP12_COMMON)
  253. /**
  254. * @}
  255. */
  256. /**
  257. * @}
  258. */
  259. /* Exported functions --------------------------------------------------------*/
  260. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  261. * @{
  262. */
  263. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  264. * @{
  265. */
  266. /**
  267. * @brief Set window mode of a pair of comparators instances
  268. * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
  269. * @param COMPxy_COMMON Comparator common instance
  270. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  271. * @param WindowMode This parameter can be one of the following values:
  272. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  273. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  274. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  275. * @retval None
  276. */
  277. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  278. {
  279. uint32_t window_mode_tmp = WindowMode;
  280. /* Note: On this PY32 series, window mode can be set from any instance */
  281. /* of the pair of comparator instances. */
  282. __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
  283. /* Clear the potential previous setting of window mode */
  284. __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));
  285. CLEAR_BIT(*preg_clear,COMP_CSR_WINMODE);
  286. /* Set window mode */
  287. MODIFY_REG(*preg, COMP_CSR_WINMODE,(window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_SETTING_MASK));
  288. }
  289. /**
  290. * @brief Get window mode of a pair of comparators instances
  291. * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
  292. * @param COMPxy_COMMON Comparator common instance
  293. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  294. * @retval Returned value can be one of the following values:
  295. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  296. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  297. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  298. *
  299. */
  300. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  301. {
  302. /* Note: On this PY32 series, window mode can be set from any instance */
  303. /* of the pair of comparator instances. */
  304. const uint32_t window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
  305. const uint32_t window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
  306. return (uint32_t)(window_mode_comp_odd | window_mode_comp_even
  307. | ((window_mode_comp_even >> LL_COMP_WINDOWMODE_BITOFFSET_POS) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK));
  308. }
  309. /**
  310. * @}
  311. */
  312. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  313. * @{
  314. */
  315. /**
  316. * @brief Set comparator instance operating mode to adjust power and speed.
  317. * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode
  318. * @param COMPx Comparator instance
  319. * @param PowerMode This parameter can be one of the following values:
  320. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  321. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  322. * @retval None
  323. */
  324. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  325. {
  326. MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
  327. }
  328. /**
  329. * @brief Get comparator instance operating mode to adjust power and speed.
  330. * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode
  331. * @param COMPx Comparator instance
  332. * @retval Returned value can be one of the following values:
  333. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  334. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  335. */
  336. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
  337. {
  338. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
  339. }
  340. /**
  341. * @}
  342. */
  343. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  344. * @{
  345. */
  346. /**
  347. * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
  348. * @note In case of comparator input selected to be connected to IO:
  349. * GPIO pins are specific to each comparator instance.
  350. * Refer to description of parameters or to reference manual.
  351. * @note On this PY32 series, a voltage scaler is used
  352. * when COMP input is based on VrefInt (VrefInt or subdivision
  353. * of VrefInt):
  354. * Voltage scaler requires a delay for voltage stabilization.
  355. * Refer to device datasheet, parameter "tSTART_SCALER".
  356. * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
  357. * CSR INPSEL LL_COMP_ConfigInputs
  358. * @param COMPx Comparator instance
  359. * @param InputMinus This parameter can be one of the following values:
  360. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  361. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  362. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  363. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  364. * @arg @ref LL_COMP_INPUT_MINUS_VCC
  365. * @arg @ref LL_COMP_INPUT_MINUS_TS
  366. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  367. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  368. * @arg @ref LL_COMP_INPUT_MINUS_IO3
  369. * @param InputPlus This parameter can be one of the following values:
  370. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  371. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  372. * @arg @ref LL_COMP_INPUT_PLUS_IO3
  373. * @arg @ref LL_COMP_INPUT_PLUS_IO4
  374. * @retval None
  375. */
  376. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  377. {
  378. MODIFY_REG(COMPx->CSR,COMP_CSR_INMSEL | COMP_CSR_INPSEL,InputMinus | InputPlus);
  379. }
  380. /**
  381. * @brief Set comparator input plus (non-inverting).
  382. * @note In case of comparator input selected to be connected to IO:
  383. * GPIO pins are specific to each comparator instance.
  384. * Refer to description of parameters or to reference manual.
  385. * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
  386. * @param COMPx Comparator instance
  387. * @param InputPlus This parameter can be one of the following values:
  388. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  389. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  390. * @arg @ref LL_COMP_INPUT_PLUS_IO3
  391. * @arg @ref LL_COMP_INPUT_PLUS_IO4
  392. * @retval None
  393. */
  394. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  395. {
  396. MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
  397. }
  398. /**
  399. * @brief Get comparator input plus (non-inverting).
  400. * @note In case of comparator input selected to be connected to IO:
  401. * GPIO pins are specific to each comparator instance.
  402. * Refer to description of parameters or to reference manual.
  403. * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
  404. * @param COMPx Comparator instance
  405. * @retval Returned value can be one of the following values:
  406. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  407. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  408. * @arg @ref LL_COMP_INPUT_PLUS_IO3
  409. * @arg @ref LL_COMP_INPUT_PLUS_IO4
  410. */
  411. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  412. {
  413. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
  414. }
  415. /**
  416. * @brief Set comparator input minus (inverting).
  417. * @note In case of comparator input selected to be connected to IO:
  418. * GPIO pins are specific to each comparator instance.
  419. * Refer to description of parameters or to reference manual.
  420. * @note On this PY32 series, a voltage scaler is used
  421. * when COMP input is based on VrefInt (VrefInt or subdivision
  422. * of VrefInt):
  423. * Voltage scaler requires a delay for voltage stabilization.
  424. * Refer to device datasheet, parameter "tSTART_SCALER".
  425. * @rmtoll CSR INMSEL LL_COMP_SetInputMinus
  426. * @param COMPx Comparator instance
  427. * @param InputMinus This parameter can be one of the following values:
  428. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  429. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  430. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  431. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  432. * @arg @ref LL_COMP_INPUT_MINUS_VCC
  433. * @arg @ref LL_COMP_INPUT_MINUS_TS
  434. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  435. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  436. * @arg @ref LL_COMP_INPUT_MINUS_IO3
  437. * @retval None
  438. */
  439. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  440. {
  441. MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL, InputMinus);
  442. }
  443. /**
  444. * @brief Get comparator input minus (inverting).
  445. * @note In case of comparator input selected to be connected to IO:
  446. * GPIO pins are specific to each comparator instance.
  447. * Refer to description of parameters or to reference manual.
  448. * @rmtoll CSR INMSEL LL_COMP_GetInputMinus
  449. * @param COMPx Comparator instance
  450. * @retval Returned value can be one of the following values:
  451. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  452. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  453. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  454. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  455. * @arg @ref LL_COMP_INPUT_MINUS_VCC
  456. * @arg @ref LL_COMP_INPUT_MINUS_TS
  457. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  458. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  459. * @arg @ref LL_COMP_INPUT_MINUS_IO3
  460. */
  461. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  462. {
  463. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL));
  464. }
  465. /**
  466. * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
  467. * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
  468. * @note COMP1/COMP2 use the same register
  469. * @param COMPx Comparator instance
  470. * @param InputHysteresis This parameter can be one of the following values:
  471. * @arg @ref LL_COMP_HYSTERESIS_DISABLE
  472. * @arg @ref LL_COMP_HYSTERESIS_ENABLE
  473. * @retval None
  474. */
  475. __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
  476. {
  477. MODIFY_REG(COMP1->CSR, COMP_CSR_HYST, InputHysteresis);
  478. }
  479. /**
  480. * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
  481. * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
  482. * @param COMPx Comparator instance
  483. * @retval Returned value can be one of the following values:
  484. * @arg @ref LL_COMP_HYSTERESIS_DISABLE
  485. * @arg @ref LL_COMP_HYSTERESIS_ENABLE
  486. */
  487. __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
  488. {
  489. return (uint32_t)(READ_BIT(COMP1->CSR, COMP_CSR_HYST));
  490. }
  491. /**
  492. * @brief Enable comparator VREFINT releated Input.
  493. * @rmtoll CSR SCALER_EN LL_COMP_EnableScaler
  494. * @note In case of comparator input selected to be connected to
  495. * VREFINT,3/4VREFINT,1/2VREFINT,1/4VREFINT.SCALER_EN should
  496. * be Enabled. COMP1/COMP2 use the same register
  497. * @param COMPx Comparator instance
  498. * @retval None
  499. */
  500. __STATIC_INLINE void LL_COMP_EnableScaler(COMP_TypeDef *COMPx)
  501. {
  502. SET_BIT(COMP1->CSR, COMP_CSR_SCALER_EN);
  503. }
  504. /**
  505. * @brief Disable comparator VREFINT releated Input.
  506. * @rmtoll CSR SCALER_EN LL_COMP_DisableScaler
  507. * @param COMPx Comparator instance
  508. * @retval None
  509. */
  510. __STATIC_INLINE void LL_COMP_DisableScaler(COMP_TypeDef *COMPx)
  511. {
  512. CLEAR_BIT(COMP1->CSR, COMP_CSR_SCALER_EN);
  513. }
  514. /**
  515. * @brief Get comparator VREFINT releated Input enable state
  516. * (0: SCALER is disabled, 1: SCALER is enabled)
  517. * @rmtoll CSR SCALER_EN LL_COMP_IsEnabledScaler
  518. * @param COMPx Comparator instance
  519. * @retval State of bit (1 or 0).
  520. */
  521. __STATIC_INLINE uint32_t LL_COMP_IsEnabledScaler(COMP_TypeDef *COMPx)
  522. {
  523. return ((READ_BIT(COMP1->CSR, COMP_CSR_SCALER_EN) == (COMP_CSR_SCALER_EN)) ? 1U : 0U);
  524. }
  525. /**
  526. * @}
  527. */
  528. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  529. * @{
  530. */
  531. /**
  532. * @brief Set comparator instance output polarity.
  533. * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
  534. * @param COMPx Comparator instance
  535. * @param OutputPolarity This parameter can be one of the following values:
  536. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  537. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  538. * @retval None
  539. */
  540. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  541. {
  542. MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
  543. }
  544. /**
  545. * @brief Get comparator instance output polarity.
  546. * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
  547. * @param COMPx Comparator instance
  548. * @retval Returned value can be one of the following values:
  549. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  550. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  551. */
  552. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
  553. {
  554. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
  555. }
  556. /**
  557. * @}
  558. */
  559. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  560. * @{
  561. */
  562. /**
  563. * @brief Enable comparator instance.
  564. * @note After enable from off state, comparator requires a delay
  565. * to reach reach propagation delay specification.
  566. * Refer to device datasheet, parameter "tSTART".
  567. * @rmtoll CSR EN LL_COMP_Enable
  568. * @param COMPx Comparator instance
  569. * @retval None
  570. */
  571. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  572. {
  573. SET_BIT(COMPx->CSR, COMP_CSR_EN);
  574. }
  575. /**
  576. * @brief Disable comparator instance.
  577. * @rmtoll CSR EN LL_COMP_Disable
  578. * @param COMPx Comparator instance
  579. * @retval None
  580. */
  581. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  582. {
  583. CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
  584. }
  585. /**
  586. * @brief Get comparator enable state
  587. * (0: COMP is disabled, 1: COMP is enabled)
  588. * @rmtoll CSR EN LL_COMP_IsEnabled
  589. * @param COMPx Comparator instance
  590. * @retval State of bit (1 or 0).
  591. */
  592. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  593. {
  594. return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1U : 0U);
  595. }
  596. /**
  597. * @brief Lock comparator instance.
  598. * @note Once locked, comparator configuration can be accessed in read-only.
  599. * @note The only way to unlock the comparator is a device hardware reset.
  600. * @rmtoll CSR LOCK LL_COMP_Lock
  601. * @param COMPx Comparator instance
  602. * @retval None
  603. */
  604. __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
  605. {
  606. SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
  607. }
  608. /**
  609. * @brief Get comparator lock state
  610. * (0: COMP is unlocked, 1: COMP is locked).
  611. * @note Once locked, comparator configuration can be accessed in read-only.
  612. * @note The only way to unlock the comparator is a device hardware reset.
  613. * @rmtoll CSR LOCK LL_COMP_IsLocked
  614. * @param COMPx Comparator instance
  615. * @retval State of bit (1 or 0).
  616. */
  617. __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
  618. {
  619. return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1U : 0U);
  620. }
  621. /**
  622. * @brief Read comparator instance output level.
  623. * @note The comparator output level depends on the selected polarity
  624. * (Refer to function @ref LL_COMP_SetOutputPolarity()).
  625. * If the comparator polarity is not inverted:
  626. * - Comparator output is low when the input plus
  627. * is at a lower voltage than the input minus
  628. * - Comparator output is high when the input plus
  629. * is at a higher voltage than the input minus
  630. * If the comparator polarity is inverted:
  631. * - Comparator output is high when the input plus
  632. * is at a lower voltage than the input minus
  633. * - Comparator output is low when the input plus
  634. * is at a higher voltage than the input minus
  635. * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
  636. * @param COMPx Comparator instance
  637. * @retval Returned value can be one of the following values:
  638. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  639. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  640. */
  641. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  642. {
  643. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP_OUT)>> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
  644. }
  645. /**
  646. * @}
  647. */
  648. /** @defgroup COMP_LL_EF_DigitalFilter DigitalFilter on comparator instance
  649. * @{
  650. */
  651. /**
  652. * @brief Enable comparator DigitalFilter.
  653. * @rmtoll FR FLTEN LL_COMP_EnableDigitalFilter
  654. * @param COMPx Comparator instance
  655. * @retval None
  656. */
  657. __STATIC_INLINE void LL_COMP_EnableDigitalFilter(COMP_TypeDef *COMPx)
  658. {
  659. SET_BIT(COMPx->FR, COMP_FR_FLTEN);
  660. }
  661. /**
  662. * @brief Disable comparator DigitalFilter.
  663. * @rmtoll FR FLTEN LL_COMP_DisableDigitalFilter
  664. * @param COMPx Comparator instance
  665. * @retval None
  666. */
  667. __STATIC_INLINE void LL_COMP_DisableDigitalFilter(COMP_TypeDef *COMPx)
  668. {
  669. CLEAR_BIT(COMPx->FR, COMP_FR_FLTEN);
  670. }
  671. /**
  672. * @brief Get comparator DigitalFilter state
  673. * (0: Filter is Disabled, 1: Filter is Enabled).
  674. * @rmtoll FR FLTEN LL_COMP_IsEnabledDigitalFilter
  675. * @param COMPx Comparator instance
  676. * @retval State of bit (1 or 0).
  677. */
  678. __STATIC_INLINE uint32_t LL_COMP_IsEnabledDigitalFilter(COMP_TypeDef *COMPx)
  679. {
  680. return ((READ_BIT(COMPx->FR, COMP_FR_FLTEN) == (COMP_FR_FLTEN)) ? 1U : 0U);
  681. }
  682. /**
  683. * @brief Set comparator DigitalFilter Value.
  684. * @rmtoll FR FLTCNT LL_COMP_SetDigitalFilter
  685. * @param COMPx Comparator instance
  686. * @param FLTCNTValue Value between Min_Data=0x0000 and Max_Data=0xFFFF
  687. * @retval None
  688. */
  689. __STATIC_INLINE void LL_COMP_SetDigitalFilter(COMP_TypeDef *COMPx,uint32_t FLTCNTValue)
  690. {
  691. MODIFY_REG(COMPx->FR,COMP_FR_FLTCNT,FLTCNTValue << COMP_FR_FLTCNT_Pos);
  692. }
  693. /**
  694. * @brief Get comparator DigitalFilter Value
  695. * @rmtoll FR FLTCNT LL_COMP_GetDigitalFilter
  696. * @param COMPx Comparator instance
  697. * @retval DigitalFilter Value between Min_Data=0x0000 and Max_Data=0xFFFF
  698. */
  699. __STATIC_INLINE uint32_t LL_COMP_GetDigitalFilter(COMP_TypeDef *COMPx)
  700. {
  701. return (uint32_t)(READ_REG(COMPx->FR)>>COMP_FR_FLTCNT_Pos);
  702. }
  703. /**
  704. * @}
  705. */
  706. #if defined(USE_FULL_LL_DRIVER)
  707. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  708. * @{
  709. */
  710. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  711. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  712. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  713. /**
  714. * @}
  715. */
  716. #endif /* USE_FULL_LL_DRIVER */
  717. /**
  718. * @}
  719. */
  720. /**
  721. * @}
  722. */
  723. #endif /* COMP1 || COMP2 */
  724. /**
  725. * @}
  726. */
  727. #ifdef __cplusplus
  728. }
  729. #endif
  730. #endif /* PY32F0xx_LL_COMP_H */
  731. /************************ (C) COPYRIGHT Puya *****END OF FILE****/