stm32l4xx_ll_opamp.h 36 KB

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