stm32l1xx_ll_opamp.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_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 __STM32L1xx_LL_OPAMP_H
  37. #define __STM32L1xx_LL_OPAMP_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l1xx.h"
  43. /** @addtogroup STM32L1xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3)
  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 (0x00000000U)
  62. #define OPAMP_POWERMODE_LPOTR_REGOFFSET (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_OPA1LPM)
  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_SW_OFFSET (16U)
  72. #define OPAMP_TRIMMING_SELECT_MASK ((OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << OPAMP_TRIMMING_SELECT_SW_OFFSET)
  73. #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH | OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW)
  74. /**
  75. * @}
  76. */
  77. /* Private macros ------------------------------------------------------------*/
  78. /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
  79. * @{
  80. */
  81. /**
  82. * @brief Driver macro reserved for internal use: set a pointer to
  83. * a register from a register basis from which an offset
  84. * is applied.
  85. * @param __REG__ Register basis from which the offset is applied.
  86. * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
  87. * @retval Register address
  88. */
  89. #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
  90. ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
  91. /**
  92. * @brief Driver macro reserved for internal use: from OPAMP instance
  93. * selected, return the instance number in decimal format.
  94. * @param __OPAMP_INSTANCE__ OPAMP instance
  95. * @retval Instance number in decimal format: value "0" for OPAMP1,
  96. * value "1" for OPAMP2, value "2" for OPAMP3.
  97. */
  98. #define __OPAMP_INSTANCE_DECIMAL(__OPAMP_INSTANCE__) \
  99. ((uint32_t)(__OPAMP_INSTANCE__) - OPAMP_BASE)
  100. /**
  101. * @brief Driver macro reserved for internal use: from OPAMP instance
  102. * selected, set offset of bits into OPAMP register.
  103. * @note Since all OPAMP instances are sharing the same register
  104. * with 3 area of bits with an offset of 8 bits (except bits
  105. * OPAxCALOUT, OPARANGE, S7SEL2), this function
  106. * returns .
  107. * @param __OPAMP_INSTANCE__ OPAMP instance
  108. * @retval Bits offset in register 32 bits: value "0" for OPAMP1,
  109. * value "8" for OPAMP2, value "16" for OPAMP3
  110. */
  111. #define __OPAMP_INSTANCE_BITOFFSET(__OPAMP_INSTANCE__) \
  112. (((uint32_t)(__OPAMP_INSTANCE__) - OPAMP_BASE) << 3U)
  113. /**
  114. * @brief Driver macro reserved for internal use: from OPAMP instance
  115. * selected, return whether it corresponds to instance OPAMP2.
  116. * @param __OPAMP_INSTANCE__ OPAMP instance
  117. * @retval Instance number in decimal format: value "0" for OPAMP1 or OPAMP3,
  118. * value "1" for OPAMP2.
  119. */
  120. #define __OPAMP_IS_INSTANCE_OPAMP2(__OPAMP_INSTANCE__) \
  121. (((uint32_t)(__OPAMP_INSTANCE__) - OPAMP_BASE) % 2)
  122. /**
  123. * @}
  124. */
  125. /* Exported types ------------------------------------------------------------*/
  126. #if defined(USE_FULL_LL_DRIVER)
  127. /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
  128. * @{
  129. */
  130. /**
  131. * @brief Structure definition of some features of OPAMP instance.
  132. */
  133. typedef struct
  134. {
  135. uint32_t PowerMode; /*!< Set OPAMP power mode.
  136. This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
  137. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
  138. uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  139. This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  140. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  141. uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
  142. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  143. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  144. uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
  145. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  146. @note OPAMP inverting input is used with OPAMP in mode standalone. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
  147. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  148. } LL_OPAMP_InitTypeDef;
  149. /**
  150. * @}
  151. */
  152. #endif /* USE_FULL_LL_DRIVER */
  153. /* Exported constants --------------------------------------------------------*/
  154. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  155. * @{
  156. */
  157. /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
  158. * @{
  159. */
  160. #define LL_OPAMP_POWERSUPPLY_RANGE_LOW (0x00000000U) /*!< Power supply range low. On STM32L1 serie: Vdda lower than 2.4V. */
  161. #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP_CSR_AOP_RANGE) /*!< Power supply range high. On STM32L1 serie: Vdda higher than 2.4V. */
  162. /**
  163. * @}
  164. */
  165. /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
  166. * @{
  167. */
  168. #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP power mode normal */
  169. #define LL_OPAMP_POWERMODE_LOWPOWER (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPA1LPM) /*!< OPAMP power mode low-power */
  170. /**
  171. * @}
  172. */
  173. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  174. * @{
  175. */
  176. #define LL_OPAMP_MODE_FUNCTIONAL (0x00000000U) /*!< OPAMP functional mode */
  177. #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_S3SEL1 | OPAMP_CSR_S4SEL1 | OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1 | OPAMP_CSR_S7SEL2) /*!< OPAMP calibration mode (on STM32L1 serie, it corresponds to all OPAMP input internal switches opened) */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  182. * @{
  183. */
  184. #define LL_OPAMP_MODE_STANDALONE (0x00000000U) /*!< OPAMP functional mode, OPAMP operation in standalone (on STM32L1 serie, it corresponds to OPAMP internal switches S3 opened (switch SanB state depends on switch S4 state)) */
  185. #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_S3SEL1) /*!< OPAMP functional mode, OPAMP operation in follower (on STM32L1 serie, it corresponds to OPAMP internal switches S3 and SanB closed) */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  190. * @{
  191. */
  192. #define LL_OPAMP_INPUT_NONINVERT_IO0 (OPAMP_CSR_S5SEL1) /*!< OPAMP non inverting input connected to GPIO pin (low leakage input) */
  193. #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (OPAMP_CSR_S6SEL1) /*!< OPAMP non inverting input connected to DAC1 channel1 output (specific to OPAMP instances: OPAMP1, OPAMP2) */
  194. #define LL_OPAMP_INPUT_NONINV_DAC1_CH2 (OPAMP_CSR_S7SEL2) /*!< OPAMP non inverting input connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP2, OPAMP3) */
  195. #if defined(OPAMP3)
  196. #define LL_OPAMP_INPUT_NONINV_DAC1_CH2_OPAMP3 (OPAMP_CSR_S6SEL1) /*!< OPAMP non inverting input connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP3) */
  197. #endif
  198. /**
  199. * @}
  200. */
  201. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  202. * @{
  203. */
  204. #define LL_OPAMP_INPUT_INVERT_IO0 (OPAMP_CSR_S4SEL1) /*!< OPAMP inverting input connected to GPIO pin (low leakage input). Note: OPAMP inverting input is used with OPAMP in mode standalone. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
  205. #define LL_OPAMP_INPUT_INVERT_IO1 (OPAMP_CSR_ANAWSEL1) /*!< OPAMP inverting input connected to GPIO pin (alternative IO pin, not low leakage, availability depends on STM32L1 serie devices packages). Note: OPAMP inverting input is used with OPAMP in mode standalone. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
  206. #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (0x00000000U) /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower) */
  207. /**
  208. * @}
  209. */
  210. /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
  211. * @{
  212. */
  213. #define LL_OPAMP_TRIMMING_FACTORY (0x00000000U) /*!< OPAMP trimming factors set to factory values */
  214. #define LL_OPAMP_TRIMMING_USER (OPAMP_OTR_OT_USER) /*!< OPAMP trimming factors set to user values */
  215. /**
  216. * @}
  217. */
  218. /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
  219. * @{
  220. */
  221. #define LL_OPAMP_TRIMMING_NMOS (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH | (OPAMP_CSR_OPA1CAL_H << OPAMP_TRIMMING_SELECT_SW_OFFSET)) /*!< OPAMP trimming of transistors differential pair NMOS */
  222. #define LL_OPAMP_TRIMMING_PMOS (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW | (OPAMP_CSR_OPA1CAL_L << OPAMP_TRIMMING_SELECT_SW_OFFSET)) /*!< OPAMP trimming of transistors differential pair PMOS */
  223. #define LL_OPAMP_TRIMMING_NONE (0x00000000U) /*!< OPAMP trimming unselect transistors differential pair NMOS and PMOs */
  224. /**
  225. * @}
  226. */
  227. /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
  228. * @note Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
  229. * not timeout values.
  230. * For details on delays values, refer to descriptions in source code
  231. * above each literal definition.
  232. * @{
  233. */
  234. /* Delay for OPAMP startup time (transition from state disable to enable). */
  235. /* Note: OPAMP startup time depends on board application environment: */
  236. /* impedance connected to OPAMP output. */
  237. /* The delay below is specified under conditions: */
  238. /* - OPAMP in mode low power */
  239. /* - load impedance of 4kOhm (min), 50pF (max) */
  240. /* Literal set to maximum value (refer to device datasheet, */
  241. /* parameter "tWAKEUP"). */
  242. /* Unit: us */
  243. #define LL_OPAMP_DELAY_STARTUP_US (30U) /*!< Delay for OPAMP startup time */
  244. /**
  245. * @}
  246. */
  247. /**
  248. * @}
  249. */
  250. /* Exported macro ------------------------------------------------------------*/
  251. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  252. * @{
  253. */
  254. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  255. * @{
  256. */
  257. /**
  258. * @brief Write a value in OPAMP register
  259. * @param __INSTANCE__ OPAMP Instance
  260. * @param __REG__ Register to be written
  261. * @param __VALUE__ Value to be written in the register
  262. * @retval None
  263. */
  264. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  265. /**
  266. * @brief Read a value in OPAMP register
  267. * @param __INSTANCE__ OPAMP Instance
  268. * @param __REG__ Register to be read
  269. * @retval Register value
  270. */
  271. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  272. /**
  273. * @}
  274. */
  275. /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
  276. * @{
  277. */
  278. /**
  279. * @brief Helper macro to select the OPAMP common instance
  280. * to which is belonging the selected OPAMP instance.
  281. * @note OPAMP common register instance can be used to
  282. * set parameters common to several OPAMP instances.
  283. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  284. * @param __OPAMPx__ OPAMP instance
  285. * @retval OPAMP common instance
  286. */
  287. #if defined(OPAMP1) && defined(OPAMP2) && defined(OPAMP3)
  288. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  289. (OPAMP123_COMMON)
  290. #else
  291. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  292. (OPAMP12_COMMON)
  293. #endif
  294. /**
  295. * @brief Helper macro to check if all OPAMP instances sharing the same
  296. * OPAMP common instance are disabled.
  297. * @note This check is required by functions with setting conditioned to
  298. * OPAMP state:
  299. * All OPAMP instances of the OPAMP common group must be disabled.
  300. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  301. * @retval 0: All OPAMP instances sharing the same OPAMP common instance
  302. * are disabled.
  303. * 1: At least one OPAMP instance sharing the same OPAMP common instance
  304. * is enabled
  305. */
  306. #if defined(OPAMP1) && defined(OPAMP2) && defined(OPAMP3)
  307. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  308. (LL_OPAMP_IsEnabled(OPAMP1) | \
  309. LL_OPAMP_IsEnabled(OPAMP2) | \
  310. LL_OPAMP_IsEnabled(OPAMP3) )
  311. #else
  312. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  313. (LL_OPAMP_IsEnabled(OPAMP1) | \
  314. LL_OPAMP_IsEnabled(OPAMP2) )
  315. #endif
  316. /**
  317. * @}
  318. */
  319. /**
  320. * @}
  321. */
  322. /* Exported functions --------------------------------------------------------*/
  323. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  324. * @{
  325. */
  326. /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances
  327. * @{
  328. */
  329. /**
  330. * @brief Set OPAMP power range.
  331. * @note The OPAMP power range applies to several OPAMP instances
  332. * (if several OPAMP instances available on the selected device).
  333. * @note On this STM32 serie, setting of this feature is conditioned to
  334. * OPAMP state:
  335. * All OPAMP instances of the OPAMP common group must be disabled.
  336. * This check can be done with function @ref LL_OPAMP_IsEnabled() for each
  337. * OPAMP instance or by using helper macro
  338. * @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE().
  339. * @rmtoll CSR AOP_RANGE LL_OPAMP_SetCommonPowerRange
  340. * @param OPAMPxy_COMMON OPAMP common instance
  341. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  342. * @param PowerRange This parameter can be one of the following values:
  343. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  344. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  345. * @retval None
  346. */
  347. __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
  348. {
  349. MODIFY_REG(OPAMP->CSR, OPAMP_CSR_AOP_RANGE, PowerRange);
  350. }
  351. /**
  352. * @brief Get OPAMP power range.
  353. * @note The OPAMP power range applies to several OPAMP instances
  354. * (if several OPAMP instances available on the selected device).
  355. * @rmtoll CSR AOP_RANGE LL_OPAMP_GetCommonPowerRange
  356. * @param OPAMPxy_COMMON OPAMP common instance
  357. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  358. * @retval Returned value can be one of the following values:
  359. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  360. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  361. */
  362. __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
  363. {
  364. return (uint32_t)(READ_BIT(OPAMP->CSR, OPAMP_CSR_AOP_RANGE));
  365. }
  366. /**
  367. * @}
  368. */
  369. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  370. * @{
  371. */
  372. /**
  373. * @brief Set OPAMP power mode.
  374. * @note The OPAMP must be disabled to change this configuration.
  375. * @rmtoll CSR OPA1LPM LL_OPAMP_SetPowerMode\n
  376. * CSR OPA2LPM LL_OPAMP_SetPowerMode\n
  377. * CSR OPA3LPM LL_OPAMP_SetPowerMode
  378. * @param OPAMPx OPAMP instance
  379. * @param PowerMode This parameter can be one of the following values:
  380. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  381. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  382. * @retval None
  383. */
  384. __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
  385. {
  386. MODIFY_REG(OPAMP->CSR,
  387. OPAMP_CSR_OPA1LPM << __OPAMP_INSTANCE_BITOFFSET(OPAMPx),
  388. (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  389. }
  390. /**
  391. * @brief Get OPAMP power mode.
  392. * @rmtoll CSR OPA1LPM LL_OPAMP_GetPowerMode\n
  393. * CSR OPA2LPM LL_OPAMP_GetPowerMode\n
  394. * CSR OPA3LPM LL_OPAMP_GetPowerMode
  395. * @param OPAMPx OPAMP instance
  396. * @retval Returned value can be one of the following values:
  397. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  398. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  399. */
  400. __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
  401. {
  402. register uint32_t power_mode = (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPA1LPM << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)));
  403. /* Shift variable to position corresponding to bitfield of OPAMP1 */
  404. power_mode >>= __OPAMP_INSTANCE_BITOFFSET(OPAMPx);
  405. /* Construct data corresponding to literal LL_OPAMP_POWERMODE_x */
  406. return (uint32_t)(power_mode | (power_mode >> (POSITION_VAL(OPAMP_CSR_OPA1LPM))));
  407. }
  408. /**
  409. * @brief Set OPAMP mode calibration or functional.
  410. * @note OPAMP mode corresponds to functional or calibration mode:
  411. * - functional mode: OPAMP operation in standalone, follower, ...
  412. * Set functional mode using function
  413. * @ref LL_OPAMP_SetFunctionalMode().
  414. * - calibration mode: offset calibration of the selected
  415. * transistors differential pair NMOS or PMOS.
  416. * @note On this STM32 serie, entering in calibration mode makes
  417. * loosing OPAMP internal switches configuration.
  418. * Therefore, when going back to functional mode,
  419. * functional mode must be set again using
  420. * @ref LL_OPAMP_SetFunctionalMode().
  421. * @rmtoll CSR S3SELx LL_OPAMP_SetMode\n
  422. * @rmtoll CSR S4SELx LL_OPAMP_SetMode\n
  423. * @rmtoll CSR S5SELx LL_OPAMP_SetMode\n
  424. * @rmtoll CSR S6SELx LL_OPAMP_SetMode\n
  425. * @rmtoll CSR S7SEL2 LL_OPAMP_SetMode
  426. * @param OPAMPx OPAMP instance
  427. * @param Mode This parameter can be one of the following values:
  428. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  429. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  430. * @retval None
  431. */
  432. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  433. {
  434. CLEAR_BIT(OPAMP->CSR,
  435. ((Mode & ~OPAMP_CSR_S7SEL2) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((Mode & OPAMP_CSR_S7SEL2) * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx)));
  436. }
  437. /**
  438. * @brief Get OPAMP mode calibration or functional.
  439. * @note OPAMP mode corresponds to functional or calibration mode:
  440. * - functional mode: OPAMP operation in standalone, follower, ...
  441. * Set functional mode using function
  442. * @ref LL_OPAMP_SetFunctionalMode().
  443. * - calibration mode: offset calibration of the selected
  444. * transistors differential pair NMOS or PMOS.
  445. * @rmtoll CSR S3SELx LL_OPAMP_SetMode\n
  446. * @rmtoll CSR S4SELx LL_OPAMP_SetMode\n
  447. * @rmtoll CSR S5SELx LL_OPAMP_SetMode\n
  448. * @rmtoll CSR S6SELx LL_OPAMP_SetMode\n
  449. * @rmtoll CSR S7SEL2 LL_OPAMP_SetMode
  450. * @param OPAMPx OPAMP instance
  451. * @retval Returned value can be one of the following values:
  452. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  453. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  454. */
  455. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  456. {
  457. return (uint32_t)(((READ_BIT(OPAMP->CSR,
  458. ((LL_OPAMP_MODE_CALIBRATION & ~OPAMP_CSR_S7SEL2) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | (OPAMP_CSR_S7SEL2 * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx)))
  459. ) == 0U) * LL_OPAMP_MODE_CALIBRATION);
  460. }
  461. /**
  462. * @brief Set OPAMP functional mode by setting internal connections.
  463. * OPAMP operation in standalone, follower, ...
  464. * @note This function reset bit of calibration mode to ensure
  465. * to be in functional mode, in order to have OPAMP parameters
  466. * (inputs selection, ...) set with the corresponding OPAMP mode
  467. * to be effective.
  468. * @rmtoll CSR S3SELx LL_OPAMP_SetFunctionalMode
  469. * @param OPAMPx OPAMP instance
  470. * @param FunctionalMode This parameter can be one of the following values:
  471. * @arg @ref LL_OPAMP_MODE_STANDALONE
  472. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  473. * @retval None
  474. */
  475. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  476. {
  477. /* Note: Bits OPAMP_CSR_OPAxCAL_y reset to ensure to be in functional mode */
  478. MODIFY_REG(OPAMP->CSR,
  479. (OPAMP_CSR_S3SEL1 | OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx),
  480. FunctionalMode << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  481. }
  482. /**
  483. * @brief Get OPAMP functional mode from setting of internal connections.
  484. * OPAMP operation in standalone, follower, ...
  485. * @rmtoll CSR S3SELx LL_OPAMP_GetFunctionalMode
  486. * @param OPAMPx OPAMP instance
  487. * @retval Returned value can be one of the following values:
  488. * @arg @ref LL_OPAMP_MODE_STANDALONE
  489. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  490. */
  491. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  492. {
  493. return (uint32_t)(READ_BIT(OPAMP->CSR, OPAMP_CSR_S3SEL1 << __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  494. >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  495. );
  496. }
  497. /**
  498. * @}
  499. */
  500. /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
  501. * @{
  502. */
  503. /**
  504. * @brief Set OPAMP non-inverting input connection.
  505. * @rmtoll CSR S5SELx LL_OPAMP_SetInputNonInverting\n
  506. * @rmtoll CSR S6SELx LL_OPAMP_SetInputNonInverting\n
  507. * @rmtoll CSR S7SEL2 LL_OPAMP_SetInputNonInverting
  508. * @param OPAMPx OPAMP instance
  509. * @param InputNonInverting This parameter can be one of the following values:
  510. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  511. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
  512. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
  513. *
  514. * (1) Parameter specific to OPAMP instances: OPAMP1, OPAMP2.\n
  515. * (2) Parameter specific to OPAMP instances: OPAMP2, OPAMP3.
  516. * @retval None
  517. */
  518. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  519. {
  520. MODIFY_REG(OPAMP->CSR,
  521. ((OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | (OPAMP_CSR_S7SEL2 * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx)),
  522. (InputNonInverting << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((InputNonInverting & OPAMP_CSR_S7SEL2) * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx))
  523. );
  524. }
  525. /**
  526. * @brief Get OPAMP non-inverting input connection.
  527. * @rmtoll CSR S5SELx LL_OPAMP_GetInputNonInverting\n
  528. * @rmtoll CSR S6SELx LL_OPAMP_GetInputNonInverting\n
  529. * @rmtoll CSR S7SEL2 LL_OPAMP_GetInputNonInverting
  530. * @param OPAMPx OPAMP instance
  531. * @retval Returned value can be one of the following values:
  532. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  533. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
  534. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
  535. *
  536. * (1) Parameter specific to OPAMP instances: OPAMP1, OPAMP2.\n
  537. * (2) Parameter specific to OPAMP instances: OPAMP2, OPAMP3.
  538. */
  539. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  540. {
  541. register uint32_t input_non_inverting_opamp_x = READ_BIT(OPAMP->CSR,
  542. (OPAMP_CSR_S5SEL1 | OPAMP_CSR_S6SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  543. | (OPAMP_CSR_S7SEL2 * __OPAMP_IS_INSTANCE_OPAMP2(OPAMPx))
  544. );
  545. return (((input_non_inverting_opamp_x & ~OPAMP_CSR_S7SEL2) >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | (input_non_inverting_opamp_x & OPAMP_CSR_S7SEL2));
  546. }
  547. /**
  548. * @brief Set OPAMP inverting input connection.
  549. * @note OPAMP inverting input is used with OPAMP in mode standalone.
  550. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  551. * is not used (not connected to GPIO pin).
  552. * @rmtoll CSR S4SELx LL_OPAMP_SetInputInverting\n
  553. * @rmtoll CSR ANAWSELx LL_OPAMP_SetInputInverting
  554. * @param OPAMPx OPAMP instance
  555. * @param InputInverting This parameter can be one of the following values:
  556. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  557. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1 (1)
  558. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  559. *
  560. * (1) Alternative IO pin, not low leakage, availability depends on STM32L1 serie devices packages.
  561. * @retval None
  562. */
  563. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  564. {
  565. MODIFY_REG(OPAMP->CSR,
  566. ((OPAMP_CSR_S4SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((OPAMP_CSR_ANAWSEL1) << __OPAMP_INSTANCE_DECIMAL(OPAMPx)),
  567. ((InputInverting & OPAMP_CSR_S4SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)) | ((InputInverting & OPAMP_CSR_ANAWSEL1) << __OPAMP_INSTANCE_DECIMAL(OPAMPx))
  568. );
  569. }
  570. /**
  571. * @brief Get OPAMP inverting input connection.
  572. * @rmtoll CSR S4SELx LL_OPAMP_SetInputInverting\n
  573. * @rmtoll CSR ANAWSELx LL_OPAMP_SetInputInverting
  574. * @param OPAMPx OPAMP instance
  575. * @retval Returned value can be one of the following values:
  576. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  577. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1 (1)
  578. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  579. *
  580. * (1) Alternative IO pin, not low leakage, availability depends on STM32L1 serie devices packages.
  581. */
  582. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  583. {
  584. register uint32_t input_inverting_opamp_x = READ_BIT(OPAMP->CSR,
  585. (OPAMP_CSR_S4SEL1) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  586. | (OPAMP_CSR_ANAWSEL1) << __OPAMP_INSTANCE_DECIMAL(OPAMPx)
  587. );
  588. #if defined(OPAMP3)
  589. return ( ((input_inverting_opamp_x & (OPAMP_CSR_S4SEL1 | OPAMP_CSR_S4SEL2 | OPAMP_CSR_S4SEL3)) >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  590. | ((input_inverting_opamp_x & (OPAMP_CSR_ANAWSEL1 | OPAMP_CSR_ANAWSEL2 | OPAMP_CSR_ANAWSEL3)) >> __OPAMP_INSTANCE_DECIMAL(OPAMPx)));
  591. #else
  592. return ( ((input_inverting_opamp_x & (OPAMP_CSR_S4SEL1 | OPAMP_CSR_S4SEL2)) >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  593. | ((input_inverting_opamp_x & (OPAMP_CSR_ANAWSEL1 | OPAMP_CSR_ANAWSEL2)) >> __OPAMP_INSTANCE_DECIMAL(OPAMPx)));
  594. #endif
  595. }
  596. /**
  597. * @}
  598. */
  599. /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
  600. * @{
  601. */
  602. /**
  603. * @brief Set OPAMP trimming mode.
  604. * @note The OPAMP trimming mode applies to several OPAMP instances
  605. * (if several OPAMP instances available on the selected device).
  606. * @rmtoll OTR OT_USER LL_OPAMP_SetCommonTrimmingMode
  607. * @param OPAMPxy_COMMON OPAMP common instance
  608. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  609. * @param TrimmingMode This parameter can be one of the following values:
  610. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  611. * @arg @ref LL_OPAMP_TRIMMING_USER
  612. * @retval None
  613. */
  614. __STATIC_INLINE void LL_OPAMP_SetCommonTrimmingMode(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t TrimmingMode)
  615. {
  616. /* Note: On STM32L1 serie, OPAMP trimming mode bit "OPAMP_OTR_OT_USER" is */
  617. /* write only, cannot be read. */
  618. MODIFY_REG(OPAMPxy_COMMON->OTR,
  619. OPAMP_OTR_OT_USER,
  620. TrimmingMode);
  621. }
  622. /**
  623. * @brief Get OPAMP trimming mode.
  624. * @note The OPAMP trimming mode applies to several OPAMP instances
  625. * (if several OPAMP instances available on the selected device).
  626. * @rmtoll OTR OT_USER LL_OPAMP_GetCommonTrimmingMode
  627. * @param OPAMPxy_COMMON OPAMP common instance
  628. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  629. * @retval Returned value can be one of the following values:
  630. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  631. * @arg @ref LL_OPAMP_TRIMMING_USER
  632. */
  633. __STATIC_INLINE uint32_t LL_OPAMP_GetCommonTrimmingMode(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
  634. {
  635. return (uint32_t)(READ_BIT(OPAMPxy_COMMON->OTR, OPAMP_OTR_OT_USER));
  636. }
  637. /**
  638. * @brief Set OPAMP offset to calibrate the selected transistors
  639. * differential pair NMOS or PMOS.
  640. * @note Preliminarily, OPAMP must be set in mode calibration
  641. * using function @ref LL_OPAMP_SetMode().
  642. * @rmtoll CSR OPA1CAL_H LL_OPAMP_SetCalibrationSelection\n
  643. * CSR OPA1CAL_L LL_OPAMP_SetCalibrationSelection
  644. * @param OPAMPx OPAMP instance
  645. * @param TransistorsDiffPair This parameter can be one of the following values:
  646. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  647. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  648. * @arg @ref LL_OPAMP_TRIMMING_NONE
  649. * @retval None
  650. */
  651. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  652. {
  653. /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
  654. /* containing other bits reserved for other purpose. */
  655. MODIFY_REG(OPAMP->CSR,
  656. (OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx),
  657. ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> OPAMP_TRIMMING_SELECT_SW_OFFSET) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  658. );
  659. }
  660. /**
  661. * @brief Get OPAMP offset to calibrate the selected transistors
  662. * differential pair NMOS or PMOS.
  663. * @note Preliminarily, OPAMP must be set in mode calibration
  664. * using function @ref LL_OPAMP_SetMode().
  665. * @rmtoll CSR OPA1CAL_H LL_OPAMP_SetCalibrationSelection\n
  666. * CSR OPA1CAL_L LL_OPAMP_SetCalibrationSelection
  667. * @param OPAMPx OPAMP instance
  668. * @retval Returned value can be one of the following values:
  669. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  670. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  671. * @arg @ref LL_OPAMP_TRIMMING_NONE
  672. */
  673. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  674. {
  675. register uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMP->CSR,
  676. (OPAMP_CSR_OPA1CAL_H | OPAMP_CSR_OPA1CAL_L) << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  677. )
  678. >> __OPAMP_INSTANCE_BITOFFSET(OPAMPx)
  679. );
  680. return ((CalibrationSelection << OPAMP_TRIMMING_SELECT_SW_OFFSET) |
  681. ((OPAMP_OTR_AO1_OPT_OFFSET_TRIM_LOW) << (OPAMP_OTR_AO1_OPT_OFFSET_TRIM_HIGH_Pos * ((CalibrationSelection & OPAMP_CSR_OPA1CAL_H) != 0U))));
  682. }
  683. /**
  684. * @brief Get OPAMP calibration result of toggling output.
  685. * @note This functions returns:
  686. * 0 if OPAMP calibration output is reset
  687. * 1 if OPAMP calibration output is set
  688. * @rmtoll CSR OPAxCALOUT LL_OPAMP_IsCalibrationOutputSet
  689. * @param OPAMPx OPAMP instance
  690. * @retval State of bit (1 or 0).
  691. */
  692. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  693. {
  694. return (READ_BIT(OPAMP->CSR, (OPAMP_CSR_OPA1CALOUT << __OPAMP_INSTANCE_DECIMAL(OPAMPx)))
  695. == (OPAMP_CSR_OPA1CALOUT << __OPAMP_INSTANCE_DECIMAL(OPAMPx)));
  696. }
  697. /**
  698. * @brief Set OPAMP trimming factor for the selected transistors
  699. * differential pair NMOS or PMOS, corresponding to the selected
  700. * power mode.
  701. * @note On STM32L1 serie, OPAMP trimming mode must be re-configured
  702. * at each update of trimming values in power mode normal.
  703. * Refer to function @ref LL_OPAMP_SetCommonTrimmingMode().
  704. * @rmtoll OTR AOx_OPT_OFFSET_TRIM_HIGH LL_OPAMP_SetTrimmingValue\n
  705. * OTR AOx_OPT_OFFSET_TRIM_LOW LL_OPAMP_SetTrimmingValue\n
  706. * LPOTR AOx_OPT_OFFSET_TRIM_LP_HIGH LL_OPAMP_SetTrimmingValue\n
  707. * LPOTR AOx_OPT_OFFSET_TRIM_LP_LOW LL_OPAMP_SetTrimmingValue
  708. * @param OPAMPx OPAMP instance
  709. * @param PowerMode This parameter can be one of the following values:
  710. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  711. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  712. * @param TransistorsDiffPair This parameter can be one of the following values:
  713. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  714. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  715. * @param TrimmingValue 0x00...0x1F
  716. * @retval None
  717. */
  718. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
  719. {
  720. register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMP->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  721. /* Set bits with position in register depending on parameter */
  722. /* "TransistorsDiffPair". */
  723. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  724. /* containing other bits reserved for other purpose. */
  725. MODIFY_REG(*preg,
  726. (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx)),
  727. TrimmingValue << (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) + (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx))));
  728. }
  729. /**
  730. * @brief Get OPAMP trimming factor for the selected transistors
  731. * differential pair NMOS or PMOS, corresponding to the selected
  732. * power mode.
  733. * @rmtoll OTR AOx_OPT_OFFSET_TRIM_HIGH LL_OPAMP_GetTrimmingValue\n
  734. * OTR AOx_OPT_OFFSET_TRIM_LOW LL_OPAMP_GetTrimmingValue\n
  735. * LPOTR AOx_OPT_OFFSET_TRIM_LP_HIGH LL_OPAMP_GetTrimmingValue\n
  736. * LPOTR AOx_OPT_OFFSET_TRIM_LP_LOW LL_OPAMP_GetTrimmingValue
  737. * @param OPAMPx OPAMP instance
  738. * @param PowerMode This parameter can be one of the following values:
  739. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  740. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  741. * @param TransistorsDiffPair This parameter can be one of the following values:
  742. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  743. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  744. * @retval 0x0...0x1F
  745. */
  746. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
  747. {
  748. register uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMP->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  749. /* Retrieve bits with position in register depending on parameter */
  750. /* "TransistorsDiffPair". */
  751. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  752. /* containing other bits reserved for other purpose. */
  753. return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx)))
  754. >> (POSITION_VAL(TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) + (OPAMP_OTR_AO2_OPT_OFFSET_TRIM_LOW_Pos * __OPAMP_INSTANCE_DECIMAL(OPAMPx)))
  755. );
  756. }
  757. /**
  758. * @}
  759. */
  760. /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
  761. * @{
  762. */
  763. /**
  764. * @brief Enable OPAMP instance.
  765. * @note After enable from off state, OPAMP requires a delay
  766. * to fullfill wake up time specification.
  767. * Refer to device datasheet, parameter "tWAKEUP".
  768. * @rmtoll CSR OPAxPD LL_OPAMP_Enable
  769. * @param OPAMPx OPAMP instance
  770. * @retval None
  771. */
  772. __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
  773. {
  774. CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  775. }
  776. /**
  777. * @brief Disable OPAMP instance.
  778. * @rmtoll CSR OPAxPD LL_OPAMP_Disable
  779. * @param OPAMPx OPAMP instance
  780. * @retval None
  781. */
  782. __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
  783. {
  784. SET_BIT(OPAMP->CSR, OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx));
  785. }
  786. /**
  787. * @brief Get OPAMP instance enable state
  788. * (0: OPAMP is disabled, 1: OPAMP is enabled)
  789. * @rmtoll CSR OPAxPD LL_OPAMP_IsEnabled
  790. * @param OPAMPx OPAMP instance
  791. * @retval State of bit (1 or 0).
  792. */
  793. __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
  794. {
  795. return (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx))
  796. != (OPAMP_CSR_OPA1PD << __OPAMP_INSTANCE_BITOFFSET(OPAMPx)));
  797. }
  798. /**
  799. * @}
  800. */
  801. #if defined(USE_FULL_LL_DRIVER)
  802. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  803. * @{
  804. */
  805. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  806. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  807. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  808. /**
  809. * @}
  810. */
  811. #endif /* USE_FULL_LL_DRIVER */
  812. /**
  813. * @}
  814. */
  815. /**
  816. * @}
  817. */
  818. #endif /* OPAMP1 || OPAMP2 || OPAMP3 */
  819. /**
  820. * @}
  821. */
  822. #ifdef __cplusplus
  823. }
  824. #endif
  825. #endif /* __STM32L1xx_LL_OPAMP_H */
  826. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/