stm32l4xx_ll_opamp.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_opamp.h
  4. * @author MCD Application Team
  5. * @version V1.7.2
  6. * @date 16-June-2017
  7. * @brief Header file of OPAMP LL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32L4xx_LL_OPAMP_H
  39. #define __STM32L4xx_LL_OPAMP_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx.h"
  45. /** @addtogroup STM32L4xx_LL_Driver
  46. * @{
  47. */
  48. #if defined (OPAMP1) || defined (OPAMP2)
  49. /** @defgroup OPAMP_LL OPAMP
  50. * @{
  51. */
  52. /* Private types -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/
  54. /* Private constants ---------------------------------------------------------*/
  55. /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
  56. * @{
  57. */
  58. /* Internal mask for OPAMP power mode: */
  59. /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */
  60. /* - OPAMP power mode into control register */
  61. /* - OPAMP trimming register offset */
  62. /* Internal register offset for OPAMP trimming configuration */
  63. #define OPAMP_POWERMODE_OTR_REGOFFSET ((uint32_t)0x00000000U)
  64. #define OPAMP_POWERMODE_LPOTR_REGOFFSET ((uint32_t)0x00000001U)
  65. #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET)
  66. /* Mask for OPAMP power mode into control register */
  67. #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPALPM)
  68. /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
  69. /* or PMOS. */
  70. /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
  71. /* - OPAMP trimming selection of transistors differential pair */
  72. /* - OPAMP trimming values of transistors differential pair */
  73. #define OPAMP_TRIMMING_SELECT_MASK (OPAMP1_CSR_CALSEL)
  74. #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
  75. /**
  76. * @}
  77. */
  78. /* Private macros ------------------------------------------------------------*/
  79. /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
  80. * @{
  81. */
  82. /**
  83. * @brief Driver macro reserved for internal use: set a pointer to
  84. * a register from a register basis from which an offset
  85. * is applied.
  86. * @param __REG__ Register basis from which the offset is applied.
  87. * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
  88. * @retval Register address
  89. */
  90. #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
  91. ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
  92. /**
  93. * @}
  94. */
  95. /* Exported types ------------------------------------------------------------*/
  96. #if defined(USE_FULL_LL_DRIVER)
  97. /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
  98. * @{
  99. */
  100. /**
  101. * @brief Structure definition of some features of OPAMP instance.
  102. */
  103. typedef struct
  104. {
  105. uint32_t PowerMode; /*!< Set OPAMP power mode.
  106. This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
  107. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
  108. uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  109. This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  110. @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
  111. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  112. uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
  113. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  114. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  115. uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
  116. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  117. @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
  118. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  119. } LL_OPAMP_InitTypeDef;
  120. /**
  121. * @}
  122. */
  123. #endif /* USE_FULL_LL_DRIVER */
  124. /* Exported constants --------------------------------------------------------*/
  125. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  126. * @{
  127. */
  128. /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
  129. * @{
  130. */
  131. #define LL_OPAMP_POWERSUPPLY_RANGE_LOW ((uint32_t)0x00000000U) /*!< Power supply range low. On STM32L4 serie: Vdda lower than 2.4V. */
  132. #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP1_CSR_OPARANGE) /*!< Power supply range high. On STM32L4 serie: Vdda higher than 2.4V. */
  133. /**
  134. * @}
  135. */
  136. /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
  137. * @{
  138. */
  139. #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP power mode normal */
  140. #define LL_OPAMP_POWERMODE_LOWPOWER (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPALPM) /*!< OPAMP power mode low-power */
  141. /**
  142. * @}
  143. */
  144. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  145. * @{
  146. */
  147. #define LL_OPAMP_MODE_FUNCTIONAL ((uint32_t)0x00000000U) /*!< OPAMP functional mode */
  148. #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
  149. /**
  150. * @}
  151. */
  152. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  153. * @{
  154. */
  155. #define LL_OPAMP_MODE_STANDALONE ((uint32_t)0x00000000U) /*!< OPAMP functional mode, OPAMP operation in standalone */
  156. #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_OPAMODE_1 | OPAMP_CSR_OPAMODE_0) /*!< OPAMP functional mode, OPAMP operation in follower */
  157. #define LL_OPAMP_MODE_PGA (OPAMP_CSR_OPAMODE_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
  158. /**
  159. * @}
  160. */
  161. /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
  162. * @{
  163. */
  164. #define LL_OPAMP_PGA_GAIN_2 ((uint32_t)0x00000000U) /*!< OPAMP PGA gain 2 */
  165. #define LL_OPAMP_PGA_GAIN_4 (OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 */
  166. #define LL_OPAMP_PGA_GAIN_8 (OPAMP_CSR_PGGAIN_1) /*!< OPAMP PGA gain 8 */
  167. #define LL_OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  172. * @{
  173. */
  174. #define LL_OPAMP_INPUT_NONINVERT_IO0 ((uint32_t)0x00000000U) /*!< OPAMP non inverting input connected to GPIO pin (pin PA0 for OPAMP1, pin PA6 for OPAMP2) */
  175. #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (OPAMP1_CSR_VPSEL) /*!< OPAMP non inverting input connected to DAC1 channel1 output */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  180. * @{
  181. */
  182. #define LL_OPAMP_INPUT_INVERT_IO0 ((uint32_t)0x00000000U) /*!< OPAMP inverting input connected to GPIO pin (valid also in PGA mode for filtering). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
  183. #define LL_OPAMP_INPUT_INVERT_IO1 (OPAMP_CSR_VMSEL_0) /*!< OPAMP inverting input (low leakage input) connected to GPIO pin (available only on package BGA132). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
  184. #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (OPAMP_CSR_VMSEL_1) /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA without external capacitors for filtering) */
  185. /**
  186. * @}
  187. */
  188. /** @defgroup OPAMP_LL_EC_INPUT_LEGACY OPAMP inputs legacy literals name
  189. * @{
  190. */
  191. #define LL_OPAMP_NONINVERTINGINPUT_IO0 LL_OPAMP_INPUT_NONINVERT_IO0
  192. #define LL_OPAMP_NONINVERTINGINPUT_DAC_CH LL_OPAMP_INPUT_NONINV_DAC1_CH1
  193. #define LL_OPAMP_INVERTINGINPUT_IO0 LL_OPAMP_INPUT_INVERT_IO0
  194. #define LL_OPAMP_INVERTINGINPUT_IO1 LL_OPAMP_INPUT_INVERT_IO1
  195. #define LL_OPAMP_INVERTINGINPUT_CONNECT_NO LL_OPAMP_INPUT_INVERT_CONNECT_NO
  196. #define LL_OPAMP_INPUT_NONINVERT_DAC1_CH1 LL_OPAMP_INPUT_NONINV_DAC1_CH1
  197. /**
  198. * @}
  199. */
  200. /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
  201. * @{
  202. */
  203. #define LL_OPAMP_TRIMMING_FACTORY ((uint32_t)0x00000000U) /*!< OPAMP trimming factors set to factory values */
  204. #define LL_OPAMP_TRIMMING_USER (OPAMP_CSR_USERTRIM) /*!< OPAMP trimming factors set to user values */
  205. /**
  206. * @}
  207. */
  208. /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
  209. * @{
  210. */
  211. #define LL_OPAMP_TRIMMING_NMOS (OPAMP_OTR_TRIMOFFSETN) /*!< OPAMP trimming of transistors differential pair NMOS */
  212. #define LL_OPAMP_TRIMMING_PMOS (OPAMP_OTR_TRIMOFFSETP | OPAMP1_CSR_CALSEL) /*!< OPAMP trimming of transistors differential pair PMOS */
  213. /**
  214. * @}
  215. */
  216. /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
  217. * @note Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
  218. * not timeout values.
  219. * For details on delays values, refer to descriptions in source code
  220. * above each literal definition.
  221. * @{
  222. */
  223. /* Delay for OPAMP startup time (transition from state disable to enable). */
  224. /* Note: OPAMP startup time depends on board application environment: */
  225. /* impedance connected to OPAMP output. */
  226. /* The delay below is specified under conditions: */
  227. /* - OPAMP in mode low power */
  228. /* - OPAMP in functional mode follower */
  229. /* - load impedance of 4kOhm (min), 50pF (max) */
  230. /* Literal set to maximum value (refer to device datasheet, */
  231. /* parameter "tWAKEUP"). */
  232. /* Unit: us */
  233. #define LL_OPAMP_DELAY_STARTUP_US ((uint32_t) 30U) /*!< Delay for OPAMP startup time */
  234. /**
  235. * @}
  236. */
  237. /**
  238. * @}
  239. */
  240. /* Exported macro ------------------------------------------------------------*/
  241. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  242. * @{
  243. */
  244. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  245. * @{
  246. */
  247. /**
  248. * @brief Write a value in OPAMP register
  249. * @param __INSTANCE__ OPAMP Instance
  250. * @param __REG__ Register to be written
  251. * @param __VALUE__ Value to be written in the register
  252. * @retval None
  253. */
  254. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  255. /**
  256. * @brief Read a value in OPAMP register
  257. * @param __INSTANCE__ OPAMP Instance
  258. * @param __REG__ Register to be read
  259. * @retval Register value
  260. */
  261. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  262. /**
  263. * @}
  264. */
  265. /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
  266. * @{
  267. */
  268. /**
  269. * @brief Helper macro to select the OPAMP common instance
  270. * to which is belonging the selected OPAMP instance.
  271. * @note OPAMP common register instance can be used to
  272. * set parameters common to several OPAMP instances.
  273. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  274. * @param __OPAMPx__ OPAMP instance
  275. * @retval OPAMP common instance
  276. */
  277. #if defined(OPAMP1) && defined(OPAMP2)
  278. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  279. (OPAMP12_COMMON)
  280. #else
  281. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  282. (OPAMP1_COMMON)
  283. #endif
  284. /**
  285. * @brief Helper macro to check if all OPAMP instances sharing the same
  286. * OPAMP common instance are disabled.
  287. * @note This check is required by functions with setting conditioned to
  288. * OPAMP state:
  289. * All OPAMP instances of the OPAMP common group must be disabled.
  290. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  291. * @retval 0: All OPAMP instances sharing the same OPAMP common instance
  292. * are disabled.
  293. * 1: At least one OPAMP instance sharing the same OPAMP common instance
  294. * is enabled
  295. */
  296. #if defined(OPAMP1) && defined(OPAMP2)
  297. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  298. (LL_OPAMP_IsEnabled(OPAMP1) | \
  299. LL_OPAMP_IsEnabled(OPAMP2) )
  300. #else
  301. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  302. (LL_OPAMP_IsEnabled(OPAMP1))
  303. #endif
  304. /**
  305. * @}
  306. */
  307. /**
  308. * @}
  309. */
  310. /* Exported functions --------------------------------------------------------*/
  311. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  312. * @{
  313. */
  314. /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances
  315. * @{
  316. */
  317. /**
  318. * @brief Set OPAMP power range.
  319. * @note The OPAMP power range applies to several OPAMP instances
  320. * (if several OPAMP instances available on the selected device).
  321. * @note On this STM32 serie, setting of this feature is conditioned to
  322. * OPAMP state:
  323. * All OPAMP instances of the OPAMP common group must be disabled.
  324. * This check can be done with function @ref LL_OPAMP_IsEnabled() for each
  325. * OPAMP instance or by using helper macro
  326. * @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE().
  327. * @rmtoll CSR OPARANGE LL_OPAMP_SetCommonPowerRange
  328. * @param OPAMPxy_COMMON OPAMP common instance
  329. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  330. * @param PowerRange This parameter can be one of the following values:
  331. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  332. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  333. * @retval None
  334. */
  335. __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
  336. {
  337. MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, PowerRange);
  338. }
  339. /**
  340. * @brief Get OPAMP power range.
  341. * @note The OPAMP power range applies to several OPAMP instances
  342. * (if several OPAMP instances available on the selected device).
  343. * @rmtoll CSR OPARANGE LL_OPAMP_GetCommonPowerRange
  344. * @param OPAMPxy_COMMON OPAMP common instance
  345. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  346. * @retval Returned value can be one of the following values:
  347. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  348. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  349. */
  350. __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
  351. {
  352. return (uint32_t)(READ_BIT(OPAMP1->CSR, OPAMP1_CSR_OPARANGE));
  353. }
  354. /**
  355. * @}
  356. */
  357. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  358. * @{
  359. */
  360. /**
  361. * @brief Set OPAMP power mode.
  362. * @note The OPAMP must be disabled to change this configuration.
  363. * @rmtoll CSR OPALPM LL_OPAMP_SetPowerMode
  364. * @param OPAMPx OPAMP instance
  365. * @param PowerMode This parameter can be one of the following values:
  366. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  367. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  368. * @retval None
  369. */
  370. __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
  371. {
  372. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
  373. }
  374. /**
  375. * @brief Get OPAMP power mode.
  376. * @rmtoll CSR OPALPM LL_OPAMP_GetPowerMode
  377. * @param OPAMPx OPAMP instance
  378. * @retval Returned value can be one of the following values:
  379. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  380. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  381. */
  382. __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
  383. {
  384. register uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPALPM));
  385. return (uint32_t)(power_mode | (power_mode >> (POSITION_VAL(OPAMP_CSR_OPALPM))));
  386. }
  387. /**
  388. * @brief Set OPAMP mode calibration or functional.
  389. * @note OPAMP mode corresponds to functional or calibration mode:
  390. * - functional mode: OPAMP operation in standalone, follower, ...
  391. * Set functional mode using function
  392. * @ref LL_OPAMP_SetFunctionalMode().
  393. * - calibration mode: offset calibration of the selected
  394. * transistors differential pair NMOS or PMOS.
  395. * @note On this STM32 serie, during calibration, OPAMP functional
  396. * mode must be set to standalone or follower mode
  397. * (in order to open internal connections to resistors
  398. * of PGA mode).
  399. * Refer to function @ref LL_OPAMP_SetFunctionalMode().
  400. * @rmtoll CSR CALON LL_OPAMP_SetMode
  401. * @param OPAMPx OPAMP instance
  402. * @param Mode This parameter can be one of the following values:
  403. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  404. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  405. * @retval None
  406. */
  407. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  408. {
  409. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
  410. }
  411. /**
  412. * @brief Get OPAMP mode calibration or functional.
  413. * @note OPAMP mode corresponds to functional or calibration mode:
  414. * - functional mode: OPAMP operation in standalone, follower, ...
  415. * Set functional mode using function
  416. * @ref LL_OPAMP_SetFunctionalMode().
  417. * - calibration mode: offset calibration of the selected
  418. * transistors differential pair NMOS or PMOS.
  419. * @rmtoll CSR CALON LL_OPAMP_GetMode
  420. * @param OPAMPx OPAMP instance
  421. * @retval Returned value can be one of the following values:
  422. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  423. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  424. */
  425. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  426. {
  427. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
  428. }
  429. /**
  430. * @brief Set OPAMP functional mode by setting internal connections.
  431. * OPAMP operation in standalone, follower, ...
  432. * @note This function reset bit of calibration mode to ensure
  433. * to be in functional mode, in order to have OPAMP parameters
  434. * (inputs selection, ...) set with the corresponding OPAMP mode
  435. * to be effective.
  436. * @rmtoll CSR OPAMODE LL_OPAMP_SetFunctionalMode
  437. * @param OPAMPx OPAMP instance
  438. * @param FunctionalMode This parameter can be one of the following values:
  439. * @arg @ref LL_OPAMP_MODE_STANDALONE
  440. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  441. * @arg @ref LL_OPAMP_MODE_PGA
  442. * @retval None
  443. */
  444. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  445. {
  446. /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
  447. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON, FunctionalMode);
  448. }
  449. /**
  450. * @brief Get OPAMP functional mode from setting of internal connections.
  451. * OPAMP operation in standalone, follower, ...
  452. * @rmtoll CSR OPAMODE LL_OPAMP_GetFunctionalMode
  453. * @param OPAMPx OPAMP instance
  454. * @retval Returned value can be one of the following values:
  455. * @arg @ref LL_OPAMP_MODE_STANDALONE
  456. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  457. * @arg @ref LL_OPAMP_MODE_PGA
  458. */
  459. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  460. {
  461. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMODE));
  462. }
  463. /**
  464. * @brief Set OPAMP PGA gain.
  465. * @note Preliminarily, OPAMP must be set in mode PGA
  466. * using function @ref LL_OPAMP_SetFunctionalMode().
  467. * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
  468. * @param OPAMPx OPAMP instance
  469. * @param PGAGain This parameter can be one of the following values:
  470. * @arg @ref LL_OPAMP_PGA_GAIN_2
  471. * @arg @ref LL_OPAMP_PGA_GAIN_4
  472. * @arg @ref LL_OPAMP_PGA_GAIN_8
  473. * @arg @ref LL_OPAMP_PGA_GAIN_16
  474. * @retval None
  475. */
  476. __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
  477. {
  478. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN, PGAGain);
  479. }
  480. /**
  481. * @brief Get OPAMP PGA gain.
  482. * @note Preliminarily, OPAMP must be set in mode PGA
  483. * using function @ref LL_OPAMP_SetFunctionalMode().
  484. * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
  485. * @param OPAMPx OPAMP instance
  486. * @retval Returned value can be one of the following values:
  487. * @arg @ref LL_OPAMP_PGA_GAIN_2
  488. * @arg @ref LL_OPAMP_PGA_GAIN_4
  489. * @arg @ref LL_OPAMP_PGA_GAIN_8
  490. * @arg @ref LL_OPAMP_PGA_GAIN_16
  491. */
  492. __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
  493. {
  494. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN));
  495. }
  496. /**
  497. * @}
  498. */
  499. /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
  500. * @{
  501. */
  502. /**
  503. * @brief Set OPAMP non-inverting input connection.
  504. * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
  505. * @param OPAMPx OPAMP instance
  506. * @param InputNonInverting This parameter can be one of the following values:
  507. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  508. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
  509. * @retval None
  510. */
  511. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  512. {
  513. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
  514. }
  515. /**
  516. * @brief Get OPAMP non-inverting input connection.
  517. * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
  518. * @param OPAMPx OPAMP instance
  519. * @retval Returned value can be one of the following values:
  520. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  521. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
  522. */
  523. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  524. {
  525. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
  526. }
  527. /**
  528. * @brief Set OPAMP inverting input connection.
  529. * @note OPAMP inverting input is used with OPAMP in mode standalone
  530. * or PGA with external capacitors for filtering circuit.
  531. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  532. * is not used (not connected to GPIO pin).
  533. * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
  534. * @param OPAMPx OPAMP instance
  535. * @param InputInverting This parameter can be one of the following values:
  536. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  537. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  538. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  539. * @retval None
  540. */
  541. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  542. {
  543. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSEL, InputInverting);
  544. }
  545. /**
  546. * @brief Get OPAMP inverting input connection.
  547. * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
  548. * @param OPAMPx OPAMP instance
  549. * @retval Returned value can be one of the following values:
  550. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  551. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  552. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  553. */
  554. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  555. {
  556. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL));
  557. }
  558. /**
  559. * @}
  560. */
  561. /** @defgroup OPAMP_LL_EF_Configuration_Legacy_Functions Configuration of OPAMP, legacy functions name
  562. * @{
  563. */
  564. /* Old functions name kept for legacy purpose, to be replaced by the */
  565. /* current functions name. */
  566. __STATIC_INLINE void LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t NonInvertingInput)
  567. {
  568. LL_OPAMP_SetInputNonInverting(OPAMPx, NonInvertingInput);
  569. }
  570. __STATIC_INLINE void LL_OPAMP_SetInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t InvertingInput)
  571. {
  572. LL_OPAMP_SetInputInverting(OPAMPx, InvertingInput);
  573. }
  574. /**
  575. * @}
  576. */
  577. /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
  578. * @{
  579. */
  580. /**
  581. * @brief Set OPAMP trimming mode.
  582. * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
  583. * @param OPAMPx OPAMP instance
  584. * @param TrimmingMode This parameter can be one of the following values:
  585. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  586. * @arg @ref LL_OPAMP_TRIMMING_USER
  587. * @retval None
  588. */
  589. __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
  590. {
  591. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
  592. }
  593. /**
  594. * @brief Get OPAMP trimming mode.
  595. * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
  596. * @param OPAMPx OPAMP instance
  597. * @retval Returned value can be one of the following values:
  598. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  599. * @arg @ref LL_OPAMP_TRIMMING_USER
  600. */
  601. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
  602. {
  603. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
  604. }
  605. /**
  606. * @brief Set OPAMP offset to calibrate the selected transistors
  607. * differential pair NMOS or PMOS.
  608. * @note Preliminarily, OPAMP must be set in mode calibration
  609. * using function @ref LL_OPAMP_SetMode().
  610. * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
  611. * @param OPAMPx OPAMP instance
  612. * @param TransistorsDiffPair This parameter can be one of the following values:
  613. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  614. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  615. * @retval None
  616. */
  617. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  618. {
  619. /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
  620. /* containing other bits reserved for other purpose. */
  621. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
  622. }
  623. /**
  624. * @brief Get OPAMP offset to calibrate the selected transistors
  625. * differential pair NMOS or PMOS.
  626. * @note Preliminarily, OPAMP must be set in mode calibration
  627. * using function @ref LL_OPAMP_SetMode().
  628. * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
  629. * @param OPAMPx OPAMP instance
  630. * @retval Returned value can be one of the following values:
  631. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  632. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  633. */
  634. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  635. {
  636. register uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
  637. return (CalibrationSelection |
  638. ((OPAMP_OTR_TRIMOFFSETN) << (POSITION_VAL(OPAMP_OTR_TRIMOFFSETP) * (CalibrationSelection && OPAMP_CSR_CALSEL))));
  639. }
  640. /**
  641. * @brief Get OPAMP calibration result of toggling output.
  642. * @note This functions returns:
  643. * 0 if OPAMP calibration output is reset
  644. * 1 if OPAMP calibration output is set
  645. * @rmtoll CSR CALOUT LL_OPAMP_IsCalibrationOutputSet
  646. * @param OPAMPx OPAMP instance
  647. * @retval State of bit (1 or 0).
  648. */
  649. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  650. {
  651. return (READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT);
  652. }
  653. /**
  654. * @brief Set OPAMP trimming factor for the selected transistors
  655. * differential pair NMOS or PMOS, corresponding to the selected
  656. * power mode.
  657. * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
  658. * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n
  659. * LPOTR TRIMLPOFFSETN LL_OPAMP_SetTrimmingValue\n
  660. * LPOTR TRIMLPOFFSETP LL_OPAMP_SetTrimmingValue
  661. * @param OPAMPx OPAMP instance
  662. * @param PowerMode This parameter can be one of the following values:
  663. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  664. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  665. * @param TransistorsDiffPair This parameter can be one of the following values:
  666. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  667. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  668. * @param TrimmingValue 0x00...0x1F
  669. * @retval None
  670. */
  671. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
  672. {
  673. register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  674. /* Set bits with position in register depending on parameter */
  675. /* "TransistorsDiffPair". */
  676. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  677. /* containing other bits reserved for other purpose. */
  678. MODIFY_REG(*preg,
  679. (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
  680. TrimmingValue << (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK)));
  681. }
  682. /**
  683. * @brief Get OPAMP trimming factor for the selected transistors
  684. * differential pair NMOS or PMOS, corresponding to the selected
  685. * power mode.
  686. * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
  687. * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n
  688. * LPOTR TRIMLPOFFSETN LL_OPAMP_GetTrimmingValue\n
  689. * LPOTR TRIMLPOFFSETP LL_OPAMP_GetTrimmingValue
  690. * @param OPAMPx OPAMP instance
  691. * @param PowerMode This parameter can be one of the following values:
  692. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  693. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  694. * @param TransistorsDiffPair This parameter can be one of the following values:
  695. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  696. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  697. * @retval 0x0...0x1F
  698. */
  699. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
  700. {
  701. register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  702. /* Retrieve bits with position in register depending on parameter */
  703. /* "TransistorsDiffPair". */
  704. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  705. /* containing other bits reserved for other purpose. */
  706. return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
  707. >> (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
  708. );
  709. }
  710. /**
  711. * @}
  712. */
  713. /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
  714. * @{
  715. */
  716. /**
  717. * @brief Enable OPAMP instance.
  718. * @note After enable from off state, OPAMP requires a delay
  719. * to fullfill wake up time specification.
  720. * Refer to device datasheet, parameter "tWAKEUP".
  721. * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
  722. * @param OPAMPx OPAMP instance
  723. * @retval None
  724. */
  725. __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
  726. {
  727. SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  728. }
  729. /**
  730. * @brief Disable OPAMP instance.
  731. * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
  732. * @param OPAMPx OPAMP instance
  733. * @retval None
  734. */
  735. __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
  736. {
  737. CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  738. }
  739. /**
  740. * @brief Get OPAMP instance enable state
  741. * (0: OPAMP is disabled, 1: OPAMP is enabled)
  742. * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
  743. * @param OPAMPx OPAMP instance
  744. * @retval State of bit (1 or 0).
  745. */
  746. __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
  747. {
  748. return (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN));
  749. }
  750. /**
  751. * @}
  752. */
  753. #if defined(USE_FULL_LL_DRIVER)
  754. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  755. * @{
  756. */
  757. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  758. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  759. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  760. /**
  761. * @}
  762. */
  763. #endif /* USE_FULL_LL_DRIVER */
  764. /**
  765. * @}
  766. */
  767. /**
  768. * @}
  769. */
  770. #endif /* OPAMP1 || OPAMP2 */
  771. /**
  772. * @}
  773. */
  774. #ifdef __cplusplus
  775. }
  776. #endif
  777. #endif /* __STM32L4xx_LL_OPAMP_H */
  778. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/