]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_opamp.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3XX / stm32f30x_opamp.c
1 /**
2 ******************************************************************************
3 * @file stm32f30x_opamp.c
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 27-February-2014
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the operational amplifiers (OPAMP1,...OPAMP4) peripheral:
9 * + OPAMP Configuration
10 * + OPAMP calibration
11 *
12 @verbatim
13
14 ==============================================================================
15 ##### OPAMP Peripheral Features #####
16 ==============================================================================
17
18 [..]
19 The device integrates 4 operational amplifiers OPAMP1, OPAMP2, OPAMP3 and OPAMP4:
20
21 (+) The OPAMPs non inverting input can be selected among the list shown by
22 table below.
23
24 (+) The OPAMPs inverting input can be selected among the list shown by
25 table below.
26
27 (+) The OPAMPs outputs can be internally connected to the inverting input
28 (follower mode)
29 (+) The OPAMPs outputs can be internally connected to resistor feedback
30 output (Programmable Gain Amplifier mode)
31
32 (+) The OPAMPs outputs can be internally connected to ADC
33
34 (+) The OPAMPs can be calibrated to compensate the offset compensation
35
36 (+) Timer-controlled Mux for automatic switch of inverting and
37 non-inverting input
38
39 OPAMPs inverting/non-inverting inputs:
40 +--------------------------------------------------------------+
41 | | | OPAMP1 | OPAMP2 | OPAMP3 | OPAMP4 |
42 |-----------------|--------|--------|--------|--------|--------|
43 | | PGA | OK | OK | OK | OK |
44 | Inverting Input | Vout | OK | OK | OK | OK |
45 | | IO1 | PC5 | PC5 | PB10 | PB10 |
46 | | IO2 | PA3 | PA5 | PB2 | PD8 |
47 |-----------------|--------|--------|--------|--------|--------|
48 | | IO1 | PA7 | PD14 | PB13 | PD11 |
49 | Non Inverting | IO2 | PA5 | PB14 | PA5 | PB11 |
50 | Input | IO3 | PA3 | PB0 | PA1 | PA4 |
51 | | IO4 | PA1 | PA7 | PB0 | PB13 |
52 +--------------------------------------------------------------+
53
54 ##### How to use this driver #####
55 ==============================================================================
56 [..]
57 This driver provides functions to configure and program the OPAMP
58 of all STM32F30x devices.
59
60 To use the OPAMP, perform the following steps:
61
62 (#) Enable the SYSCFG APB clock to get write access to OPAMP
63 register using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
64
65 (#) Configure the OPAMP input in analog mode using GPIO_Init()
66
67 (#) Configure the OPAMP using OPAMP_Init() function:
68 (++) Select the inverting input
69 (++) Select the non-inverting inverting input
70
71 (#) Enable the OPAMP using OPAMP_Cmd() function
72
73 @endverbatim
74
75 ******************************************************************************
76 * @attention
77 *
78 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
79 *
80 * Redistribution and use in source and binary forms, with or without modification,
81 * are permitted provided that the following conditions are met:
82 * 1. Redistributions of source code must retain the above copyright notice,
83 * this list of conditions and the following disclaimer.
84 * 2. Redistributions in binary form must reproduce the above copyright notice,
85 * this list of conditions and the following disclaimer in the documentation
86 * and/or other materials provided with the distribution.
87 * 3. Neither the name of STMicroelectronics nor the names of its contributors
88 * may be used to endorse or promote products derived from this software
89 * without specific prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
92 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
94 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
98 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
99 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
100 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
101 *
102 ******************************************************************************
103 */
104
105 /* Includes ------------------------------------------------------------------*/
106 #include "stm32f30x_opamp.h"
107
108 /** @addtogroup STM32F30x_StdPeriph_Driver
109 * @{
110 */
111
112 /** @defgroup OPAMP
113 * @brief OPAMP driver modules
114 * @{
115 */
116
117 /* Private typedef -----------------------------------------------------------*/
118 /* Private define ------------------------------------------------------------*/
119 #define OPAMP_CSR_DEFAULT_MASK ((uint32_t)0xFFFFFF93)
120 #define OPAMP_CSR_TIMERMUX_MASK ((uint32_t)0xFFFFF8FF)
121 #define OPAMP_CSR_TRIMMING_MASK ((uint32_t)0x0000001F)
122
123 /* Private macro -------------------------------------------------------------*/
124 /* Private variables ---------------------------------------------------------*/
125 /* Private function prototypes -----------------------------------------------*/
126 /* Private functions ---------------------------------------------------------*/
127
128 /** @defgroup OPAMP_Private_Functions
129 * @{
130 */
131
132 /** @defgroup OPAMP_Group1 Initialization and Configuration functions
133 * @brief Initialization and Configuration functions
134 *
135 @verbatim
136 ===============================================================================
137 ##### Initialization and Configuration functions #####
138 ===============================================================================
139
140 @endverbatim
141 * @{
142 */
143
144 /**
145 * @brief Deinitializes OPAMP peripheral registers to their default reset values.
146 * @note Deinitialization can't be performed if the OPAMP configuration is locked.
147 * To unlock the configuration, perform a system reset.
148 * @param OPAMP_Selection: the selected OPAMP.
149 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
150 * to select the OPAMP peripheral.
151 * @param None
152 * @retval None
153 */
154 void OPAMP_DeInit(uint32_t OPAMP_Selection)
155 {
156 /*!< Set OPAMP_CSR register to reset value */
157 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = ((uint32_t)0x00000000);
158 }
159
160 /**
161 * @brief Initializes the OPAMP peripheral according to the specified parameters
162 * in OPAMP_InitStruct
163 * @note If the selected OPAMP is locked, initialization can't be performed.
164 * To unlock the configuration, perform a system reset.
165 * @param OPAMP_Selection: the selected OPAMP.
166 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
167 * to select the OPAMP peripheral.
168 * @param OPAMP_InitStruct: pointer to an OPAMP_InitTypeDef structure that contains
169 * the configuration information for the specified OPAMP peripheral.
170 * - OPAMP_InvertingInput specifies the inverting input of OPAMP
171 * - OPAMP_NonInvertingInput specifies the non inverting input of OPAMP
172 * @retval None
173 */
174 void OPAMP_Init(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct)
175 {
176 uint32_t tmpreg = 0;
177
178 /* Check the parameters */
179 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
180 assert_param(IS_OPAMP_INVERTING_INPUT(OPAMP_InitStruct->OPAMP_InvertingInput));
181 assert_param(IS_OPAMP_NONINVERTING_INPUT(OPAMP_InitStruct->OPAMP_NonInvertingInput));
182
183 /*!< Get the OPAMPx_CSR register value */
184 tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
185
186 /*!< Clear the inverting and non inverting bits selection bits */
187 tmpreg &= (uint32_t) (OPAMP_CSR_DEFAULT_MASK);
188
189 /*!< Configure OPAMP: inverting and non inverting inputs */
190 tmpreg |= (uint32_t)(OPAMP_InitStruct->OPAMP_InvertingInput | OPAMP_InitStruct->OPAMP_NonInvertingInput);
191
192 /*!< Write to OPAMPx_CSR register */
193 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
194 }
195
196 /**
197 * @brief Fills each OPAMP_InitStruct member with its default value.
198 * @param OPAMP_InitStruct: pointer to an OPAMP_InitTypeDef structure which will
199 * be initialized.
200 * @retval None
201 */
202 void OPAMP_StructInit(OPAMP_InitTypeDef* OPAMP_InitStruct)
203 {
204 OPAMP_InitStruct->OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO1;
205 OPAMP_InitStruct->OPAMP_InvertingInput = OPAMP_InvertingInput_IO1;
206 }
207
208 /**
209 * @brief Configure the feedback resistor gain.
210 * @note If the selected OPAMP is locked, gain configuration can't be performed.
211 * To unlock the configuration, perform a system reset.
212 * @param OPAMP_Selection: the selected OPAMP.
213 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
214 * to select the OPAMP peripheral.
215 * @param NewState: new state of the OPAMP peripheral.
216 * This parameter can be: ENABLE or DISABLE.
217 * @retval None
218 */
219 void OPAMP_PGAConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_PGAGain, uint32_t OPAMP_PGAConnect)
220 {
221 /* Check the parameters */
222 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
223 assert_param(IS_OPAMP_PGAGAIN(OPAMP_PGAGain));
224 assert_param(IS_OPAMP_PGACONNECT(OPAMP_PGAConnect));
225
226 /* Reset the configuration bits */
227 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_PGGAIN);
228
229 /* Set the new configuration */
230 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_PGAGain | OPAMP_PGAConnect);
231 }
232
233 /**
234 * @brief Configure the OPAMP's internal reference.
235 * @note This feature is used when calibration enabled or OPAMP's reference
236 * connected to the non inverting input.
237 * @note If the selected OPAMP is locked, Vref configuration can't be performed.
238 * To unlock the configuration, perform a system reset.
239 * @param OPAMP_Selection: the selected OPAMP.
240 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
241 * to select the OPAMP peripheral.
242 * @param OPAMP_Vref: This parameter can be:
243 * OPAMP_Vref_3VDDA: OPMAP Vref = 3.3% VDDA
244 * OPAMP_Vref_10VDDA: OPMAP Vref = 10% VDDA
245 * OPAMP_Vref_50VDDA: OPMAP Vref = 50% VDDA
246 * OPAMP_Vref_90VDDA: OPMAP Vref = 90% VDDA
247 * @retval None
248 */
249 void OPAMP_VrefConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Vref)
250 {
251 uint32_t tmpreg = 0;
252
253 /* Check the parameters */
254 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
255 assert_param(IS_OPAMP_VREF(OPAMP_Vref));
256
257 /*!< Get the OPAMPx_CSR register value */
258 tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
259
260 /*!< Clear the CALSEL bits */
261 tmpreg &= (uint32_t) (~OPAMP_CSR_CALSEL);
262
263 /*!< Configure OPAMP reference */
264 tmpreg |= (uint32_t)(OPAMP_Vref);
265
266 /*!< Write to OPAMPx_CSR register */
267 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
268 }
269
270 /**
271 * @brief Connnect the internal reference to the OPAMP's non inverting input.
272 * @note If the selected OPAMP is locked, Vref configuration can't be performed.
273 * To unlock the configuration, perform a system reset.
274 * @param OPAMP_Selection: the selected OPAMP.
275 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
276 * to select the OPAMP peripheral.
277 * @param NewState: new state of the OPAMP peripheral.
278 * This parameter can be: ENABLE or DISABLE.
279 * @retval None
280 */
281 void OPAMP_VrefConnectNonInvertingInput(uint32_t OPAMP_Selection, FunctionalState NewState)
282 {
283 /* Check the parameters */
284 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
285 assert_param(IS_FUNCTIONAL_STATE(NewState));
286
287 if (NewState != DISABLE)
288 {
289 /* Connnect the internal reference to the OPAMP's non inverting input */
290 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_FORCEVP);
291 }
292 else
293 {
294 /* Disconnnect the internal reference to the OPAMP's non inverting input */
295 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_FORCEVP);
296 }
297 }
298
299 /**
300 * @brief Enables or disables connecting the OPAMP's internal reference to ADC.
301 * @note If the selected OPAMP is locked, Vref connection can't be performed.
302 * To unlock the configuration, perform a system reset.
303 * @param NewState: new state of the Vrefint output.
304 * This parameter can be: ENABLE or DISABLE.
305 * @retval None
306 */
307 void OPAMP_VrefConnectADCCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
308 {
309 /* Check the parameters */
310 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
311 assert_param(IS_FUNCTIONAL_STATE(NewState));
312
313 if (NewState != DISABLE)
314 {
315 /* Enable output internal reference */
316 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_TSTREF);
317 }
318 else
319 {
320 /* Disable output internal reference */
321 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_TSTREF);
322 }
323 }
324
325 /**
326 * @brief Configure the OPAMP peripheral (secondary inputs) for timer-controlled
327 * mux mode according to the specified parameters in OPAMP_InitStruct.
328 * @note If the selected OPAMP is locked, timer-controlled mux configuration
329 * can't be performed.
330 * To unlock the configuration, perform a system reset.
331 * @param OPAMP_Selection: the selected OPAMP.
332 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
333 * to select the OPAMP peripheral.
334 * @param OPAMP_InitStruct: pointer to an OPAMP_InitTypeDef structure that contains
335 * the configuration information for the specified OPAMP peripheral.
336 * - OPAMP_InvertingInput specifies the inverting input of OPAMP
337 * - OPAMP_NonInvertingInput specifies the non inverting input of OPAMP
338 * @note PGA and Vout can't be selected as seconadry inverting input.
339 * @retval None
340 */
341 void OPAMP_TimerControlledMuxConfig(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct)
342 {
343 uint32_t tmpreg = 0;
344
345 /* Check the parameters */
346 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
347 assert_param(IS_OPAMP_SECONDARY_INVINPUT(OPAMP_InitStruct->OPAMP_InvertingInput));
348 assert_param(IS_OPAMP_NONINVERTING_INPUT(OPAMP_InitStruct->OPAMP_NonInvertingInput));
349
350 /*!< Get the OPAMPx_CSR register value */
351 tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
352
353 /*!< Clear the secondary inverting bit, secondary non inverting bit and TCMEN bits */
354 tmpreg &= (uint32_t) (OPAMP_CSR_TIMERMUX_MASK);
355
356 /*!< Configure OPAMP: secondary inverting and non inverting inputs */
357 tmpreg |= (uint32_t)((uint32_t)(OPAMP_InitStruct->OPAMP_InvertingInput<<3) | (uint32_t)(OPAMP_InitStruct->OPAMP_NonInvertingInput<<7));
358
359 /*!< Write to OPAMPx_CSR register */
360 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
361 }
362
363 /**
364 * @brief Enable or disable the timer-controlled mux mode.
365 * @note If the selected OPAMP is locked, enable/disable can't be performed.
366 * To unlock the configuration, perform a system reset.
367 * @param OPAMP_Selection: the selected OPAMP.
368 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
369 * to select the OPAMP peripheral.
370 * @param NewState: new state of the OPAMP peripheral.
371 * This parameter can be: ENABLE or DISABLE.
372 * @retval None
373 */
374 void OPAMP_TimerControlledMuxCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
375 {
376 /* Check the parameters */
377 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
378 assert_param(IS_FUNCTIONAL_STATE(NewState));
379
380 if (NewState != DISABLE)
381 {
382 /* Enable the timer-controlled Mux mode */
383 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_TCMEN);
384 }
385 else
386 {
387 /* Disable the timer-controlled Mux mode */
388 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_TCMEN);
389 }
390 }
391
392 /**
393 * @brief Enable or disable the OPAMP peripheral.
394 * @note If the selected OPAMP is locked, enable/disable can't be performed.
395 * To unlock the configuration, perform a system reset.
396 * @param OPAMP_Selection: the selected OPAMP.
397 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
398 * to select the OPAMP peripheral.
399 * @param NewState: new state of the OPAMP peripheral.
400 * This parameter can be: ENABLE or DISABLE.
401 * @retval None
402 */
403 void OPAMP_Cmd(uint32_t OPAMP_Selection, FunctionalState NewState)
404 {
405 /* Check the parameters */
406 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
407 assert_param(IS_FUNCTIONAL_STATE(NewState));
408
409 if (NewState != DISABLE)
410 {
411 /* Enable the selected OPAMPx peripheral */
412 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_OPAMPxEN);
413 }
414 else
415 {
416 /* Disable the selected OPAMPx peripheral */
417 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_OPAMPxEN);
418 }
419 }
420
421 /**
422 * @brief Return the output level (high or low) during calibration of the selected OPAMP.
423 * @param OPAMP_Selection: the selected OPAMP.
424 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
425 * to select the OPAMP peripheral.
426 * - OPAMP output is low when the non-inverting input is at a lower
427 * voltage than the inverting input
428 * - OPAMP output is high when the non-inverting input is at a higher
429 * voltage than the inverting input
430 * @note OPAMP ouput level is provided only during calibration phase.
431 * @retval Returns the selected OPAMP output level: low or high.
432 *
433 */
434 uint32_t OPAMP_GetOutputLevel(uint32_t OPAMP_Selection)
435 {
436 uint32_t opampout = 0x0;
437
438 /* Check the parameters */
439 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
440
441 /* Check if selected OPAMP output is high */
442 if ((*(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) & (OPAMP_CSR_OUTCAL)) != 0)
443 {
444 opampout = OPAMP_OutputLevel_High;
445 }
446 else
447 {
448 opampout = OPAMP_OutputLevel_Low;
449 }
450
451 /* Return the OPAMP output level */
452 return (uint32_t)(opampout);
453 }
454
455 /**
456 * @brief Select the trimming mode.
457 * @param OffsetTrimming: the selected offset trimming mode.
458 * This parameter can be one of the following values:
459 * @arg OPAMP_Trimming_Factory: factory trimming values are used for offset
460 * calibration
461 * @arg OPAMP_Trimming_User: user trimming values are used for offset
462 * calibration
463 * @note When OffsetTrimming_User is selected, use OPAMP_OffsetTrimConfig()
464 * function or OPAMP_OffsetTrimLowPowerConfig() function to adjust
465 * trimming value.
466 * @retval None
467 */
468 void OPAMP_OffsetTrimModeSelect(uint32_t OPAMP_Selection, uint32_t OPAMP_Trimming)
469 {
470 /* Check the parameters */
471 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
472 assert_param(IS_OPAMP_TRIMMING(OPAMP_Trimming));
473
474 /* Reset USERTRIM bit */
475 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (~(uint32_t) (OPAMP_CSR_USERTRIM));
476
477 /* Select trimming mode */
478 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= OPAMP_Trimming;
479 }
480
481 /**
482 * @brief Configure the trimming value of the OPAMP.
483 * @param OPAMP_Selection: the selected OPAMP.
484 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
485 * to select the OPAMP peripheral.
486 * @param OPAMP_Input: the selected OPAMP input.
487 * This parameter can be one of the following values:
488 * @arg OPAMP_Input_Inverting: Inverting input is selected to configure the trimming value
489 * @arg OPAMP_Input_NonInverting: Non inverting input is selected to configure the trimming value
490 * @param OPAMP_TrimValue: the trimming value. This parameter can be any value lower
491 * or equal to 0x0000001F.
492 * @retval None
493 */
494 void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
495 {
496 uint32_t tmpreg = 0;
497
498 /* Check the parameters */
499 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
500 assert_param(IS_OPAMP_INPUT(OPAMP_Input));
501 assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
502
503 /*!< Get the OPAMPx_CSR register value */
504 tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
505
506 /*!< Clear the trimming bits */
507 tmpreg &= ((uint32_t)~(OPAMP_CSR_TRIMMING_MASK<<OPAMP_Input));
508
509 /*!< Configure the new trimming value */
510 tmpreg |= (uint32_t)(OPAMP_TrimValue<<OPAMP_Input);
511
512 /*!< Write to OPAMPx_CSR register */
513 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
514 }
515
516 /**
517 * @brief Start or stop the calibration of selected OPAMP peripheral.
518 * @note If the selected OPAMP is locked, start/stop can't be performed.
519 * To unlock the configuration, perform a system reset.
520 * @param OPAMP_Selection: the selected OPAMP.
521 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
522 * to select the OPAMP peripheral.
523 * @param NewState: new state of the OPAMP peripheral.
524 * This parameter can be: ENABLE or DISABLE.
525 * @retval None
526 */
527 void OPAMP_StartCalibration(uint32_t OPAMP_Selection, FunctionalState NewState)
528 {
529 /* Check the parameters */
530 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
531 assert_param(IS_FUNCTIONAL_STATE(NewState));
532
533 if (NewState != DISABLE)
534 {
535 /* Start the OPAMPx calibration */
536 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_CALON);
537 }
538 else
539 {
540 /* Stop the OPAMPx calibration */
541 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_CALON);
542 }
543 }
544
545 /**
546 * @}
547 */
548
549 /** @defgroup OPAMP_Group2 OPAMP configuration locking function
550 * @brief OPAMP1,...OPAMP4 configuration locking function
551 * OPAMP1,...OPAMP4 configuration can be locked each separately.
552 * Unlocking is performed by system reset.
553 *
554 @verbatim
555 ===============================================================================
556 ##### Configuration Lock function #####
557 ===============================================================================
558
559 @endverbatim
560 * @{
561 */
562
563 /**
564 * @brief Lock the selected OPAMP configuration.
565 * @note Locking the configuration means that all control bits are read-only.
566 * To unlock the OPAMP configuration, perform a system reset.
567 * @param OPAMP_Selection: the selected OPAMP.
568 * This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
569 * to select the OPAMP peripheral.
570 * @retval None
571 */
572 void OPAMP_LockConfig(uint32_t OPAMP_Selection)
573 {
574 /* Check the parameter */
575 assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
576
577 /* Set the lock bit corresponding to selected OPAMP */
578 *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_LOCK);
579 }
580
581 /**
582 * @}
583 */
584
585 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum